@tzstamp/merkle
v1.1.0
Published
Appendable merkle tree library
Downloads
3
Keywords
Readme
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