Skip to main content

MerkleMap

Constructors

new MerkleMap()

new MerkleMap(): MerkleMap

Creates a new, empty Merkle Map.

Returns

MerkleMap

A new MerkleMap

Example

const merkleMap = new MerkleMap();

Source

lib/provable/merkle-map.ts:21

Properties

tree

tree: MerkleTree;

Source

lib/provable/merkle-map.ts:11

Methods

_keyToIndex()

_keyToIndex(key: Field): bigint

Parameters

key: Field

Returns

bigint

Source

lib/provable/merkle-map.ts:25


get()

get(key: Field): Field

Returns a value given a key. Values are by default Field(0).

Parameters

key: Field

The key to get the value from.

Returns

Field

The value stored at the key.

Example

const key = Field(5);
const value = merkleMap.get(key);
console.log(value); // Output: the value at key 5 or Field(0) if key does not exist

Source

lib/provable/merkle-map.ts:71


getRoot()

getRoot(): Field

Returns the root of the Merkle Map.

Returns

Field

The root of the Merkle Map.

Example

const root = merkleMap.getRoot();

Source

lib/provable/merkle-map.ts:84


getWitness()

getWitness(key: Field): MerkleMapWitness

Returns a circuit-compatible witness (also known as Merkle Proof or Merkle Witness) for the given key.

Parameters

key: Field

The key to make a witness for.

Returns

MerkleMapWitness

A MerkleMapWitness, which can be used to assert changes to the MerkleMap, and the witness's key.

Example

const key = Field(5);
const witness = merkleMap.getWitness(key);

Source

lib/provable/merkle-map.ts:98


set()

set(key: Field, value: Field): void

Sets a key of the merkle map to a given value.

Parameters

key: Field

The key to set in the map.

value: Field

The value to set.

Returns

void

Example

const key = Field(5);
const value = Field(10);
merkleMap.set(key, value);

Source

lib/provable/merkle-map.ts:55