Expand description
Decentralized identifiers (DIDs), DID URLs, DID documents and resolution types.
Pure data: no I/O, no async, no crypto. The module has three parts:
- Identifiers.
DidandDidUrlimplement the DID and DID URL syntax, described below;DidUrlReferenceis a DID URL or a relative reference such as#key-1;Uriis any RFC 3986 URI, kept as written;DidMethodnames a method, with an optional namespace (did:demo,did:demo:dev), for parties that declare or negotiate which methods they support. - Documents.
DidDocumentwithVerificationMethod,MethodRef,Serviceand the other types of DID Core §5, serialized deterministically with extension properties in insertion order, plus the operations to edit and query a document. - Resolution.
ResolutionResult,DocumentMetadata,ResolutionMetadata,ResolutionOptionsandResolutionError, whoseResolutionErrorKindis the error vocabulary of DID Core §7.1.
§DID syntax
Did and DidUrl are validated when constructed and otherwise keep the input unchanged.
They implement the syntax of W3C DID Core 1.0 §3.1 and §3.2 together with the RFC 3986
productions it references:
did = "did:" method-name ":" method-specific-id
method-name = 1*method-char
method-char = %x61-7A / DIGIT ; lowercase a-z and 0-9 only
method-specific-id = *( *idchar ":" ) 1*idchar ; colons allowed, last segment non-empty
idchar = ALPHA / DIGIT / "." / "-" / "_" / pct-encoded
pct-encoded = "%" HEXDIG HEXDIG
did-url = did path-abempty [ "?" query ] [ "#" fragment ]Consequences worth knowing:
did:and the method name are lowercase and case-sensitive:DID:example:123anddid:Example:123are invalid.- The method-specific id may contain
:and empty inner segments (did:example:a::bis valid) but must not end with:(did:example:a:is invalid). - Percent-encoding is checked for completeness (
%3Avalid,%3and%G1invalid) but never decoded, and nothing is normalized. Two DIDs are equal exactly when their strings are equal. - A space,
/,?,#or non-ASCII character ends the DID.Did::parserejects it;DidUrl::parsetakes/,?and#as the start of the path, query or fragment. - Parsing rejects input longer than
DEFAULT_MAX_LENbytes; useDid::parse_with_max_lenorDidUrl::parse_with_max_lento change the limit.
Both types implement Display, FromStr, TryFrom<&str>, TryFrom<String>, AsRef<str>,
Clone, Eq, Ord, Hash, and serde Serialize/Deserialize as a plain string, where
deserialization validates.
§Examples
use identity_kit::did::{Did, DidUrl};
let did: Did = "did:example:123".parse()?;
let key = did.join("#key-1")?;
assert_eq!(key.to_string(), "did:example:123#key-1");
let url = DidUrl::parse("did:example:123/path?versionId=1#key-1")?;
assert_eq!(url.did(), &did);
assert_eq!(url.path(), Some("/path"));
assert_eq!(url.query(), Some("versionId=1"));
assert_eq!(url.fragment(), Some("key-1"));Re-exports§
pub use crate::jose::OneOrMany;
Structs§
- Context
- The
@contextof a DID document, carried verbatim: a string, a map or a non-empty array of them. - Did
- A decentralized identifier such as
did:web:example.com. - DidDocument
- A DID document (DID Core §5): the core properties as fields, everything else in
properties. - DidDocument
Builder - Builds a
DidDocument, reporting the first invariant violation atbuild. - DidMethod
- A DID method, named with an optional namespace:
did:demoordid:demo:dev. - DidUrl
- A DID URL such as
did:example:123/path?versionId=1#key-1. - Document
Metadata - Metadata about the DID document (DID Core §7.1.3 “DID document metadata”).
- Method
Type - The
typeof a verification method: an open string with constants for the types this crate produces. - Resolution
Error - Why a DID could not be resolved: a
ResolutionErrorKindkeyword, and optionally a human-readable detail and the underlying error. - Resolution
Metadata - Metadata about the resolution process (DID Core §7.1.3 “DID resolution metadata”).
- Resolution
Options - Options passed to a resolver (DID Core §7.1.1 “DID resolution options”).
- Resolution
Result - What a resolver returns: the document when resolution succeeded, and the two metadata structures (DID Core §7.1.1).
- Service
- A service (DID Core §5.4): a way of interacting with the DID subject.
- Uri
- A URI (RFC 3986) stored exactly as written: no normalization, no percent-decoding, no case folding.
- Verification
Method - A verification method (DID Core §5.2): a public key with an id, a type and a controller.
Enums§
- DidError
- Why a string is not a valid DID, DID URL or DID method.
- DidUrl
Reference - A reference to a resource of a DID document: either an absolute
DidUrlor a relative DID URL (DID Core §3.2.2) such as#key-1, which is resolved against the document’sid. - Document
Error - Why a
DidDocumentoperation was refused. - Method
Ref - An entry of a verification relationship: a reference to a method in
verificationMethod, or a method embedded in the relationship and usable for that purpose only (DID Core §5.3). - Resolution
Error Kind - The error keywords of DID resolution (DID Core §7.1.2, DID Resolution).
- Service
Endpoint - The
serviceEndpointof a service (DID Core §5.4): a URI, a set of URIs, or a map. - Verification
Material - The verification material of a verification method (DID Core §5.2.1): exactly one of
publicKeyJwkandpublicKeyMultibase. - Verification
Relationship - A verification relationship (DID Core §5.3): the purpose a verification method may be used
for. The
DisplayandFromStrforms are the DID document property names.
Constants§
- APPLICATION_
DID_ JSON - Media type of the plain JSON representation of a DID document (DID Core §6.2).
- APPLICATION_
DID_ LD_ JSON - Media type of the JSON-LD representation of a DID document (DID Core §6.3).
- DEFAULT_
MAX_ LEN - Default maximum input length in bytes for
Did::parseandDidUrl::parse: 2 KiB.