@dorafactory/maci-sdk 0.0.52 → 0.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -587,6 +587,8 @@ var hashOne = (preImage) => poseidonT3([preImage, BigInt(0)]);
587
587
  // src/libs/crypto/tree.ts
588
588
  var Tree = class _Tree {
589
589
  constructor(degree, depth, zero) {
590
+ this.nodes = [];
591
+ this.zeros = [];
590
592
  this.DEPTH = depth;
591
593
  this.HEIGHT = depth + 1;
592
594
  this.DEGREE = degree;
@@ -600,23 +602,26 @@ var Tree = class _Tree {
600
602
  return this.nodes[0];
601
603
  }
602
604
  initZero(zero) {
603
- this.zeros = new Array(this.HEIGHT);
604
- this.zeros[0] = zero;
605
- for (let i = 1; i < this.zeros.length; i++) {
606
- this.zeros[i] = poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
605
+ const zeros = new Array(this.HEIGHT);
606
+ zeros[0] = zero;
607
+ for (let i = 1; i < zeros.length; i++) {
608
+ const children = new Array(this.DEGREE).fill(zeros[i - 1]);
609
+ zeros[i] = poseidon(children);
607
610
  }
611
+ this.zeros = zeros;
608
612
  }
609
613
  initNodes() {
610
614
  const DEGREE = this.DEGREE;
611
- this.nodes = new Array(this.NODES_COUNT);
615
+ const nodes = new Array(this.NODES_COUNT);
612
616
  for (let d = this.DEPTH; d >= 0; d--) {
613
617
  const size = DEGREE ** d;
614
618
  const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
615
619
  const zero = this.zeros[this.DEPTH - d];
616
620
  for (let i = 0; i < size; i++) {
617
- this.nodes[idx0 + i] = zero;
621
+ nodes[idx0 + i] = zero;
618
622
  }
619
623
  }
624
+ this.nodes = nodes;
620
625
  }
621
626
  initLeaves(leaves) {
622
627
  const DEGREE = this.DEGREE;
@@ -664,7 +669,7 @@ var Tree = class _Tree {
664
669
  for (let i = 0; i < this.DEPTH; i++) {
665
670
  const parentIdx = Math.floor((idx - 1) / this.DEGREE);
666
671
  const childrenIdx0 = parentIdx * this.DEGREE + 1;
667
- pathIdx.push(idx - childrenIdx0);
672
+ pathIdx.push(BigInt(idx - childrenIdx0));
668
673
  idx = parentIdx;
669
674
  }
670
675
  return pathIdx;
@@ -712,13 +717,12 @@ var Tree = class _Tree {
712
717
  const parentIdx = Math.floor((idx - 1) / this.DEGREE);
713
718
  const childrenIdx0 = parentIdx * this.DEGREE + 1;
714
719
  this.nodes[parentIdx] = poseidon(
715
- this.nodes.slice(childrenIdx0, childrenIdx0 + this.DEGREE)
720
+ this.nodes.slice(childrenIdx0, childrenIdx0 + 5)
716
721
  );
717
722
  idx = parentIdx;
718
723
  }
719
724
  }
720
725
  };
721
- var tree_default = Tree;
722
726
 
723
727
  // src/libs/crypto/babyjub.ts
724
728
  import assert3 from "assert";
@@ -927,7 +931,7 @@ var genAddKeyInput = (depth, {
927
931
  BigInt(oldKey.formatedPrivKey),
928
932
  1444992409218394441042n
929
933
  ]);
930
- const tree = new tree_default(5, depth, 0n);
934
+ const tree = new Tree(5, depth, 0n);
931
935
  const leaves = deactivates.map((d) => poseidon(d));
932
936
  tree.initLeaves(leaves);
933
937
  const deactivateRoot = tree.root;