MerkleList
Class: MerkleList\<T>
Dynamic-length list which is represented as a single hash
Supported operations are () and () and some variants thereof.
A Merkle list is generic over its element types, so before using it you must create a subclass for your element type:
class MyList extends MerkleList.create(MyType) {}
// now use it
let list = MyList.empty();
list.push(new MyType(...));
let element = list.pop();
Internal detail: push() adds elements to the start of the internal array and pop() removes them from the start.
This is so that the hash which represents the list is consistent with MerkleListIterator,
and so a MerkleList can be used as input to MerkleListIterator.startIterating(list)
(which will then iterate starting from the last pushed element).
Type parameters
| Name |
|---|
T |
Hierarchy
MerkleList
Implements
MerkleListBase\<T>
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new MerkleList\<T>(«destructured»)
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
«destructured» | MerkleListBase\<T> |
Defined in
lib/provable-types/merkle-list.ts:82
Properties
data
• data: Unconstrained\<WithHash\<T>[]>
Implementation of
MerkleListBase.data
Defined in
lib/provable-types/merkle-list.ts:80
hash
• hash: Field
Implementation of
MerkleListBase.hash
Defined in
lib/provable-types/merkle-list.ts:79
_emptyHash
▪ Static _emptyHash: undefined | Field
Defined in
lib/provable-types/merkle-list.ts:257
_innerProvable
▪ Static _innerProvable: undefined | ProvableHashable\<any>
Defined in
lib/provable-types/merkle-list.ts:260
_nextHash
▪ Static _nextHash: undefined | (hash: Field, t: any) => Field
Defined in
lib/provable-types/merkle-list.ts:256
_provable
▪ Static _provable: undefined | ProvableHashable\<MerkleList\<any>>
Defined in
lib/provable-types/merkle-list.ts:259
Accessors
Constructor
• get Constructor(): typeof MerkleList
Returns
typeof MerkleList
Defined in
lib/provable-types/merkle-list.ts:262
innerProvable
• get innerProvable(): ProvableHashable\<T>
Returns
ProvableHashable\<T>
Defined in
lib/provable-types/merkle-list.ts:279
emptyHash
• Static get emptyHash(): Field
Returns
Defined in
lib/provable-types/merkle-list.ts:274
Methods
clone
▸ clone(): MerkleList\<T>
Returns
MerkleList\<T>
Defined in
lib/provable-types/merkle-list.ts:187
isEmpty
▸ isEmpty(): Bool
Returns
Defined in
lib/provable-types/merkle-list.ts:87
nextHash
▸ nextHash(hash, value): Field
Parameters
| Name | Type |
|---|---|
hash | Field |
value | T |
Returns
Defined in
lib/provable-types/merkle-list.ts:266
pop
▸ pop(): T
Remove the last element from the list and return it.
If the list is empty, returns a dummy element.
Returns
T
Defined in
lib/provable-types/merkle-list.ts:152
popExn
▸ popExn(): T
Remove the last element from the list and return it.
This proves that the list is non-empty, and fails otherwise.
Returns
T
Defined in
lib/provable-types/merkle-list.ts:137
popIf
▸ popIf(condition): T
Return the last element, but only remove it if condition is true.
If the list is empty, returns a dummy element.
Parameters
| Name | Type |
|---|---|
condition | Bool |
Returns
T
Defined in
lib/provable-types/merkle-list.ts:171
popWitness
▸ Private popWitness(): WithHash\<T>
Returns
WithHash\<T>
Defined in
lib/provable-types/merkle-list.ts:120
push
▸ push(element): void
Push a new element to the list.
Parameters
| Name | Type |
|---|---|
element | T |
Returns
void
Defined in
lib/provable-types/merkle-list.ts:94
pushIf
▸ pushIf(condition, element): void
Push a new element to the list, if the condition is true.
Parameters
| Name | Type |
|---|---|
condition | Bool |
element | T |
Returns
void
Defined in
lib/provable-types/merkle-list.ts:106
startIterating
▸ startIterating(): MerkleListIterator\<T>
Returns
Defined in
lib/provable-types/merkle-list.ts:192
create
▸ Static create\<T>(type, nextHash?, emptyHash_?): typeof MerkleList & { empty: () => MerkleList\<T> ; from: (array: T[]) => MerkleList\<T> ; provable: ProvableHashable\<MerkleList\<T>> }
Create a Merkle list type
Optionally, you can tell create() how to do the hash that pushes a new list element, by passing a nextHash function.
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Default value |
|---|---|---|
type | ProvableHashable\<T> | undefined |
nextHash | (hash: Field, value: T) => Field | undefined |
emptyHash_ | Field | emptyHash |
Returns
typeof MerkleList & { empty: () => MerkleList\<T> ; from: (array: T[]) => MerkleList\<T> ; provable: ProvableHashable\<MerkleList\<T>> }
Example
class MyList extends MerkleList.create(Field, (hash, x) =>
Poseidon.hashWithPrefix('custom', [hash, x])
) {}