@maci-protocol/sdk 0.0.0-ci.9342f07 → 0.0.0-ci.9819a21
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/LICENSE +1 -2
- package/build/package.json +16 -8
- package/build/ts/browser/index.d.ts +4 -2
- package/build/ts/browser/index.d.ts.map +1 -1
- package/build/ts/browser/index.js +7 -1
- package/build/ts/browser/index.js.map +1 -1
- package/build/ts/browser/joinPoll.d.ts +4 -2
- package/build/ts/browser/joinPoll.d.ts.map +1 -1
- package/build/ts/browser/joinPoll.js +21 -17
- package/build/ts/browser/joinPoll.js.map +1 -1
- package/build/ts/browser/utils.d.ts +2 -2
- package/build/ts/browser/utils.d.ts.map +1 -1
- package/build/ts/browser/utils.js +3 -3
- package/build/ts/browser/utils.js.map +1 -1
- package/build/ts/deploy/index.d.ts +2 -2
- package/build/ts/deploy/index.d.ts.map +1 -1
- package/build/ts/deploy/index.js +3 -3
- package/build/ts/deploy/index.js.map +1 -1
- package/build/ts/deploy/maci.js +1 -1
- package/build/ts/deploy/maci.js.map +1 -1
- package/build/ts/deploy/poll.d.ts +1 -1
- package/build/ts/deploy/poll.d.ts.map +1 -1
- package/build/ts/deploy/poll.js +13 -9
- package/build/ts/deploy/poll.js.map +1 -1
- package/build/ts/deploy/types.d.ts +19 -10
- package/build/ts/deploy/types.d.ts.map +1 -1
- package/build/ts/deploy/utils.js +1 -1
- package/build/ts/deploy/utils.js.map +1 -1
- package/build/ts/deploy/verifyingKeysRegistry.d.ts +7 -0
- package/build/ts/deploy/verifyingKeysRegistry.d.ts.map +1 -0
- package/build/ts/deploy/verifyingKeysRegistry.js +14 -0
- package/build/ts/deploy/verifyingKeysRegistry.js.map +1 -0
- package/build/ts/index.d.ts +3 -2
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +16 -9
- package/build/ts/index.js.map +1 -1
- package/build/ts/maci/state.d.ts +1 -1
- package/build/ts/maci/state.js +8 -8
- package/build/ts/maci/state.js.map +1 -1
- package/build/ts/maci/types.d.ts +1 -1
- package/build/ts/maciKeys/__tests__/keypair.test.js +7 -7
- package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -1
- package/build/ts/maciKeys/__tests__/publicKeys.test.js +7 -7
- package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -1
- package/build/ts/maciKeys/keypair.d.ts.map +1 -1
- package/build/ts/maciKeys/keypair.js +4 -3
- package/build/ts/maciKeys/keypair.js.map +1 -1
- package/build/ts/maciKeys/publicKeys.d.ts +2 -2
- package/build/ts/maciKeys/publicKeys.d.ts.map +1 -1
- package/build/ts/maciKeys/publicKeys.js +6 -6
- package/build/ts/maciKeys/publicKeys.js.map +1 -1
- package/build/ts/maciKeys/types.d.ts +5 -0
- package/build/ts/maciKeys/types.d.ts.map +1 -1
- package/build/ts/poll/poll.d.ts.map +1 -1
- package/build/ts/poll/poll.js +9 -9
- package/build/ts/poll/poll.js.map +1 -1
- package/build/ts/poll/types.d.ts +6 -6
- package/build/ts/poll/types.d.ts.map +1 -1
- package/build/ts/proof/__tests__/download.test.js +8 -5
- package/build/ts/proof/__tests__/download.test.js.map +1 -1
- package/build/ts/proof/download.d.ts +3 -3
- package/build/ts/proof/download.d.ts.map +1 -1
- package/build/ts/proof/download.js +5 -7
- package/build/ts/proof/download.js.map +1 -1
- package/build/ts/proof/generate.d.ts +2 -2
- package/build/ts/proof/generate.d.ts.map +1 -1
- package/build/ts/proof/generate.js +29 -23
- package/build/ts/proof/generate.js.map +1 -1
- package/build/ts/proof/prove.js +13 -13
- package/build/ts/proof/prove.js.map +1 -1
- package/build/ts/proof/types.d.ts +40 -14
- package/build/ts/proof/types.d.ts.map +1 -1
- package/build/ts/proof/utils.d.ts +10 -0
- package/build/ts/proof/utils.d.ts.map +1 -0
- package/build/ts/proof/utils.js +24 -0
- package/build/ts/proof/utils.js.map +1 -0
- package/build/ts/relayer/__tests__/messages.test.js +1 -1
- package/build/ts/relayer/__tests__/messages.test.js.map +1 -1
- package/build/ts/relayer/__tests__/utils.test.js +3 -3
- package/build/ts/relayer/__tests__/utils.test.js.map +1 -1
- package/build/ts/relayer/messages.js +1 -1
- package/build/ts/relayer/utils.js +1 -1
- package/build/ts/relayer/utils.js.map +1 -1
- package/build/ts/subgraph/index.d.ts +3 -0
- package/build/ts/subgraph/index.d.ts.map +1 -0
- package/build/ts/subgraph/index.js +18 -0
- package/build/ts/subgraph/index.js.map +1 -0
- package/build/ts/subgraph/maciSubgraph.d.ts +28 -0
- package/build/ts/subgraph/maciSubgraph.d.ts.map +1 -0
- package/build/ts/subgraph/maciSubgraph.js +64 -0
- package/build/ts/subgraph/maciSubgraph.js.map +1 -0
- package/build/ts/subgraph/types.d.ts +20 -0
- package/build/ts/subgraph/types.d.ts.map +1 -0
- package/build/ts/subgraph/types.js +3 -0
- package/build/ts/subgraph/types.js.map +1 -0
- package/build/ts/tally/commitments.d.ts.map +1 -1
- package/build/ts/tally/commitments.js +8 -7
- package/build/ts/tally/commitments.js.map +1 -1
- package/build/ts/tally/index.d.ts +2 -1
- package/build/ts/tally/index.d.ts.map +1 -1
- package/build/ts/tally/index.js +5 -1
- package/build/ts/tally/index.js.map +1 -1
- package/build/ts/tally/results.d.ts +20 -0
- package/build/ts/tally/results.d.ts.map +1 -0
- package/build/ts/tally/results.js +49 -0
- package/build/ts/tally/results.js.map +1 -0
- package/build/ts/tally/types.d.ts +55 -15
- package/build/ts/tally/types.d.ts.map +1 -1
- package/build/ts/tally/utils.d.ts +3 -3
- package/build/ts/tally/utils.d.ts.map +1 -1
- package/build/ts/tally/utils.js +10 -10
- package/build/ts/tally/utils.js.map +1 -1
- package/build/ts/tally/verification.d.ts +1 -1
- package/build/ts/tally/verification.d.ts.map +1 -1
- package/build/ts/tally/verification.js +10 -10
- package/build/ts/tally/verification.js.map +1 -1
- package/build/ts/trees/index.d.ts +2 -2
- package/build/ts/trees/index.d.ts.map +1 -1
- package/build/ts/trees/index.js +3 -1
- package/build/ts/trees/index.js.map +1 -1
- package/build/ts/trees/stateTree.d.ts +23 -1
- package/build/ts/trees/stateTree.d.ts.map +1 -1
- package/build/ts/trees/stateTree.js +74 -13
- package/build/ts/trees/stateTree.js.map +1 -1
- package/build/ts/trees/types.d.ts +11 -2
- package/build/ts/trees/types.d.ts.map +1 -1
- package/build/ts/user/index.d.ts +2 -2
- package/build/ts/user/index.d.ts.map +1 -1
- package/build/ts/user/index.js +5 -1
- package/build/ts/user/index.js.map +1 -1
- package/build/ts/user/joinPoll.d.ts +1 -1
- package/build/ts/user/joinPoll.d.ts.map +1 -1
- package/build/ts/user/joinPoll.js +11 -11
- package/build/ts/user/joinPoll.js.map +1 -1
- package/build/ts/user/signup.d.ts +3 -3
- package/build/ts/user/signup.d.ts.map +1 -1
- package/build/ts/user/signup.js +26 -21
- package/build/ts/user/signup.js.map +1 -1
- package/build/ts/user/types.d.ts +63 -19
- package/build/ts/user/types.d.ts.map +1 -1
- package/build/ts/user/utils.d.ts +34 -14
- package/build/ts/user/utils.d.ts.map +1 -1
- package/build/ts/user/utils.js +91 -57
- package/build/ts/user/utils.js.map +1 -1
- package/build/ts/utils/index.d.ts +1 -1
- package/build/ts/utils/index.d.ts.map +1 -1
- package/build/ts/utils/index.js +2 -1
- package/build/ts/utils/index.js.map +1 -1
- package/build/ts/utils/params.d.ts +1 -1
- package/build/ts/utils/params.d.ts.map +1 -1
- package/build/ts/utils/params.js +3 -3
- package/build/ts/utils/params.js.map +1 -1
- package/build/ts/utils/proofs.d.ts +2 -2
- package/build/ts/utils/proofs.d.ts.map +1 -1
- package/build/ts/utils/proofs.js +4 -4
- package/build/ts/utils/proofs.js.map +1 -1
- package/build/ts/utils/types.d.ts +2 -2
- package/build/ts/utils/types.d.ts.map +1 -1
- package/build/ts/utils/utils.d.ts +5 -0
- package/build/ts/utils/utils.d.ts.map +1 -1
- package/build/ts/utils/utils.js +13 -1
- package/build/ts/utils/utils.js.map +1 -1
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts +1 -1
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts.map +1 -1
- package/build/ts/verifyingKeys/checkVerifyingKeys.js +18 -19
- package/build/ts/verifyingKeys/checkVerifyingKeys.js.map +1 -1
- package/build/ts/verifyingKeys/index.d.ts +2 -2
- package/build/ts/verifyingKeys/index.d.ts.map +1 -1
- package/build/ts/verifyingKeys/index.js +5 -5
- package/build/ts/verifyingKeys/index.js.map +1 -1
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts +1 -1
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts.map +1 -1
- package/build/ts/verifyingKeys/setVerifyingKeys.js +75 -41
- package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -1
- package/build/ts/verifyingKeys/types.d.ts +56 -48
- package/build/ts/verifyingKeys/types.d.ts.map +1 -1
- package/build/ts/verifyingKeys/utils.d.ts +10 -10
- package/build/ts/verifyingKeys/utils.d.ts.map +1 -1
- package/build/ts/verifyingKeys/utils.js +75 -60
- package/build/ts/verifyingKeys/utils.js.map +1 -1
- package/build/ts/vote/generate.d.ts +1 -1
- package/build/ts/vote/generate.d.ts.map +1 -1
- package/build/ts/vote/generate.js +4 -4
- package/build/ts/vote/generate.js.map +1 -1
- package/build/ts/vote/index.d.ts +2 -1
- package/build/ts/vote/index.d.ts.map +1 -1
- package/build/ts/vote/index.js +4 -2
- package/build/ts/vote/index.js.map +1 -1
- package/build/ts/vote/invalidate.js +4 -4
- package/build/ts/vote/invalidate.js.map +1 -1
- package/build/ts/vote/publish.d.ts +1 -1
- package/build/ts/vote/publish.d.ts.map +1 -1
- package/build/ts/vote/publish.js +19 -19
- package/build/ts/vote/publish.js.map +1 -1
- package/build/ts/vote/submit.js +2 -2
- package/build/ts/vote/submit.js.map +1 -1
- package/build/ts/vote/types.d.ts +6 -6
- package/build/ts/vote/types.d.ts.map +1 -1
- package/build/ts/vote/utils.d.ts +2 -2
- package/build/ts/vote/utils.d.ts.map +1 -1
- package/build/ts/vote/utils.js +5 -5
- package/build/ts/vote/utils.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +22 -14
- package/build/ts/deploy/vkRegistry.d.ts +0 -7
- package/build/ts/deploy/vkRegistry.d.ts.map +0 -1
- package/build/ts/deploy/vkRegistry.js +0 -14
- package/build/ts/deploy/vkRegistry.js.map +0 -1
- package/build/ts/proof/constants.d.ts +0 -17
- package/build/ts/proof/constants.d.ts.map +0 -1
- package/build/ts/proof/constants.js +0 -20
- package/build/ts/proof/constants.js.map +0 -1
package/build/ts/trees/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateSignUpTree = void 0;
|
|
3
|
+
exports.generateSignUpTreeFromKeys = exports.generateSignUpTreeWithEndKey = exports.generateSignUpTree = void 0;
|
|
4
4
|
var stateTree_1 = require("./stateTree");
|
|
5
5
|
Object.defineProperty(exports, "generateSignUpTree", { enumerable: true, get: function () { return stateTree_1.generateSignUpTree; } });
|
|
6
|
+
Object.defineProperty(exports, "generateSignUpTreeWithEndKey", { enumerable: true, get: function () { return stateTree_1.generateSignUpTreeWithEndKey; } });
|
|
7
|
+
Object.defineProperty(exports, "generateSignUpTreeFromKeys", { enumerable: true, get: function () { return stateTree_1.generateSignUpTreeFromKeys; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/trees/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/trees/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2G;AAAlG,+GAAA,kBAAkB,OAAA;AAAE,yHAAA,4BAA4B,OAAA;AAAE,uHAAA,0BAA0B,OAAA"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PublicKey } from "@maci-protocol/domainobjs";
|
|
2
|
+
import { LeanIMT } from "@zk-kit/lean-imt";
|
|
3
|
+
import type { IGenerateSignUpTreeArgs, IGenerateSignUpTree, IGenerateSignUpTreeWithEndKeyArgs } from "./types";
|
|
2
4
|
/**
|
|
3
5
|
* Generate a State tree object from the events of a MACI smart contracts
|
|
4
6
|
* @param provider - the ethereum provider
|
|
@@ -10,4 +12,24 @@ import type { IGenerateSignUpTreeArgs, IGenerateSignUpTree } from "./types";
|
|
|
10
12
|
* @returns State tree
|
|
11
13
|
*/
|
|
12
14
|
export declare const generateSignUpTree: ({ provider, address, fromBlock, blocksPerRequest, endBlock, sleepAmount, }: IGenerateSignUpTreeArgs) => Promise<IGenerateSignUpTree>;
|
|
15
|
+
/**
|
|
16
|
+
* Generate a State tree object from the events of a MACI smart contracts
|
|
17
|
+
* @param provider - the ethereum provider
|
|
18
|
+
* @param address - the address of the MACI contract
|
|
19
|
+
* @param fromBlock - the block number from which to start fetching events
|
|
20
|
+
* @param blocksPerRequest - the number of blocks to fetch in each request
|
|
21
|
+
* @param endBlock - the block number at which to stop fetching events
|
|
22
|
+
* @param sleepAmount - the amount of time to sleep between each request
|
|
23
|
+
* @param userPublicKey - the user public key where we end/stop the signUpTree replica.
|
|
24
|
+
* If user public key is 4th then the returned signUpTree will have only 4 leaves
|
|
25
|
+
* (does not matter if MACI' signUpTree has more).
|
|
26
|
+
* @returns State tree
|
|
27
|
+
*/
|
|
28
|
+
export declare const generateSignUpTreeWithEndKey: ({ provider, address, fromBlock, blocksPerRequest, endBlock, sleepAmount, userPublicKey, }: IGenerateSignUpTreeWithEndKeyArgs) => Promise<IGenerateSignUpTree>;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a sign up tree from the public keys
|
|
31
|
+
* @param publicKeys - the public keys to generate the sign up tree from
|
|
32
|
+
* @returns the sign up tree
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateSignUpTreeFromKeys: (publicKeys: PublicKey[]) => LeanIMT;
|
|
13
35
|
//# sourceMappingURL=stateTree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateTree.d.ts","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stateTree.d.ts","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAA4B,MAAM,kBAAkB,CAAC;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAI/G;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAU,4EAOtC,uBAAuB,KAAG,OAAO,CAAC,mBAAmB,CAoCvD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,4BAA4B,GAAU,2FAQhD,iCAAiC,KAAG,OAAO,CAAC,mBAAmB,CA8CjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,GAAI,YAAY,SAAS,EAAE,KAAG,OAMpE,CAAC"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateSignUpTree = void 0;
|
|
3
|
+
exports.generateSignUpTreeFromKeys = exports.generateSignUpTreeWithEndKey = exports.generateSignUpTree = void 0;
|
|
7
4
|
/* eslint-disable no-underscore-dangle */
|
|
8
5
|
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
9
6
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
10
7
|
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
11
8
|
const lean_imt_1 = require("@zk-kit/lean-imt");
|
|
12
|
-
const assert_1 = __importDefault(require("assert"));
|
|
13
9
|
const utils_1 = require("../utils/utils");
|
|
14
10
|
/**
|
|
15
11
|
* Generate a State tree object from the events of a MACI smart contracts
|
|
@@ -26,7 +22,7 @@ const generateSignUpTree = async ({ provider, address, fromBlock = 0, blocksPerR
|
|
|
26
22
|
const maciContract = typechain_types_1.MACI__factory.connect(address, provider);
|
|
27
23
|
const signUpTree = new lean_imt_1.LeanIMT(crypto_1.hashLeanIMT);
|
|
28
24
|
signUpTree.insert(crypto_1.PAD_KEY_HASH);
|
|
29
|
-
const
|
|
25
|
+
const publicKeys = [];
|
|
30
26
|
// Fetch event logs in batches (lastBlock inclusive)
|
|
31
27
|
for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) {
|
|
32
28
|
// the last block batch will be either current iteration block + blockPerRequest
|
|
@@ -35,12 +31,11 @@ const generateSignUpTree = async ({ provider, address, fromBlock = 0, blocksPerR
|
|
|
35
31
|
// eslint-disable-next-line no-await-in-loop
|
|
36
32
|
const signUpLogs = await maciContract.queryFilter(maciContract.filters.SignUp(), i, toBlock);
|
|
37
33
|
signUpLogs.forEach((event) => {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
signUpTree.insert((0, crypto_1.hashLeftRight)(pubKeyX, pubKeyY));
|
|
34
|
+
const publicKeyX = event.args._userPublicKeyX;
|
|
35
|
+
const publicKeyY = event.args._userPublicKeyY;
|
|
36
|
+
const publicKey = new domainobjs_1.PublicKey([publicKeyX, publicKeyY]);
|
|
37
|
+
publicKeys.push(publicKey);
|
|
38
|
+
signUpTree.insert((0, crypto_1.hashLeftRight)(publicKeyX, publicKeyY));
|
|
44
39
|
});
|
|
45
40
|
if (sleepAmount) {
|
|
46
41
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -49,8 +44,74 @@ const generateSignUpTree = async ({ provider, address, fromBlock = 0, blocksPerR
|
|
|
49
44
|
}
|
|
50
45
|
return {
|
|
51
46
|
signUpTree,
|
|
52
|
-
|
|
47
|
+
publicKeys,
|
|
53
48
|
};
|
|
54
49
|
};
|
|
55
50
|
exports.generateSignUpTree = generateSignUpTree;
|
|
51
|
+
/**
|
|
52
|
+
* Generate a State tree object from the events of a MACI smart contracts
|
|
53
|
+
* @param provider - the ethereum provider
|
|
54
|
+
* @param address - the address of the MACI contract
|
|
55
|
+
* @param fromBlock - the block number from which to start fetching events
|
|
56
|
+
* @param blocksPerRequest - the number of blocks to fetch in each request
|
|
57
|
+
* @param endBlock - the block number at which to stop fetching events
|
|
58
|
+
* @param sleepAmount - the amount of time to sleep between each request
|
|
59
|
+
* @param userPublicKey - the user public key where we end/stop the signUpTree replica.
|
|
60
|
+
* If user public key is 4th then the returned signUpTree will have only 4 leaves
|
|
61
|
+
* (does not matter if MACI' signUpTree has more).
|
|
62
|
+
* @returns State tree
|
|
63
|
+
*/
|
|
64
|
+
const generateSignUpTreeWithEndKey = async ({ provider, address, fromBlock = 0, blocksPerRequest = 50, endBlock, sleepAmount, userPublicKey, }) => {
|
|
65
|
+
const lastBlock = endBlock || (await provider.getBlockNumber());
|
|
66
|
+
const maciContract = typechain_types_1.MACI__factory.connect(address, provider);
|
|
67
|
+
const signUpTree = new lean_imt_1.LeanIMT(crypto_1.hashLeanIMT);
|
|
68
|
+
signUpTree.insert(crypto_1.PAD_KEY_HASH);
|
|
69
|
+
const publicKeys = [];
|
|
70
|
+
// Fetch event logs in batches (lastBlock inclusive)
|
|
71
|
+
for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) {
|
|
72
|
+
// the last block batch will be either current iteration block + blockPerRequest
|
|
73
|
+
// or the end block if it is set
|
|
74
|
+
const toBlock = i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest;
|
|
75
|
+
// eslint-disable-next-line no-await-in-loop
|
|
76
|
+
const signUpLogs = await maciContract.queryFilter(maciContract.filters.SignUp(), i, toBlock);
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
78
|
+
for (let j = 0; j < signUpLogs.length; j += 1) {
|
|
79
|
+
const event = signUpLogs[j];
|
|
80
|
+
const publicKeyX = event.args._userPublicKeyX;
|
|
81
|
+
const publicKeyY = event.args._userPublicKeyY;
|
|
82
|
+
const publicKey = new domainobjs_1.PublicKey([publicKeyX, publicKeyY]);
|
|
83
|
+
publicKeys.push(publicKey);
|
|
84
|
+
signUpTree.insert((0, crypto_1.hashLeftRight)(publicKeyX, publicKeyY));
|
|
85
|
+
// early return cause we found the user
|
|
86
|
+
if (publicKey.equals(userPublicKey)) {
|
|
87
|
+
return {
|
|
88
|
+
signUpTree,
|
|
89
|
+
publicKeys,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (sleepAmount) {
|
|
94
|
+
// eslint-disable-next-line no-await-in-loop
|
|
95
|
+
await (0, utils_1.sleep)(sleepAmount);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
signUpTree,
|
|
100
|
+
publicKeys,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
exports.generateSignUpTreeWithEndKey = generateSignUpTreeWithEndKey;
|
|
104
|
+
/**
|
|
105
|
+
* Generate a sign up tree from the public keys
|
|
106
|
+
* @param publicKeys - the public keys to generate the sign up tree from
|
|
107
|
+
* @returns the sign up tree
|
|
108
|
+
*/
|
|
109
|
+
const generateSignUpTreeFromKeys = (publicKeys) => {
|
|
110
|
+
const signUpTree = new lean_imt_1.LeanIMT(crypto_1.hashLeanIMT);
|
|
111
|
+
publicKeys.forEach((key) => {
|
|
112
|
+
signUpTree.insert(key.hash());
|
|
113
|
+
});
|
|
114
|
+
return signUpTree;
|
|
115
|
+
};
|
|
116
|
+
exports.generateSignUpTreeFromKeys = generateSignUpTreeFromKeys;
|
|
56
117
|
//# sourceMappingURL=stateTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateTree.js","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stateTree.js","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,8EAAwF;AACxF,kDAAiF;AACjF,0DAAsD;AACtD,+CAAqE;AAIrE,0CAAuC;AAEvC;;;;;;;;;GASG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,QAAQ,EACR,OAAO,EACP,SAAS,GAAG,CAAC,EACb,gBAAgB,GAAG,EAAE,EACrB,QAAQ,EACR,WAAW,GACa,EAAgC,EAAE;IAC1D,MAAM,SAAS,GAAG,QAAQ,IAAI,CAAC,MAAM,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;IAEhE,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,kBAAO,CAAC,oBAAkC,CAAC,CAAC;IACnE,UAAU,CAAC,MAAM,CAAC,qBAAY,CAAC,CAAC;IAChC,MAAM,UAAU,GAAgB,EAAE,CAAC;IAEnC,oDAAoD;IACpD,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC,IAAI,gBAAgB,GAAG,CAAC,EAAE,CAAC;QAClE,gFAAgF;QAChF,gCAAgC;QAChC,MAAM,OAAO,GAAG,CAAC,GAAG,gBAAgB,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;QAErF,4CAA4C;QAC5C,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7F,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,MAAM,UAAU,GAAG,KAAK,CA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O,CAAC,oBAAW,CAAC,CAAC;IAC5C,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AANW,QAAA,0BAA0B,8BAMrC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PublicKey } from "@maci-protocol/domainobjs";
|
|
2
2
|
import type { LeanIMT } from "@zk-kit/lean-imt";
|
|
3
3
|
import type { Provider } from "ethers";
|
|
4
4
|
/**
|
|
@@ -30,6 +30,15 @@ export interface IGenerateSignUpTreeArgs {
|
|
|
30
30
|
*/
|
|
31
31
|
sleepAmount?: number;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* An interface that represents arguments of generation sign up tree which stops fetching at a given public key
|
|
35
|
+
*/
|
|
36
|
+
export interface IGenerateSignUpTreeWithEndKeyArgs extends IGenerateSignUpTreeArgs {
|
|
37
|
+
/**
|
|
38
|
+
* The public key of the user
|
|
39
|
+
*/
|
|
40
|
+
userPublicKey: PublicKey;
|
|
41
|
+
}
|
|
33
42
|
/**
|
|
34
43
|
* An interface that represents sign up tree and state leaves
|
|
35
44
|
*/
|
|
@@ -41,6 +50,6 @@ export interface IGenerateSignUpTree {
|
|
|
41
50
|
/**
|
|
42
51
|
* State leaves
|
|
43
52
|
*/
|
|
44
|
-
|
|
53
|
+
publicKeys: PublicKey[];
|
|
45
54
|
}
|
|
46
55
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/trees/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/trees/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iCAAkC,SAAQ,uBAAuB;IAChF;;OAEG;IACH,aAAa,EAAE,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB"}
|
package/build/ts/user/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { joinPoll } from "./joinPoll";
|
|
2
2
|
export { getSignedupUserData, signup, hasUserSignedUp } from "./signup";
|
|
3
|
-
export { getJoinedUserData, hasUserJoinedPoll } from "./utils";
|
|
4
|
-
export type { IJoinedUserArgs, IIsRegisteredUser, IIsJoinedUser, ISignupArgs, IRegisteredUserArgs, IPollJoinedCircuitInputs, IPollJoiningCircuitInputs, IJoinPollArgs, IIsNullifierOnChainArgs, IGetPollJoiningCircuitEventsArgs, IGetPollJoiningCircuitInputsFromStateFileArgs, IJoinPollData, IParsePollJoinEventsArgs, IParseSignupEventsArgs, ISignupData, IHasUserSignedUpArgs, } from "./types";
|
|
3
|
+
export { getJoinedUserData, hasUserJoinedPoll, generateMaciStateTree, generateMaciStateTreeWithEndKey, getPollJoiningCircuitEvents, joiningCircuitInputs, } from "./utils";
|
|
4
|
+
export type { IJoinedUserArgs, IIsRegisteredUser, IIsJoinedUser, ISignupArgs, IRegisteredUserArgs, IPollJoinedCircuitInputs, IPollJoiningCircuitInputs, IJoinPollArgs, IIsNullifierOnChainArgs, IGetPollJoiningCircuitEventsArgs, IGetPollJoiningCircuitInputsFromStateFileArgs, IJoinPollData, IParsePollJoinEventsArgs, IParseSignupEventsArgs, ISignupData, IHasUserSignedUpArgs, IGenerateMaciStateTreeArgs, IGenerateMaciStateTreeWithEndKeyArgs, } from "./types";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,+BAA+B,EAC/B,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACb,uBAAuB,EACvB,gCAAgC,EAChC,6CAA6C,EAC7C,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,SAAS,CAAC"}
|
package/build/ts/user/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.hasUserSignedUp = exports.signup = exports.getSignedupUserData = exports.joinPoll = void 0;
|
|
3
|
+
exports.joiningCircuitInputs = exports.getPollJoiningCircuitEvents = exports.generateMaciStateTreeWithEndKey = exports.generateMaciStateTree = exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.hasUserSignedUp = exports.signup = exports.getSignedupUserData = exports.joinPoll = void 0;
|
|
4
4
|
var joinPoll_1 = require("./joinPoll");
|
|
5
5
|
Object.defineProperty(exports, "joinPoll", { enumerable: true, get: function () { return joinPoll_1.joinPoll; } });
|
|
6
6
|
var signup_1 = require("./signup");
|
|
@@ -10,4 +10,8 @@ Object.defineProperty(exports, "hasUserSignedUp", { enumerable: true, get: funct
|
|
|
10
10
|
var utils_1 = require("./utils");
|
|
11
11
|
Object.defineProperty(exports, "getJoinedUserData", { enumerable: true, get: function () { return utils_1.getJoinedUserData; } });
|
|
12
12
|
Object.defineProperty(exports, "hasUserJoinedPoll", { enumerable: true, get: function () { return utils_1.hasUserJoinedPoll; } });
|
|
13
|
+
Object.defineProperty(exports, "generateMaciStateTree", { enumerable: true, get: function () { return utils_1.generateMaciStateTree; } });
|
|
14
|
+
Object.defineProperty(exports, "generateMaciStateTreeWithEndKey", { enumerable: true, get: function () { return utils_1.generateMaciStateTreeWithEndKey; } });
|
|
15
|
+
Object.defineProperty(exports, "getPollJoiningCircuitEvents", { enumerable: true, get: function () { return utils_1.getPollJoiningCircuitEvents; } });
|
|
16
|
+
Object.defineProperty(exports, "joiningCircuitInputs", { enumerable: true, get: function () { return utils_1.joiningCircuitInputs; } });
|
|
13
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,mCAAwE;AAA/D,6GAAA,mBAAmB,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,yGAAA,eAAe,OAAA;AACrD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,mCAAwE;AAA/D,6GAAA,mBAAmB,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,yGAAA,eAAe,OAAA;AACrD,iCAOiB;AANf,0GAAA,iBAAiB,OAAA;AACjB,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA;AACrB,wHAAA,+BAA+B,OAAA;AAC/B,oHAAA,2BAA2B,OAAA;AAC3B,6GAAA,oBAAoB,OAAA"}
|
|
@@ -4,5 +4,5 @@ import type { IJoinPollData, IJoinPollArgs } from "./types";
|
|
|
4
4
|
* @param {IJoinPollArgs} args - The arguments for the join poll command
|
|
5
5
|
* @returns {IJoinPollData} The poll state index of the joined user and transaction hash
|
|
6
6
|
*/
|
|
7
|
-
export declare const joinPoll: ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark,
|
|
7
|
+
export declare const joinPoll: ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark, pollWitnessGenerator, pollWasm, sgDataArg, ivcpDataArg, }: IJoinPollArgs) => Promise<IJoinPollData>;
|
|
8
8
|
//# sourceMappingURL=joinPoll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joinPoll.d.ts","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQ5D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,
|
|
1
|
+
{"version":3,"file":"joinPoll.d.ts","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQ5D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,6LAgB5B,aAAa,KAAG,OAAO,CAAC,aAAa,CAmGvC,CAAC"}
|
|
@@ -13,20 +13,20 @@ const utils_1 = require("./utils");
|
|
|
13
13
|
* @param {IJoinPollArgs} args - The arguments for the join poll command
|
|
14
14
|
* @returns {IJoinPollData} The poll state index of the joined user and transaction hash
|
|
15
15
|
*/
|
|
16
|
-
const joinPoll = async ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark,
|
|
16
|
+
const joinPoll = async ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark, pollWitnessGenerator, pollWasm, sgDataArg, ivcpDataArg, }) => {
|
|
17
17
|
const validContract = await (0, contracts_1.contractExists)(signer.provider, maciAddress);
|
|
18
18
|
if (!validContract) {
|
|
19
19
|
throw new Error("MACI contract does not exist");
|
|
20
20
|
}
|
|
21
|
-
if (!domainobjs_1.
|
|
21
|
+
if (!domainobjs_1.PrivateKey.isValidSerialized(privateKey)) {
|
|
22
22
|
throw new Error("Invalid MACI private key");
|
|
23
23
|
}
|
|
24
24
|
if (pollId < 0) {
|
|
25
25
|
throw new Error("Invalid poll id");
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const nullifier = (0, crypto_1.poseidon)([BigInt(
|
|
27
|
+
const userMaciPrivateKey = domainobjs_1.PrivateKey.deserialize(privateKey);
|
|
28
|
+
const userMaciPublicKey = new domainobjs_1.Keypair(userMaciPrivateKey).publicKey;
|
|
29
|
+
const nullifier = (0, crypto_1.poseidon)([BigInt(userMaciPrivateKey.asCircuitInputs()), pollId]);
|
|
30
30
|
// check if the user has already joined the poll based on the nullifier
|
|
31
31
|
const hasUserJoinedAlready = await (0, utils_1.hasUserJoinedPoll)({
|
|
32
32
|
maciAddress,
|
|
@@ -41,14 +41,14 @@ const joinPoll = async ({ maciAddress, privateKey, stateFile, pollId, signer, st
|
|
|
41
41
|
const pollContracts = await maciContract.getPoll(pollId);
|
|
42
42
|
const pollContract = typechain_types_1.Poll__factory.connect(pollContracts.poll, signer);
|
|
43
43
|
// get the state index from the MACI contract
|
|
44
|
-
const stateIndex = await maciContract.getStateIndex(
|
|
44
|
+
const stateIndex = await maciContract.getStateIndex(userMaciPublicKey.hash()).catch(() => -1n);
|
|
45
45
|
let circuitInputs;
|
|
46
46
|
if (stateFile) {
|
|
47
47
|
circuitInputs = await (0, utils_1.getPollJoiningCircuitInputsFromStateFile)({
|
|
48
48
|
stateFile,
|
|
49
49
|
pollId,
|
|
50
50
|
stateIndex,
|
|
51
|
-
|
|
51
|
+
userMaciPrivateKey,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
@@ -56,18 +56,18 @@ const joinPoll = async ({ maciAddress, privateKey, stateFile, pollId, signer, st
|
|
|
56
56
|
maciContract,
|
|
57
57
|
stateIndex,
|
|
58
58
|
pollId,
|
|
59
|
-
|
|
59
|
+
userMaciPrivateKey,
|
|
60
60
|
signer,
|
|
61
61
|
startBlock,
|
|
62
62
|
endBlock,
|
|
63
63
|
blocksPerBatch,
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
const currentStateRootIndex = Number.parseInt((await maciContract.
|
|
66
|
+
const currentStateRootIndex = Number.parseInt((await maciContract.totalSignups()).toString(), 10) - 1;
|
|
67
67
|
// generate the proof for this batch
|
|
68
|
-
const proof = await (0, proofs_1.generateAndVerifyProof)(circuitInputs, pollJoiningZkey, useWasm, rapidsnark,
|
|
68
|
+
const proof = await (0, proofs_1.generateAndVerifyProof)(circuitInputs, pollJoiningZkey, useWasm, rapidsnark, pollWitnessGenerator, pollWasm);
|
|
69
69
|
// submit the message onchain as well as the encryption public key
|
|
70
|
-
const tx = await pollContract.joinPoll(nullifier,
|
|
70
|
+
const tx = await pollContract.joinPoll(nullifier, userMaciPublicKey.asContractParam(), currentStateRootIndex, proof, sgDataArg, ivcpDataArg);
|
|
71
71
|
const receipt = await tx.wait();
|
|
72
72
|
if (receipt?.status !== 1) {
|
|
73
73
|
throw new Error("Transaction failed");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joinPoll.js","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,8EAAsH;AACtH,kDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"joinPoll.js","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,8EAAsH;AACtH,kDAAiD;AACjD,0DAAgE;AAKhE,kDAAoD;AACpD,4CAAyD;AAEzD,mCAAmH;AAEnH;;;;GAIG;AACI,MAAM,QAAQ,GAAG,KAAK,EAAE,EAC7B,WAAW,EACX,UAAU,EACV,SAAS,EACT,MAAM,EACN,MAAM,EACN,UAAU,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,OAAO,EACP,UAAU,EACV,oBAAoB,EACpB,QAAQ,EACR,SAAS,EACT,WAAW,GACG,EAA0B,EAAE;IAC1C,MAAM,aAAa,GAAG,MAAM,IAAA,0BAAc,EAAC,MAAM,CAAC,QAAS,EAAE,WAAW,CAAC,CAAC;IAE1E,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,CAAC,uBAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,M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,QAAA,QAAQ,YAmHnB"}
|
|
@@ -4,17 +4,17 @@ import type { IIsRegisteredUser, ISignupArgs, ISignupData, IRegisteredUserArgs,
|
|
|
4
4
|
* @param IRegisteredArgs - The arguments for the check register command
|
|
5
5
|
* @returns whether the user is registered or not and their state index
|
|
6
6
|
*/
|
|
7
|
-
export declare const getSignedupUserData: ({ maciAddress,
|
|
7
|
+
export declare const getSignedupUserData: ({ maciAddress, maciPublicKey, signer, }: IRegisteredUserArgs) => Promise<IIsRegisteredUser>;
|
|
8
8
|
/**
|
|
9
9
|
* Signup a user to the MACI contract
|
|
10
10
|
* @param {SignupArgs} args - The arguments for the signup command
|
|
11
11
|
* @returns {ISignupData} The state index of the user and transaction hash
|
|
12
12
|
*/
|
|
13
|
-
export declare const signup: ({
|
|
13
|
+
export declare const signup: ({ maciPublicKey, maciAddress, sgData, signer }: ISignupArgs) => Promise<ISignupData>;
|
|
14
14
|
/**
|
|
15
15
|
* Checks if a user is signed up with a given public key
|
|
16
16
|
* @param {IIsSignedUpArgs} args - The arguments for the is signed up command
|
|
17
17
|
* @returns {boolean} Whether the user is signed up or not
|
|
18
18
|
*/
|
|
19
|
-
export declare const hasUserSignedUp: ({ maciAddress,
|
|
19
|
+
export declare const hasUserSignedUp: ({ maciAddress, maciPublicKey, signer, }: IHasUserSignedUpArgs) => Promise<boolean>;
|
|
20
20
|
//# sourceMappingURL=signup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAItH;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,yCAIvC,mBAAmB,KAAG,OAAO,CAAC,iBAAiB,CAsBjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAU,gDAAgD,WAAW,KAAG,OAAO,CAAC,WAAW,CA6C7G,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,yCAInC,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAMxC,CAAC"}
|
package/build/ts/user/signup.js
CHANGED
|
@@ -5,27 +5,32 @@ const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
|
5
5
|
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
6
6
|
const ethers_1 = require("ethers");
|
|
7
7
|
const contracts_1 = require("../utils/contracts");
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
8
|
/**
|
|
10
9
|
* Checks if user is registered with a given public key and get its data
|
|
11
10
|
* @param IRegisteredArgs - The arguments for the check register command
|
|
12
11
|
* @returns whether the user is registered or not and their state index
|
|
13
12
|
*/
|
|
14
|
-
const getSignedupUserData = async ({ maciAddress,
|
|
13
|
+
const getSignedupUserData = async ({ maciAddress, maciPublicKey, signer, }) => {
|
|
15
14
|
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
16
|
-
const publicKey = domainobjs_1.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
const publicKey = domainobjs_1.PublicKey.deserialize(maciPublicKey);
|
|
16
|
+
try {
|
|
17
|
+
const stateIndex = await maciContract.getStateIndex(publicKey.hash());
|
|
18
|
+
return {
|
|
19
|
+
isRegistered: stateIndex !== 0n, // 0 index is reserved for deleted leaves
|
|
20
|
+
stateIndex: String(stateIndex),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
// Check if this is a "UserNotSignedUp" maci contract error
|
|
25
|
+
if (error instanceof Error && error.message.includes("UserNotSignedUp()")) {
|
|
26
|
+
return {
|
|
27
|
+
isRegistered: false,
|
|
28
|
+
stateIndex: undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// If it's a different error, rethrow it
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
29
34
|
};
|
|
30
35
|
exports.getSignedupUserData = getSignedupUserData;
|
|
31
36
|
/**
|
|
@@ -33,12 +38,12 @@ exports.getSignedupUserData = getSignedupUserData;
|
|
|
33
38
|
* @param {SignupArgs} args - The arguments for the signup command
|
|
34
39
|
* @returns {ISignupData} The state index of the user and transaction hash
|
|
35
40
|
*/
|
|
36
|
-
const signup = async ({
|
|
41
|
+
const signup = async ({ maciPublicKey, maciAddress, sgData, signer }) => {
|
|
37
42
|
// validate user key
|
|
38
|
-
if (!domainobjs_1.
|
|
43
|
+
if (!domainobjs_1.PublicKey.isValidSerialized(maciPublicKey)) {
|
|
39
44
|
throw new Error("Invalid MACI public key");
|
|
40
45
|
}
|
|
41
|
-
const
|
|
46
|
+
const userMaciPublicKey = domainobjs_1.PublicKey.deserialize(maciPublicKey);
|
|
42
47
|
const validContract = await (0, contracts_1.contractExists)(signer.provider, maciAddress);
|
|
43
48
|
if (!validContract) {
|
|
44
49
|
throw new Error("There is no contract deployed at the specified address");
|
|
@@ -51,7 +56,7 @@ const signup = async ({ maciPubKey, maciAddress, sgData, signer }) => {
|
|
|
51
56
|
let stateIndex = "";
|
|
52
57
|
let receipt = null;
|
|
53
58
|
// sign up to the MACI contract
|
|
54
|
-
const tx = await maciContract.signUp(
|
|
59
|
+
const tx = await maciContract.signUp(userMaciPublicKey.asContractParam(), sgData);
|
|
55
60
|
receipt = await tx.wait();
|
|
56
61
|
if (receipt?.status !== 1) {
|
|
57
62
|
throw new Error("The transaction failed");
|
|
@@ -70,9 +75,9 @@ exports.signup = signup;
|
|
|
70
75
|
* @param {IIsSignedUpArgs} args - The arguments for the is signed up command
|
|
71
76
|
* @returns {boolean} Whether the user is signed up or not
|
|
72
77
|
*/
|
|
73
|
-
const hasUserSignedUp = async ({ maciAddress,
|
|
78
|
+
const hasUserSignedUp = async ({ maciAddress, maciPublicKey, signer, }) => {
|
|
74
79
|
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
75
|
-
const stateIndex = await maciContract.getStateIndex(domainobjs_1.
|
|
80
|
+
const stateIndex = await maciContract.getStateIndex(domainobjs_1.PublicKey.deserialize(maciPublicKey).hash());
|
|
76
81
|
return stateIndex !== 0n;
|
|
77
82
|
};
|
|
78
83
|
exports.hasUserSignedUp = hasUserSignedUp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signup.js","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":";;;AAAA,8EAAwF;AACxF,
|
|
1
|
+
{"version":3,"file":"signup.js","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":";;;AAAA,8EAAwF;AACxF,0DAAsD;AACtD,mCAAsE;AAItE,kDAAoD;AAEpD;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,WAAW,EACX,aAAa,EACb,MAAM,GACc,EAA8B,EAAE;IACpD,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,sBAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAEvD,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QAEtE,OAAO;YACL,YAAY,EAAE,UAAU,KAAK,EAAE,EAAE,yCAAyC;YAC1E,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;SAC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