Skip to main content
Version: 2.15.0

MerkleMap

Defined in: lib/provable/merkle-map.ts:10

Constructors​

Constructor​

new MerkleMap(): MerkleMap;

Defined in: lib/provable/merkle-map.ts:27

Creates a new, empty Merkle Map.

A Merkle Map is a data structure that allows for efficient storage and retrieval of key-value pairs. The values are stored in a Merkle tree, and the keys are formed by using the first 254 bits of the key as an index. The inner Merkle tree has a height of 256.

Returns​

MerkleMap

A new MerkleMap

Example​

const merkleMap = new MerkleMap();

Properties​

tree​

tree: MerkleTree;

Defined in: lib/provable/merkle-map.ts:11

Methods​

_keyToIndex()​

_keyToIndex(key: Field): bigint;

Defined in: lib/provable/merkle-map.ts:31

Parameters​

key​

Field

Returns​

bigint


get()​

get(key: Field): Field;

Defined in: lib/provable/merkle-map.ts:77

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

getRoot()​

getRoot(): Field;

Defined in: lib/provable/merkle-map.ts:90

Returns the root of the Merkle Map.

Returns​

Field

The root of the Merkle Map.

Example​

const root = merkleMap.getRoot();

getWitness()​

getWitness(key: Field): MerkleMapWitness;

Defined in: lib/provable/merkle-map.ts:104

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);

set()​

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

Defined in: lib/provable/merkle-map.ts:61

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);