A library for ATProtocol identities.
1//! Shared trait definitions for AT Protocol identity operations. 2//! 3//! This module centralizes async traits used across the identity crate so they can 4//! be implemented without introducing circular module dependencies. 5 6use anyhow::Result; 7use async_trait::async_trait; 8 9use crate::errors::ResolveError; 10use crate::key::KeyData; 11use crate::model::Document; 12 13/// Trait for AT Protocol identity resolution. 14/// 15/// Implementations must resolve handles or DIDs to canonical DID documents. 16#[async_trait] 17pub trait IdentityResolver: Send + Sync { 18 /// Resolves an AT Protocol subject to its DID document. 19 async fn resolve(&self, subject: &str) -> Result<Document>; 20} 21 22/// Trait for DNS resolution operations used during handle lookups. 23#[async_trait] 24pub trait DnsResolver: Send + Sync { 25 /// Resolves TXT records for a given domain name. 26 async fn resolve_txt(&self, domain: &str) -> Result<Vec<String>, ResolveError>; 27} 28 29/// Trait for retrieving private keys by identifier. 30#[async_trait] 31/// Trait for resolving key references (e.g., DID verification methods) to [`KeyData`]. 32#[async_trait] 33pub trait KeyResolver: Send + Sync { 34 /// Resolves a key reference string into key material. 35 async fn resolve(&self, key: &str) -> Result<KeyData>; 36} 37 38/// Trait for DID document storage backends. 39#[async_trait] 40pub trait DidDocumentStorage: Send + Sync { 41 /// Retrieves a DID document if present. 42 async fn get_document_by_did(&self, did: &str) -> Result<Option<Document>>; 43 44 /// Stores or updates a DID document. 45 async fn store_document(&self, document: Document) -> Result<()>; 46 47 /// Deletes a DID document by DID. 48 async fn delete_document_by_did(&self, did: &str) -> Result<()>; 49}