Merkle tree structure. Type 'TData' is the type of the nodes in the tree. Type 'TLeaf' is the type of the leaf nodes specifically, which may be a more specific sub-type of 'TData'. Type 'TMetadata' is the type of the metadata.

Type Parameters

  • TData

  • TLeaf extends TData

  • TMetadata

Hierarchy

  • MerkleTree

Implements

Constructors

  • Type Parameters

    • TData

    • TLeaf

    • TMetadata

    Parameters

    • mergeFn: MergeFunction<TData, TMetadata>

      Function that merges nodes at lower levels to produce nodes for higher levels of the tree

    • root: Node<TData>

      Node corresponding to the root of the merkle tree.

    • leafNodes: Node<TLeaf>[]

      Leaf nodes of the tree

    • metadata: null | TMetadata

      Tree metadata

    Returns MerkleTree<TData, TLeaf, TMetadata>

Properties

leafNodes: Node<TLeaf>[]

Leaf nodes of the tree

metadata: null | TMetadata

Tree metadata

root: Node<TData>

Node corresponding to the root of the merkle tree.

Methods

  • Get proof for particular element by index. The proof is an array of nodes representing the various subtrees that do not contain the given element. The idea is that by repeatedly merging the element with successive nodes from the proof array, you eventually should get the root node of the original merkle tree.

    Returns

    Array of proof Nodes.

    Parameters

    • elemIndex: number

      Element index

    Returns Node<TData>[]