@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.js CHANGED
@@ -673,6 +673,8 @@ var hashOne = (preImage) => poseidonT3([preImage, BigInt(0)]);
673
673
  // src/libs/crypto/tree.ts
674
674
  var Tree = class _Tree {
675
675
  constructor(degree, depth, zero) {
676
+ this.nodes = [];
677
+ this.zeros = [];
676
678
  this.DEPTH = depth;
677
679
  this.HEIGHT = depth + 1;
678
680
  this.DEGREE = degree;
@@ -686,23 +688,26 @@ var Tree = class _Tree {
686
688
  return this.nodes[0];
687
689
  }
688
690
  initZero(zero) {
689
- this.zeros = new Array(this.HEIGHT);
690
- this.zeros[0] = zero;
691
- for (let i = 1; i < this.zeros.length; i++) {
692
- this.zeros[i] = poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
691
+ const zeros = new Array(this.HEIGHT);
692
+ zeros[0] = zero;
693
+ for (let i = 1; i < zeros.length; i++) {
694
+ const children = new Array(this.DEGREE).fill(zeros[i - 1]);
695
+ zeros[i] = poseidon(children);
693
696
  }
697
+ this.zeros = zeros;
694
698
  }
695
699
  initNodes() {
696
700
  const DEGREE = this.DEGREE;
697
- this.nodes = new Array(this.NODES_COUNT);
701
+ const nodes = new Array(this.NODES_COUNT);
698
702
  for (let d = this.DEPTH; d >= 0; d--) {
699
703
  const size = DEGREE ** d;
700
704
  const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
701
705
  const zero = this.zeros[this.DEPTH - d];
702
706
  for (let i = 0; i < size; i++) {
703
- this.nodes[idx0 + i] = zero;
707
+ nodes[idx0 + i] = zero;
704
708
  }
705
709
  }
710
+ this.nodes = nodes;
706
711
  }
707
712
  initLeaves(leaves) {
708
713
  const DEGREE = this.DEGREE;
@@ -750,7 +755,7 @@ var Tree = class _Tree {
750
755
  for (let i = 0; i < this.DEPTH; i++) {
751
756
  const parentIdx = Math.floor((idx - 1) / this.DEGREE);
752
757
  const childrenIdx0 = parentIdx * this.DEGREE + 1;
753
- pathIdx.push(idx - childrenIdx0);
758
+ pathIdx.push(BigInt(idx - childrenIdx0));
754
759
  idx = parentIdx;
755
760
  }
756
761
  return pathIdx;
@@ -798,13 +803,12 @@ var Tree = class _Tree {
798
803
  const parentIdx = Math.floor((idx - 1) / this.DEGREE);
799
804
  const childrenIdx0 = parentIdx * this.DEGREE + 1;
800
805
  this.nodes[parentIdx] = poseidon(
801
- this.nodes.slice(childrenIdx0, childrenIdx0 + this.DEGREE)
806
+ this.nodes.slice(childrenIdx0, childrenIdx0 + 5)
802
807
  );
803
808
  idx = parentIdx;
804
809
  }
805
810
  }
806
811
  };
807
- var tree_default = Tree;
808
812
 
809
813
  // src/libs/crypto/babyjub.ts
810
814
  var import_assert3 = __toESM(require("assert"));
@@ -1013,7 +1017,7 @@ var genAddKeyInput = (depth, {
1013
1017
  BigInt(oldKey.formatedPrivKey),
1014
1018
  1444992409218394441042n
1015
1019
  ]);
1016
- const tree = new tree_default(5, depth, 0n);
1020
+ const tree = new Tree(5, depth, 0n);
1017
1021
  const leaves = deactivates.map((d) => poseidon(d));
1018
1022
  tree.initLeaves(leaves);
1019
1023
  const deactivateRoot = tree.root;