didjs

0.0.4 • Public • Published

didjs

didjs is a javascript package that parses and stringifies Decentralized Identifiers (DIDs).

Install

yarn add didjs

or

<script type="text/javascript" src="./dist/didjs.min.js"></script>

Example

import * as didjs from 'didjs'
 
const d = didjs.parse('did:example:1234567890/asdf/qwerty')
console.log(d)

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 = didjs.parse("did:example:1234567890#keys-1")
console.log(d.fragment)
// Output: keys-1

This package also stringifies DID objects into valid DID strings:

const d = {
    method: 'example',
    id: '1234567890'
}
console.log(didjs.stringify(d))
// Output: did:example:1234567890

or with a refence with a fragment:

const d = {
    method: 'example',
    id: '1234567890',
    fragment: 'keys-1'
}
console.log(didjs.stringify(d))
// 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.

Package Sidebar

Install

npm i didjs

Weekly Downloads

83

Version

0.0.4

License

none

Unpacked Size

42.4 kB

Total Files

6

Last publish

Collaborators

  • fognet