@dorafactory/maci-sdk 0.0.51 → 0.0.52

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
@@ -570,9 +570,10 @@ var import_ethers3 = require("ethers");
570
570
  var import_baby_jubjub2 = require("@zk-kit/baby-jubjub");
571
571
  var import_eddsa_poseidon2 = require("@zk-kit/eddsa-poseidon");
572
572
 
573
- // src/libs/crypto/babyjub.ts
573
+ // src/libs/crypto/hashing.ts
574
+ var import_poseidon_cipher = require("@zk-kit/poseidon-cipher");
575
+ var import_ethers2 = require("ethers");
574
576
  var import_assert2 = __toESM(require("assert"));
575
- var import_crypto_js = __toESM(require("crypto-js"));
576
577
 
577
578
  // src/libs/crypto/constants.ts
578
579
  var import_baby_jubjub = require("@zk-kit/baby-jubjub");
@@ -589,100 +590,7 @@ var PAD_KEY_HASH = BigInt(
589
590
  "1309255631273308531193241901289907343161346846555918942743921933037802809814"
590
591
  );
591
592
 
592
- // src/libs/crypto/babyjub.ts
593
- var G1Point = class {
594
- /**
595
- * Create a new instance of G1Point
596
- * @param x the x coordinate
597
- * @param y the y coordinate
598
- */
599
- constructor(x, y) {
600
- (0, import_assert2.default)(x < SNARK_FIELD_SIZE && x >= 0, "G1Point x out of range");
601
- (0, import_assert2.default)(y < SNARK_FIELD_SIZE && y >= 0, "G1Point y out of range");
602
- this.x = x;
603
- this.y = y;
604
- }
605
- /**
606
- * Check whether two points are equal
607
- * @param pt the point to compare with
608
- * @returns whether they are equal or not
609
- */
610
- equals(pt) {
611
- return this.x === pt.x && this.y === pt.y;
612
- }
613
- /**
614
- * Return the point as a contract param in the form of an object
615
- * @returns the point as a contract param
616
- */
617
- asContractParam() {
618
- return {
619
- x: this.x.toString(),
620
- y: this.y.toString()
621
- };
622
- }
623
- };
624
- var G2Point = class {
625
- /**
626
- * Create a new instance of G2Point
627
- * @param x the x coordinate
628
- * @param y the y coordinate
629
- */
630
- constructor(x, y) {
631
- this.checkPointsRange(x, "x");
632
- this.checkPointsRange(y, "y");
633
- this.x = x;
634
- this.y = y;
635
- }
636
- /**
637
- * Check whether two points are equal
638
- * @param pt the point to compare with
639
- * @returns whether they are equal or not
640
- */
641
- equals(pt) {
642
- return this.x[0] === pt.x[0] && this.x[1] === pt.x[1] && this.y[0] === pt.y[0] && this.y[1] === pt.y[1];
643
- }
644
- /**
645
- * Return the point as a contract param in the form of an object
646
- * @returns the point as a contract param
647
- */
648
- asContractParam() {
649
- return {
650
- x: this.x.map((n) => n.toString()),
651
- y: this.y.map((n) => n.toString())
652
- };
653
- }
654
- /**
655
- * Check whether the points are in range
656
- * @param x the x coordinate
657
- * @param type the type of the coordinate
658
- */
659
- checkPointsRange(x, type) {
660
- (0, import_assert2.default)(
661
- x.every((n) => n < SNARK_FIELD_SIZE && n >= 0),
662
- `G2Point ${type} out of range`
663
- );
664
- }
665
- };
666
- var genRandomBabyJubValue = () => {
667
- const min = BigInt(
668
- "6350874878119819312338956282401532410528162663560392320966563075034087161851"
669
- );
670
- let privKey = SNARK_FIELD_SIZE;
671
- do {
672
- const rand = BigInt(
673
- `0x${import_crypto_js.default.lib.WordArray.random(32).toString(import_crypto_js.default.enc.Hex)}`
674
- );
675
- if (rand >= min) {
676
- privKey = rand % SNARK_FIELD_SIZE;
677
- }
678
- } while (privKey >= SNARK_FIELD_SIZE);
679
- return privKey;
680
- };
681
-
682
593
  // src/libs/crypto/hashing.ts
683
- var import_poseidon_cipher = require("@zk-kit/poseidon-cipher");
684
- var import_ethers2 = require("ethers");
685
- var import_assert3 = __toESM(require("assert"));
686
594
  var sha256Hash = (input) => {
687
595
  const types = [];
688
596
  input.forEach(() => {
@@ -697,19 +605,19 @@ var sha256Hash = (input) => {
697
605
  };
698
606
  var poseidon = (inputs) => (0, import_poseidon_cipher.poseidonPerm)([BigInt(0), ...inputs.map((x) => BigInt(x))])[0];
699
607
  var poseidonT3 = (inputs) => {
700
- (0, import_assert3.default)(inputs.length === 2);
608
+ (0, import_assert2.default)(inputs.length === 2);
701
609
  return poseidon(inputs);
702
610
  };
703
611
  var poseidonT4 = (inputs) => {
704
- (0, import_assert3.default)(inputs.length === 3);
612
+ (0, import_assert2.default)(inputs.length === 3);
705
613
  return poseidon(inputs);
706
614
  };
707
615
  var poseidonT5 = (inputs) => {
708
- (0, import_assert3.default)(inputs.length === 4);
616
+ (0, import_assert2.default)(inputs.length === 4);
709
617
  return poseidon(inputs);
710
618
  };
711
619
  var poseidonT6 = (inputs) => {
712
- (0, import_assert3.default)(inputs.length === 5);
620
+ (0, import_assert2.default)(inputs.length === 5);
713
621
  return poseidon(inputs);
714
622
  };
715
623
  var hashLeftRight = (left, right) => poseidonT3([left, right]);
@@ -777,14 +685,14 @@ var Tree = class _Tree {
777
685
  get root() {
778
686
  return this.nodes[0];
779
687
  }
780
- async initZero(zero) {
688
+ initZero(zero) {
781
689
  this.zeros = new Array(this.HEIGHT);
782
690
  this.zeros[0] = zero;
783
691
  for (let i = 1; i < this.zeros.length; i++) {
784
- this.zeros[i] = await poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
692
+ this.zeros[i] = poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
785
693
  }
786
694
  }
787
- async initNodes() {
695
+ initNodes() {
788
696
  const DEGREE = this.DEGREE;
789
697
  this.nodes = new Array(this.NODES_COUNT);
790
698
  for (let d = this.DEPTH; d >= 0; d--) {
@@ -884,12 +792,12 @@ var Tree = class _Tree {
884
792
  subTree._update(this.LEAVES_IDX_0 + length - 1);
885
793
  return subTree;
886
794
  }
887
- async _update(nodeIdx) {
795
+ _update(nodeIdx) {
888
796
  let idx = nodeIdx;
889
797
  while (idx > 0) {
890
798
  const parentIdx = Math.floor((idx - 1) / this.DEGREE);
891
799
  const childrenIdx0 = parentIdx * this.DEGREE + 1;
892
- this.nodes[parentIdx] = await poseidon(
800
+ this.nodes[parentIdx] = poseidon(
893
801
  this.nodes.slice(childrenIdx0, childrenIdx0 + this.DEGREE)
894
802
  );
895
803
  idx = parentIdx;
@@ -898,6 +806,97 @@ var Tree = class _Tree {
898
806
  };
899
807
  var tree_default = Tree;
900
808
 
809
+ // src/libs/crypto/babyjub.ts
810
+ var import_assert3 = __toESM(require("assert"));
811
+ var import_crypto_js = __toESM(require("crypto-js"));
812
+ var G1Point = class {
813
+ /**
814
+ * Create a new instance of G1Point
815
+ * @param x the x coordinate
816
+ * @param y the y coordinate
817
+ */
818
+ constructor(x, y) {
819
+ (0, import_assert3.default)(x < SNARK_FIELD_SIZE && x >= 0, "G1Point x out of range");
820
+ (0, import_assert3.default)(y < SNARK_FIELD_SIZE && y >= 0, "G1Point y out of range");
821
+ this.x = x;
822
+ this.y = y;
823
+ }
824
+ /**
825
+ * Check whether two points are equal
826
+ * @param pt the point to compare with
827
+ * @returns whether they are equal or not
828
+ */
829
+ equals(pt) {
830
+ return this.x === pt.x && this.y === pt.y;
831
+ }
832
+ /**
833
+ * Return the point as a contract param in the form of an object
834
+ * @returns the point as a contract param
835
+ */
836
+ asContractParam() {
837
+ return {
838
+ x: this.x.toString(),
839
+ y: this.y.toString()
840
+ };
841
+ }
842
+ };
843
+ var G2Point = class {
844
+ /**
845
+ * Create a new instance of G2Point
846
+ * @param x the x coordinate
847
+ * @param y the y coordinate
848
+ */
849
+ constructor(x, y) {
850
+ this.checkPointsRange(x, "x");
851
+ this.checkPointsRange(y, "y");
852
+ this.x = x;
853
+ this.y = y;
854
+ }
855
+ /**
856
+ * Check whether two points are equal
857
+ * @param pt the point to compare with
858
+ * @returns whether they are equal or not
859
+ */
860
+ equals(pt) {
861
+ return this.x[0] === pt.x[0] && this.x[1] === pt.x[1] && this.y[0] === pt.y[0] && this.y[1] === pt.y[1];
862
+ }
863
+ /**
864
+ * Return the point as a contract param in the form of an object
865
+ * @returns the point as a contract param
866
+ */
867
+ asContractParam() {
868
+ return {
869
+ x: this.x.map((n) => n.toString()),
870
+ y: this.y.map((n) => n.toString())
871
+ };
872
+ }
873
+ /**
874
+ * Check whether the points are in range
875
+ * @param x the x coordinate
876
+ * @param type the type of the coordinate
877
+ */
878
+ checkPointsRange(x, type) {
879
+ (0, import_assert3.default)(
880
+ x.every((n) => n < SNARK_FIELD_SIZE && n >= 0),
881
+ `G2Point ${type} out of range`
882
+ );
883
+ }
884
+ };
885
+ var genRandomBabyJubValue = () => {
886
+ const min = 6350874878119819312338956282401532410528162663560392320966563075034087161851n;
887
+ let rand;
888
+ while (true) {
889
+ rand = BigInt(
890
+ `0x${import_crypto_js.default.lib.WordArray.random(32).toString(import_crypto_js.default.enc.Hex)}`
891
+ );
892
+ if (rand >= min) {
893
+ break;
894
+ }
895
+ }
896
+ const privKey = rand % 2n ** 253n;
897
+ return privKey;
898
+ };
899
+
901
900
  // src/libs/crypto/keys.ts
902
901
  var SNARK_FIELD_SIZE2 = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
903
902
  var genPrivKey = () => BigInt(`0x${import_crypto_js2.default.lib.WordArray.random(32).toString(import_crypto_js2.default.enc.Hex)}`);
@@ -6203,6 +6202,15 @@ var MaciClient2 = class {
6203
6202
  contractAddress
6204
6203
  });
6205
6204
  }
6205
+ async getRounds(after, limit) {
6206
+ const rounds = await this.indexer.getRounds(after || "", limit || 10);
6207
+ if (isErrorResponse(rounds)) {
6208
+ throw new Error(
6209
+ `Failed to get rounds: ${rounds.code} ${rounds.error.message}`
6210
+ );
6211
+ }
6212
+ return rounds;
6213
+ }
6206
6214
  async getRoundInfo({ contractAddress }) {
6207
6215
  return await this.maci.getRoundInfo({ contractAddress });
6208
6216
  }