2个不稳定版本
0.2.0 | 2023年6月30日 |
---|---|
0.1.0 | 2022年10月13日 |
#12 in #delegation
1,883 每月下载量
在 13 个crate中使用 (直接使用 2 个)
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/public
和kepler:ens:example.eth://default/kv/dapp-space
中进行list
、get
、检索metadata
、put
和delete
操作,且不受限制
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