#did #ssi #cache #sdk #resolver #local #error

affinidi-did-resolver-cache-sdk

Affinidi DID Resolver SDK

5 releases

new 0.1.10 Sep 18, 2024
0.1.9 Sep 16, 2024
0.1.7 Sep 10, 2024
0.1.6 Sep 9, 2024
0.1.5 Sep 9, 2024

#54 in Caching

Download history 475/week @ 2024-09-04 426/week @ 2024-09-11

901 downloads per month
Used in 4 crates

Apache-2.0 and Apache-2.0…

100KB
2K SLoC

Rust 1.5K SLoC // 0.0% comments JavaScript 222 SLoC // 0.1% comments

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.

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

~45–63MB
~1M SLoC