10 releases

new 0.2.2 Dec 8, 2024
0.2.1 Nov 12, 2024
0.1.13 Oct 1, 2024
0.1.12 Sep 23, 2024

#147 in Authentication

Download history 526/week @ 2024-09-05 509/week @ 2024-09-12 530/week @ 2024-09-19 225/week @ 2024-09-26 187/week @ 2024-10-03 126/week @ 2024-10-10 18/week @ 2024-10-17 3/week @ 2024-10-24 12/week @ 2024-10-31 108/week @ 2024-11-07 34/week @ 2024-11-14 21/week @ 2024-11-21 8/week @ 2024-11-28 111/week @ 2024-12-05

216 downloads per month
Used in 4 crates

Apache-2.0

130KB
2.5K SLoC

Affinidi DID Resolver- DID Universal Resolver Cache SDK

Provides local caching for DID resolution and caching of DID Documents

You can use this SDK in either local (resolving occurs locally) or in network (requests are forwarded to a remote server) mode.

Supported DID Methods

  1. did:key
  2. did:ethr
  3. did:jwk
  4. did.pkh
  5. did.peer
  6. did.web

Prerequisites

Rust version 1.79

NOTE: For network mode, you will need access to a running a DID Universal Resolver Cache!

Local Mode

A local cache is operated and all DID resolving is handled from the client itself.

When handling DID methods that require network access (e.g did:web), then the client will call those network services.

Example Local mode with defaults

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

    // Create a new local client configuration, use default values
    let local_config = ClientConfigBuilder::default().build();
    let local_resolver = DIDCacheClient::new(local_config).await?;
    let doc = local_resolver.resolve("did:key:...").await?;

    match local_resolver.resolve(peer_did).await {
        Ok(request) => {
            println!(
                "Resolved DID ({}) did_hash({}) Document:\n{:#?}\n",
                request.did, request.did_hash, request.doc
            );
        }
        Err(e) => {
            println!("Error: {:?}", e);
        }
    }

Network Mode

NOTE: When in network mode, the SDK will still cache locally to save on remote calls!

All DID resolving is handled remotely, just the DID Document is returned and cached locally.

You will need to enable the crate feature network to use Network Mode.

Example Network mode with optional settings

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

    // create a network client configuration, set the service address.
    let network_config = ClientConfigBuilder::default()
        .with_network_mode("ws://127.0.0.1:8080/did/v1/ws")
        .with_cache_ttl(60) // Change the cache TTL to 60 seconds
        .with_network_timeout(20_000) // Change the network timeout to 20 seconds
        .build();
    let network_resolver = DIDCacheClient::new(network_config).await?;

    match local_resolver.resolve("did:key:...").await {
        Ok((request) => {
            println!(
                "Resolved DID ({}) did_hash({}) Document:\n{:#?}\n",
                request.did, request.did_hash, request.doc
            );
        }
        Err(e) => {
            println!("Error: {:?}", e);
        }
    }

Running benchmark suite for testing

A reference benchmark example is included that can be used to measure performance. To run this use the following:

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

Run the above from the $affinidi-did-resolver/affinidi-did-resolver-cache-sdk directory

Affinidi DID Cache SDK

Usage: benchmark [OPTIONS] --generate-count <GENERATE_COUNT> --resolve-count <RESOLVE_COUNT>

Options:
-n, --network-address <NETWORK_ADDRESS>
        network address if running in network mode (ws://127.0.0.1:8080/did/v1/ws)
-g, --generate-count <GENERATE_COUNT>
        Number of keys to generate
-r, --resolve-count <RESOLVE_COUNT>
        Number of DIDs to resolve
-h, --help
        Print help
-V, --version
        Print version

Dependencies

~44–61MB
~1M SLoC