#ethereum #capability #mechanism #capabilities #delegation #message #eip-5573

siwe-recap

EIP-5573:在以太坊登录的基础上,通过可扩展范围机制授权能力的信息同意机制

2个不稳定版本

0.2.0 2023年6月30日
0.1.0 2022年10月13日

#12 in #delegation

Download history 608/week @ 2024-04-04 730/week @ 2024-04-11 693/week @ 2024-04-18 897/week @ 2024-04-25 814/week @ 2024-05-02 726/week @ 2024-05-09 738/week @ 2024-05-16 405/week @ 2024-05-23 587/week @ 2024-05-30 476/week @ 2024-06-06 599/week @ 2024-06-13 613/week @ 2024-06-20 549/week @ 2024-06-27 403/week @ 2024-07-04 636/week @ 2024-07-11 206/week @ 2024-07-18

1,883 每月下载量
13 个crate中使用 (直接使用 2 个)

Apache-2.0 OR MIT

26KB
506 行代码

EIP-5573: SIWE ReCap

此crate实现了EIP-5573。使用此crate构建具有能力委托的钱包可签名消息。生成的消息包含能力的两种表示:一种无歧义的机器可读表示,以及一种人类可读的描述。在这两种表示中,后者由前者确定性地生成。

消息格式

我们目前支持以下消息格式

  • EIP-4361:使用以太坊登录 (SIWE)

SIWE示例

一个例子,具有以下能力

  • 展示任何凭证的能力,不受限制
  • 展示类型为 type1 的凭证的能力(技术上冗余)
  • 列出、获取和从kepler位置 kepler:ens:example.eth://default/kv 获取和检索 metadata 的能力,不受限制
  • 能够从kepler位置 kepler:ens:example.eth://default/kv/publickepler:ens:example.eth://default/kv/dapp-space 中进行 listget、检索 metadataputdelete 操作,且不受限制
let msg: siwe::Message = Builder::new()
    .with_actions_convert("urn:credential:type:type1", [("credential/present", [])])?
    .with_actions_convert(
        "kepler:ens:example.eth://default/kv",
        [("kv/list", []), ("kv/get", []), ("kv/metadata", [])],
    )?
    .with_actions_convert(
        "kepler:ens:example.eth://default/kv/public",
        [
            ("kv/list", []),
            ("kv/get", []),
            ("kv/metadata", []),
            ("kv/put", []),
            ("kv/delete", []),
        ],
    )?
    .with_actions_convert(
        "kepler:ens:example.eth://default/kv/dapp-space",
        [
            ("kv/list", []),
            ("kv/get", []),
            ("kv/metadata", []),
            ("kv/put", []),
            ("kv/delete", []),
        ],
    )?
    .build(siwe::Message {
        domain: "example.com".parse().unwrap(),
        address: Default::default(),
        statement: None,
        uri: "did:key:example".parse().unwrap(),
        version: siwe::Version::V1,
        chain_id: 1,
        nonce: "mynonce1".into(),
        issued_at: "2022-06-21T12:00:00.000Z".parse().unwrap(),
        expiration_time: None,
        not_before: None,
        request_id: None,
        resources: vec![],
    })?;

这会产生以下SIWE消息

example.com wants you to sign in with your Ethereum account:
0x0000000000000000000000000000000000000000

I further authorize the state URI to perform the following actions on my behalf: (1) "kv": "get", "list", "metadata" for "kepler:ens:example.eth://default/kv". (2) "kv": "delete", "get", "list", "metadata", "put" for "kepler:ens:example.eth://default/kv/dapp-space". (3) "kv": "delete", "get", "list", "metadata", "put" for "kepler:ens:example.eth://default/kv/public". (4) "credential": "present" for "urn:credential:type:type1".

URI: did:key:example
Version: 1
Chain ID: 1
Nonce: mynonce1
Issued At: 2022-06-21T12:00:00.000Z
Resources:
- urn:recap:eyJhdHQiOnsia2VwbGVyOmVuczpleGFtcGxlLmV0aDovL2RlZmF1bHQva3YiOnsia3YvZ2V0IjpbXSwia3YvbGlzdCI6W10sImt2L21ldGFkYXRhIjpbXX0sImtlcGxlcjplbnM6ZXhhbXBsZS5ldGg6Ly9kZWZhdWx0L2t2L2RhcHAtc3BhY2UiOnsia3YvZGVsZXRlIjpbXSwia3YvZ2V0IjpbXSwia3YvbGlzdCI6W10sImt2L21ldGFkYXRhIjpbXSwia3YvcHV0IjpbXX0sImtlcGxlcjplbnM6ZXhhbXBsZS5ldGg6Ly9kZWZhdWx0L2t2L3B1YmxpYyI6eyJrdi9kZWxldGUiOltdLCJrdi9nZXQiOltdLCJrdi9saXN0IjpbXSwia3YvbWV0YWRhdGEiOltdLCJrdi9wdXQiOltdfSwidXJuOmNyZWRlbnRpYWw6dHlwZTp0eXBlMSI6eyJjcmVkZW50aWFsL3ByZXNlbnQiOltdfX0sInByZiI6W119

仅签到

消息可以不包含任何功能,此时将生成只包含“签到”消息的声明

let msg: siwe::Message = DelegationBuilder::new()
    .build(siwe::Message {
        domain: "example.com".parse().unwrap(),
        address: Default::default(),
        statement: None,
        uri: "did:key:example".parse().unwrap(),
        version: siwe::Version::V1,
        chain_id: 1,
        nonce: "mynonce1".into(),
        issued_at: "2022-06-21T12:00:00.000Z".parse().unwrap(),
        expiration_time: None,
        not_before: None,
        request_id: None,
        resources: vec![],
    }))?;

这会产生以下SIWE消息

'example.com wants you to sign in with your Ethereum account:
0x0000000000000000000000000000000000000000


URI: did:key:example
Version: 1
Chain ID: 1
Nonce: mynonce1
Issued At: 2022-06-21T12:00:00.000Z

依赖项

~9MB
~155K SLoC