@dorafactory/maci-sdk 0.0.52 → 0.0.55
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/README.md +1 -8
- package/dist/index.js +34 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -17
- package/dist/index.mjs.map +1 -1
- package/dist/libs/crypto/tree.d.ts +13 -14
- package/dist/libs/maci/maci.d.ts +1 -2
- package/dist/maci.d.ts +4 -4
- package/package.json +1 -1
- package/src/libs/crypto/keys.ts +1 -1
- package/src/libs/crypto/tree.ts +33 -30
- package/src/libs/maci/maci.ts +12 -7
- package/src/maci.ts +14 -4
package/README.md
CHANGED
|
@@ -188,17 +188,10 @@ const signupResponse = await client.maci.signup({
|
|
|
188
188
|
gasStation: true, // Whether to use gas station
|
|
189
189
|
});
|
|
190
190
|
|
|
191
|
-
// 5.
|
|
192
|
-
const stateIdx = await client.maci.getStateIdxByPubKey({
|
|
193
|
-
contractAddress: 'dora1...',
|
|
194
|
-
pubKey: maciAccount.pubKey,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// 6. Cast vote
|
|
191
|
+
// 5. Cast vote
|
|
198
192
|
const voteResponse = await client.maci.vote({
|
|
199
193
|
signer: wallet,
|
|
200
194
|
address,
|
|
201
|
-
stateIdx,
|
|
202
195
|
contractAddress: 'dora1...',
|
|
203
196
|
selectedOptions: [
|
|
204
197
|
{ idx: 0, vc: 2 }, // Option index and voting weight
|
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
|
-
|
|
690
|
-
|
|
691
|
-
for (let i = 1; i <
|
|
692
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 +
|
|
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
|
|
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;
|
|
@@ -5501,15 +5505,23 @@ var MACI = class {
|
|
|
5501
5505
|
async vote({
|
|
5502
5506
|
signer,
|
|
5503
5507
|
address,
|
|
5504
|
-
stateIdx,
|
|
5505
5508
|
contractAddress,
|
|
5506
5509
|
selectedOptions,
|
|
5507
5510
|
operatorCoordPubKey,
|
|
5508
5511
|
maciKeypair,
|
|
5509
5512
|
gasStation = false
|
|
5510
5513
|
}) {
|
|
5514
|
+
if (maciKeypair === void 0) {
|
|
5515
|
+
maciKeypair = this.maciKeypair;
|
|
5516
|
+
}
|
|
5517
|
+
const stateIdx = await this.getStateIdxByPubKey({
|
|
5518
|
+
contractAddress,
|
|
5519
|
+
pubKey: maciKeypair.pubKey
|
|
5520
|
+
});
|
|
5511
5521
|
if (stateIdx === -1) {
|
|
5512
|
-
throw new Error(
|
|
5522
|
+
throw new Error(
|
|
5523
|
+
"State index is not set, Please signup or addNewKey first"
|
|
5524
|
+
);
|
|
5513
5525
|
}
|
|
5514
5526
|
try {
|
|
5515
5527
|
const round = await this.indexer.getRoundWithFields(contractAddress, [
|
|
@@ -5561,9 +5573,6 @@ var MACI = class {
|
|
|
5561
5573
|
if (!address) {
|
|
5562
5574
|
address = (await signer.getAccounts())[0].address;
|
|
5563
5575
|
}
|
|
5564
|
-
if (maciKeypair === void 0) {
|
|
5565
|
-
maciKeypair = this.maciKeypair;
|
|
5566
|
-
}
|
|
5567
5576
|
const plan = options.map((o) => {
|
|
5568
5577
|
return [o.idx, o.vc];
|
|
5569
5578
|
});
|
|
@@ -6122,8 +6131,18 @@ var MaciClient2 = class {
|
|
|
6122
6131
|
async getVoiceCreditBalance({
|
|
6123
6132
|
signer,
|
|
6124
6133
|
stateIdx,
|
|
6134
|
+
maciKeypair,
|
|
6125
6135
|
contractAddress
|
|
6126
6136
|
}) {
|
|
6137
|
+
if (maciKeypair === void 0) {
|
|
6138
|
+
maciKeypair = this.maciKeypair;
|
|
6139
|
+
}
|
|
6140
|
+
if (stateIdx === void 0) {
|
|
6141
|
+
stateIdx = await this.getStateIdxByPubKey({
|
|
6142
|
+
contractAddress,
|
|
6143
|
+
pubKey: maciKeypair.pubKey
|
|
6144
|
+
});
|
|
6145
|
+
}
|
|
6127
6146
|
return await this.maci.getVoiceCreditBalance({
|
|
6128
6147
|
signer: this.getSigner(signer),
|
|
6129
6148
|
stateIdx,
|
|
@@ -6283,7 +6302,6 @@ var MaciClient2 = class {
|
|
|
6283
6302
|
async vote({
|
|
6284
6303
|
signer,
|
|
6285
6304
|
address,
|
|
6286
|
-
stateIdx,
|
|
6287
6305
|
contractAddress,
|
|
6288
6306
|
selectedOptions,
|
|
6289
6307
|
operatorCoordPubKey,
|
|
@@ -6293,7 +6311,6 @@ var MaciClient2 = class {
|
|
|
6293
6311
|
return await this.maci.vote({
|
|
6294
6312
|
signer: this.getSigner(signer),
|
|
6295
6313
|
address,
|
|
6296
|
-
stateIdx,
|
|
6297
6314
|
contractAddress,
|
|
6298
6315
|
selectedOptions,
|
|
6299
6316
|
operatorCoordPubKey,
|