Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

did-resolver

Package Overview
Dependencies
Maintainers
5
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

did-resolver - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

88

lib/resolver.d.ts

@@ -0,2 +1,11 @@

/**
* Defines an object type that can be extended with other properties.
*/
export declare type Extensible = Record<string, any>;
/**
* Defines the result of a DID resolution operation.
*
* @see {@link Resolvable.resolve}
* @see {@link https://www.w3.org/TR/did-core/#did-resolution}
*/
export interface DIDResolutionResult {

@@ -8,5 +17,15 @@ '@context'?: 'https://w3id.org/did-resolution/v1' | string | string[];

}
/**
* Describes the options forwarded to the resolver when executing a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-resolution-options}
*/
export interface DIDResolutionOptions extends Extensible {
accept?: string;
}
/**
* Encapsulates the resolution metadata resulting from a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-resolution-metadata}
*/
export interface DIDResolutionMetadata extends Extensible {

@@ -16,2 +35,7 @@ contentType?: string;

}
/**
* Represents metadata about the DID document resulting from a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-document-metadata}
*/
export interface DIDDocumentMetadata extends Extensible {

@@ -27,3 +51,13 @@ created?: string;

}
/**
* Represents the Verification Relationship between a DID subject and a Verification Method.
*
* @see {@link https://www.w3.org/TR/did-core/#verification-relationships}
*/
export declare type KeyCapabilitySection = 'authentication' | 'assertionMethod' | 'keyAgreement' | 'capabilityInvocation' | 'capabilityDelegation';
/**
* Represents a DID document.
*
* @see {@link https://www.w3.org/TR/did-core/#did-document-properties}
*/
export declare type DIDDocument = {

@@ -43,2 +77,8 @@ '@context'?: 'https://www.w3.org/ns/did/v1' | string | string[];

};
/**
* Represents a Service entry in a {@link https://www.w3.org/TR/did-core/#did-document-properties | DID document}.
*
* @see {@link https://www.w3.org/TR/did-core/#services}
* @see {@link https://www.w3.org/TR/did-core/#service-properties}
*/
export interface Service {

@@ -50,2 +90,8 @@ id: string;

}
/**
* Represents an endpoint of a Service entry in a DID document.
*
* @see {@link https://www.w3.org/TR/did-core/#dfn-serviceendpoint}
* @see {@link https://www.w3.org/TR/did-core/#services}
*/
export declare type ServiceEndpoint = string | Record<string, any>;

@@ -58,2 +104,4 @@ /**

* (and accidental disclosure) of private keys in DID documents.
*
* @see {@link https://www.rfc-editor.org/rfc/rfc7517 | RFC7517 JsonWebKey (JWK)}
*/

@@ -73,2 +121,11 @@ export interface JsonWebKey extends Extensible {

}
/**
* Represents the properties of a Verification Method listed in a DID document.
*
* This data type includes public key representations that are no longer present in the spec but are still used by
* several DID methods / resolvers and kept for backward compatibility.
*
* @see {@link https://www.w3.org/TR/did-core/#verification-methods}
* @see {@link https://www.w3.org/TR/did-core/#verification-method-properties}
*/
export interface VerificationMethod {

@@ -86,5 +143,16 @@ id: string;

}
/**
* URI params resulting from parsing a DID URI
*/
export interface Params {
[index: string]: string;
}
/**
* An object containing the results of parsing a DID URI string.
*
* This is forwarded to implementations of particular DID resolvers when calling the `resolve` method.
*
* @see {@link Resolver}
* @see {@link Resolvable.resolve}
*/
export interface ParsedDID {

@@ -100,2 +168,5 @@ did: string;

}
/**
* The DID resolution function that DID Resolver implementations must implement.
*/
export declare type DIDResolver = (did: string, parsed: ParsedDID, resolver: Resolvable, options: DIDResolutionOptions) => Promise<DIDResolutionResult>;

@@ -115,10 +186,23 @@ export declare type WrappedResolver = () => Promise<DIDResolutionResult>;

export declare function noCache(parsed: ParsedDID, resolve: WrappedResolver): Promise<DIDResolutionResult>;
/**
* Parses a DID URL and builds a {@link ParsedDID | ParsedDID object}
*
* @param didUrl - the DID URL string to be parsed
* @returns a ParsedDID object, or null if the input is not a DID URL
*/
export declare function parse(didUrl: string): ParsedDID | null;
export declare function wrapLegacyResolver(resolve: LegacyDIDResolver): DIDResolver;
/**
* The method signature implemented by this resolver.
*/
export interface Resolvable {
resolve: (didUrl: string, options?: DIDResolutionOptions) => Promise<DIDResolutionResult>;
}
/**
* This implementation of {@link Resolvable} bundles together multiple implementations of {@link DIDResolver} and
* presents a single function call to users.
*/
export declare class Resolver implements Resolvable {
private registry;
private cache;
private readonly registry;
private readonly cache;
constructor(registry?: ResolverRegistry, options?: ResolverOptions);

@@ -125,0 +209,0 @@ resolve(didUrl: string, options?: DIDResolutionOptions): Promise<DIDResolutionResult>;

51

lib/resolver.module.js
// Copyright 2018 Consensys AG
function _catch(body, recover) {

@@ -8,10 +9,7 @@ try {

}
if (result && result.then) {
return result.then(void 0, recover);
}
return result;
}
function inMemoryCache() {

@@ -22,3 +20,2 @@ const cache = new Map();

let _exit;
function _temp2(_result) {

@@ -29,11 +26,8 @@ if (_exit) return _result;

var _result$didResolution;
if (((_result$didResolution = result.didResolutionMetadata) == null ? void 0 : _result$didResolution.error) !== 'notFound') {
cache.set(parsed.didUrl, result);
}
return result;
});
}
const _temp = function () {

@@ -47,3 +41,2 @@ if (parsed.params && parsed.params['no-cache'] === 'true') {

}();
return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));

@@ -69,6 +62,11 @@ } catch (e) {

const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`);
/**
* Parses a DID URL and builds a {@link ParsedDID | ParsedDID object}
*
* @param didUrl - the DID URL string to be parsed
* @returns a ParsedDID object, or null if the input is not a DID URL
*/
function parse(didUrl) {
if (didUrl === '' || !didUrl) return null;
const sections = didUrl.match(DID_MATCHER);
if (sections) {

@@ -81,7 +79,5 @@ const parts = {

};
if (sections[4]) {
const params = sections[4].slice(1).split(';');
parts.params = {};
for (const p of params) {

@@ -92,3 +88,2 @@ const kv = p.split('=');

}
if (sections[6]) parts.path = sections[6];

@@ -99,3 +94,2 @@ if (sections[7]) parts.query = sections[7].slice(1);

}
return null;

@@ -113,3 +107,4 @@ }

return Promise.resolve(resolve(did, parsed, resolver)).then(function (doc) {
return { ...EMPTY_RESULT,
return {
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -119,10 +114,11 @@ contentType: 'application/did+ld+json'

didDocument: doc
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
});
}, function (e) {
return { ...EMPTY_RESULT,
return {
...EMPTY_RESULT,
didResolutionMetadata: {
error: 'notFound',
message: e.toString() // This is not in spec, but may be helpful
}

@@ -136,2 +132,6 @@ };

}
/**
* This implementation of {@link Resolvable} bundles together multiple implementations of {@link DIDResolver} and
* presents a single function call to users.
*/
class Resolver {

@@ -143,7 +143,7 @@ constructor(registry = {}, options = {}) {

this.cache = options.cache === true ? inMemoryCache() : options.cache || noCache;
if (options.legacyResolvers) {
Object.keys(options.legacyResolvers).map(methodName => {
if (!this.registry[methodName]) {
this.registry[methodName] = wrapLegacyResolver( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.registry[methodName] = wrapLegacyResolver(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.legacyResolvers[methodName]);

@@ -154,11 +154,9 @@ }

}
resolve(didUrl, options = {}) {
try {
const _this = this;
const parsed = parse(didUrl);
if (parsed === null) {
return Promise.resolve({ ...EMPTY_RESULT,
return Promise.resolve({
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -169,7 +167,6 @@ error: 'invalidDid'

}
const resolver = _this.registry[parsed.method];
if (!resolver) {
return Promise.resolve({ ...EMPTY_RESULT,
return Promise.resolve({
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -180,3 +177,2 @@ error: 'unsupportedDidMethod'

}
return Promise.resolve(_this.cache(parsed, () => resolver(parsed.did, parsed, _this, options)));

@@ -187,3 +183,2 @@ } catch (e) {

}
}

@@ -190,0 +185,0 @@

@@ -7,2 +7,3 @@ (function (global, factory) {

// Copyright 2018 Consensys AG
function _catch(body, recover) {

@@ -14,10 +15,7 @@ try {

}
if (result && result.then) {
return result.then(void 0, recover);
}
return result;
}
function inMemoryCache() {

@@ -28,3 +26,2 @@ const cache = new Map();

let _exit;
function _temp2(_result) {

@@ -35,11 +32,8 @@ if (_exit) return _result;

var _result$didResolution;
if (((_result$didResolution = result.didResolutionMetadata) == null ? void 0 : _result$didResolution.error) !== 'notFound') {
cache.set(parsed.didUrl, result);
}
return result;
});
}
const _temp = function () {

@@ -53,3 +47,2 @@ if (parsed.params && parsed.params['no-cache'] === 'true') {

}();
return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));

@@ -75,6 +68,11 @@ } catch (e) {

const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`);
/**
* Parses a DID URL and builds a {@link ParsedDID | ParsedDID object}
*
* @param didUrl - the DID URL string to be parsed
* @returns a ParsedDID object, or null if the input is not a DID URL
*/
function parse(didUrl) {
if (didUrl === '' || !didUrl) return null;
const sections = didUrl.match(DID_MATCHER);
if (sections) {

@@ -87,7 +85,5 @@ const parts = {

};
if (sections[4]) {
const params = sections[4].slice(1).split(';');
parts.params = {};
for (const p of params) {

@@ -98,3 +94,2 @@ const kv = p.split('=');

}
if (sections[6]) parts.path = sections[6];

@@ -105,3 +100,2 @@ if (sections[7]) parts.query = sections[7].slice(1);

}
return null;

@@ -119,3 +113,4 @@ }

return Promise.resolve(resolve(did, parsed, resolver)).then(function (doc) {
return { ...EMPTY_RESULT,
return {
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -125,10 +120,11 @@ contentType: 'application/did+ld+json'

didDocument: doc
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
});
}, function (e) {
return { ...EMPTY_RESULT,
return {
...EMPTY_RESULT,
didResolutionMetadata: {
error: 'notFound',
message: e.toString() // This is not in spec, but may be helpful
}

@@ -142,2 +138,6 @@ };

}
/**
* This implementation of {@link Resolvable} bundles together multiple implementations of {@link DIDResolver} and
* presents a single function call to users.
*/
class Resolver {

@@ -149,7 +149,7 @@ constructor(registry = {}, options = {}) {

this.cache = options.cache === true ? inMemoryCache() : options.cache || noCache;
if (options.legacyResolvers) {
Object.keys(options.legacyResolvers).map(methodName => {
if (!this.registry[methodName]) {
this.registry[methodName] = wrapLegacyResolver( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.registry[methodName] = wrapLegacyResolver(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.legacyResolvers[methodName]);

@@ -160,11 +160,9 @@ }

}
resolve(didUrl, options = {}) {
try {
const _this = this;
const parsed = parse(didUrl);
if (parsed === null) {
return Promise.resolve({ ...EMPTY_RESULT,
return Promise.resolve({
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -175,7 +173,6 @@ error: 'invalidDid'

}
const resolver = _this.registry[parsed.method];
if (!resolver) {
return Promise.resolve({ ...EMPTY_RESULT,
return Promise.resolve({
...EMPTY_RESULT,
didResolutionMetadata: {

@@ -186,3 +183,2 @@ error: 'unsupportedDidMethod'

}
return Promise.resolve(_this.cache(parsed, () => resolver(parsed.did, parsed, _this, options)));

@@ -193,3 +189,2 @@ } catch (e) {

}
}

@@ -196,0 +191,0 @@

{
"name": "did-resolver",
"version": "4.0.0",
"version": "4.0.1",
"description": "Resolve DID documents",

@@ -9,5 +9,3 @@ "type": "module",

"module": "./lib/resolver.module.js",
"unpkg": "./lib/resolver.umd.js",
"types": "./lib/resolver.d.ts",
"umd:main": "./lib/resolver.umd.js",
"files": [

@@ -21,2 +19,3 @@ "lib",

".": {
"types": "./lib/resolver.d.ts",
"require": "./lib/resolver.cjs",

@@ -59,24 +58,21 @@ "import": "./lib/resolver.module.js"

"devDependencies": {
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.4",
"@babel/preset-typescript": "7.18.6",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@types/jest": "28.1.4",
"@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.5",
"babel-jest": "28.1.2",
"eslint": "8.19.0",
"@types/jest": "29.1.2",
"@typescript-eslint/eslint-plugin": "5.40.0",
"@typescript-eslint/parser": "5.40.0",
"babel-jest": "29.2.0",
"eslint": "8.25.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "26.5.3",
"eslint-plugin-jest": "27.1.2",
"eslint-plugin-prettier": "4.2.1",
"jest": "28.1.2",
"microbundle": "0.15.0",
"jest": "29.2.0",
"microbundle": "0.15.1",
"prettier": "2.7.1",
"semantic-release": "19.0.3",
"typescript": "4.7.4"
},
"resolutions": {
"@babel/core": "7.18.10"
"semantic-release": "19.0.5",
"typescript": "4.8.4"
}
}

@@ -15,5 +15,14 @@ // Copyright 2018 Consensys AG

/**
* Defines an object type that can be extended with other properties.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Extensible = Record<string, any>
/**
* Defines the result of a DID resolution operation.
*
* @see {@link Resolvable.resolve}
* @see {@link https://www.w3.org/TR/did-core/#did-resolution}
*/
export interface DIDResolutionResult {

@@ -26,2 +35,7 @@ '@context'?: 'https://w3id.org/did-resolution/v1' | string | string[]

/**
* Describes the options forwarded to the resolver when executing a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-resolution-options}
*/
export interface DIDResolutionOptions extends Extensible {

@@ -31,2 +45,7 @@ accept?: string

/**
* Encapsulates the resolution metadata resulting from a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-resolution-metadata}
*/
export interface DIDResolutionMetadata extends Extensible {

@@ -37,2 +56,7 @@ contentType?: string

/**
* Represents metadata about the DID document resulting from a {@link Resolvable.resolve} operation.
*
* @see {@link https://www.w3.org/TR/did-core/#did-document-metadata}
*/
export interface DIDDocumentMetadata extends Extensible {

@@ -49,2 +73,7 @@ created?: string

/**
* Represents the Verification Relationship between a DID subject and a Verification Method.
*
* @see {@link https://www.w3.org/TR/did-core/#verification-relationships}
*/
export type KeyCapabilitySection =

@@ -57,2 +86,7 @@ | 'authentication'

/**
* Represents a DID document.
*
* @see {@link https://www.w3.org/TR/did-core/#did-document-properties}
*/
export type DIDDocument = {

@@ -73,2 +107,8 @@ '@context'?: 'https://www.w3.org/ns/did/v1' | string | string[]

/**
* Represents a Service entry in a {@link https://www.w3.org/TR/did-core/#did-document-properties | DID document}.
*
* @see {@link https://www.w3.org/TR/did-core/#services}
* @see {@link https://www.w3.org/TR/did-core/#service-properties}
*/
export interface Service {

@@ -78,5 +118,14 @@ id: string

serviceEndpoint: ServiceEndpoint | ServiceEndpoint[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[x: string]: any
}
/**
* Represents an endpoint of a Service entry in a DID document.
*
* @see {@link https://www.w3.org/TR/did-core/#dfn-serviceendpoint}
* @see {@link https://www.w3.org/TR/did-core/#services}
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ServiceEndpoint = string | Record<string, any>

@@ -90,2 +139,4 @@

* (and accidental disclosure) of private keys in DID documents.
*
* @see {@link https://www.rfc-editor.org/rfc/rfc7517 | RFC7517 JsonWebKey (JWK)}
*/

@@ -106,2 +157,11 @@ export interface JsonWebKey extends Extensible {

/**
* Represents the properties of a Verification Method listed in a DID document.
*
* This data type includes public key representations that are no longer present in the spec but are still used by
* several DID methods / resolvers and kept for backward compatibility.
*
* @see {@link https://www.w3.org/TR/did-core/#verification-methods}
* @see {@link https://www.w3.org/TR/did-core/#verification-method-properties}
*/
export interface VerificationMethod {

@@ -120,2 +180,5 @@ id: string

/**
* URI params resulting from parsing a DID URI
*/
export interface Params {

@@ -125,2 +188,10 @@ [index: string]: string

/**
* An object containing the results of parsing a DID URI string.
*
* This is forwarded to implementations of particular DID resolvers when calling the `resolve` method.
*
* @see {@link Resolver}
* @see {@link Resolvable.resolve}
*/
export interface ParsedDID {

@@ -137,2 +208,5 @@ did: string

/**
* The DID resolution function that DID Resolver implementations must implement.
*/
export type DIDResolver = (

@@ -190,2 +264,8 @@ did: string,

/**
* Parses a DID URL and builds a {@link ParsedDID | ParsedDID object}
*
* @param didUrl - the DID URL string to be parsed
* @returns a ParsedDID object, or null if the input is not a DID URL
*/
export function parse(didUrl: string): ParsedDID | null {

@@ -245,2 +325,5 @@ if (didUrl === '' || !didUrl) return null

/**
* The method signature implemented by this resolver.
*/
export interface Resolvable {

@@ -250,5 +333,9 @@ resolve: (didUrl: string, options?: DIDResolutionOptions) => Promise<DIDResolutionResult>

/**
* This implementation of {@link Resolvable} bundles together multiple implementations of {@link DIDResolver} and
* presents a single function call to users.
*/
export class Resolver implements Resolvable {
private registry: ResolverRegistry
private cache: DIDCache
private readonly registry: ResolverRegistry
private readonly cache: DIDCache

@@ -255,0 +342,0 @@ constructor(registry: ResolverRegistry = {}, options: ResolverOptions = {}) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc