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
crypto/ts/quinTree.ts:42
Properties
arity
• arity: number
Defined in
crypto/ts/quinTree.ts:15
capacity
• capacity: number
Defined in
crypto/ts/quinTree.ts:33
depth
• depth: number
Defined in
crypto/ts/quinTree.ts:9
hashFunc
• hashFunc: (leaves
: bigint
[]) => bigint
Type declaration
▸ (leaves
): bigint
Parameters
Name | Type |
---|---|
leaves | bigint [] |
Returns
bigint
Defined in
crypto/ts/quinTree.ts:18
nextIndex
• nextIndex: number
= 0
Defined in
crypto/ts/quinTree.ts:21
nodes
• nodes: Node
Defined in
crypto/ts/quinTree.ts:29
numNodes
• numNodes: number
Defined in
crypto/ts/quinTree.ts:31
root
• root: bigint
Defined in
crypto/ts/quinTree.ts:27
zeroValue
• zeroValue: bigint
Defined in
crypto/ts/quinTree.ts:12
zeros
• zeros: bigint
[] = []
Defined in
crypto/ts/quinTree.ts:25
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
crypto/ts/quinTree.ts:272
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
crypto/ts/quinTree.ts:358
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
crypto/ts/quinTree.ts:105
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
crypto/ts/quinTree.ts:248
copy
▸ copy(): IncrementalQuinTree
Copy the tree to a new instance
Returns
The new instance
Defined in
crypto/ts/quinTree.ts:338
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
crypto/ts/quinTree.ts:122
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
crypto/ts/quinTree.ts:168
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
crypto/ts/quinTree.ts:299
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
crypto/ts/quinTree.ts:68
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
crypto/ts/quinTree.ts:327
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
crypto/ts/quinTree.ts:79
verifyProof
▸ verifyProof(proof
): boolean
Verify a proof
Parameters
Name | Type | Description |
---|---|---|
proof | IMerkleProof | The proof to verify |
Returns
boolean
Whether the proof is valid
Defined in
crypto/ts/quinTree.ts:221