{"name":"did-resolver","version":"4.1.0","description":"Resolve DID documents","type":"module","source":"src/resolver.ts","main":"./lib/resolver.cjs","module":"./lib/resolver.module.js","types":"./lib/resolver.d.ts","exports":{".":{"types":"./lib/resolver.d.ts","require":"./lib/resolver.cjs","import":"./lib/resolver.module.js"}},"sideEffects":false,"repository":{"type":"git","url":"git+ssh://git@github.com/decentralized-identity/did-resolver.git"},"author":{"name":"Pelle Braendgaard"},"contributors":[{"name":"Mircea Nistor","email":"mircea.nistor@mesh.xyz"},{"name":"Jack Tanner","email":"jack+public@tonomy.foundation"},{"name":"Rebal Alhaqash","email":"rebal@tonomy.foundation"}],"license":"Apache-2.0","scripts":{"test":"jest","test:ci":"jest --coverage","build":"microbundle --compress=false","format":"prettier --write \"src/**/*.[jt]s\"","lint":"eslint --ignore-pattern \"src/**/*.test.[jt]s\" \"src/**/*.[jt]s\"","prepublishOnly":"yarn test:ci && yarn format && yarn lint","release":"semantic-release --debug"},"jest":{"clearMocks":true,"collectCoverageFrom":["src/**/*.{ts,tsx}","!src/**/*.d.ts","!**/node_modules/**","!**/__tests__/**"],"testEnvironment":"node","testMatch":["**/__tests__/**/*.test.[jt]s"]},"devDependencies":{"@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":"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":"27.1.2","eslint-plugin-prettier":"4.2.1","jest":"29.2.0","microbundle":"0.15.1","prettier":"2.7.1","semantic-release":"19.0.5","typescript":"4.8.4"},"gitHead":"79569d60bed77af24cf332d6001a33b8b438dab1","bugs":{"url":"https://github.com/decentralized-identity/did-resolver/issues"},"homepage":"https://github.com/decentralized-identity/did-resolver#readme","_id":"did-resolver@4.1.0","_nodeVersion":"14.21.3","_npmVersion":"8.19.2","dist":{"integrity":"sha512-S6fWHvCXkZg2IhS4RcVHxwuyVejPR7c+a4Go0xbQ9ps5kILa8viiYQgrM4gfTyeTjJ0ekgJH9gk/BawTpmkbZA==","shasum":"740852083c4fd5bf9729d528eca5d105aff45eb6","tarball":"http://registry-npm.ywwl.com/did-resolver/download/did-resolver-4.1.0.tgz","fileCount":13,"unpackedSize":131375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3K5FyG8K493dZc5acNdLHDcJWVn7ouTT8jc2QI9pWmQIgcVYDiYzN4MuSud+Ze4p5zgpOyI7k8D7BnMHUgYoFxbk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkCJYwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoxjhAAiYp73cb4f9rQCwECYc11ccw71gf1ZuHs0y6qyb96mGrEY6k6\r\n0iVKU7Y0fnL8d1G/0bkYtnpsIhyPQ9UXLbHfGfLe3cZrsh6ylKUpeYyLIjm7\r\nig9amPY1IwLNnXAM1hNVUgCmlfeg1Q8OwRqXNUA1IO0WlpKXKifrN3l2+E9b\r\nCjeir3idsLMb6z3th9GaRn/YahTgYtgbMQSJgpAkeWVfbpK+JRm7mr0MPXKH\r\n1YDAbM6Z+d15sPWboTzc6JV1G1sEfuexrZMQGfGz+sfxbFLtfd2xWIGS4d0M\r\nkB9GUswcrHFpIHA5L7AIvBgDl0YyirH+gMgR0jXfE9hsnIIIFg1Oa3iCLWt8\r\nj2E1I6pfgdwmpHLYLVqy9eMA78D7ILr7TdNhMbESslndl6XUdiTHKiJIfWlO\r\nmf+mZEyZQhm0oOEzrBmpC2ollPJ3h48rDlet9vpiZO+IwNRUiTIFnkK5g78i\r\nuGhaVy0N2uyHQgXJuD60/md2Gmnk1EGZTSzdmPQmhgNqUNLpJKxZlagsSHNc\r\nk6iKlajYrPI56U/NWtITuVuQxxkueJ7NhWvSfTw/MbwZEF0OnL8pvf8X7LCi\r\nXXYXSidveSCFlUeXrmSnVZ8bAKnLrnB7b24AZqigVSKxk9KleXC4BYMhCSrT\r\n6SdodS3hA8GW3ZxrsGriV6VtA4uNLkJltA0=\r\n=kOza\r\n-----END PGP SIGNATURE-----\r\n","size":20119,"noattachment":false,"key":"/did-resolver/-/did-resolver-4.1.0.tgz"},"_npmUser":{"name":"uport-automation-bot","email":"devops@uport.me"},"directories":{},"maintainers":[{"name":"simonas-notcat","email":"simonas@not.cat"},{"name":"mirceanis","email":"mirceanis@gmail.com"},{"name":"uport-automation-bot","email":"devops@uport.me"},{"name":"pelleb","email":"pelleb@gmail.com"},{"name":"mike.xu","email":"mike.xu@consensys.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/did-resolver_4.1.0_1678284336566_0.3142912705295535"},"_hasShrinkwrap":false,"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 => 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) => {\n  // DID spec requires to not cache if no-cache param is set\n  if (parsed.params && 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<DIDDocument> {\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","publish_time":1678284336741,"_cnpm_publish_time":1678284336741,"dist-tags":{"alpha":"0.0.7-alpha.0","latest":"6.0.0","preview":"5.0.0-feat-publishing-maintenance.1"}}