Registry / security / did-uri

did-uri

JSON →
library0.6.0jsnpmunverified

W3C compliant DID URI parser and formatter for Node.js. Version 0.6.0 provides parsing, formatting, and validation of Decentralized Identifier URIs with support for method, identifier, path, query, fragment, and parameter components. Largely stable but with irregular updates; the project was forked from the abandoned AraBlocks repository and is now maintained separately. Differs from alternatives like did-resolver by focusing solely on URI manipulation without DID resolution logic.

npm install did-uri
INSTALL
IMPORT
SIG · DID-URI
D
did-uri
securityjavascriptv0.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

did-uri (default)
const did = require('did-uri')
import did from 'did-uri'
Package uses CommonJS. ESM import may not work; use require or dynamic import.
DID
const { DID } = require('did-uri')
const DID = require('did-uri').DID
Named export for the DID class; both patterns work but the latter is redundant.
parse
const { parse } = require('did-uri')
const parse = require('did-uri').parse
Named export for the parse function; direct property access works but destructuring is preferred.

Parsing a DID URI, formatting a new DID, and using the DID class to extract query parameters.

const did = require('did-uri'); const spec = did.parse('did:example:123456789abcdefghi'); console.log(spec); // Output: { reference: 'did:example:123456789abcdefghi', did: 'did:example:123456789abcdefghi', method: 'example', identifier: '123456789abcdefghi', path: '', fragment: '', query: '', param: '' } const formatted = did.format({ method: 'example', identifier: 'abc' }); console.log(formatted); // Output: 'did:example:abc' const instance = new did.DID('did:example:123/path?key=val'); console.log(instance.queryParameters); // Output: { key: 'val' }
Debug
Known issues
gotchaPackage uses CommonJS; ESM import via 'import did from 'did-uri'' may fail in Node.js without a wrapper or dynamic import.
fix
Use const did = require('did-uri') or dynamic import('did-uri').
affects: >=0.0.0
gotchaThe parsed 'did' field does not include the trailing slash before path; it is just 'did:method:identifier'. The path is separate.
fix
Reconstruct the full URI using did.reference or concatenate parts manually.
affects: >=0.0.0
deprecatedThe 'param' field (matrix parameters) is deprecated in newer DID specs; may be removed in future versions.
fix
Use 'parameters' object instead of 'param' string.
affects: >=0.6.0
Errors
Common errors & fixes
Cannot find module 'did-uri'
Package not installed or missing from node_modules.
fix
Run 'npm install did-uri' in your project root.
TypeError: did.parse is not a function
Using ESM import incorrectly: import did from 'did-uri' may not yield the default export.
fix
Use const did = require('did-uri') or use named imports: import { parse } from 'did-uri' (if using a bundler that supports CJS interop).
ReferenceError: require is not defined
Running in an ESM context (e.g., package.json type: module) without proper require support.
fix
Use dynamic import: const did = await import('did-uri') or switch to CommonJS.
Upgrade
Version history
0.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
did-uri — npm install did-uri · libregistry