Skip to content

Commit a7a4a1d

Browse files
committed
add extra flag on note merkle tree
1 parent af6b814 commit a7a4a1d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ultralane/sdk",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"license": "MIT",
55
"author": "Soham Zemse",
66
"publishConfig": {"access": "public"},

src/note-merkle-tree.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ export class NoteMerkleTree extends MerkleTree {
2323
constructor(
2424
public depth: number,
2525
public numInputs: number = 2,
26-
public numOutputs: number = 1
26+
public numOutputs: number = 1,
27+
insertNoteZero: boolean = true
2728
) {
2829
super(depth);
29-
this.insert(
30-
// Note.zero().commitment()
31-
Field.from(
32-
6693032976676388986107828574443457670072006098614160789085314534828627402874n
33-
)
34-
);
30+
if (insertNoteZero) {
31+
this.insert(
32+
// Note.zero().commitment()
33+
Field.from(
34+
6693032976676388986107828574443457670072006098614160789085314534828627402874n
35+
)
36+
);
37+
}
3538
if (this.numOutputs !== 1) {
3639
throw new Error('exactly 1 outputs are currently supported');
3740
}
@@ -52,6 +55,19 @@ export class NoteMerkleTree extends MerkleTree {
5255
return tree;
5356
}
5457

58+
static fromAllNoteCommitments(
59+
commitments: bigint[],
60+
depth: number,
61+
numInputs: number = 2,
62+
numOutputs: number = 1
63+
) {
64+
let tree = new NoteMerkleTree(depth, numInputs, numOutputs, false);
65+
for (let commitment of commitments) {
66+
tree.insert(Field.from(commitment));
67+
}
68+
return tree;
69+
}
70+
5571
/**
5672
* Spend input notes and create new notes if necessary
5773
* Two source notes and one output note is currently supported

0 commit comments

Comments
 (0)