affinidi-did-resolver-cache-sdk

Crates.ioaffinidi-did-resolver-cache-sdk
lib.rsaffinidi-did-resolver-cache-sdk
version
sourcesrc
created_at2024-09-09 10:51:06.541117
updated_at2024-12-08 15:30:34.714497
descriptionAffinidi DID Resolver SDK
homepagehttps://affinidi.com/
repositoryhttps://github.com/affinidi/affinidi-did-resolver
max_upload_size
id1369139
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(affinidibot)

documentation

README

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
Commit count: 32

cargo fmt