IncrementalQuinTree
An implementation of an incremental Merkle tree
Dev
adapted from https://github.com/weijiekoh/optimisedmt
Table of contents
Constructors
Properties
Methods
- calcChildIndices
- calcInitialVals
- calcLeafIndices
- calcParentIndices
- copy
- genProof
- genSubrootProof
- getNode
- insert
- setNode
- update
- verifyProof
Constructors
constructor
• new IncrementalQuinTree(depth
, zeroValue
, arity
, hashFunc
): IncrementalQuinTree
Create a new instance of the MaciQuinTree
Parameters
Name | Type | Description |
---|---|---|
depth | number | The depth of the tree |
zeroValue | bigint | The zero value of the tree |
arity | number | The arity of the tree |
hashFunc | (leaves : bigint []) => bigint | The hash function of the tree |
Returns
Defined in
Properties
arity
• arity: number
Defined in
capacity
• capacity: number
Defined in
depth
• depth: number
Defined in
hashFunc
• hashFunc: (leaves
: bigint
[]) => bigint
Type declaration
▸ (leaves
): bigint
Parameters
Name | Type |
---|---|
leaves | bigint [] |
Returns
bigint
Defined in
nextIndex
• nextIndex: number
= 0
Defined in
nodes
• nodes: Node
Defined in
numNodes
• numNodes: number
Defined in
root
• root: bigint
Defined in
zeroValue
• zeroValue: bigint
Defined in
zeros
• zeros: bigint
[] = []
Defined in
Methods
calcChildIndices
▸ calcChildIndices(index
): number
[]
Calculate the indices of the children of a node
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the node |
Returns
number
[]
The indices of the children
Defined in
calcInitialVals
▸ calcInitialVals(arity
, depth
, zeroValue
, hashFunc
): Object
Calculate the zeroes and the root of a tree
Parameters
Name | Type | Description |
---|---|---|
arity | number | The arity of the tree |
depth | number | The depth of the tree |
zeroValue | bigint | The zero value of the tree |
hashFunc | (leaves : bigint []) => bigint | The hash function of the tree |
Returns
Object
The zeros and the root
Name | Type |
---|---|
root | bigint |
zeros | bigint [] |
Defined in
calcLeafIndices
▸ calcLeafIndices(index
): number
[]
Calculate the indices of the leaves in the path to the root
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the leaf |
Returns
number
[]
The indices of the leaves in the path to the root
Defined in
calcParentIndices
▸ calcParentIndices(index
): number
[]
Calculate the indices of the parent
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the leaf |
Returns
number
[]
The indices of the parent
Defined in
copy
▸ copy(): IncrementalQuinTree
Copy the tree to a new instance
Returns
The new instance
Defined in
genProof
▸ genProof(index
): IMerkleProof
Generate a proof for a given leaf index
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the leaf to generate a proof for |
Returns
IMerkleProof
The proof
Defined in
genSubrootProof
▸ genSubrootProof(startIndex
, endIndex
): IMerkleProof
Generates a Merkle proof from a subroot to the root.
Parameters
Name | Type | Description |
---|---|---|
startIndex | number | The index of the first leaf |
endIndex | number | The index of the last leaf |
Returns
IMerkleProof
The Merkle proof
Defined in
getNode
▸ getNode(index
): bigint
Get a node at a given index
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the node |
Returns
bigint
The node
Defined in
insert
▸ insert(value
): void
Insert a leaf at the next available index
Parameters
Name | Type | Description |
---|---|---|
value | bigint | The value to insert |
Returns
void
Defined in
setNode
▸ setNode(index
, value
): void
Set a node (not the root)
Parameters
Name | Type | Description |
---|---|---|
index | number | the index of the node |
value | bigint | the value of the node |
Returns
void
Defined in
update
▸ update(index
, value
): void
Update a leaf at a given index
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the leaf to update |
value | bigint | The value to update the leaf with |
Returns
void
Defined in
verifyProof
▸ verifyProof(proof
): boolean
Verify a proof
Parameters
Name | Type | Description |
---|---|---|
proof | IMerkleProof | The proof to verify |
Returns
boolean
Whether the proof is valid