1.1.0 • Published 3 years ago

@tzstamp/merkle v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Merkle

Appendable merkle tree library

Installation

$ npm install --save @tzstamp/merkle

Proofs

const { Proof } = require('@tzstamp/merkle')

Deserialize a proof from JSON:

const proofString = fs.readFileSync('./my-proof.json')
const proof = Proof.parse(proofString)

Reserialize with:

JSON.stringify(proof)

proof.derive(hash)

Derive the merkle root, given the leaf hash.

  • hash: Uint8Array
  • returns: Uint8Array

proof.verify(hash, root)

Verify the proof, given the leaf hash and merkle root.

  • hash: Uint8Array
  • root: Uint8Array
  • returns: boolean

MerkleTree

const { MerkleTree } = require('@tzstamp/merkle')

Instantiate optionally with leaves:

const merkleTree = new MerkleTree(...leaves)

merkleTree.append(...hashes)

Append leaves to the merkle tree. Deduplicates leaves.

  • hashes: ...Uint8Array

merkleTree.prove(hash)

Build a proof, given a leaf hash included in the tree.

  • hash: Uint8Array
  • return: Proof
  • throws an error when the leaf is not included in the tree.

merkleTree.leaves

Array of all leaves included in the tree.

License

MIT © 2020 The TzStamp Authors

1.1.0

3 years ago

1.0.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago