The DidResolver class provides mechanisms for resolving Decentralized Identifiers (DIDs) to their corresponding DID documents.

The class is designed to handle various DID methods by utilizing an array of DidMethodResolver instances, each responsible for a specific DID method.

Providing a cache implementation can significantly enhance resolution performance by avoiding redundant resolutions for previously resolved DIDs. If omitted, a no-operation cache is used, which effectively disables caching.

Usage:

  • Construct the DidResolver with an array of DidMethodResolver instances and an optional cache.
  • Use resolve to resolve a DID to its DID Resolution Result.
  • Use dereference to extract specific resources from a DID URL, like service endpoints or verification methods.

Example

const resolver = new DidResolver({
didResolvers: [<array of DidMethodResolver instances>],
cache: new DidResolverCacheNoop()
});

const resolutionResult = await resolver.resolve('did:example:123456');
const dereferenceResult = await resolver.dereference({ didUri: 'did:example:123456#key-1' });

Implements

Constructors

Properties

Methods

Constructors

Properties

A cache for storing resolved DID documents.

didResolvers: Map<string, DidMethodResolver> = ...

A map to store method resolvers against method names.

Methods

  • Dereferences a DID (Decentralized Identifier) URL to a corresponding DID resource.

    This method interprets the DID URL's components, which include the DID method, method-specific identifier, path, query, and fragment, and retrieves the related resource as per the DID Core specifications.

    The dereferencing process involves resolving the DID contained in the DID URL to a DID document, and then extracting the specific part of the document identified by the fragment in the DID URL. If no fragment is specified, the entire DID document is returned.

    This method supports resolution of different components within a DID document such as service endpoints and verification methods, based on their IDs. It accommodates both full and DID URLs as specified in the DID Core specification.

    More information on DID URL dereferencing can be found in the DID Core specification.

    TODO: This is a partial implementation and does not fully implement DID URL dereferencing. (https://github.com/TBD54566975/web5-js/issues/387)

    Parameters

    • didUrl: string

      The DID URL string to dereference.

    • Optional _options: DidDereferencingOptions

      Input options to the dereference function. Optional.

    Returns Promise<DidDereferencingResult>

    a DidDereferencingResult

  • Resolves a DID to a DID Resolution Result.

    If the DID Resolution Result is present in the cache, it returns the cached result. Otherwise, it uses the appropriate method resolver to resolve the DID, stores the resolution result in the cache, and returns the resolultion result.

    Parameters

    Returns Promise<DidResolutionResult>

    A promise that resolves to the DID Resolution Result.