@lightprotocol/stateless.js - v0.22.1-alpha.1
    Preparing search index...

    Class MerkleTree

    Merkle tree

    Index

    Constructors

    Properties

    levels: number

    Constructor

    Number of levels in the tree

    Initial elements

    Function used to hash 2 leaves

    Value for non-existent leaves

    capacity: number
    zeroElement: string
    _zeros: string[]
    _layers: string[][]
    _lightWasm: LightWasm

    Methods

    • Get merkle path to a leaf

      Parameters

      • index: number

        Leaf index to generate path for

      Returns { pathElements: string[]; pathIndices: number[] }

      An object containing adjacent elements and left-right index

    • Find an element in the tree

      Parameters

      • element: string

        An element to find

      • comparator: ((element: string, el: string) => boolean) | null = null

        A function that checks leaf value equality

      Returns number

      Index if element is found, otherwise -1

    • Serialize entire tree state including intermediate layers into a plain object Deserializing it back will not require to recompute any hashes Elements are not converted to a plain type, this is responsibility of the caller

      Returns { levels: number; _zeros: string[]; _layers: string[][] }

    • Deserialize data into a MerkleTree instance Make sure to provide the same hashFunction as was used in the source tree, otherwise the tree state will be invalid

      Parameters

      • data: any
      • hashFunction: (left: string, right: string) => string

      Returns any