@therootnetwork/doughnut-nodejs
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

@therootnetwork/doughnut-nodejs

Wasm Doughnut codec and maker. Currently compliant with the version 0, 1 spec.

Create a Doughnut (unsigned)

const Doughnut = require('@therootnetwork/doughnut-nodejs').Doughnut;
const { SignatureVersion,  PayloadVersion, FeeMode } = require("@therootnetwork/doughnut-nodejs");

const issuer = new Uint8Array(33);
const holder = new Uint8Array(33);
const expiry = 100;
const notBefore = 1;

return new Doughnut( PayloadVersion.V1, issuer, holder, FeeMode.ISSUER, expiry, notBefore).addTopping('trn', [1, 2, 3]);

Verify Doughnut

Check a doughnut is:

  • valid for use by holder at unix timestamp when
  • correctly signed by the issuer Note: this does not verify the terms of embedded permission domains.
const doughnut = new Doughnut(...);
doughnut.verify(holder, now);

Inspect Doughnut Fields

Getter functions for inspecting a doughnut

const d = new Doughnut(...);
const doughnut = {
  issuer: d.issuer(),
  holder: d.holder(),
  expiry: d.expiry(),
  not_before: d.notBefore(),
  signature_version: d.signatureVersion(),
  payload_version: d.payloadVersion(),
}
// query topping bytes
// It will throw 'undefined' if the topping does not exist
let testDomain = d.topping("trn");

Doughnut Encoding and Decoding

Encoding: Encode a doughnut object

Decoding: Create a doughnut object from a encoded doughnut

const Doughnut = require('@therootnetwork/doughnut-nodejs').default;

const payload = [64, 24, 64, 22, 126, 150, 15, 176, 190, ..., 235, 3, 21, 63, 79, 192, 137, 6];
const doughnut = Doughnut.decode();
doughnut.issuer();

const doughnut = new Doughnut(...);
const encoded = doughnut.encode();

Signing Doughnuts

This package provides some convenience functions for signing doughnuts

const Doughnut = require('@therootnetwork/doughnut-nodejs').default;
let doughnut = new Doughnut(...);
// ECDSA
doughnut.signECDSA(<ECDSA secret key bytes>);
// or EIP191
doughnut.signEIP191(<EIP191 secret key bytes>);

console.log(doughnut.signature)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.21latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.21
0.1.10
0.1.00

Package Sidebar

Install

npm i @therootnetwork/doughnut-nodejs

Weekly Downloads

1

Version

0.1.2

License

UNLICENSED

Unpacked Size

1.39 MB

Total Files

5

Last publish

Collaborators

  • zees-fv
  • karishma09
  • aidan-starke
  • kenvu-ai