Weave documentation
Weave Identity

Resolvers

Identity resolvers in Weave Identity — turn DID-like identifiers into resolved documents via pluggable adapter chains.

Purpose

Identity abstraction with DID-like documents, adapters, keypairs, public keys, signatures, delegation, and resolvers.

Primary types to know

  • DelegationCertificate — adapters/weave-identity/src/ed25519_adapter.rs
  • Ed25519Adapter — adapters/weave-identity/src/ed25519_adapter.rs
  • Identity — adapters/weave-identity/src/identity.rs
  • IdentityDocument — adapters/weave-identity/src/resolver.rs
  • KeyPair — adapters/weave-identity/src/keypair.rs
  • PublicKey — adapters/weave-identity/src/keypair.rs
  • Signature — adapters/weave-identity/src/signature.rs
  • VerificationMethod — adapters/weave-identity/src/resolver.rs
  • IdentityError — adapters/weave-identity/src/error.rs
  • IdentityType — adapters/weave-identity/src/identity.rs
  • IdentityResolver — adapters/weave-identity/src/resolver.rs
  • WeaveIdentityAdapter — adapters/weave-identity/src/adapter.rs

Resolver behavior

resolve and exists are application-provided async methods. The default verification_methods and verification_method helpers call resolve and filter its document. A local map proves only that an entry was loaded; use an authenticated source and explicit freshness/revocation policy when resolving remote identities.

Local structural example

use async_trait::async_trait;
use weave_identity::error::{IdentityError, Result};
use weave_identity::resolver::{IdentityDocument, IdentityResolver, VerificationMethod};
use weave_identity::{Identity, PublicKey};

/// Static resolver that pre-loads a fixed set of identity documents.
struct StaticResolver {
    docs: std::collections::HashMap<String, IdentityDocument>,
}

#[async_trait]
impl IdentityResolver for StaticResolver {
    async fn resolve(&self, identity: &Identity) -> Result<IdentityDocument> {
        self.docs
            .get(identity.id())
            .cloned()
            .ok_or_else(|| IdentityError::NotFound(identity.id().into()))
    }

    async fn exists(&self, identity: &Identity) -> Result<bool> {
        Ok(self.docs.contains_key(identity.id()))
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let owner = Identity::agent_from_public_key(vec![0u8; 32], Some("alice"))?;
    let mut doc = IdentityDocument::new(owner.clone());
    doc.add_verification_method(
        VerificationMethod::new(format!("{}#key-0", owner.id()), PublicKey::new(vec![1u8; 32]))
            .with_purpose("assertionMethod"),
    );

    let resolver = StaticResolver {
        docs: std::collections::HashMap::from([(owner.id().to_string(), doc)]),
    };

    let methods = resolver.verification_methods(&owner).await?;
    println!("exists={} methods={}", resolver.exists(&owner).await?, methods.len());
    Ok(())
}

On this page