{"id":13566867,"url":"https://github.com/decentralized-identity/did-resolver","last_synced_at":"2025-05-15T01:04:31.338Z","repository":{"id":29609688,"uuid":"122224660","full_name":"decentralized-identity/did-resolver","owner":"decentralized-identity","description":"Universal did-resolver for javascript environments","archived":false,"fork":false,"pushed_at":"2025-05-12T01:36:59.000Z","size":2571,"stargazers_count":218,"open_issues_count":4,"forks_count":46,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-12T03:03:35.966Z","etag":null,"topics":["wg-id"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/decentralized-identity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-20T16:33:55.000Z","updated_at":"2025-05-05T06:47:21.000Z","dependencies_parsed_at":"2023-11-13T05:28:28.320Z","dependency_job_id":"5ce2a8c5-f69b-4e30-bc51-78dcb6e710ed","html_url":"https://github.com/decentralized-identity/did-resolver","commit_stats":{"total_commits":352,"total_committers":24,"mean_commits":"14.666666666666666","dds":"0.43181818181818177","last_synced_commit":"79569d60bed77af24cf332d6001a33b8b438dab1"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decentralized-identity","download_url":"https://codeload.github.com/decentralized-identity/did-resolver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249176,"owners_count":22039027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wg-id"],"created_at":"2024-08-01T13:02:18.399Z","updated_at":"2025-05-15T01:04:31.189Z","avatar_url":"https://github.com/decentralized-identity.png","language":"TypeScript","funding_links":[],"categories":["🛠 Tools \u0026 Technologies","TypeScript"],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/dt/did-resolver.svg)](https://www.npmjs.com/package/did-resolver)\n[![npm](https://img.shields.io/npm/v/did-resolver.svg)](https://www.npmjs.com/package/did-resolver)\n[![codecov](https://codecov.io/gh/decentralized-identity/did-resolver/branch/master/graph/badge.svg)](https://codecov.io/gh/decentralized-identity/did-resolver)\n\n# Typescript DID Resolver\n\nThis library is intended as a simple common interface for javascript applications to resolve DID documents from\nDecentralized Identifiers (DIDs).\n\nThis is intended to support the proposed [Decentralized Identifiers](https://w3c.github.io/did-core/#identifier) spec\nfrom the [W3C Credentials Community Group](https://w3c-ccg.github.io).\n\nThe library does not implement any specific DID method, but allows DID method implementors to release npm packages that\napplications can add.\n\n## Configure `Resolver` object\n\nYou are now required to preconfigure a resolver during instantiation. The `Resolver` constructor expects a registry of\nmethods mapped to a resolver function. For example:\n\n```js\n{\n  ethr: resolve,\n  web: resolve\n}\n```\n\nEach method resolver should expose a function called `getResolver` which will return an object containing one of these\nkey/value pairs. Then you can flatten them into one object to pass into the `Resolver` constructor.\n\n```js\nimport { Resolver } from 'did-resolver'\nimport ethr from 'ethr-did-resolver'\nimport web from 'web-did-resolver'\nimport sov from 'sov-did-resolver'\n\n//returns an object of { methodName: resolveFunction}\nethrResolver = ethr.getResolver()\nwebResolver = web.getResolver()\n\n//If you are using multiple methods you need to flatten them into one object\nconst resolver = new Resolver({\n  ...ethrResolver,\n  ...webResolver,\n})\n\n//If you are using one method you can simply pass the result of getResolver( into the constructor\nconst resolver = new Resolver(ethrResolver)\n```\n\n### Using legacy DID Method resolvers\n\nDID Method resolvers created before version `3.0.0` of this library can be used as legacy resolvers.\n\n```js\nimport { Resolver } from 'did-resolver'\nimport web from 'web-did-resolver'\nimport sov from 'sov-did-resolver'\n\n//returns an object of { methodName: resolveFunction}\nwebResolver = web.getResolver()\nsovResolver = sov.getResolver()\n\n//If you are using multiple methods you need to flatten them into one object\nconst resolver = new Resolver({}, {\n  legacyResolvers: {\n    ...webResolver,\n    ...sovResolver,\n  }\n})\n\n//If you are using one method you can simply pass the result of getResolver( into the constructor\nconst resolver = new Resolver(ethrResolver)\n```\n\n## Resolving a DID document\n\nThe resolver presents a simple `resolve()` function that returns a ES6 Promise returning the DID document.\n\n```js\nresolver.resolve('did:ethr:0xF3beAC30C498D9E26865F34fCAa57dBB935b0D74/some/path#fragment=123').then(doc =\u003e console.log)\n\n// You can also use ES7 async/await syntax\nconst doc = await resolver.resolve('did:ethr:0xF3beAC30C498D9E26865F34fCAa57dBB935b0D74/some/path#fragment=123')\n```\n\n## Caching\n\nResolving DID Documents can be expensive. It is in most cases best to cache DID documents. Caching has to be\nspecifically enabled using the `cache` parameter\n\nThe built-in cache uses a Map, but does not have an automatic TTL, so entries don't expire. This is fine in most web,\nmobile and serverless contexts. If you run a long-running process you may want to use an existing configurable caching\nsystem.\n\nThe built-in Cache can be enabled by passing in a `true` value to the constructor:\n\n```js\nconst resolver = new DIDResolver({\n  ethr,\n  web\n}, {\n  cache: true\n})\n```\n\nHere is an example using `js-cache` which has not been tested.\n\n```js\nvar cache = require('js-cache')\nconst customCache : DIDCache = (parsed, resolve) =\u003e {\n  // DID spec requires to not cache if no-cache param is set\n  if (parsed.params \u0026\u0026 parsed.params['no-cache'] === 'true') return await resolve()\n  const cached = cache.get(parsed.didUrl)\n  if (cached !== undefined) return cached\n  const doc = await resolve()\n  cache.set(parsed, doc, 60000)\n  return doc\n}\n\nconst resolver = new DIDResolver({\n  ethr,\n  web\n}, {\n  cache: customCache\n})\n```\n\n## Implementing a DID method\n\nEach DID method will have its own methods for looking up an identifier on its respective blockchain or other\ndecentralized storage mechanism.\n\nTo avoid misconfiguration, method implementers should export a `getResolver()` function which returns an object mapping\nthe method name to a `resolve(did: string, parsed: ParsedDID, didResolver: DIDResolver, options: DIDResolutionOptions)`\nfunction. e.g. `{ ethr: resolve }`.\n\nThe resolve function should accept a did string, and an object of\ntype [ParsedDID](https://github.com/decentralized-identity/did-resolver/blob/master/src/resolver.ts#L112)\n\n```js\nexport function getResolver() {\n  async function resolve(\n    did: string,\n    parsed: ParsedDID,\n    didResolver: Resolver,\n    options: DIDResolutionOptions\n  ): Promise\u003cDIDDocument\u003e {\n    console.log(parsed)\n    // {method: 'mymethod', id: 'abcdefg', did: 'did:mymethod:abcdefg/some/path#fragment=123', path: '/some/path', fragment: 'fragment=123'}\n    const didDoc = ...// lookup doc\n    // If you need to lookup another did as part of resolving this did document, the primary DIDResolver object is passed in as well\n    const parentDID = await didResolver.resolve(...)\n    // Return the DIDResolutionResult object\n    return {\n      didResolutionMetadata: { contentType: 'application/did+ld+json' },\n      didDocument: didDoc\n      didDocumentMetadata: { ... }\n    }\n  }\n\n  return { myMethod: resolve }\n}\n```\n\nThe MyMethod `getResolver()` result could then be passed into the DIDResolver constructor. Note that it should be\nflattened if used with other methods as well.\n\n```js\nimport { DIDResolver } from 'did-resolver'\nimport MyMethod from 'mymethod-did-resolver'\n\nconst myResolver = MyMethod.getResolver()\nconst resolver = new DIDResolver(myResolver)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecentralized-identity%2Fdid-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-resolver/lists"}