logo
pub trait DIDResolver: Sync {
    fn resolve<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 str,
        input_metadata: &'life2 ResolutionInputMetadata
    ) -> Pin<Box<dyn Future<Output = (ResolutionMetadata, Option<Document>, Option<DocumentMetadata>)> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn resolve_representation<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 str,
        input_metadata: &'life2 ResolutionInputMetadata
    ) -> Pin<Box<dyn Future<Output = (ResolutionMetadata, Vec<u8>, Option<DocumentMetadata>)> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
fn dereference<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _primary_did_url: &'life1 PrimaryDIDURL,
        _did_url_dereferencing_input_metadata: &'life2 DereferencingInputMetadata
    ) -> Pin<Box<dyn Future<Output = Option<(DereferencingMetadata, Content, ContentMetadata)>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
fn to_did_method(&self) -> Option<&dyn DIDMethod> { ... } }
Expand description

A DID resolver, implementing the DID Resolution algorithm and optionally DID URL Dereferencing.

Example

An example of a DID resolver with a static DID document.

use async_trait::async_trait;
use ssi::did::Document;
use ssi::did_resolve::{
    DIDResolver, DocumentMetadata, ResolutionInputMetadata, ResolutionMetadata,
    ERROR_NOT_FOUND
};

pub struct DIDExampleStatic;

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl DIDResolver for DIDExampleStatic {
    async fn resolve(
        &self,
        did: &str,
        _input_metadata: &ResolutionInputMetadata,
    ) -> (
        ResolutionMetadata,
        Option<Document>,
        Option<DocumentMetadata>,
    ) {
        match did {
            "did:example:foo" => {
                let doc = match Document::from_json(include_str!("../tests/did-example-foo.json")) {
                    Ok(doc) => doc,
                    Err(e) => {
                        return (
                            ResolutionMetadata::from_error(&format!(
                                "Unable to parse DID document: {:?}",
                                e
                            )),
                            None,
                            None,
                        );
                    }
                };
                (
                    ResolutionMetadata::default(),
                    Some(doc),
                    Some(DocumentMetadata::default()),
                )
            }
            _ => return (ResolutionMetadata::from_error(ERROR_NOT_FOUND), None, None),
        }
    }
}

Required methods

Resolve a DID

i.e. the resolve function from DID Core and DID Resolution.

Provided methods

Resolve a DID in a given representation

i.e. the resolveRepresentation function from DID Core and DID Resolution.

Dereference a DID URL.

DID methods implement this function to support dereferencing DID URLs with paths and query strings. Callers should use dereference instead of this function.

Cast the resolver as a DIDMethod, if possible.

Implementors