Skip to main content

DID Resolver

The @cef-ebsi/ebsi-did-resolver library supports the proposed did:ebsi method spec from EBSI.

It requires the did-resolver library, which is the primary interface for resolving DIDs.

Installation

npm install @cef-ebsi/ebsi-did-resolver

or if you use yarn:

yarn add @cef-ebsi/ebsi-did-resolver

Resolving a DID document

The library presents a resolve() function that returns a Promise returning the DID document. It is not meant to be used directly but through the did-resolver aggregator.

You can use the getResolver(config) method to produce an entry that can be used with the Resolver constructor.

import { Resolver } from "did-resolver";
import { getResolver } from "@cef-ebsi/ebsi-did-resolver";

// You must set the address of the DID Registry to be used in order to resolve Legal Entities DID Documents
const resolverConfig = {
registry: "https://api.preprod.ebsi.eu/did-registry/v3/identifiers",
};

// getResolver will return an object with a key/value pair of { "ebsi": resolver } where resolver is a function used by the generic did resolver.
const ebsiDidResolver = getResolver(resolverConfig);
const didResolver = new Resolver(ebsiDidResolver);

didResolver
.resolve("did:ebsi:zub5ZZUfHLLptCduwEy8xRj")
.then((doc) => console.log);

// You can also use ES7 async/await syntax
const doc = await didResolver.resolve("did:ebsi:zub5ZZUfHLLptCduwEy8xRj");

EBSI DID method v2 (Natural Persons)

import { Resolver } from "did-resolver";
import { getResolver } from "@cef-ebsi/ebsi-did-resolver";

// Example of a JWK shared by a Natural Person
const knownJwk = {
kty: "EC",
crv: "secp256k1",
x: "Gk0927lG8jRAd-6z-jQdhN-pcELMxKEQJRhPuzz4nic",
y: "zPs6-edBMiY7rOCLBn87Bp2pINeskJV_7KnFd0nNHGQ",
};

// You must provide a set of known JWKs in order to resolve a Natural Person's DID Document
const resolverConfig = {
naturalPersonJwks: [knownJwk],
};

// getResolver will return an object with a key/value pair of { "ebsi": resolver } where resolver is a function used by the generic did resolver.
const ebsiDidResolver = getResolver(resolverConfig);
const didResolver = new Resolver(ebsiDidResolver);

didResolver
.resolve("did:ebsi:zpBqM2DGALyfULDjNTp95cXrSjcNG6b1fYeNZD6WhPEgi")
.then((doc) => console.log);

// You can also use ES7 async/await syntax
const doc = await didResolver.resolve(
"did:ebsi:zpBqM2DGALyfULDjNTp95cXrSjcNG6b1fYeNZD6WhPEgi"
);

Try it online