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.
This page follows the real source shape for Weave Identity and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Primary types to know
DelegationCertificate— adapters/weave-identity/src/ed25519_adapter.rsEd25519Adapter— adapters/weave-identity/src/ed25519_adapter.rsIdentity— adapters/weave-identity/src/identity.rsIdentityDocument— adapters/weave-identity/src/resolver.rsKeyPair— adapters/weave-identity/src/keypair.rsPublicKey— adapters/weave-identity/src/keypair.rsSignature— adapters/weave-identity/src/signature.rsVerificationMethod— adapters/weave-identity/src/resolver.rsIdentityError— adapters/weave-identity/src/error.rsIdentityType— adapters/weave-identity/src/identity.rsIdentityResolver— adapters/weave-identity/src/resolver.rsWeaveIdentityAdapter— adapters/weave-identity/src/adapter.rs
Example shape
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(())
}