MerkleMap
Constructors
new MerkleMap()
new MerkleMap(): MerkleMap
Creates a new, empty Merkle Map.
Returns
A new MerkleMap
Example
const merkleMap = new MerkleMap();
Source
Properties
tree
tree: MerkleTree;
Source
Methods
_keyToIndex()
_keyToIndex(key: Field): bigint
Parameters
• key: Field
Returns
bigint
Source
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
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
getRoot()
getRoot(): Field
Returns the root of the Merkle Map.
Returns
The root of the Merkle Map.
Example
const root = merkleMap.getRoot();
Source
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
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
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);