use std::{
future::Future,
pin::Pin,
};
use did::Did;
use thiserror::Error;
pub mod did;
pub mod did_url;
pub mod document;
mod uri;
pub type MethodFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait Method: Send + Sync {
fn method_name(&self) -> &'static str;
fn resolve<'a>(
&'a self,
did: &'a Did,
) -> MethodFuture<'a, Result<document::Document, ResolutionError>>;
}
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum ResolutionError {
#[error("invalid DID")]
InvalidDid,
#[error("document id does not match the resolved DID")]
DocumentMismatch,
#[error("resolution target is not permitted")]
TargetNotAllowed,
#[error("document exceeds the configured size limit")]
DocumentTooLarge,
#[error("no document is published for this DID")]
NotFound,
#[error("could not reach the DID's host: {0}")]
Transport(String),
#[error("response is not a DID document: {0}")]
Malformed(String),
#[error("unsupported method")]
UnsupportedMethod,
}