Affinidi DID Common Library
Contains common structs, traits and methods relating to Decentralized Identifiers (DID)
Prerequisites
Rust version 1.90
Building DID Documents
The crate provides builder types (DocumentBuilder, VerificationMethodBuilder,
ServiceBuilder) for ergonomic, programmatic construction of DID Documents.
Creating a DID Document with a Service
use ;
use json;
// 1. Build a verification method
let vm = new
.unwrap
.public_key_multibase
.build;
// 2. Build a service with a simple URL endpoint
let linked_domain = new_with_url
.unwrap
.id
.unwrap
.build;
// 3. Build a DIDComm service with a map endpoint and extra properties
let didcomm = new_with_map
.id
.unwrap
.build;
// 4. Assemble the full document
let doc = new
.unwrap
.context_did_v1
.context_multikey_v1
.verification_method
.authentication_reference
.unwrap
.assertion_method_reference
.unwrap
.service
.service
.build;
assert_eq!;
Service endpoint variants
The ServiceBuilder supports both endpoint forms defined by the
CID specification:
| Endpoint form | Constructor |
|---|---|
| Single URL string | ServiceBuilder::new_with_url("type", "https://...") |
| Map or ordered set | ServiceBuilder::new_with_map("type", json!({...})) |
Pre-built Endpoint |
ServiceBuilder::new("type", endpoint) |