affinidi-did-resolver-traits 0.1.1

Resolver traits for pluggable DID resolution
Documentation

affinidi-did-resolver-traits

Crates.io Documentation Rust License

Pluggable DID resolution traits for the Affinidi TDK. Implement these traits to add custom DID method support to the resolver.

Installation

[dependencies]
affinidi-did-resolver-traits = "0.1"

Traits

  • Resolver (sync) — for methods requiring no IO (e.g., did:key, did:peer)
  • AsyncResolver (async, dyn-compatible) — for methods requiring network access

Every Resolver is automatically an AsyncResolver via a blanket impl, so the SDK composes all resolvers uniformly.

Return Convention

Resolvers return Option<Result<Document, ResolverError>>:

Return Value Meaning
None Not my DID method — pass to the next resolver
Some(Ok(doc)) Resolved successfully
Some(Err(e)) Recognised the DID but resolution failed

Built-in Resolvers

  • KeyResolver — resolves did:key (Ed25519, P-256, P-384, secp256k1, X25519)
  • PeerResolver — resolves did:peer (numalgo 0 and 2)

Custom Resolver Example

use affinidi_did_resolver_traits::{AsyncResolver, Resolution};
use affinidi_did_common::DID;
use std::future::Future;
use std::pin::Pin;

struct MyResolver;

impl AsyncResolver for MyResolver {
    fn name(&self) -> &str { "MyResolver" }

    fn resolve<'a>(
        &'a self, did: &'a DID,
    ) -> Pin<Box<dyn Future<Output = Resolution> + Send + 'a>> {
        Box::pin(async move {
            if did.to_string().starts_with("did:mymethod:") {
                // Your resolution logic here
                todo!()
            } else {
                None
            }
        })
    }
}

Related Crates

License

Apache-2.0