affinidi-did-resolver-cache-sdk 0.8.6

Affinidi DID Resolver SDK
Documentation

affinidi-did-resolver-cache-sdk

Crates.io Documentation Rust License

SDK for resolving Decentralised Identifiers (DIDs) with built-in local caching. Operates in local mode (resolving happens in your process) or network mode (requests are forwarded to a remote cache server).

Installation

[dependencies]
affinidi-did-resolver-cache-sdk = "0.8"

Supported DID Methods

Method Default Feature Flag
did:key Yes
did:peer Yes
did:web Yes
did:ethr Yes
did:pkh Yes
did:webvh Yes did-methods
did:cheqd Yes did-methods
did:scid Yes did-methods
did:ebsi No did-ebsi (EBSI DID Registry API)
did:example No did_example (must be manually loaded)

Feature Flags

Feature Default Description
local Yes Reserved for future local-only features
did-methods Yes Includes did-webvh, did-cheqd, did-scid
did-ebsi No EBSI DID method (requires network access to EU API)
network No Enable network mode for remote cache server
did-webvh WebVH DID method support
did-cheqd Cheqd blockchain DID method support
did-scid Self-Certifying Identifier DID method
did_example Example DID method for testing

Usage

Local Mode (default)

use affinidi_did_resolver_cache_sdk::{config::ClientConfigBuilder, DIDCacheClient};

let config = ClientConfigBuilder::default().build();
let resolver = DIDCacheClient::new(config).await?;

match resolver.resolve("did:key:z6Mkr...").await {
    Ok(result) => println!("Document: {:#?}", result.doc),
    Err(e) => println!("Error: {:?}", e),
}

Network Mode

Enable the network feature, then point to a running cache server:

let config = ClientConfigBuilder::default()
    .with_network_mode("ws://127.0.0.1:8080/did/v1/ws")
    .with_cache_ttl(60)            // Cache TTL in seconds
    .with_network_timeout(20_000)  // Timeout in milliseconds
    .build();
let resolver = DIDCacheClient::new(config).await?;

Network mode still caches locally to reduce remote calls.

Caching Strategy

The cache uses per-method TTL to avoid unnecessary re-resolution:

Category Methods TTL Rationale
Immutable did:key, did:peer, did:jwk, did:ethr, did:pkh None (capacity-evicted only) Document is derived deterministically from the DID string
Mutable did:web, did:webvh, did:cheqd, did:scid Configurable (cache_ttl, default 300s) Document is fetched from external infrastructure and can change

The cache_ttl configuration option only applies to mutable DID methods. Immutable DIDs stay cached until evicted by capacity pressure, since their documents can never change.

Benchmarks

cargo run --features network --example benchmark -- \
  -g 1000 -r 10000 -n ws://127.0.0.1:8080/did/v1/ws

Running Tests

Integration tests require the network feature:

cargo test --features network

Related Crates

License

Apache-2.0