Internally stores the hashes of all of the data that was passed in.
Internally stores the state of whether something has been added to the tree since the last time it was updated or not.
Internally stores the root hash. Should only be accessible through
#computeRootHash.
Use this to check if a node has been added to the tree between now and the last time #computeRootHash was called.
The count of each node in the base of the tree.
Any form of data can be passed here. It will be stringified, hashed, and only store the hash.
A promise containing the new length of the base of the Merkle Tree.
Adds an array of data to the hash nodes.
An array of any data.
A promise containing the new length of the base of the Merkle Tree.
Use this to compare the root hash of this tree with another tree.
Constructs a Merkle Tree based off of the hashes found in the endmost descendant nodes (the hashes that came from your data). It then builds all of the intermediate nodes of the tree until it reaches the root, at which it will then return the root hash which is comprised of the sum of all of the descendant node hashes.
Note: This will return the previous hash which is cached in the tree as long as nothing has been added to the tree since the last time #computeRootHash was called.
Diagram of the Merkle Tree result:
H(7) where H(x) is a hashing function
/ \ that takes any data as it's input,
H(5) H(6) H(5) = H(1) + H(2),
/ \ / \ H(6) = H(3) + H(4),
H(1) H(2) H(3) H(4) H(7) = H(5) + H(6).
Used internally to convert a layer of hashes in a Merkle Tree to the next smaller layer. This is where the most of the Merkle Tree algorithm resides.
Use this to get a new instance of a MerkleTree.
Create a new instance of a MerkleTree with predefined data.
An array of any data.
A Merkle Tree containing the hashes of the data that was passed in.
Generated using TypeDoc
The Merkle Tree provides you with a way to audit a vector of data by comparing the hashes of each datum. It does this by building a layer using your initial hashes, and then takes a hash sum of two hashes until it reaches the last hash, effectively creating a smaller layer on top.
Note that since the Merkle Tree is a binary tree, whenever a layer has an odd amount of nodes, it must duplicate the odd node and add the hash to itself.
MerkleTree