Resolve an IOTA Identity
DID resolution is the process of fetching and decoding a DID Document corresponding to a given DID. The IOTA Identity framework supports resolving DID Documents that are stored on the IOTA and Shimmer networks and enables users to plug in handlers for additional methods.
This is similar to, but not to be confused with, the W3C DID Resolution specification, which defines function signatures for resolution in the context of web or REST APIs, whereas the IOTA Identity framework provides strongly-typed resolution for a better developer experience.
This functionality is primarily provided by the Resolver
, which can:
- Resolve IOTA DID Documents.
- Resolve DID Documents from multiple DID methods.
- Resolve the DID Documents referenced in a verifiable presentation or credential.
Resolving an IOTA DID
The following examples demonstrate how to resolve an IOTA DID Document from its DID.
Resolver
Once you have configured a Resolver
with a Client
, it will resolve
IOTA DID Documents according to the read procedure defined in the IOTA DID Method Specification.
It fetches the latest Alias Output from the network specified in the DID (see DID Format),
then extracts and validates the DID Document from it.
- Rust
- Typescript (Node.js)
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::resolver::Resolver;
use iota_sdk::client::Client;
#[tokio::main]
async fn main() -> anyhow::Result<()>{
// Configure a client for the Shimmer testnet "rms".
let node_url = "https://api.testnet.shimmer.network/";
let client = Client::builder()
.with_primary_node(node_url, None)?
.finish()?;
// Construct a resolver using the client.
let mut resolver = Resolver::<IotaDocument>::new();
resolver.attach_iota_handler(client);
// Parse the DID and resolve its DID Document.
let did = IotaDID::parse("did:iota:rms:0x7b48b06232b8a1e7a31c314cab1ceedb84e2e9dd2b1fae79b67eaa4595f15e47")?;
let document: IotaDocument = resolver.resolve(&did).await?;
Ok(())
}
const {
Resolver,
IotaDID,
IotaIdentityClient,
} = require('@iota/identity-wasm/node');
const { Client } = require('@iota/client-wasm/node');
// Configure a client for the Shimmer testnet "rms".
const nodeUrl = 'https://api.testnet.shimmer.network/';
const client = new Client({
primaryNode: nodeUrl,
localPow: true,
});
const didClient = new IotaIdentityClient(client);
// Construct a resolver using the client.
const resolver = new Resolver({
client: didClient,
});
// Resolve the given did
const did =
'did:iota:rms:0x7b48b06232b8a1e7a31c314cab1ceedb84e2e9dd2b1fae79b67eaa4595f15e47';
const document = await resolver.resolve(did);
Client
You can also use the Client
directly to resolve individual DIDs from its configured network.
- Rust
- Typescript (Node.js)
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use iota_sdk::client::Client;
#[tokio::main]
async fn main() -> anyhow::Result<()>{
// Configure a client for the Shimmer testnet "rms".
let node_url = "https://api.testnet.shimmer.network/";
let client = Client::builder()
.with_primary_node(node_url, None)?
.finish()?;
// Parse the DID and resolve its DID Document.
let did = IotaDID::parse("did:iota:rms:0x7b48b06232b8a1e7a31c314cab1ceedb84e2e9dd2b1fae79b67eaa4595f15e47")?;
let document: IotaDocument = client.resolve_did(&did).await?;
Ok(())
}
const { IotaDID, IotaIdentityClient } = require('@iota/identity-wasm/node');
const { Client } = require('@iota/client-wasm/node');
// Configure a client for the Shimmer testnet "rms".
const nodeUrl = 'https://api.testnet.shimmer.network/';
const client = new Client({
primaryNode: nodeUrl,
localPow: true,
});
const didClient = new IotaIdentityClient(client);
// Parse the DID and resolve its DID Document.
const did = IotaDID.parse(
'did:iota:rms:0x7b48b06232b8a1e7a31c314cab1ceedb84e2e9dd2b1fae79b67eaa4595f15e47',
);
const document = await didClient.resolveDid(did);
Advanced Resolver Configuration
You can configure the Resolver
to support many use cases by attaching custom resolution handlers.
This enables the Resolver
to resolve multiple DID methods, as well as customizing how
a particular DID method (such as the IOTA method) gets resolved.
This feature is mainly intended to be used together with the Resolver's convenience methods for handling verifiable presentations and credentials.
Resolving Multiple DID Methods
- Rust
- Typescript (Node.js)
loading...
loading...
Resolution for Verifiable Presentations
When validating verifiable presentations, you need to resolve the DID Documents of the verifiable credential issuers and presentation holder to verify their signatures.
Resolving the necessary DID Documents is
performed automatically when verifying presentations via the Resolver
When direct access to these DID Documents is desired, the Resolver
also provides standalone methods to:
- Resolve a presentation holder's DID Document.
- Resolve the DID Documents of the issuers of the credentials in a verifiable presentation.
- Resolve the issuer's DID Document for a given verifiable credential.