js-did-hypns

4.3.1 • Public • Published

js-did-hypns

travis-ci-badge

Javascript Decentralized Identifiers using Hyperdrive Protocol

A HypnsId = DID + HyPNS Node + Keypair

What

This is a javascript implementation of the Decentralized Identity Document (DID Doc) method implementation.

Pre-alpha level software. Use a your own risk.

It uses a fork of kappa-db/multifeed (because waiting) which incorporates hypercore, corestore, and networker.

Multifeed was used because I want to be able to update my feed from any of my devices, as well as have backups. May switch to a HyPNS based multi-hyperbee later.

Why?

Most of the DID method implementations I have seen are based on blockchains. I wanted an implementation that worked without having to buy cryptocurrency and then spend the crypto every time you want to change your DID Doc. Hypercore-protocol is truly peer-to-peer, and free to the user.

So with this, anyone can create their own digital identity document and save it to their own machine. Theirs stays online as long as their computer is up, or any friends also have their computer running.

Browser

My design goals included:

  • [x] No download
  • [x] No sign-up
  • [x] No payment
  • [x] Use existing accounts/assets/platforms

#1 No download: This meant it had to work in the browser, as everyone already has a browser downloaded

#2 It had to work anonymously and without any server involvement to register or sign-up.

#3 No payment. Why pay for hardware, processing, or storage when we all have phones, computers, and other hardware already at our disposal? Also, buyign cryptocurrency is a hassle, and a huge barrier to entry for most people.

#4 Use existing accounts/platforms. To ease adoption, right along with using the browser, the system uses existing user-owner hardware and already installed software.

HypnsComponent

To get the software to work in the browser, I needed a protocol that works peer to peer and automatically pins peers. The winner for mutable data is the Hypercore-Protocol.

I developed a Svelte Hypns Component as well to make working with Hyper and Multifeed easier.

Svelte has a built-in onDestroy feature that automatically calls a function when the component is destroyed. So by baking the SDK and Hyperdrive into a Svelte component, I can "set it and forget it" about calling the await close() after I'm done with the SDK. See HyPNS for more details.

API

import { createDidHyper, getDid } from "js-did-hypns";
import HyPNS from 'hypns' // or use the HyPNS-Svelte-Component in Svelte!

var myNode = new HyPNS({ persist: false })
const myInstance = await myNode.open({ keypair }) // or leave empty to generate new pair
await myInstance.ready() // must wait for it to configure

// initate the hypnsId object using the node
hypnsId = createDidHyper(myNode);

const createOps = (document) => {
  document.addPublicKey({
    id: "master",
    type: "RsaVerificationKey2018",
    publicKeyHex: keypair.publicKey.toString('hex'),
  });
};

// make a DID doc on this HyPNS instance
const initialDocument = await hypnsId.create(myInstance, operations)

const updateOps = (document) => {
  document.addPublicKey({
    id: "secondary",
    type: "RsaVerificationKey2018",
    publicKeyHex: "someOtherHexPublicKeyHere",
  });
};

// update an existing DID doc on this drive
updatedContents = await hypnsId.update(myInstance, updateOps);

// get the DID of this drive
did = await getDid(myInstance);
// did:hypns:abc123def....

// get the DID Doc of this DID (if possible)
resolveSelfContents = await hypnsId.resolve(did);
// the actual DID doc with all the keys, methods, services, etc.

// get the DID Doc of a peer
peersContents = await hypnsId.resolve("did:hypns:123cba456def...");

Document and Key Manager ("Wallet")

TODO: demo needs updating

Goal: Show how to interact with the did-hypns module and save DID doc details directly. In reality, you'll likely use a DID wallet to manage all this, like https://github.com/DougAnderson444/streamlined-idm-wallet-sdk or any other DID doc management software.

Create, Read, Update and Delete did:hypns identities

You can create a DID doc by simply passing a hypns reference into this module.

PRs welcome, this is a work in progress.

Package Sidebar

Install

npm i js-did-hypns

Weekly Downloads

2

Version

4.3.1

License

MIT

Unpacked Size

66.9 kB

Total Files

24

Last publish

Collaborators

  • douganderson444