Class SparseMerkleTree<K, V>

Sparse Merkle Tree

SparseMerkleTree

Type Parameters

  • K
  • V

Constructors

  • Type Parameters

    • K
    • V

    Parameters

    • root: Field
    • store: Store<V>
    • keyType: Provable<K>
    • valueType: Provable<V>
    • hasher: Hasher
    • config: {
          hashKey: boolean;
          hashValue: boolean;
      }
      • hashKey: boolean
      • hashValue: boolean

    Returns SparseMerkleTree<K, V>

Properties

config: {
    hashKey: boolean;
    hashValue: boolean;
}

Type declaration

  • hashKey: boolean
  • hashValue: boolean
hasher: Hasher
keyType: Provable<K>
root: Field
store: Store<V>
valueType: Provable<V>
initialPoseidonHashRoot: Field = ...

Initial empty tree root based on poseidon hash algorithm

Static

Memberof

SparseMerkleTree

Methods

  • Clear the tree.

    Returns Promise<void>

    {Promise}

    Memberof

    SparseMerkleTree

  • Delete a value from tree and return the new root of the tree.

    Parameters

    • key: K

    Returns Promise<Field>

    {Promise}

    Memberof

    SparseMerkleTree

  • Get the depth of the tree.

    Returns number

    {number}

    Memberof

    SparseMerkleTree

  • Get the value for a key from the tree.

    Parameters

    • key: K

    Returns Promise<null | V>

    {(Promise<V | null>)}

    Memberof

    SparseMerkleTree

  • Get the root of the tree.

    Returns Field

    {Field}

    Memberof

    SparseMerkleTree

  • Check if the key exists in the tree.

    Parameters

    • key: K

    Returns Promise<boolean>

    {Promise}

    Memberof

    SparseMerkleTree

  • Check if the tree is empty.

    Returns boolean

    {boolean}

    Memberof

    SparseMerkleTree

  • Set the root of the tree.

    Parameters

    • root: Field

    Returns Promise<void>

    Memberof

    SparseMerkleTree

  • Parameters

    • root: Field
    • path: Field

    Returns Promise<{
        leafData: Field;
        pathNodes: Field[];
        sideNodes: Field[];
    }>

  • Update a new value for a key in the tree and return the new root of the tree.

    Parameters

    • key: K
    • Optional value: V

    Returns Promise<Field>

    {Promise}

    Memberof

    SparseMerkleTree

  • Update multiple leaves and return the new root of the tree.

    Parameters

    • kvs: {
          key: K;
          value?: V;
      }[]

    Returns Promise<Field>

    {Promise}

    Memberof

    SparseMerkleTree

  • Parameters

    • root: Field
    • key: K
    • Optional value: V

    Returns Promise<Field>

  • Parameters

    • sideNodes: Field[]
    • pathNodes: Field[]
    • oldLeafData: Field
    • path: Field
    • Optional value: V

    Returns Field

  • Build a new sparse merkle tree

    Type Parameters

    • K
    • V

    Parameters

    • store: Store<V>
    • KeyType: Provable<K>
    • ValueType: Provable<V>
    • Optional options: {
          hashKey?: boolean;
          hashValue?: boolean;
          hasher?: Hasher;
      } = ...

      hasher: The hash function to use, defaults to PoseidonHasherFunc; hashKey: whether to hash the key, the default is true; hashValue: whether to hash the value, the default is true.

      • Optional hashKey?: boolean
      • Optional hashValue?: boolean
      • Optional hasher?: Hasher

    Returns Promise<SparseMerkleTree<K, V>>

    {Promise<SparseMerkleTree<K, V>>}

    Static

    Memberof

    SparseMerkleTree

  • Import a sparse merkle tree via existing store

    Type Parameters

    • K
    • V

    Parameters

    • store: Store<V>
    • keyType: Provable<K>
    • valueType: Provable<V>
    • Optional options: {
          hashKey?: boolean;
          hashValue?: boolean;
          hasher?: Hasher;
      } = ...

      hasher: The hash function to use, defaults to PoseidonHasherFunc; hashKey: whether to hash the key, the default is true; hashValue: whether to hash the value, the default is true.

      • Optional hashKey?: boolean
      • Optional hashValue?: boolean
      • Optional hasher?: Hasher

    Returns Promise<SparseMerkleTree<K, V>>

    {Promise<SparseMerkleTree<K, V>>}

    Static

    Memberof

    SparseMerkleTree