RAILGUN Reloaded
    Preparing search index...

    Module @railgun-reloaded/merkle-tree

    Source: dev 8f5c9df

    @railgun-reloaded/merkle-tree

    Collection of Merkle Tree implementations as used in RAILGUN

    import { SparseMerkleTree } from "@railgun-reloaded/merkle-tree";

    const treeDepth = 16;

    const zeroElement = new Uint8Array(32);

    const hashFn = (out, left, right) => {
    crypto.createHash("sha3-256").update(left).update(right).digest(out);
    };

    const tree = SparseMerkleTree.create({ treeDepth, zeroElement, hashFn });

    // Append three leaves to the tree
    const newLength = tree.append([node1, node2, node3]);

    // Get the root node of the tree
    const rootNode = tree.root();

    // Generate a proof for the second leaf of the tree
    const proofLeaf1 = tree.proof(1);

    // Serialize the tree to primitives that can be stored
    const flat = tree.serialize();
    npm install --save @railgun-reloaded/merkle-tree
    

    Sparse Merkle Tree implementation with efficient batch inserts. Inherits all methods from MerkleTree.

    Create a new Sparse Merkle Tree instance with the given parameters.

    Current length of set leaf nodes in the tree

    Insert one or more leaf nodes efficiently in the tree. Returns the new length of the tree.

    Returns a zero-copy flat object representation of the tree, which can be stored or transmitted. The object includes all properties that are not global system parameters. Zero-copy here means that references are preserved, hence no modification to the returned object must be made.

    General base Merkle Tree implementation.

    The underlying buffer of the tree, which contains all nodes in a flat structure.

    Bytes per node

    Total number of nodes in the tree

    Total number of leaf nodes in the tree

    Depth of the tree

    Get a reference to the leaf node at a given index. Note the node is read-only and must not be modified.

    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.

    Get a referent to the root node of the tree. Note the node is read-only and must not be modified.

    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.

    Clone the current tree into an independent instance

    Returns a zero-copy flat object representation of the tree, which can be stored or transmitted. The object includes all properties that are not global system parameters. Zero-copy here means that references are preserved, hence no modification to the returned object must be made.

    MIT

    MerkleTree
    SparseMerkleTree
    InplaceMerkleHashFn
    MerkleProof