xdid_core/
lib.rs

1//! Core types for DID methods to implement.
2
3use std::{future::Future, pin::Pin};
4
5use did::Did;
6use thiserror::Error;
7
8pub mod did;
9pub mod did_url;
10pub mod document;
11mod uri;
12
13pub trait Method: Send + Sync {
14    fn method_name(&self) -> &'static str;
15
16    /// Attempt to resolve the provided DID to its DID document.
17    fn resolve(
18        &self,
19        did: Did,
20    ) -> Pin<Box<dyn Future<Output = Result<document::Document, ResolutionError>> + Send + Sync>>;
21}
22
23#[derive(Error, Debug)]
24pub enum ResolutionError {
25    #[error("invalid DID")]
26    InvalidDid,
27    #[error("resolution failed: {0}")]
28    ResolutionFailed(String),
29    #[error("unsupported method")]
30    UnsupportedMethod,
31}