Skip to main content

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
13/// Boxed future for [`Method::resolve`].
14pub type MethodFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
15
16pub trait Method: Send + Sync {
17    fn method_name(&self) -> &'static str;
18    fn resolve(&self, did: Did) -> MethodFuture<Result<document::Document, ResolutionError>>;
19}
20
21#[derive(Error, Debug)]
22pub enum ResolutionError {
23    #[error("invalid DID")]
24    InvalidDid,
25    #[error("resolution failed: {0}")]
26    ResolutionFailed(String),
27    #[error("unsupported method")]
28    UnsupportedMethod,
29}