Skip to main content

xdid_core/
lib.rs

1//! Core types for DID methods to implement.
2
3use std::{
4    future::Future,
5    pin::Pin,
6};
7
8use did::Did;
9use thiserror::Error;
10
11pub mod did;
12pub mod did_url;
13pub mod document;
14mod uri;
15
16/// Boxed future for [`Method::resolve`].
17pub type MethodFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
18
19pub trait Method: Send + Sync {
20    fn method_name(&self) -> &'static str;
21    fn resolve(&self, did: Did) -> MethodFuture<Result<document::Document, ResolutionError>>;
22}
23
24#[derive(Error, Debug)]
25pub enum ResolutionError {
26    #[error("invalid DID")]
27    InvalidDid,
28    /// The resolved document's `id` was not the DID being resolved, so the
29    /// document speaks for an identifier its host does not control.
30    #[error("document id does not match the resolved DID")]
31    DocumentMismatch,
32    /// The target was rejected before any request was sent.
33    #[error("resolution target is not permitted")]
34    TargetNotAllowed,
35    #[error("document exceeds the configured size limit")]
36    DocumentTooLarge,
37    /// Detail never includes the resolved URL, which would make resolution
38    /// errors an oracle for probing internal hosts.
39    #[error("resolution failed: {0}")]
40    ResolutionFailed(String),
41    #[error("unsupported method")]
42    UnsupportedMethod,
43}