did-btc1-js

DID BTC1 JS

codecov

did:btc1 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the DID document. It improves on prior work by allowing: zero-cost off-chain DID creation; aggregated updates for scalable on-chain update costs; long-term identifiers that can support frequent updates; private communication of the DID document; private DID resolution; and non-repudiation appropriate for serious contracts.

did:btc1 is created for those who wish to have it all:

Technical Specification

To learn more about did:btc1 method, visit the specification at dcdpr.github.io/did-btc1.

Implementation Documentation

To learn more about the JS/TS implementation and its component packages, visit the documentation at btc1.tools/docs.

Contributing

If you would like to contribute a fix or feature, please open an issue, fork the repo, follow the steps below to get the project setup for local development and submit a PR from your fork to this repo.

npm i -g pnpm
git clone https://github.com/{USERNAME}/did-btc1-js.git
cd did-btc1-js
pnpm install
pnpm build

Usage

To use the @did-btc1/method package in your own project, install it using your favorite package manager.

pnpm install @did-btc1/{common,cryptosuite,key-pair,method}
# Swap in npm or yarn depending on preference or requirement

Once installed, import the method to your project and use it to perform CRUD operations or interact with Beacons.

CRUD operations

// ESM
import { DidBtc1 } from "@did-btc1/method";

const idType = 'key';
const pubKeyBytes = new Uint8Array(32);

// Create
const { did, initialDocument } = await DidBtc1.create({ idType, pubKeyBytes })
console.log('{ did, initialDocument }', { did, initialDocument });

// Read / Resolve
const resolution = await DidBtc1.resolve(did);
console.log('resolution', resolution);

// Update
const update = await DidBtc1.update({
  identifier           : did,
  sourceDocument       : initialDocument,
  sourceVersionId      : 1,
  patch                : [[
    {
      "op": "add",
      "path": "/service/1",
      "value": {
        "id": "#initialP2PKH",
        "type": "SingletonBeacon",
        "serviceEndpoint": "z66p..."
      }
    }
  ],],
  verificationMethodId : `#initialP2PKH`,
  beaconIds            : [`${did}#initialP2PKH`],
});

// TODO: Deactivate / Delete
// CommonJS
const { DidBtc1 } = require("@did-btc1/method");
const idType = 'key';
const pubKeyBytes = new Uint8Array(32);
const { did, initialDocument } = await DidBtc1.create({ idType, pubKeyBytes })
console.log('did', did);
console.log('initialDocument', initialDocument);

Packages

Package Versions

package npm issues prs
@did-btc1/common NPM Package Open Issues Open PRs
@did-btc1/cryptosuite NPM Package Open Issues Open PRs
@did-btc1/key-pair NPM Package Open Issues Open PRs
@did-btc1/method NPM Package Open Issues Open PRs
@did-btc1/cli NPM Package Open Issues Open PRs
@did-btc1/smt NPM Package Open Issues Open PRs

Project Resources

Resource Description
CODEOWNERS Outlines the project lead(s)
LICENSE Project Open Source License MPL-2.0