Constructor
new MerkleTree(elements, ordered)
Parameters:
Name | Type | Description |
---|---|---|
elements |
Array.<Buffer> | an array of 32 Byte hashed Buffer elements that will make up the tree |
ordered |
bool | determines if the elements preserve ordering as we walk up the tree to generate proofs |
- Source:
Methods
_getProofPair(index, level) → {Buffer}
Internal _getProofPair - returns the adjacent object in the level when walking the tree to generate a proof
Parameters:
Name | Type | Description |
---|---|---|
index |
int | |
level |
Array.<Buffer> |
- Source:
Returns:
or Null
- Type
- Buffer
generateHashTree()
Internal generateHashTree - a side-effect driven function that generates the levels of the merkle tree; there are log2(n) levels
- Source:
generateProof(hashedElement) → {Array.<Buffer>}
generateProof - generates a merkle tree proof for the given hashed element
Parameters:
Name | Type | Description |
---|---|---|
hashedElement |
Buffer | a 32 Byte Buffer of the hashed element |
- Source:
Returns:
- Type
- Array.<Buffer>
getRoot() → {Buffer}
getRoot - returns the 32 byte merkle root element or 0 buffer otherewise
- Source:
Returns:
- Type
- Buffer
sumLevel()
Internal sumLevell
- Source:
verify(proof, hashedElement) → {bool}
Internal verify - returns true or false if the proof and hashedElement equate to the current merkleTree's root
Parameters:
Name | Type | Description |
---|---|---|
proof |
Array.<Buffer> | an array of bytes32 elements that represent the merkle proof |
hashedElement |
Buffer | hashed bytes32 leaf element to prove exists in the tree |
- Source:
Returns:
- Type
- bool