RAILGUN Reloaded
    Preparing search index...

    General base Merkle Tree implementation.

    Hierarchy (View Summary)

    Index
    • The constructor is not meant to be used directly, use create or from methods instead.

      Parameters

      • args: ConstructorParams

        Constructor parameters

        • buf

          Uint8Array big enough to hold all nodes in the tree

        • hashFn

          Hash function for internal nodes. Must follow the InplaceMerkleHashFn signature

        • bytesPerElement

          Size of each node in bytes. Must be at least 1 byte

      Returns MerkleTree

    • Create a new MerkleTree instance with the given parameters, allocating memory to contain all nodes. Initializes the tree with the zero element. Returns an instance to use

      Parameters

      • params: CreateParams

        Creation parameters

        • depth

          Depth of the tree, excluding the root node. Must be at least 1

        • hashFn

          Hash function to use for internal nodes. Must follow the InplaceMerkleHashFn signature

        • zeroElement

          Zero element to use for leaf nodes. Internal nodes are calculated up to the root. Must be at least 1 byte

      Returns MerkleTree

      Instance of MerkleTree

    • Create a new MerkleTree instance from a serialized object and global parameters

      Parameters

      • obj: Serialized

        Serialized object of the merkle tree

      • params: Omit<ConstructorParams, keyof Serialized>

        Additional system parameters

      Returns MerkleTree

      Instance

    • Internal method to get a reference to the buffer slice for a node at a given index

      Parameters

      • index: number

        element-wise index

      Returns Uint8Array<ArrayBufferLike>

      subarray of bytesPerElement aligned to a multiple of the node size

    • Internal method to set a node at a given

      Parameters

      • index: number

        element-wise index

      • value: Readonly<Uint8Array>

        bytesPerElement-sized buffer to copy

      Returns void

    • Get a reference to the leaf node at a given index

      Parameters

      • index: number

        Zero-based index of the leaf node. Out of bounds indices will throw an error

      Returns Readonly<Uint8Array>

      Read-only zero-copy leaf node

    • Insert nodes at a given index of the tree. Supports either a single node or an array of nodes, efficiently updating parents. Note only up to size elements can be filled, overfilling will cause an assertion error.

      Parameters

      • index: number

        start index of first element

      • nodes: Readonly<Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike>[]>

        single element or sequence of consecutive elements

      Returns number

      index after last element inserted. Useful for chaining inserts

    • Return the root element of the tree

      Returns Readonly<Uint8Array>

      Read-only zero-copy root element

    • Generate an inclusion proof for a given index. Returns an object with the index, root and path elements, where path elements are the first sibling and uncles of the node up to the root.

      Parameters

      • index: number

        Leaf index to prove

      Returns MerkleProof

      Merkle proof for the given leaf index

    • Zero-copy a serialisable representation of the current tree into a plain object

      Returns Serialized

      Serializable object representation of the tree

    LEAF_LEVEL: number = 0

    Level of leaf nodes in the tree. All leaf nodes are at this level, while all internal nodes are at higher levels.

    buf: Uint8Array

    Underlying buffer holding all tree nodes

    3-arity hash function deriving parents. First argument is output buffer to be populated with the hash digest

    bytesPerElement: number

    Bytes per node

    capacity: number

    Total number of nodes in the tree

    _rootIndex: number

    Cached index of root node

    size: number

    Total number of leaf nodes in the tree

    depth: number

    Depth of the tree