@maci-protocol/sdk 0.0.0-ci.a1bedc5 → 0.0.0-ci.a45d012
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 +12 -4
- package/build/ts/browser/index.d.ts +2 -1
- package/build/ts/browser/index.d.ts.map +1 -1
- package/build/ts/browser/index.js +6 -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 +7 -7
- package/build/ts/deploy/poll.js.map +1 -1
- package/build/ts/deploy/types.d.ts +7 -6
- 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 +2 -1
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +12 -7
- 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 +3 -3
- package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -1
- package/build/ts/maciKeys/__tests__/publicKeys.test.js +5 -5
- package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -1
- package/build/ts/maciKeys/publicKeys.js +2 -2
- package/build/ts/maciKeys/publicKeys.js.map +1 -1
- package/build/ts/poll/poll.js +7 -7
- package/build/ts/poll/poll.js.map +1 -1
- package/build/ts/poll/types.d.ts +3 -3
- package/build/ts/poll/types.d.ts.map +1 -1
- package/build/ts/proof/__tests__/download.test.js +5 -2
- 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 +28 -22
- 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/messages.js +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 +62 -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 +4 -1
- package/build/ts/tally/index.js.map +1 -1
- package/build/ts/tally/results.d.ts +14 -0
- package/build/ts/tally/results.d.ts.map +1 -0
- package/build/ts/tally/results.js +44 -0
- package/build/ts/tally/results.js.map +1 -0
- package/build/ts/tally/types.d.ts +42 -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 +10 -1
- 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 +1 -1
- package/build/ts/user/signup.d.ts.map +1 -1
- package/build/ts/user/signup.js +22 -17
- package/build/ts/user/signup.js.map +1 -1
- package/build/ts/user/types.d.ts +53 -9
- package/build/ts/user/types.d.ts.map +1 -1
- package/build/ts/user/utils.d.ts +23 -11
- package/build/ts/user/utils.d.ts.map +1 -1
- package/build/ts/user/utils.js +72 -43
- package/build/ts/user/utils.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/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 +39 -40
- package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -1
- package/build/ts/verifyingKeys/types.d.ts +50 -46
- 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.map +1 -1
- package/build/ts/vote/generate.js +3 -3
- package/build/ts/vote/generate.js.map +1 -1
- package/build/ts/vote/index.d.ts +1 -1
- package/build/ts/vote/index.d.ts.map +1 -1
- package/build/ts/vote/index.js +2 -2
- package/build/ts/vote/index.js.map +1 -1
- package/build/ts/vote/invalidate.js +2 -2
- package/build/ts/vote/invalidate.js.map +1 -1
- package/build/ts/vote/publish.js +12 -12
- package/build/ts/vote/publish.js.map +1 -1
- package/build/ts/vote/utils.d.ts +1 -1
- package/build/ts/vote/utils.d.ts.map +1 -1
- package/build/ts/vote/utils.js +3 -3
- package/build/ts/vote/utils.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -10
- 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
|
@@ -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.PrivateKey.
|
|
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,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,
|
|
1
|
+
{"version":3,"file":"joinPoll.js","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,8EAAsH;AACtH,kDAAiD;AACjD,0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AM,EAAE,CAAC,IAAI,EAAE,CAAC;IAEhC,IAAI,OAAO,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,YAAY,CAAC,WAAW,CAC/C,YAAY,CAAC,OAAO,CAAC,UAAU,EAC/B,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,WAAW,CACpB,CAAC;IAEF,OAAO;QACL,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;QAC/C,YAAY,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE;QACjD,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;QAC/B,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC;AACJ,CAAC,CAAC;AAnHW,QAAA,QAAQ,YAmHnB"}
|
|
@@ -4,7 +4,7 @@ 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, maciPublicKey, signer,
|
|
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
|
|
@@ -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, maciPublicKey, signer,
|
|
13
|
+
const getSignedupUserData = async ({ maciAddress, maciPublicKey, signer, }) => {
|
|
15
14
|
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
16
15
|
const publicKey = domainobjs_1.PublicKey.deserialize(maciPublicKey);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
/**
|
|
@@ -35,10 +40,10 @@ exports.getSignedupUserData = getSignedupUserData;
|
|
|
35
40
|
*/
|
|
36
41
|
const signup = async ({ maciPublicKey, maciAddress, sgData, signer }) => {
|
|
37
42
|
// validate user key
|
|
38
|
-
if (!domainobjs_1.PublicKey.
|
|
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 ({ maciPublicKey, 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");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signup.js","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":";;;AAAA,8EAAwF;AACxF,0DAAsD;AACtD,mCAAiE;AAIjE,kDAAoD;AAEpD
|
|
1
|
+
{"version":3,"file":"signup.js","sourceRoot":"","sources":["../../../ts/user/signup.ts"],"names":[],"mappings":";;;AAAA,8EAAwF;AACxF,0DAAsD;AACtD,mCAAiE;AAIjE,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/B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,2DAA2D;QAC3D,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC1E,OAAO;gBACL,YAAY,EAAE,KAAK;gBACnB,UAAU,EAAE,SAAS;aACtB,CAAC;QACJ,CAAC;QACD,wCAAwC;QACxC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AA1BW,QAAA,mBAAmB,uBA0B9B;AAEF;;;;GAIG;AACI,MAAM,MAAM,GAAG,KAAK,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,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W,CACpB,CAAC;IAEF,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAEhC,OAAO;QACL,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE;QACnD,eAAe,EAAE,OAAO,CAAC,IAAI;KAC9B,CAAC;AACJ,CAAC,CAAC;AA7CW,QAAA,MAAM,UA6CjB;AAEF;;;;GAIG;AACI,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,WAAW,EACX,aAAa,EACb,MAAM,GACe,EAAoB,EAAE;IAC3C,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAE9D,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,sBAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjG,OAAO,UAAU,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B"}
|
package/build/ts/user/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
|
|
1
2
|
import type { MACI, Poll } from "@maci-protocol/contracts/typechain-types";
|
|
2
3
|
import type { PrivateKey, PublicKey } from "@maci-protocol/domainobjs";
|
|
3
4
|
import type { Signer } from "ethers";
|
|
@@ -244,11 +245,7 @@ export interface IJoinPollArgs {
|
|
|
244
245
|
*/
|
|
245
246
|
pollId: bigint;
|
|
246
247
|
/**
|
|
247
|
-
*
|
|
248
|
-
*/
|
|
249
|
-
stateIndex?: bigint;
|
|
250
|
-
/**
|
|
251
|
-
* Path to the state file with MACI state
|
|
248
|
+
* Path to the state file with MACI state. Not available in the browser's SDK
|
|
252
249
|
*/
|
|
253
250
|
stateFile?: string;
|
|
254
251
|
/**
|
|
@@ -280,9 +277,9 @@ export interface IJoinPollArgs {
|
|
|
280
277
|
*/
|
|
281
278
|
rapidsnark?: string;
|
|
282
279
|
/**
|
|
283
|
-
* The path to the poll
|
|
280
|
+
* The path to the poll witness generator binary
|
|
284
281
|
*/
|
|
285
|
-
|
|
282
|
+
pollWitnessGenerator?: string;
|
|
286
283
|
/**
|
|
287
284
|
* The path to the poll wasm file
|
|
288
285
|
*/
|
|
@@ -296,6 +293,19 @@ export interface IJoinPollArgs {
|
|
|
296
293
|
*/
|
|
297
294
|
ivcpDataArg: string;
|
|
298
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Interface for the arguments to the joinPoll command for the browser
|
|
298
|
+
*/
|
|
299
|
+
export interface IJoinPollBrowserArgs extends IJoinPollArgs {
|
|
300
|
+
/**
|
|
301
|
+
* Whether to use of not the latest state index
|
|
302
|
+
*/
|
|
303
|
+
useLatestStateIndex?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* The inclusion proof
|
|
306
|
+
*/
|
|
307
|
+
inclusionProof?: LeanIMTMerkleProof;
|
|
308
|
+
}
|
|
299
309
|
/**
|
|
300
310
|
* Interface for the return data to the joinPoll command
|
|
301
311
|
*/
|
|
@@ -338,6 +348,40 @@ export interface IIsNullifierOnChainArgs {
|
|
|
338
348
|
*/
|
|
339
349
|
signer: Signer;
|
|
340
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Arguments for IGenerateMaciStateTreeArgs
|
|
353
|
+
*/
|
|
354
|
+
export interface IGenerateMaciStateTreeArgs {
|
|
355
|
+
/**
|
|
356
|
+
* The MACI contract
|
|
357
|
+
*/
|
|
358
|
+
maciContract: MACI;
|
|
359
|
+
/**
|
|
360
|
+
* The signer
|
|
361
|
+
*/
|
|
362
|
+
signer: Signer;
|
|
363
|
+
/**
|
|
364
|
+
* The start block
|
|
365
|
+
*/
|
|
366
|
+
startBlock?: number;
|
|
367
|
+
/**
|
|
368
|
+
* The end block
|
|
369
|
+
*/
|
|
370
|
+
endBlock?: number;
|
|
371
|
+
/**
|
|
372
|
+
* The blocks per batch
|
|
373
|
+
*/
|
|
374
|
+
blocksPerBatch?: number;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Arguments for IGenerateMaciStateTreeWithEndKeyArgs
|
|
378
|
+
*/
|
|
379
|
+
export interface IGenerateMaciStateTreeWithEndKeyArgs extends IGenerateMaciStateTreeArgs {
|
|
380
|
+
/**
|
|
381
|
+
* The public key of the user
|
|
382
|
+
*/
|
|
383
|
+
userPublicKey: PublicKey;
|
|
384
|
+
}
|
|
341
385
|
/**
|
|
342
386
|
* Arguments for getPollJoiningCircuitEvents
|
|
343
387
|
*/
|
|
@@ -357,7 +401,7 @@ export interface IGetPollJoiningCircuitEventsArgs {
|
|
|
357
401
|
/**
|
|
358
402
|
* The user's maci private key
|
|
359
403
|
*/
|
|
360
|
-
|
|
404
|
+
userMaciPrivateKey: PrivateKey;
|
|
361
405
|
/**
|
|
362
406
|
* The signer
|
|
363
407
|
*/
|
|
@@ -394,7 +438,7 @@ export interface IGetPollJoiningCircuitInputsFromStateFileArgs {
|
|
|
394
438
|
/**
|
|
395
439
|
* The user's maci private key
|
|
396
440
|
*/
|
|
397
|
-
|
|
441
|
+
userMaciPrivateKey: PrivateKey;
|
|
398
442
|
}
|
|
399
443
|
/**
|
|
400
444
|
* Interface for the arguments for the is signed up command
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/user/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,C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MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,kBAAkB,EAAE,UAAU,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
package/build/ts/user/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PrivateKey, PublicKey } from "@maci-protocol/domainobjs";
|
|
2
|
-
import type { IGetPollJoiningCircuitEventsArgs, IGetPollJoiningCircuitInputsFromStateFileArgs, IParsePollJoinEventsArgs, IParseSignupEventsArgs,
|
|
2
|
+
import type { IGetPollJoiningCircuitEventsArgs, IGetPollJoiningCircuitInputsFromStateFileArgs, IParsePollJoinEventsArgs, IParseSignupEventsArgs, IJoinedUserArgs, IIsNullifierOnChainArgs, IGenerateMaciStateTreeArgs, IGenerateMaciStateTreeWithEndKeyArgs } from "./types";
|
|
3
3
|
import type { IGenerateSignUpTree } from "../trees/types";
|
|
4
|
-
import type {
|
|
4
|
+
import type { TCircuitInputs } from "../utils/types";
|
|
5
|
+
import type { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
|
|
5
6
|
/**
|
|
6
7
|
* Parse the poll joining events from the Poll contract
|
|
7
8
|
*/
|
|
@@ -33,30 +34,41 @@ export declare const parseSignupEvents: ({ maciContract, startBlock, currentBloc
|
|
|
33
34
|
}>;
|
|
34
35
|
/**
|
|
35
36
|
* Get state index from maci state leaves or from sign up leaves
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
37
|
+
* @param publicKeys Public keys from maci state or sign up tree
|
|
38
|
+
* @param userMaciPublicKey Public key of the maci user
|
|
38
39
|
* @param stateIndex State index from the command
|
|
39
40
|
* @returns State index
|
|
40
41
|
*/
|
|
41
|
-
export declare const getStateIndex: (
|
|
42
|
+
export declare const getStateIndex: (publicKeys: PublicKey[], userMaciPublicKey: PublicKey, stateIndex?: bigint) => bigint | undefined;
|
|
42
43
|
/**
|
|
43
44
|
* Create circuit input for pollJoining
|
|
44
45
|
* @param signUpData Sign up tree and state leaves
|
|
45
46
|
* @param stateTreeDepth Maci state tree depth
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @param pollPrivKey Poll's private key for the poll joining
|
|
47
|
+
* @param maciPrivateKey User's private key for signing up
|
|
48
|
+
* @param pollPrivateKey Poll's private key for the poll joining
|
|
49
49
|
* @param pollPublicKey Poll's public key for the poll joining
|
|
50
50
|
* @param pollId Poll's id
|
|
51
51
|
* @returns stringified circuit inputs
|
|
52
52
|
*/
|
|
53
|
-
export declare const joiningCircuitInputs: (
|
|
53
|
+
export declare const joiningCircuitInputs: (inclusionProof: LeanIMTMerkleProof, stateTreeDepth: bigint, maciPrivateKey: PrivateKey, pollPublicKey: PublicKey, pollId: bigint) => TCircuitInputs;
|
|
54
54
|
/**
|
|
55
55
|
* Get the poll joining circuit inputs from a state file
|
|
56
56
|
* @param stateFile - The path to the state file
|
|
57
57
|
* @returns The poll joining circuit inputs
|
|
58
58
|
*/
|
|
59
|
-
export declare const getPollJoiningCircuitInputsFromStateFile: ({ stateFile, pollId, stateIndex,
|
|
59
|
+
export declare const getPollJoiningCircuitInputsFromStateFile: ({ stateFile, pollId, stateIndex, userMaciPrivateKey, }: IGetPollJoiningCircuitInputsFromStateFileArgs) => Promise<TCircuitInputs>;
|
|
60
|
+
/**
|
|
61
|
+
* Generate MACI's state tree from the MACI contract
|
|
62
|
+
* @param {IGenerateMaciStateTreeArgs} args - The arguments for the generate maci state tree command
|
|
63
|
+
* @returns The MACI's state tree
|
|
64
|
+
*/
|
|
65
|
+
export declare const generateMaciStateTree: ({ maciContract, signer, startBlock, endBlock, blocksPerBatch, }: IGenerateMaciStateTreeArgs) => Promise<IGenerateSignUpTree>;
|
|
66
|
+
/**
|
|
67
|
+
* Generate MACI's state tree from the MACI contract with a given end key
|
|
68
|
+
* @param {IGenerateMaciStateTreeWithEndKeyArgs} args - The arguments for the generate maci state tree command
|
|
69
|
+
* @returns The MACI's state tree
|
|
70
|
+
*/
|
|
71
|
+
export declare const generateMaciStateTreeWithEndKey: ({ maciContract, signer, startBlock, endBlock, blocksPerBatch, userPublicKey, }: IGenerateMaciStateTreeWithEndKeyArgs) => Promise<IGenerateSignUpTree>;
|
|
60
72
|
/**
|
|
61
73
|
* Get the poll joining circuit events from a state file
|
|
62
74
|
* @param maciContract - The MACI contract
|
|
@@ -64,5 +76,5 @@ export declare const getPollJoiningCircuitInputsFromStateFile: ({ stateFile, pol
|
|
|
64
76
|
* @param signer - The signer
|
|
65
77
|
* @returns The poll joining circuit events
|
|
66
78
|
*/
|
|
67
|
-
export declare const getPollJoiningCircuitEvents: ({ maciContract, stateIndex, pollId,
|
|
79
|
+
export declare const getPollJoiningCircuitEvents: ({ maciContract, stateIndex, pollId, userMaciPrivateKey, signer, startBlock, endBlock, blocksPerBatch, }: IGetPollJoiningCircuitEventsArgs) => Promise<TCircuitInputs>;
|
|
68
80
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3E,OAAO,KAAK,EACV,gCAAgC,EAChC,6CAA6C,EAC7C,wBAAwB,EACxB,sBAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3E,OAAO,KAAK,EACV,gCAAgC,EAChC,6CAA6C,EAC7C,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EACf,uBAAuB,EACv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BxE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAU,iEAMzC,0BAA0B,KAAG,OAAO,CAAC,mBAAmB,CAgB1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAAU,gFAOnD,oCAAoC,KAAG,OAAO,CAAC,mBAAmB,CAgBpE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAAU,yGAS/C,gCAAgC,KAAG,OAAO,CAAC,cAAc,CA+B3D,CAAC"}
|
package/build/ts/user/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPollJoiningCircuitEvents = exports.getPollJoiningCircuitInputsFromStateFile = exports.joiningCircuitInputs = exports.getStateIndex = exports.parseSignupEvents = exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.parsePollJoinEvents = void 0;
|
|
6
|
+
exports.getPollJoiningCircuitEvents = exports.generateMaciStateTreeWithEndKey = exports.generateMaciStateTree = exports.getPollJoiningCircuitInputsFromStateFile = exports.joiningCircuitInputs = exports.getStateIndex = exports.parseSignupEvents = exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.parsePollJoinEvents = void 0;
|
|
7
7
|
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
8
8
|
const core_1 = require("@maci-protocol/core");
|
|
9
9
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
@@ -78,7 +78,7 @@ const parseSignupEvents = async ({ maciContract, startBlock, currentBlock, publi
|
|
|
78
78
|
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
79
79
|
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
80
80
|
// eslint-disable-next-line no-await-in-loop
|
|
81
|
-
const newEvents = await maciContract.queryFilter(maciContract.filters.SignUp(undefined, undefined, publicKey.
|
|
81
|
+
const newEvents = await maciContract.queryFilter(maciContract.filters.SignUp(undefined, undefined, publicKey.raw[0], publicKey.raw[1]), block, toBlock);
|
|
82
82
|
if (newEvents.length > 0) {
|
|
83
83
|
const [event] = newEvents;
|
|
84
84
|
return {
|
|
@@ -93,14 +93,14 @@ const parseSignupEvents = async ({ maciContract, startBlock, currentBlock, publi
|
|
|
93
93
|
exports.parseSignupEvents = parseSignupEvents;
|
|
94
94
|
/**
|
|
95
95
|
* Get state index from maci state leaves or from sign up leaves
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
96
|
+
* @param publicKeys Public keys from maci state or sign up tree
|
|
97
|
+
* @param userMaciPublicKey Public key of the maci user
|
|
98
98
|
* @param stateIndex State index from the command
|
|
99
99
|
* @returns State index
|
|
100
100
|
*/
|
|
101
|
-
const getStateIndex = (
|
|
101
|
+
const getStateIndex = (publicKeys, userMaciPublicKey, stateIndex) => {
|
|
102
102
|
if (!stateIndex) {
|
|
103
|
-
const index =
|
|
103
|
+
const index = publicKeys.findIndex((key) => key.equals(userMaciPublicKey));
|
|
104
104
|
if (index > 0) {
|
|
105
105
|
return BigInt(index);
|
|
106
106
|
}
|
|
@@ -113,18 +113,15 @@ exports.getStateIndex = getStateIndex;
|
|
|
113
113
|
* Create circuit input for pollJoining
|
|
114
114
|
* @param signUpData Sign up tree and state leaves
|
|
115
115
|
* @param stateTreeDepth Maci state tree depth
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @param pollPrivKey Poll's private key for the poll joining
|
|
116
|
+
* @param maciPrivateKey User's private key for signing up
|
|
117
|
+
* @param pollPrivateKey Poll's private key for the poll joining
|
|
119
118
|
* @param pollPublicKey Poll's public key for the poll joining
|
|
120
119
|
* @param pollId Poll's id
|
|
121
120
|
* @returns stringified circuit inputs
|
|
122
121
|
*/
|
|
123
|
-
const joiningCircuitInputs = (
|
|
124
|
-
// Get the state leaf on the index position
|
|
125
|
-
const { signUpTree: stateTree } = signUpData;
|
|
122
|
+
const joiningCircuitInputs = (inclusionProof, stateTreeDepth, maciPrivateKey, pollPublicKey, pollId) => {
|
|
126
123
|
// calculate the path elements for the state tree given the original state tree
|
|
127
|
-
const { siblings, index } =
|
|
124
|
+
const { siblings, index, root: stateRoot } = inclusionProof;
|
|
128
125
|
const siblingsLength = siblings.length;
|
|
129
126
|
// The index must be converted to a list of indices, 1 for each tree level.
|
|
130
127
|
// The circuit tree depth is this.stateTreeDepth, so the number of siblings must be this.stateTreeDepth,
|
|
@@ -140,15 +137,13 @@ const joiningCircuitInputs = (signUpData, stateTreeDepth, maciPrivKey, stateLeaf
|
|
|
140
137
|
}
|
|
141
138
|
const siblingsArray = siblings.map((sibling) => [sibling]);
|
|
142
139
|
// Create nullifier from private key
|
|
143
|
-
const inputNullifier = BigInt(
|
|
140
|
+
const inputNullifier = BigInt(maciPrivateKey.asCircuitInputs());
|
|
144
141
|
const nullifier = (0, crypto_1.poseidon)([inputNullifier, pollId]);
|
|
145
|
-
// Get pll state tree's root
|
|
146
|
-
const stateRoot = stateTree.root;
|
|
147
142
|
// Set actualStateTreeDepth as number of initial siblings length
|
|
148
143
|
const actualStateTreeDepth = BigInt(siblingsLength);
|
|
149
144
|
// Calculate public input hash from nullifier, credits and current root
|
|
150
145
|
const circuitInputs = {
|
|
151
|
-
privateKey:
|
|
146
|
+
privateKey: maciPrivateKey.asCircuitInputs(),
|
|
152
147
|
pollPublicKey: pollPublicKey.asCircuitInputs(),
|
|
153
148
|
siblings: siblingsArray,
|
|
154
149
|
indices,
|
|
@@ -165,47 +160,38 @@ exports.joiningCircuitInputs = joiningCircuitInputs;
|
|
|
165
160
|
* @param stateFile - The path to the state file
|
|
166
161
|
* @returns The poll joining circuit inputs
|
|
167
162
|
*/
|
|
168
|
-
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex,
|
|
163
|
+
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex, userMaciPrivateKey, }) => {
|
|
169
164
|
const file = await fs_1.default.promises.readFile(stateFile);
|
|
170
165
|
const content = JSON.parse(file.toString());
|
|
171
166
|
const maciState = core_1.MaciState.fromJSON(content);
|
|
172
167
|
const poll = maciState.polls.get(pollId);
|
|
173
|
-
const { publicKey:
|
|
174
|
-
const loadedStateIndex = (0, exports.getStateIndex)(maciState.
|
|
168
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
169
|
+
const loadedStateIndex = (0, exports.getStateIndex)(maciState.publicKeys, userPublicKey, stateIndex);
|
|
175
170
|
// check < 1 cause index zero is a blank state leaf
|
|
176
171
|
if (loadedStateIndex < 1) {
|
|
177
172
|
throw new Error("Invalid state index");
|
|
178
173
|
}
|
|
179
|
-
poll.updatePoll(BigInt(maciState.
|
|
174
|
+
poll.updatePoll(BigInt(maciState.publicKeys.length));
|
|
180
175
|
const circuitInputs = poll.joiningCircuitInputs({
|
|
181
|
-
maciPrivateKey:
|
|
176
|
+
maciPrivateKey: userMaciPrivateKey,
|
|
182
177
|
stateLeafIndex: stateIndex,
|
|
183
|
-
pollPublicKey:
|
|
178
|
+
pollPublicKey: userPublicKey,
|
|
184
179
|
});
|
|
185
180
|
return circuitInputs;
|
|
186
181
|
};
|
|
187
182
|
exports.getPollJoiningCircuitInputsFromStateFile = getPollJoiningCircuitInputsFromStateFile;
|
|
188
183
|
/**
|
|
189
|
-
*
|
|
190
|
-
* @param
|
|
191
|
-
* @
|
|
192
|
-
* @param signer - The signer
|
|
193
|
-
* @returns The poll joining circuit events
|
|
184
|
+
* Generate MACI's state tree from the MACI contract
|
|
185
|
+
* @param {IGenerateMaciStateTreeArgs} args - The arguments for the generate maci state tree command
|
|
186
|
+
* @returns The MACI's state tree
|
|
194
187
|
*/
|
|
195
|
-
const
|
|
188
|
+
const generateMaciStateTree = async ({ maciContract, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
196
189
|
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
197
|
-
const
|
|
198
|
-
maciContract
|
|
199
|
-
|
|
200
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
201
|
-
maciContract
|
|
202
|
-
.queryFilter(maciContract.filters.DeployPoll(), startBlock ?? 0)
|
|
203
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
204
|
-
maciContract.stateTreeDepth(),
|
|
205
|
-
]);
|
|
206
|
-
const defaultStartBlock = Math.min(defaultStartBlockPoll, defaultStartBlockSignup);
|
|
190
|
+
const defaultStartBlock = await maciContract
|
|
191
|
+
.queryFilter(maciContract.filters.SignUp(), startBlock ?? 0)
|
|
192
|
+
.then((events) => events[0]?.blockNumber ?? 0);
|
|
207
193
|
const fromBlock = startBlock ? Number(startBlock) : defaultStartBlock;
|
|
208
|
-
|
|
194
|
+
return (0, stateTree_1.generateSignUpTree)({
|
|
209
195
|
provider: signer.provider,
|
|
210
196
|
address: await maciContract.getAddress(),
|
|
211
197
|
blocksPerRequest: blocksPerBatch || 50,
|
|
@@ -213,12 +199,55 @@ const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId, u
|
|
|
213
199
|
endBlock,
|
|
214
200
|
sleepAmount: 0,
|
|
215
201
|
});
|
|
216
|
-
|
|
217
|
-
|
|
202
|
+
};
|
|
203
|
+
exports.generateMaciStateTree = generateMaciStateTree;
|
|
204
|
+
/**
|
|
205
|
+
* Generate MACI's state tree from the MACI contract with a given end key
|
|
206
|
+
* @param {IGenerateMaciStateTreeWithEndKeyArgs} args - The arguments for the generate maci state tree command
|
|
207
|
+
* @returns The MACI's state tree
|
|
208
|
+
*/
|
|
209
|
+
const generateMaciStateTreeWithEndKey = async ({ maciContract, signer, startBlock, endBlock, blocksPerBatch, userPublicKey, }) => {
|
|
210
|
+
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
211
|
+
const defaultStartBlock = await maciContract
|
|
212
|
+
.queryFilter(maciContract.filters.SignUp(), startBlock ?? 0)
|
|
213
|
+
.then((events) => events[0]?.blockNumber ?? 0);
|
|
214
|
+
const fromBlock = startBlock ? Number(startBlock) : defaultStartBlock;
|
|
215
|
+
return (0, stateTree_1.generateSignUpTreeWithEndKey)({
|
|
216
|
+
provider: signer.provider,
|
|
217
|
+
address: await maciContract.getAddress(),
|
|
218
|
+
blocksPerRequest: blocksPerBatch || 50,
|
|
219
|
+
fromBlock,
|
|
220
|
+
endBlock,
|
|
221
|
+
userPublicKey,
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
exports.generateMaciStateTreeWithEndKey = generateMaciStateTreeWithEndKey;
|
|
225
|
+
/**
|
|
226
|
+
* Get the poll joining circuit events from a state file
|
|
227
|
+
* @param maciContract - The MACI contract
|
|
228
|
+
* @param startBlock - The start block
|
|
229
|
+
* @param signer - The signer
|
|
230
|
+
* @returns The poll joining circuit events
|
|
231
|
+
*/
|
|
232
|
+
const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId, userMaciPrivateKey, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
233
|
+
const stateTreeDepth = await maciContract.stateTreeDepth();
|
|
234
|
+
const signUpData = await (0, exports.generateMaciStateTree)({
|
|
235
|
+
maciContract,
|
|
236
|
+
signer,
|
|
237
|
+
startBlock,
|
|
238
|
+
endBlock,
|
|
239
|
+
blocksPerBatch,
|
|
240
|
+
});
|
|
241
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
242
|
+
const loadedStateIndex = (0, exports.getStateIndex)(signUpData.publicKeys, userPublicKey, stateIndex);
|
|
218
243
|
if (loadedStateIndex < 1) {
|
|
219
244
|
throw new Error("Invalid state index");
|
|
220
245
|
}
|
|
221
|
-
|
|
246
|
+
// Get the state leaf on the index position
|
|
247
|
+
const { signUpTree: stateTree } = signUpData;
|
|
248
|
+
// calculate the path elements for the state tree given the original state tree
|
|
249
|
+
const inclusionProof = stateTree.generateProof(Number(loadedStateIndex));
|
|
250
|
+
return (0, exports.joiningCircuitInputs)(inclusionProof, stateTreeDepth, userMaciPrivateKey, userPublicKey, pollId);
|
|
222
251
|
};
|
|
223
252
|
exports.getPollJoiningCircuitEvents = getPollJoiningCircuitEvents;
|
|
224
253
|
//# sourceMappingURL=utils.js.map
|