
EBSI NP DID Resolver
This library supports the did:key method:
did-key-format := did:key:MULTIBASE(base58-btc, MULTICODEC(public-key-type, raw-public-key-bytes))
Note: the library only supports the jwk_jcs-pub public key type (code: 0xeb51). It corresponds to a JWK with required members only through JCS.
It requires the did-resolver library, which is the primary interface for resolving DIDs.
Table of Contents
Installation
npm install @cef-ebsi/key-did-resolver
or if you use yarn:
yarn add @cef-ebsi/key-did-resolver
Resolving a DID document
The library provides a resolver that is meant to be used through the did-resolver aggregator.
import { Resolver } from "did-resolver";
import { getResolver } from "@cef-ebsi/key-did-resolver";
const keyResolver = getResolver();
const didResolver = new Resolver(keyResolver);
didResolver
.resolve(
"did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsEYvdrjxMjQ4tpnje9BDBTzuNDP3knn6qLZErzd4bJ5go2CChoPjd5GAH3zpFJP5fuwSk66U5Pq6EhF4nKnHzDnznEP8fX99nZGgwbAh1o7Gj1X52Tdhf7U4KTk66xsA5r",
)
.then((doc) => console.log(doc));
const doc = await didResolver.resolve(
"did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsEYvdrjxMjQ4tpnje9BDBTzuNDP3knn6qLZErzd4bJ5go2CChoPjd5GAH3zpFJP5fuwSk66U5Pq6EhF4nKnHzDnznEP8fX99nZGgwbAh1o7Gj1X52Tdhf7U4KTk66xsA5r",
);
console.log(doc);
Creating a DID from a JWK
The library exposes a method allowing you to create a DID from a JWK:
import { util } from "@cef-ebsi/key-did-resolver";
const jwk = {
kty: "EC",
crv: "P-256",
x: "ngy44T1vxAT6Di4nr-UaM9K3Tlnz9pkoksDokKFkmNc",
y: "QCRfOKlSM31GTkb4JHx3nXB4G_jSPMsbdjzlkT_UpPc",
};
const did = util.createDid(jwk);
Validating a DID
The library also exposes a method to assert if a DID is valid:
import { util } from "@cef-ebsi/key-did-resolver";
const did =
"did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsEYvdrjxMjQ4tpnje9BDBTzuNDP3knn6qLZErzd4bJ5go2CChoPjd5GAH3zpFJP5fuwSk66U5Pq6EhF4nKnHzDnznEP8fX99nZGgwbAh1o7Gj1X52Tdhf7U4KTk66xsA5r";
util.validateDid(did);
License
Copyright (C) 2025 European Union
This program is free software: you can redistribute it and/or modify it under the terms of the EUROPEAN UNION PUBLIC LICENCE v. 1.2 as published by the European Union.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the EUROPEAN UNION PUBLIC LICENCE v. 1.2 for further details.
You should have received a copy of the EUROPEAN UNION PUBLIC LICENCE v. 1.2. along with this program. If not, see https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.