{"id":19122915,"url":"https://github.com/digitalbazaar/did-io","last_synced_at":"2025-06-20T10:06:16.369Z","repository":{"id":31735588,"uuid":"35301582","full_name":"digitalbazaar/did-io","owner":"digitalbazaar","description":"Decentralized identifier management library for browser and node.js","archived":false,"fork":false,"pushed_at":"2022-12-07T14:48:10.000Z","size":398,"stargazers_count":44,"open_issues_count":9,"forks_count":8,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-06-03T18:52:17.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.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}},"created_at":"2015-05-08T21:00:18.000Z","updated_at":"2025-03-09T16:50:22.000Z","dependencies_parsed_at":"2022-08-07T16:30:55.790Z","dependency_job_id":null,"html_url":"https://github.com/digitalbazaar/did-io","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/digitalbazaar/did-io","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fdid-io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fdid-io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fdid-io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fdid-io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/did-io/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fdid-io/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260924450,"owners_count":23083522,"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":[],"created_at":"2024-11-09T05:23:30.989Z","updated_at":"2025-06-20T10:06:11.359Z","avatar_url":"https://github.com/digitalbazaar.png","language":"JavaScript","funding_links":[],"categories":["🛠 Tools \u0026 Technologies"],"sub_categories":[],"readme":"# Selective DID Resolver Client _(@digitalbazaar/did-io)_\n\n\u003c!--[![Build status](https://img.shields.io/github/workflow/status/digitalbazaar/did-io/Node.js%20CI)](https://github.com/digitalbazaar/did-io/actions?query=workflow%3A%22Node.js+CI%22)\n[![Coverage status](https://img.shields.io/codecov/c/github/digitalbazaar/did-io)](https://codecov.io/gh/digitalbazaar/did-io)--\u003e\n[![NPM Version](https://img.shields.io/npm/v/@digitalbazaar/did-io.svg)](https://npm.im/@digitalbazaar/did-io)\n\n\u003e A [DID](https://w3c.github.io/did-core) (Decentralized Identifier) resolution library for Javascript.\n\n## Table of Contents\n\n- [Background](#background)\n- [Install](#install)\n- [Usage](#usage)\n  - [Supported DID method drivers](#supported-did-method-drivers)\n- [Contribute](#contribute)\n- [Commercial Support](#commercial-support)\n- [License](#license)\n\n## Background\n\nSee also (related specs):\n\n* [DID Core v1](https://w3c.github.io/did-core)\n* [Decentralized Identifier Resolution v2](https://w3c-ccg.github.io/did-resolution/)\n* [DID Specification Registries](https://www.w3.org/TR/did-spec-registries/)\n* [Linked Data Cryptographic Suite Registry](https://w3c-ccg.github.io/ld-cryptosuite-registry/)\n* [Linked Data Proofs](https://w3c-ccg.github.io/ld-proofs/)\n* [Authorization Capabilities (zCaps) for Linked Data](https://w3c-ccg.github.io/zcap-ld/)\n\n### Version Compatibility\n\n`did-io` v1.0 is a major breaking release, see the\n[1.0 CHANGELOG entry](CHANGELOG.md#100---2021-04-06) and\n[Upgrading from v0.8.x to v1.0.0](docs/upgrading-0.8-to-1.0.md) checklist for\ndetails.\n\n`did-io` v1.0 is compatible with the following libraries:\n\n* `crypto-ld` `\u003e= 5.0.0` (and related crypto suites).\n* `jsonld-signatures` `\u003e= 9.0.0`\n* `@digitalbazaar/did-method-key` `\u003e= 1.0.0`\n* `did-veres-one` `\u003e= 13.0.0` (currently, [branch `v13.x`](https://github.com/veres-one/did-veres-one/pull/56))\n* `vc-js` `\u003e= 7.0` (currently, [branch `v7.x`](https://github.com/digitalbazaar/vc-js/pull/83))\n\n## Install\n\nRequires Node.js 14+\n\nTo install locally (for development):\n\n```\ngit clone https://github.com/digitalbazaar/did-io.git\ncd did-io\nnpm install\n```\n\nTo install as a dependency in another project, add this to your `package.json`:\n\n```\n\"@digitalbazaar/did-io\": \"^X.x.x\"\n```\n\n## Usage\n\n### Supported DID method drivers\n\n* [`did:v1`](https://github.com/veres-one/did-veres-one)\n* [`did:key`](https://github.com/digitalbazaar/did-method-key-js)\n* [`did:web`](https://github.com/interop-alliance/did-web-resolver)\n\n### Using the CachedResolver to `get()` DID documents and keys\n\n```js\nimport {CachedResolver} from '@digitalbazaar/did-io';\n\n// You can pass cache options to the constructor (see Cache Management below)\nconst resolver = new CachedResolver({max: 100}); // defaults to 100\n```\n\nOn its own, the resolver does not know how to fetch or resolve any DID methods.\nSupport for each one has to be enabled explicitly. It uses a\n[Chai](https://www.chaijs.com/)-like plugin architecture, where each driver\nis loaded via `.use(driver)`.\n\n```js\nimport * as didKey from '@digitalbazaar/did-method-key';\nimport * as didVeresOne from 'did-veres-one';\n\nconst didKeyDriver = didKey.driver();\n// Dev / testnet / live modes\nconst didVeresOneDriver = didVeresOne.driver({mode: 'dev'});\n\n// Enable resolver to use the did:key and did:v1 methods for cached fetching.\nresolver.use(didKeyDriver);\nresolver.use(didVeresOneDriver);\n```\n\nAfter enabling individual DID methods, you can `get()` individual\nDIDs. CachedResolver will use the appropriate driver, based on the `did:` prefix,\nor throw an 'unsupported did method' error if no driver was installed for that\nmethod.\n\n```js\nawait resolver.get({did}); // -\u003e did document\nawait resolver.get({url: keyId}); // -\u003e public key node\n```\n\n### Key Convenience Methods\n\nYou can use the provided convenience methods (`methodFor()` with\n`.generate()`,  and `didMethodDriver.publicMethodFor()` with `.get()`) to get a\nhold of key pair instances (previously, this was done via a manual process of\ndetermining key id and using `didDocument.keys[keyId]`).\n\nWhen retrieving documents with `.get()`:\n\n```js\nconst didDocument = await resolver.get({did});\nconst publicKeyData = resolver.publicMethodFor({didDocument, purpose: 'authentication'});\n// Then you can use the resulting plain JS object to get a key pair instance.\n// via a configured CryptoLD instance, when you're working with multiple key types\n// (see `crypto-ld` library for setup and usage):\nconst authPublicKey = await cryptoLd.from(publicKeyData);\n// or, directly (if you already know the key type)\nconst authPublicKey = await Ed25519VerificationKey2020.from(publicKeyData);\n```\n\nWhen retrieving individual key objects with a `.get()`, you don't even need to\nuse `publicMethodFor()`:\n\n```js\nconst keyData = await resolver.get({url: keyId});\nconst publicKey = await cryptoLd.from(keyData);\n```\n\n### Generating and registering DIDs and DID documents\n\n`did-io` and `CachedResolver` are currently only for `get()` operations\non multiple DID methods. To generate and register new DIDs or DID documents,\nuse each individual driver's `.generate()` method. (The generation\nand registration process for each DID method is so different, that it didn't\nmake sense to unify them on the `CachedResolver` level.)\n\nEach driver's `.generate()` returns a tuple of `didDocument`, a `Map`\nof public/private key pairs (by key id), and a convenience `methodFor` function\nthat allows lookup of key (verification method) by its intended purpose.\n\n```js\nconst {didDocument, keyPairs, methodFor} = await didMethodDriver.generate();\ndidDocument\n// -\u003e plain JS object, representing a DID document.\nkeyPairs\n// -\u003e a javascript Map of public/private LDKeyPair instances (from crypto-ld),\n//   by key id\nmethodFor({purpose: 'keyAgreement'});\n// for example, an X25519KeyAgreementKey2020 key pair instance, that can\n// be used for encryption/decryption using `@digitalbazaar/minimal-cipher`.\nmethodFor({purpose: 'assertionMethod'});\n// for example, an Ed25519VerificationKey2020 key pair instance for\n// signing and verifying Verifiable Claims (VCs).\n```\n\n### Using CachedResolver as a `documentLoader`\n\nOne of the most common uses of DIDs and their public keys is for cryptographic\noperations such as signing and verifying signatures of \n[Verifiable Credentials](https://github.com/digitalbazaar/vc-js) and \n[other documents](https://github.com/digitalbazaar/jsonld-signatures), and for \n[encrypting and decrypting objects](https://github.com/digitalbazaar/minimal-cipher).\n\nFor these and other Linked Data Security operations, a `documentLoader` function\nis often required. For example, NPM's `package.json` and `package-lock.json`\nmechanisms allow application developers to securely lock down a library's\ndependencies (by specifying exact content hashes or approximate versions).\nIn the same manner, `documentLoader`s allow developers to secure their\nLinked Data Security load operations, such as when loading JSON-LD contexts,\nfetching DID Documents of supported DID methods, retrieving public keys, and\nso on.\n\nYou can use an initialized `CachedResolver` instance when constructing a\n`documentLoader` for your use case (to handle DID and DID key resolution for \ninstalled methods). For example:\n\n```js\nconst resolver = new CachedResolver();\nresolver.use(didMethodDriver1);\nresolver.use(didMethodDriver2);\n\nconst documentLoader = async url =\u003e {\n  // Handle other static document and contexts here...\n  \n  // Use CachedResolver to fetch did: links.\n  if(url \u0026\u0026 url.startsWith('did:')) {\n    // this will handle both DIDs and key IDs for the 2 installed drivers\n    const document = await resolver.get({url});\n    return {\n      url,\n      document,\n      static: true\n    }\n  }\n}\n```\n\n### Cache management\n\nCachedResolver uses [`lru-memoize`](https://github.com/digitalbazaar/lru-memoize)\nto [memoize](https://en.wikipedia.org/wiki/Memoization) `get()` promises \n(as opposed to just the results of the operations),\nwhich helps in high-concurrency use cases. (And that library in turn uses\n[`lru-cache`](https://www.npmjs.com/package/lru-cache) under the hood.)\n\nThe `CachedResolver` constructor passes any options given to it through to\nthe `lru-cache` constructor, so  see that repo for the full list of cache \nmanagement options. Commonly used ones include:\n\n* `max` (default: 100) - maximum size of the cache.\n* `maxAge` (default: 5 sec/5000 ms) - maximum age of an item in ms.\n* `updateAgeOnGet` (default: `false`) - When using time-expiring entries with \n  `maxAge`, setting this to true will make each entry's effective time update to\n  the current time whenever it is retrieved from cache, thereby extending the \n  expiration date of the entry.\n\n## Contribute\n\nSee [the contribute file](https://github.com/digitalbazaar/bedrock/blob/master/CONTRIBUTING.md)!\n\nPRs accepted.\n\nIf editing the Readme, please conform to the\n[standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## Commercial Support\n\nCommercial support for this library is available upon request from\nDigital Bazaar: support@digitalbazaar.com\n\n## License\n\n[New BSD License (3-clause)](LICENSE) © Digital Bazaar\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fdid-io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fdid-io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fdid-io/lists"}