22个版本 (7个稳定版)
1.3.1 | 2024年6月12日 |
---|---|
1.2.0 | 2024年3月27日 |
1.0.0 | 2023年11月2日 |
0.7.0-alpha.8 | 2023年9月28日 |
0.6.1 | 2022年6月30日 |
#46 在 身份认证 中
每月422次下载
1MB
20K SLoC
简介 ◈ 绑定 ◈ 文档和资源 ◈ 入门 ◈ 示例 ◈ 路线图 ◈ 贡献
简介
IOTA身份识别是一种基于Rust语言的去中心化数字身份实现,也称为自我主权身份(SSI)。它实现了W3C的去中心化标识符(DID)和可验证凭证规范。该库可用于创建、解析和验证数字身份,以及创建可验证的凭证和展示,以便以可验证的方式共享信息并在数字世界中建立信任。它通过支持安全存储加密密钥来实现这一点,这些密钥可以针对您首选的密钥管理系统进行实现。许多单独的库(Rust crates)对具体的DID方法不敏感,但有一些库专门用于实现IOTA DID方法,这是在IOTA和Shimmer网络上实现的去中心化数字身份。IOTA身份识别是用稳定的Rust编写的,在保持卓越性能的同时,提供了内存安全和进程完整性的强烈保证。
绑定
外部函数接口(FFI)绑定,将此Rust库绑定到其他编程语言
- Web Assembly(JavaScript/TypeScript)
gRPC
我们提供了一组实验性的gRPC服务
文档和资源
- API参考
- Rust API参考:包文档(cargo文档)。
- Wasm API参考:Wasm包文档。
- 身份文档页面:补充与身份相关的文档,以及关于库使用的一些简单示例。
- 示例:用于开始使用库的实际代码片段。
先决条件
入门
如果您想在项目中包含IOTA身份识别,只需将其添加到您的Cargo.toml
中的依赖项即可。
[dependencies]
identity_iota = { version = "1.3.1" }
要尝试示例,您也可以这样做
- 克隆存储库,例如通过
git clone https://github.com/iotaledger/identity.rs
- 按照下一节中所述启动IOTA沙盒
- 运行示例以使用
cargo run --release --example 0_create_did
创建DID
示例:创建身份
以下代码创建并发布了一个新的IOTA DID文档到本地运行的私有网络。有关运行您自己的私有网络的说明,请参阅说明。
Cargo.toml
[package]
name = "iota_identity_example"
version = "1.0.0"
edition = "2021"
[dependencies]
identity_iota = { version = "1.3.1", features = ["memstore"] }
iota-sdk = { version = "1.0.2", default-features = true, features = ["tls", "client", "stronghold"] }
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.62"
rand = "0.8.5"
main.rs
use identity_iota::core::ToJson;
use identity_iota::iota::IotaClientExt;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use identity_iota::iota::NetworkName;
use identity_iota::storage::JwkDocumentExt;
use identity_iota::storage::JwkMemStore;
use identity_iota::storage::KeyIdMemstore;
use identity_iota::storage::Storage;
use identity_iota::verification::jws::JwsAlgorithm;
use identity_iota::verification::MethodScope;
use iota_sdk::client::api::GetAddressesOptions;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::crypto::keys::bip39;
use iota_sdk::types::block::address::Bech32Address;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::dto::AliasOutputDto;
use tokio::io::AsyncReadExt;
// The endpoint of the IOTA node to use.
static API_ENDPOINT: &str = "https://127.0.0.1";
/// Demonstrates how to create a DID Document and publish it in a new Alias Output.
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a new client to interact with the IOTA ledger.
let client: Client = Client::builder()
.with_primary_node(API_ENDPOINT, None)?
.finish()
.await?;
// Create a new Stronghold.
let stronghold = StrongholdSecretManager::builder()
.password("secure_password".to_owned())
.build("./example-strong.hodl")?;
// Generate a mnemonic and store it in the Stronghold.
let random: [u8; 32] = rand::random();
let mnemonic =
bip39::wordlist::encode(random.as_ref(), &bip39::wordlist::ENGLISH).map_err(|err| anyhow::anyhow!("{err:?}"))?;
stronghold.store_mnemonic(mnemonic).await?;
// Create a new secret manager backed by the Stronghold.
let secret_manager: SecretManager = SecretManager::Stronghold(stronghold);
// Get the Bech32 human-readable part (HRP) of the network.
let network_name: NetworkName = client.network_name().await?;
// Get an address from the secret manager.
let address: Bech32Address = secret_manager
.generate_ed25519_addresses(
GetAddressesOptions::default()
.with_range(0..1)
.with_bech32_hrp((&network_name).try_into()?),
)
.await?[0];
println!("Your wallet address is: {}", address);
println!("Please request funds from https://127.0.0.1/faucet/, wait for a couple of seconds and then press Enter.");
tokio::io::stdin().read_u8().await?;
// Create a new DID document with a placeholder DID.
// The DID will be derived from the Alias Id of the Alias Output after publishing.
let mut document: IotaDocument = IotaDocument::new(&network_name);
// Insert a new Ed25519 verification method in the DID document.
let storage: Storage<JwkMemStore, KeyIdMemstore> = Storage::new(JwkMemStore::new(), KeyIdMemstore::new());
document
.generate_method(
&storage,
JwkMemStore::ED25519_KEY_TYPE,
JwsAlgorithm::EdDSA,
None,
MethodScope::VerificationMethod,
)
.await?;
// Construct an Alias Output containing the DID document, with the wallet address
// set as both the state controller and governor.
let alias_output: AliasOutput = client.new_did_output(address.into(), document, None).await?;
println!("Alias Output: {}", AliasOutputDto::from(&alias_output).to_json_pretty()?);
// Publish the Alias Output and get the published DID document.
let document: IotaDocument = client.publish_did_output(&secret_manager, alias_output).await?;
println!("Published DID document: {:#}", document);
Ok(())
}
示例输出
{
"doc": {
"id": "did:iota:tst:0xa947df036e78c2eada8b16e019d517c9e38d4b19cb0c1fa066e752c3074b715d",
"verificationMethod": [
{
"id": "did:iota:tst:0xa947df036e78c2eada8b16e019d517c9e38d4b19cb0c1fa066e752c3074b715d#9KdQCWcvR8kmGPLFOYnTzypsDWsoUIvR",
"controller": "did:iota:tst:0xa947df036e78c2eada8b16e019d517c9e38d4b19cb0c1fa066e752c3074b715d",
"type": "JsonWebKey",
"publicKeyJwk": {
"kty": "OKP",
"alg": "EdDSA",
"kid": "9KdQCWcvR8kmGPLFOYnTzypsDWsoUIvR",
"crv": "Ed25519",
"x": "JJoYoeFWU7jWvdQmOKDvM4nZJ2cUbP9yhWZzFgd044I"
}
}
]
},
"meta": {
"created": "2023-08-29T14:47:26Z",
"updated": "2023-08-29T14:47:26Z",
"governorAddress": "tst1qqd7kyu8xadzx9vutznu72336npqpj92jtp27uyu2tj2sa5hx6n3k0vrzwv",
"stateControllerAddress": "tst1qqd7kyu8xadzx9vutznu72336npqpj92jtp27uyu2tj2sa5hx6n3k0vrzwv"
}
}
路线图和里程碑
有关详细开发进度,请参阅IOTA身份识别开发的看板。
贡献
我们非常希望您能帮助我们开发IOTA身份识别。我们高度重视每一项贡献!
请参阅贡献和工作流程部分,这些部分位于IOTA Wiki中。
要直接向存储库贡献,只需叉取项目,将您的更改推送到您的叉子,然后创建一个拉取请求以包含它们!
参与有关此库的讨论或寻求支持的最好地方是 IOTA Discord 上的 #identity
频道。您也可以在我们的 Stack Exchange 上提问。
依赖关系
~18–57MB
~1M SLoC