didjs
didjs
is a javascript package that parses and stringifies
Decentralized Identifiers (DIDs).
Install
yarn add didjs
or
Example
const d = didjsconsole
The above example parses the input string according to the rules defined in the DID Grammar and prints the following object:
id: "1234567890" idStrings: "1234567890" method: "example" path: "asdf/qwerty" pathSegments: "asdf" "qwerty"
The input string may also be a DID Reference with a DID Fragment:
const d = didjsconsole// Output: keys-1
This package also stringifies DID objects into valid DID strings:
const d = method: 'example' id: '1234567890'console// Output: did:example:1234567890
or with a refence with a fragment:
const d = method: 'example' id: '1234567890' fragment: 'keys-1'console// Output: did:example:1234567890#keys-1
Build
To compile the code in this repository, run:
webpack
Test
This repository includes a suite of tests that check for various edge cases within the DID Grammar.
To run the tests, run:
npm run test
License
This package is licensed under Apache License 2.0.