{"_id":"did-resolver@6.0.0","dist":{"shasum":"178f489c52a31ceac6d2b212bfa77a308d2d0c9c","tarball":"http://registry-npm.ywwl.com/did-resolver/download/did-resolver-6.0.0.tgz","fileCount":11,"integrity":"sha512-qYlNpucsgfBE0foIqlnEjLx7ZvMTUOkPeIjOhVKPJKm4h8afFNS78zDLbiJPZ2yvY3Z7C79FW1UHSRyehRCpOg==","signatures":[{"sig":"MEUCIFoNlFK0BxDf4p7a7ns8ExisL+vL7KHv3minco7YYQnmAiEAyXBesjEiq/K8aab20rYjJHpBwyAuLf+DE7PeCasPt+c=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDVl6LNBsgmbdDBNGnrxrILH1x7iiOX3rlpRIQn3EHOqAIgR8jn61tmBqpimeXqsG8jI8oh+1Mtv5ZXirj8TJhg3VE="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/did-resolver@6.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":74529,"size":16876,"noattachment":false,"key":"/did-resolver/-/did-resolver-6.0.0.tgz"},"main":"./lib/index.cjs","name":"did-resolver","type":"module","types":"./lib/index.d.ts","author":"Pelle Braendgaard","module":"./lib/index.mjs","source":"src/index.ts","exports":{".":{"import":{"types":"./lib/index.d.mts","default":"./lib/index.mjs"},"require":{"types":"./lib/index.d.cts","default":"./lib/index.cjs"}}},"license":"Apache-2.0","scripts":{"lint":"eslint \"src/**/*.[jt]s\"","test":"vitest run","build":"tsc && tsc -p tsconfig.cjs.json && node scripts/postbuild.mjs","clean":"rm -rf lib","format":"prettier --write \"src/**/*.[jt]s\"","test:ci":"vitest run --coverage","changeset":"changeset","release:publish":"changeset publish"},"version":"6.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:bf0c4c96-9ca1-455f-89dc-be1380d7ae4c"}},"repository":{"url":"git+https://github.com/decentralized-identity/did-resolver.git","type":"git"},"description":"Resolve DID documents","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"}],"sideEffects":false,"contributors":["Mircea Nistor <work@mirceanis.xyz>","Jack Tanner <jack+public@tonomy.foundation>","Rebal Alhaqash <rebal@tonomy.foundation>"],"_hasShrinkwrap":false,"devDependencies":{"eslint":"10.10.0","vitest":"5.0.1","prettier":"3.9.6","typescript":"npm:@typescript/typescript6@6.0.2","@changesets/cli":"3.0.3","@typescript/native":"npm:typescript@7.0.2","@vitest/coverage-v8":"5.0.1","@vitest/eslint-plugin":"1.6.27","eslint-config-prettier":"10.1.8","eslint-plugin-prettier":"5.5.6","@typescript-eslint/parser":"8.70.0","@typescript-eslint/eslint-plugin":"8.70.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/did-resolver_6.0.0_1790001526840_0.2707928535648285"},"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## DID verification relationships\n\nThe `VerificationRelationship` runtime constants represent the verification relationships defined by DID Core:\n\n```ts\nimport { VerificationRelationship, type DIDDocument } from 'did-resolver'\n\nconst document: DIDDocument = {\n  id: 'did:example:123',\n  [VerificationRelationship.Authentication]: ['did:example:123#key-1'],\n}\n```\n\nThe corresponding `VerificationRelationship` type also accepts the underlying string literals. The existing\n`KeyCapabilitySection` type remains available as a backwards-compatible alias.\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 is controlled via the `cache` option, which accepts a boolean value or a custom `DIDCache` function.\n\n### Built-in caching\n\nThe built-in cache uses a `Map` and does not have an automatic TTL, so entries don't expire. This is fine in most web, mobile and serverless contexts. If you run a long-running process, consider using a custom cache with expiration.\n\nEnable the built-in cache by passing `cache: true` to the constructor:\n\n```js\nconst resolver = new Resolver({\n  ethr,\n  web\n}, {\n  cache: true\n})\n```\n\n### Disabling cache\n\nTo disable caching entirely, pass `cache: false`:\n\n```js\nconst resolver = new Resolver({\n  ethr,\n  web\n}, {\n  cache: false\n})\n```\n\n### Per-call cache control\n\nYou can override the global cache setting on a per-call basis using the `cache` option in `DIDResolutionOptions`:\n\n```js\n// Global cache enabled, but disable for this specific resolution\nconst doc = await resolver.resolve('did:ethr:0xabcd...', { cache: false })\n\n// Global cache disabled, but enable for this specific resolution\nconst doc = await resolver.resolve('did:ethr:0xabcd...', { cache: true })\n```\n\n### Custom cache implementation\n\nFor advanced use cases, implement a custom `DIDCache` function. It receives the parsed DID, a resolve function, and optional resolution options:\n\n```js\nconst customCache: DIDCache = async (parsed, resolve, options) => {\n  // Respect per-call cache control\n  if (options?.cache === false) return await resolve()\n  \n  const cached = cache.get(parsed.didUrl)\n  if (cached !== undefined) return cached\n  \n  const doc = await resolve()\n  cache.set(parsed.didUrl, doc, 60000) // 60s TTL\n  return doc\n}\n\nconst resolver = new Resolver({\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\n### Per-Method Parsing\n\nIf your method has special syntax constraints beyond the base DID Core v1.0 spec, you can attach a method-specific parser to your resolver. This allows stricter syntax validation without duplicate parsing work.\n\n**Architecture:** Method-specific parsers receive a DID Core v1.0 compliant `ParsedDID` result from the global parser and only check method-specific syntax constraints. This ensures all DIDs pass DID Core v1.0 parsing first, then method-specific syntax rules. The parser is part of the resolver enhancement — both are exported together from `getResolver()`.\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    \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    \n    // Return the DIDResolutionResult object\n    return {\n      didResolutionMetadata: { contentType: 'application/did+ld+json' },\n      didDocument: didDoc,\n      didDocumentMetadata: { ... }\n    }\n  }\n\n  function parser(parsed: ParsedDID): ParsedDID | null {\n    // Receive DID Core v1.0 compliant ParsedDID from global parser\n    // Only add method-specific syntax constraints\n    \n    // Example: enforce minimum id length for this method\n    if (parsed.id.length < 5) {\n      return null  // Reject with invalidDid error\n    }\n    \n    // Can refine/enrich the parsed result if needed\n    return {\n      ...parsed,\n      methodSpecificField: 'value'\n    }\n  }\n\n  // Attach parser to resolver — this is required for the parser to be used\n  resolve.parser = parser\n\n  return { myMethod: resolve }\n}\n```\n\nConsumers register the resolver normally — the parser is part of it:\n\n```js\nimport { Resolver } from 'did-resolver'\nimport MyMethod from 'mymethod-did-resolver'\n\n// For a single method\nconst resolver = new Resolver(MyMethod.getResolver())\n\n// For multiple methods, flatten them together\nimport OtherMethod from 'other-did-resolver'\nconst resolver = new Resolver({\n  ...MyMethod.getResolver(),\n  ...OtherMethod.getResolver(),\n})\n```\n\n**Benefits:**\n\n- Method libraries control their own parse→resolve pipeline as a cohesive unit\n- Parser is discovered automatically via the resolver's `.parser` property\n- No duplicate parsing work\n- All DIDs guaranteed to pass DID Core v1.0 parsing first\n- Method parsers only implement method-specific syntax constraints\n- Parsers can refine/enrich the parsed result if needed\n- If parser returns `null`, resolution fails with `invalidDid` error\n","publish_time":1790001526933,"_cnpm_publish_time":1790001526933,"dist-tags":{"alpha":"0.0.7-alpha.0","latest":"6.0.0","preview":"5.0.0-feat-publishing-maintenance.1"}}