DID Methods.
This library provides Decentralized Identifiers (DIDs), a type of identifier defined by the W3C that enables verifiable, self-sovereign digital identities. Unlike traditional identifiers, such as email addresses or usernames, DIDs are not tied to a central authority. Instead, they are generated and managed on decentralized networks like blockchains, providing greater privacy, security, and control to the individual or entity that owns them.
Each DID is an URI using the did scheme. This library uses the [DID] and
[DIDBuf] (similar to [str] and [String]) to parse and store DIDs.
use ;
// Create a `&DID` from a `&str`.
let did = DIDnew.unwrap;
// Create a `DIDBuf` from a `String`.
let owned_did = from_string.unwrap;
Just like regular URLs, it is possible to provide the DID with a fragment
part. The result is a DID URL, which can be parsed and stored using
[DIDURL] and [DIDURLBuf].
use ;
// Create a `&DIDURL` from a `&str`.
let did_url = DIDURLnew.unwrap;
// Create a `DIDBuf` from a `String`.
let owned_did_url = from_string.unwrap;
Note that a DID URL, with a fragment, is not a valid DID.
DID document resolution
DID resolution is the process of retrieving the DID document associated with a specific DID. A DID document is a JSON-LD formatted file that contains crucial information needed to interact with the DID, such as verification methods containing the user's public keys, and service endpoints. Here is an example DID document:
DID documents are represented using the [Document] type and can be
resolved from a DID using any implementation of the [DIDResolver] trait.
The [AnyDidMethod] type is provided as a default implementation for
[DIDResolver] that supports various DID methods (see below).
# async
Instead of resolving a DID document and extracting verification methods
manually, you can use the dereference method to resolve a DID URL:
# async
DID methods
A key component of the DID system is the concept of DID methods. A DID method defines how a specific type of DID is created, resolved, updated, and deactivated on a particular decentralized network or ledger. Each DID method corresponds to a unique identifier format and a set of operations that can be performed on the associated DIDs. The general syntax of DIDs depends on the method used:
did:method:method-specific-id
There exists various DID methods, each defined by their own specification.
In this library, methods are defining by implementing the [DIDMethod]
trait. Implementations are provided for the following methods:
did:key: for static cryptographic keys, implemented by [DIDKey].did:jwk: for Json Web Keys (JWK) implemented by [DIDJWK].did:web: for web-hosted DID documents, implemented by [DIDWeb].did:pkh: implemented by [DIDPKH].did:ethr: implemented by [DIDEthr].did:ion: implemented by [DIDION].did:tz: implemented by [DIDTz].
The [AnyDidMethod] regroups all those methods into one [DIDResolver]
implementation.
DID method types can also be used to generate fresh DID URLs:
use JWK;
use DIDJWK;
/// Generate a new JWK.
let jwk = JWKgenerate_p256;
/// Generate a DID URL out of our JWK URL.
let did_url = DIDJWKgenerate_url;