![banner](https://github.com/iotaledger/identity.rs/raw/HEAD/.github/banner_identity.svg)
Introduction ◈ Bindings ◈ Documentation & Resources ◈ Getting Started ◈ Example ◈ Roadmap ◈ Contributing
--- ## Introduction IOTA Identity is a [Rust](https://www.rust-lang.org/) implementation of decentralized digital identity, also known as Self-Sovereign Identity (SSI). It implements the W3C [Decentralized Identifiers (DID)](https://www.w3.org/TR/did-core/) and [Verifiable Credentials](https://www.w3.org/TR/vc-data-model/) specifications. This library can be used to create, resolve and authenticate digital identities and to create verifiable credentials and presentations in order to share information in a verifiable manner and establish trust in the digital world. It does so while supporting secure storage of cryptographic keys, which can be implemented for your preferred key management system. Many of the individual libraries (Rust crates) are agnostic over the concrete DID method, with the exception of some libraries dedicated to implement the [IOTA DID method](https://wiki.iota.org/identity.rs/specs/did/iota_did_method_spec/), which is an implementation of decentralized digital identity on the IOTA and Shimmer networks. Written in stable Rust, IOTA Identity has strong guarantees of memory safety and process integrity while maintaining exceptional performance. ## Bindings [Foreign Function Interface (FFI)](https://en.wikipedia.org/wiki/Foreign_function_interface) Bindings of this [Rust](https://www.rust-lang.org/) library to other programming languages: - [Web Assembly](https://github.com/iotaledger/identity.rs/blob/HEAD/bindings/wasm/) (JavaScript/TypeScript) ## gRPC We provide a collection of experimental [gRPC services](https://github.com/iotaledger/identity.rs/blob/HEAD/bindings/grpc/) ## Documentation and Resources - API References: - [Rust API Reference](https://docs.rs/identity_iota/latest/identity_iota/): Package documentation (cargo docs). - [Wasm API Reference](https://wiki.iota.org/identity.rs/libraries/wasm/api_reference/): Wasm Package documentation. - [Identity Documentation Pages](https://wiki.iota.org/identity.rs/introduction): Supplementing documentation with context around identity and simple examples on library usage. - [Examples](https://github.com/iotaledger/identity.rs/blob/HEAD/examples): Practical code snippets to get you started with the library. ## Prerequisites - [Rust](https://www.rust-lang.org/) (>= 1.65) - [Cargo](https://doc.rust-lang.org/cargo/) (>= 1.65) ## Getting Started If you want to include IOTA Identity in your project, simply add it as a dependency in your `Cargo.toml`: ```toml [dependencies] identity_iota = { version = "1.3.1" } ``` To try out the [examples](https://github.com/iotaledger/identity.rs/blob/HEAD/examples), you can also do this: 1. Clone the repository, e.g. through `git clone https://github.com/iotaledger/identity.rs` 2. Start IOTA Sandbox as described in the [next section](#example-creating-an-identity) 3. Run the example to create a DID using `cargo run --release --example 0_create_did` ## Example: Creating an Identity The following code creates and publishes a new IOTA DID Document to a locally running private network. See the [instructions](https://github.com/iotaledger/iota-sandbox) on running your own private network for development. _Cargo.toml_ ```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_ ```rust,no_run 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 = "http://localhost"; /// 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 http://localhost/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