@maci-protocol/sdk 0.0.0-ci.fd7cff6 → 0.0.0-ci.fdde0de
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 -7
- package/build/ts/browser/index.d.ts +6 -7
- package/build/ts/browser/index.d.ts.map +1 -1
- package/build/ts/browser/index.js +16 -20
- package/build/ts/browser/index.js.map +1 -1
- package/build/ts/browser/joinPoll.d.ts +10 -0
- package/build/ts/browser/joinPoll.d.ts.map +1 -0
- package/build/ts/browser/joinPoll.js +88 -0
- package/build/ts/browser/joinPoll.js.map +1 -0
- package/build/ts/browser/utils.d.ts +18 -0
- package/build/ts/browser/utils.d.ts.map +1 -0
- package/build/ts/browser/utils.js +37 -0
- package/build/ts/browser/utils.js.map +1 -0
- package/build/ts/deploy/index.d.ts +3 -2
- package/build/ts/deploy/index.d.ts.map +1 -1
- package/build/ts/deploy/index.js +5 -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 +20 -13
- package/build/ts/deploy/poll.js.map +1 -1
- package/build/ts/deploy/types.d.ts +21 -8
- 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 +26 -8
- package/build/ts/index.js.map +1 -1
- package/build/ts/maci/policy.d.ts +13 -1
- package/build/ts/maci/policy.d.ts.map +1 -1
- package/build/ts/maci/policy.js +41 -2
- package/build/ts/maci/policy.js.map +1 -1
- package/build/ts/maci/state.d.ts +1 -1
- package/build/ts/maci/state.js +11 -11
- package/build/ts/maci/state.js.map +1 -1
- package/build/ts/maci/types.d.ts +34 -2
- package/build/ts/maci/types.d.ts.map +1 -1
- package/build/ts/maci/types.js +2 -0
- package/build/ts/maci/types.js.map +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 +8 -8
- package/build/ts/poll/poll.js.map +1 -1
- package/build/ts/poll/types.d.ts +6 -7
- package/build/ts/poll/types.d.ts.map +1 -1
- package/build/ts/poll/utils.js +3 -3
- package/build/ts/poll/utils.js.map +1 -1
- package/build/ts/proof/__tests__/download.test.js +7 -4
- 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 +31 -25
- package/build/ts/proof/generate.js.map +1 -1
- package/build/ts/proof/prove.js +16 -16
- package/build/ts/proof/prove.js.map +1 -1
- package/build/ts/proof/types.d.ts +41 -15
- 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 +4 -4
- 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 +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 +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 +76 -12
- 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 +4 -2
- package/build/ts/user/index.d.ts.map +1 -1
- package/build/ts/user/index.js +14 -8
- package/build/ts/user/index.js.map +1 -1
- package/build/ts/user/joinPoll.d.ts +8 -0
- package/build/ts/user/joinPoll.d.ts.map +1 -0
- package/build/ts/user/joinPoll.js +84 -0
- package/build/ts/user/joinPoll.js.map +1 -0
- package/build/ts/user/signup.d.ts +20 -0
- package/build/ts/user/signup.d.ts.map +1 -0
- package/build/ts/user/signup.js +84 -0
- package/build/ts/user/signup.js.map +1 -0
- package/build/ts/user/types.d.ts +63 -27
- package/build/ts/user/types.d.ts.map +1 -1
- package/build/ts/user/utils.d.ts +42 -14
- package/build/ts/user/utils.d.ts.map +1 -1
- package/build/ts/user/utils.js +121 -49
- 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/utils/utils.d.ts +8 -0
- package/build/ts/utils/utils.d.ts.map +1 -1
- package/build/ts/utils/utils.js +14 -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 +46 -35
- package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -1
- package/build/ts/verifyingKeys/types.d.ts +54 -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 +76 -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 +5 -5
- 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 +7 -7
- package/build/ts/vote/utils.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +22 -13
- 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/user/user.d.ts +0 -42
- package/build/ts/user/user.d.ts.map +0 -1
- package/build/ts/user/user.js +0 -192
- package/build/ts/user/user.js.map +0 -1
package/build/ts/user/utils.js
CHANGED
|
@@ -3,12 +3,13 @@ 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.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
|
+
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
7
8
|
const core_1 = require("@maci-protocol/core");
|
|
8
9
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
9
10
|
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
10
11
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const
|
|
12
|
+
const stateTree_1 = require("../trees/stateTree");
|
|
12
13
|
const constants_1 = require("../utils/constants");
|
|
13
14
|
/**
|
|
14
15
|
* Parse the poll joining events from the Poll contract
|
|
@@ -16,13 +17,13 @@ const constants_1 = require("../utils/constants");
|
|
|
16
17
|
const parsePollJoinEvents = async ({ pollContract, startBlock, currentBlock, pollPublicKey, }) => {
|
|
17
18
|
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
18
19
|
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
19
|
-
const
|
|
20
|
+
const publicKey = pollPublicKey.asArray();
|
|
20
21
|
// eslint-disable-next-line no-await-in-loop
|
|
21
|
-
const newEvents = await pollContract.queryFilter(pollContract.filters.PollJoined(
|
|
22
|
+
const newEvents = await pollContract.queryFilter(pollContract.filters.PollJoined(publicKey[0], publicKey[1], undefined, undefined, undefined), block, toBlock);
|
|
22
23
|
if (newEvents.length > 0) {
|
|
23
24
|
const [event] = newEvents;
|
|
24
25
|
return {
|
|
25
|
-
pollStateIndex: event.args[
|
|
26
|
+
pollStateIndex: event.args[4].toString(),
|
|
26
27
|
voiceCredits: event.args[2].toString(),
|
|
27
28
|
};
|
|
28
29
|
}
|
|
@@ -33,6 +34,43 @@ const parsePollJoinEvents = async ({ pollContract, startBlock, currentBlock, pol
|
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
exports.parsePollJoinEvents = parsePollJoinEvents;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if user is joined to a poll with their public key and get its data
|
|
39
|
+
* @param {IJoinedUserArgs} - The arguments for the join check command
|
|
40
|
+
* @returns user joined or not and poll state index, voice credit balance
|
|
41
|
+
*/
|
|
42
|
+
const getJoinedUserData = async ({ maciAddress, pollId, pollPublicKey: serializedPollPublicKey, signer, startBlock, }) => {
|
|
43
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
44
|
+
const pollContracts = await maciContract.getPoll(pollId);
|
|
45
|
+
const pollContract = typechain_types_1.Poll__factory.connect(pollContracts.poll, signer);
|
|
46
|
+
const pollPublicKey = domainobjs_1.PublicKey.deserialize(serializedPollPublicKey);
|
|
47
|
+
const startBlockNumber = startBlock || 0;
|
|
48
|
+
const currentBlock = await signer.provider.getBlockNumber();
|
|
49
|
+
const { pollStateIndex, voiceCredits } = await (0, exports.parsePollJoinEvents)({
|
|
50
|
+
pollContract,
|
|
51
|
+
startBlock: startBlockNumber,
|
|
52
|
+
currentBlock,
|
|
53
|
+
pollPublicKey,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
isJoined: pollStateIndex !== undefined,
|
|
57
|
+
pollStateIndex,
|
|
58
|
+
voiceCredits,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.getJoinedUserData = getJoinedUserData;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a user joined a poll with a given nullifier
|
|
64
|
+
* @param {IIsNullifierOnChainArgs} args - The arguments for the is nullifier on chain command
|
|
65
|
+
* @returns whether the nullifier is on chain or not
|
|
66
|
+
*/
|
|
67
|
+
const hasUserJoinedPoll = async ({ maciAddress, pollId, nullifier, signer, }) => {
|
|
68
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
69
|
+
const pollContracts = await maciContract.getPoll(pollId);
|
|
70
|
+
const pollContract = typechain_types_1.Poll__factory.connect(pollContracts.poll, signer);
|
|
71
|
+
return pollContract.pollNullifiers(nullifier);
|
|
72
|
+
};
|
|
73
|
+
exports.hasUserJoinedPoll = hasUserJoinedPoll;
|
|
36
74
|
/**
|
|
37
75
|
* Parse the signup events from the MACI contract
|
|
38
76
|
*/
|
|
@@ -40,7 +78,7 @@ const parseSignupEvents = async ({ maciContract, startBlock, currentBlock, publi
|
|
|
40
78
|
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
41
79
|
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
42
80
|
// eslint-disable-next-line no-await-in-loop
|
|
43
|
-
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);
|
|
44
82
|
if (newEvents.length > 0) {
|
|
45
83
|
const [event] = newEvents;
|
|
46
84
|
return {
|
|
@@ -55,14 +93,14 @@ const parseSignupEvents = async ({ maciContract, startBlock, currentBlock, publi
|
|
|
55
93
|
exports.parseSignupEvents = parseSignupEvents;
|
|
56
94
|
/**
|
|
57
95
|
* Get state index from maci state leaves or from sign up leaves
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
96
|
+
* @param publicKeys Public keys from maci state or sign up tree
|
|
97
|
+
* @param userMaciPublicKey Public key of the maci user
|
|
60
98
|
* @param stateIndex State index from the command
|
|
61
99
|
* @returns State index
|
|
62
100
|
*/
|
|
63
|
-
const getStateIndex = (
|
|
101
|
+
const getStateIndex = (publicKeys, userMaciPublicKey, stateIndex) => {
|
|
64
102
|
if (!stateIndex) {
|
|
65
|
-
const index =
|
|
103
|
+
const index = publicKeys.findIndex((key) => key.equals(userMaciPublicKey));
|
|
66
104
|
if (index > 0) {
|
|
67
105
|
return BigInt(index);
|
|
68
106
|
}
|
|
@@ -75,18 +113,15 @@ exports.getStateIndex = getStateIndex;
|
|
|
75
113
|
* Create circuit input for pollJoining
|
|
76
114
|
* @param signUpData Sign up tree and state leaves
|
|
77
115
|
* @param stateTreeDepth Maci state tree depth
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
81
|
-
* @param pollPubKey Poll's public 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
|
|
118
|
+
* @param pollPublicKey Poll's public key for the poll joining
|
|
82
119
|
* @param pollId Poll's id
|
|
83
120
|
* @returns stringified circuit inputs
|
|
84
121
|
*/
|
|
85
|
-
const joiningCircuitInputs = (
|
|
86
|
-
// Get the state leaf on the index position
|
|
87
|
-
const { signUpTree: stateTree } = signUpData;
|
|
122
|
+
const joiningCircuitInputs = (inclusionProof, stateTreeDepth, maciPrivateKey, pollPublicKey, pollId) => {
|
|
88
123
|
// calculate the path elements for the state tree given the original state tree
|
|
89
|
-
const { siblings, index } =
|
|
124
|
+
const { siblings, index, root: stateRoot } = inclusionProof;
|
|
90
125
|
const siblingsLength = siblings.length;
|
|
91
126
|
// The index must be converted to a list of indices, 1 for each tree level.
|
|
92
127
|
// The circuit tree depth is this.stateTreeDepth, so the number of siblings must be this.stateTreeDepth,
|
|
@@ -102,16 +137,14 @@ const joiningCircuitInputs = (signUpData, stateTreeDepth, maciPrivKey, stateLeaf
|
|
|
102
137
|
}
|
|
103
138
|
const siblingsArray = siblings.map((sibling) => [sibling]);
|
|
104
139
|
// Create nullifier from private key
|
|
105
|
-
const inputNullifier = BigInt(
|
|
140
|
+
const inputNullifier = BigInt(maciPrivateKey.asCircuitInputs());
|
|
106
141
|
const nullifier = (0, crypto_1.poseidon)([inputNullifier, pollId]);
|
|
107
|
-
// Get pll state tree's root
|
|
108
|
-
const stateRoot = stateTree.root;
|
|
109
142
|
// Set actualStateTreeDepth as number of initial siblings length
|
|
110
143
|
const actualStateTreeDepth = BigInt(siblingsLength);
|
|
111
144
|
// Calculate public input hash from nullifier, credits and current root
|
|
112
145
|
const circuitInputs = {
|
|
113
|
-
|
|
114
|
-
|
|
146
|
+
privateKey: maciPrivateKey.asCircuitInputs(),
|
|
147
|
+
pollPublicKey: pollPublicKey.asCircuitInputs(),
|
|
115
148
|
siblings: siblingsArray,
|
|
116
149
|
indices,
|
|
117
150
|
nullifier,
|
|
@@ -127,47 +160,39 @@ exports.joiningCircuitInputs = joiningCircuitInputs;
|
|
|
127
160
|
* @param stateFile - The path to the state file
|
|
128
161
|
* @returns The poll joining circuit inputs
|
|
129
162
|
*/
|
|
130
|
-
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex,
|
|
163
|
+
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex, userMaciPrivateKey, }) => {
|
|
131
164
|
const file = await fs_1.default.promises.readFile(stateFile);
|
|
132
165
|
const content = JSON.parse(file.toString());
|
|
133
166
|
const maciState = core_1.MaciState.fromJSON(content);
|
|
134
167
|
const poll = maciState.polls.get(pollId);
|
|
135
|
-
const {
|
|
136
|
-
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);
|
|
137
170
|
// check < 1 cause index zero is a blank state leaf
|
|
138
171
|
if (loadedStateIndex < 1) {
|
|
139
172
|
throw new Error("Invalid state index");
|
|
140
173
|
}
|
|
141
|
-
poll.updatePoll(BigInt(maciState.
|
|
174
|
+
poll.updatePoll(BigInt(maciState.publicKeys.length));
|
|
142
175
|
const circuitInputs = poll.joiningCircuitInputs({
|
|
143
|
-
|
|
176
|
+
maciPrivateKey: userMaciPrivateKey,
|
|
144
177
|
stateLeafIndex: stateIndex,
|
|
145
|
-
|
|
178
|
+
pollPublicKey: userPublicKey,
|
|
146
179
|
});
|
|
147
180
|
return circuitInputs;
|
|
148
181
|
};
|
|
149
182
|
exports.getPollJoiningCircuitInputsFromStateFile = getPollJoiningCircuitInputsFromStateFile;
|
|
150
183
|
/**
|
|
151
|
-
*
|
|
152
|
-
* @param
|
|
153
|
-
* @
|
|
154
|
-
* @param signer - The signer
|
|
155
|
-
* @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
|
|
156
187
|
*/
|
|
157
|
-
const
|
|
188
|
+
const generateMaciStateTree = async ({ maciContractAddress, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
189
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciContractAddress, signer);
|
|
158
190
|
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
159
|
-
const
|
|
160
|
-
maciContract
|
|
161
|
-
|
|
162
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
163
|
-
maciContract
|
|
164
|
-
.queryFilter(maciContract.filters.DeployPoll(), startBlock ?? 0)
|
|
165
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
166
|
-
maciContract.stateTreeDepth(),
|
|
167
|
-
]);
|
|
168
|
-
const defaultStartBlock = Math.min(defaultStartBlockPoll, defaultStartBlockSignup);
|
|
191
|
+
const defaultStartBlock = await maciContract
|
|
192
|
+
.queryFilter(maciContract.filters.SignUp(), startBlock ?? 0)
|
|
193
|
+
.then((events) => events[0]?.blockNumber ?? 0);
|
|
169
194
|
const fromBlock = startBlock ? Number(startBlock) : defaultStartBlock;
|
|
170
|
-
|
|
195
|
+
return (0, stateTree_1.generateSignUpTree)({
|
|
171
196
|
provider: signer.provider,
|
|
172
197
|
address: await maciContract.getAddress(),
|
|
173
198
|
blocksPerRequest: blocksPerBatch || 50,
|
|
@@ -175,12 +200,59 @@ const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId, u
|
|
|
175
200
|
endBlock,
|
|
176
201
|
sleepAmount: 0,
|
|
177
202
|
});
|
|
178
|
-
|
|
179
|
-
|
|
203
|
+
};
|
|
204
|
+
exports.generateMaciStateTree = generateMaciStateTree;
|
|
205
|
+
/**
|
|
206
|
+
* Generate MACI's state tree from the MACI contract with a given end key
|
|
207
|
+
* @param {IGenerateMaciStateTreeWithEndKeyArgs} args - The arguments for the generate maci state tree command
|
|
208
|
+
* @returns The MACI's state tree
|
|
209
|
+
*/
|
|
210
|
+
const generateMaciStateTreeWithEndKey = async ({ maciContractAddress, signer, startBlock, endBlock, blocksPerBatch, userPublicKey, }) => {
|
|
211
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciContractAddress, signer);
|
|
212
|
+
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
213
|
+
const defaultStartBlock = await maciContract
|
|
214
|
+
.queryFilter(maciContract.filters.SignUp(), startBlock ?? 0)
|
|
215
|
+
.then((events) => events[0]?.blockNumber ?? 0);
|
|
216
|
+
const fromBlock = startBlock ? Number(startBlock) : defaultStartBlock;
|
|
217
|
+
return (0, stateTree_1.generateSignUpTreeWithEndKey)({
|
|
218
|
+
provider: signer.provider,
|
|
219
|
+
address: await maciContract.getAddress(),
|
|
220
|
+
blocksPerRequest: blocksPerBatch || 50,
|
|
221
|
+
fromBlock,
|
|
222
|
+
endBlock,
|
|
223
|
+
userPublicKey,
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
exports.generateMaciStateTreeWithEndKey = generateMaciStateTreeWithEndKey;
|
|
227
|
+
/**
|
|
228
|
+
* Get the poll joining circuit events from a state file
|
|
229
|
+
* @param maciContract - The MACI contract
|
|
230
|
+
* @param startBlock - The start block
|
|
231
|
+
* @param signer - The signer
|
|
232
|
+
* @returns The poll joining circuit events
|
|
233
|
+
*/
|
|
234
|
+
const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId, userMaciPrivateKey, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
235
|
+
const [stateTreeDepth, maciContractAddress] = await Promise.all([
|
|
236
|
+
maciContract.stateTreeDepth(),
|
|
237
|
+
maciContract.getAddress(),
|
|
238
|
+
]);
|
|
239
|
+
const signUpData = await (0, exports.generateMaciStateTree)({
|
|
240
|
+
maciContractAddress,
|
|
241
|
+
signer,
|
|
242
|
+
startBlock,
|
|
243
|
+
endBlock,
|
|
244
|
+
blocksPerBatch,
|
|
245
|
+
});
|
|
246
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
247
|
+
const loadedStateIndex = (0, exports.getStateIndex)(signUpData.publicKeys, userPublicKey, stateIndex);
|
|
180
248
|
if (loadedStateIndex < 1) {
|
|
181
249
|
throw new Error("Invalid state index");
|
|
182
250
|
}
|
|
183
|
-
|
|
251
|
+
// Get the state leaf on the index position
|
|
252
|
+
const { signUpTree: stateTree } = signUpData;
|
|
253
|
+
// calculate the path elements for the state tree given the original state tree
|
|
254
|
+
const inclusionProof = stateTree.generateProof(Number(loadedStateIndex));
|
|
255
|
+
return (0, exports.joiningCircuitInputs)(inclusionProof, stateTreeDepth, userMaciPrivateKey, userPublicKey, pollId);
|
|
184
256
|
};
|
|
185
257
|
exports.getPollJoiningCircuitEvents = getPollJoiningCircuitEvents;
|
|
186
258
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAgE;AAChE,kDAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAsH;AACtH,8CAAgE;AAChE,kDAAmE;AACnE,0DAA2E;AAE3E,4CAAoB;AAgBpB,kDAAsF;AACtF,kDAAiD;AAEjD;;GAEG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,aAAa,GACY,EAGxB,EAAE;IACH,KAAK,IAAI,KAAK,GAAG,UAAU,EAAE,KAAK,IAAI,YAAY,EAAE,KAAK,IAAI,uBAAW,EAAE,CAAC;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,uBAAW,GAAG,CAAC,EAAE,YAAY,CAAC,CAAC;QAChE,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1C,4CAA4C;QAC5C,MAAM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Validate the circuit parameters
|
|
4
4
|
* @param params - The circuit parameters
|
|
5
5
|
*/
|
|
6
|
-
export declare const validateParams: ({ stateTreeDepth,
|
|
6
|
+
export declare const validateParams: ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, }: ICircuitParams) => boolean;
|
|
7
7
|
//# sourceMappingURL=params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../../ts/utils/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../../ts/utils/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,2FAK5B,cAAc,KAAG,OAWnB,CAAC"}
|
package/build/ts/utils/params.js
CHANGED
|
@@ -5,12 +5,12 @@ exports.validateParams = void 0;
|
|
|
5
5
|
* Validate the circuit parameters
|
|
6
6
|
* @param params - The circuit parameters
|
|
7
7
|
*/
|
|
8
|
-
const validateParams = ({ stateTreeDepth,
|
|
8
|
+
const validateParams = ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, }) => {
|
|
9
9
|
// validate args
|
|
10
|
-
if (stateTreeDepth < 1 ||
|
|
10
|
+
if (stateTreeDepth < 1 || tallyProcessingStateTreeDepth < 1 || voteOptionTreeDepth < 1 || messageBatchSize < 1) {
|
|
11
11
|
throw new Error("Invalid depth or batch size parameters");
|
|
12
12
|
}
|
|
13
|
-
if (stateTreeDepth <
|
|
13
|
+
if (stateTreeDepth < tallyProcessingStateTreeDepth) {
|
|
14
14
|
throw new Error("Invalid state tree depth or intermediate state tree depth");
|
|
15
15
|
}
|
|
16
16
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../ts/utils/params.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,EAC7B,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../ts/utils/params.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,EAC7B,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,EACnB,gBAAgB,GACD,EAAW,EAAE;IAC5B,gBAAgB;IAChB,IAAI,cAAc,GAAG,CAAC,IAAI,6BAA6B,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,IAAI,gBAAgB,GAAG,CAAC,EAAE,CAAC;QAC/G,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,cAAc,GAAG,6BAA6B,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TCircuitInputs } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Generate and verify poll proof
|
|
4
4
|
* @param inputs - the inputs to the circuit
|
|
@@ -9,5 +9,5 @@ import type { CircuitInputs } from "./types";
|
|
|
9
9
|
* @param wasmPath - the path to the wasm witness
|
|
10
10
|
* @returns proof - an array of strings
|
|
11
11
|
*/
|
|
12
|
-
export declare const generateAndVerifyProof: (inputs:
|
|
12
|
+
export declare const generateAndVerifyProof: (inputs: TCircuitInputs, zkeyPath: string, useWasm: boolean | undefined, rapidsnarkExePath: string | undefined, witnessExePath: string | undefined, wasmPath: string | undefined) => Promise<string[]>;
|
|
13
13
|
//# sourceMappingURL=proofs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proofs.d.ts","sourceRoot":"","sources":["../../../ts/utils/proofs.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"proofs.d.ts","sourceRoot":"","sources":["../../../ts/utils/proofs.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,cAAc,EACtB,UAAU,MAAM,EAChB,SAAS,OAAO,GAAG,SAAS,EAC5B,mBAAmB,MAAM,GAAG,SAAS,EACrC,gBAAgB,MAAM,GAAG,SAAS,EAClC,UAAU,MAAM,GAAG,SAAS,KAC3B,OAAO,CAAC,MAAM,EAAE,CA4BlB,CAAC"}
|
package/build/ts/utils/proofs.js
CHANGED
|
@@ -14,16 +14,16 @@ const contracts_1 = require("@maci-protocol/contracts");
|
|
|
14
14
|
*/
|
|
15
15
|
const generateAndVerifyProof = async (inputs, zkeyPath, useWasm, rapidsnarkExePath, witnessExePath, wasmPath) => {
|
|
16
16
|
let r;
|
|
17
|
-
const
|
|
17
|
+
const verifyingKey = await (0, contracts_1.extractVerifyingKey)(zkeyPath);
|
|
18
18
|
if (useWasm === true || useWasm === undefined) {
|
|
19
|
-
r = await (0, contracts_1.
|
|
19
|
+
r = await (0, contracts_1.generateProofSnarkjs)({
|
|
20
20
|
inputs,
|
|
21
21
|
zkeyPath,
|
|
22
22
|
wasmPath,
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
r = await (0, contracts_1.
|
|
26
|
+
r = await (0, contracts_1.generateProofRapidSnark)({
|
|
27
27
|
inputs,
|
|
28
28
|
zkeyPath,
|
|
29
29
|
rapidsnarkExePath,
|
|
@@ -31,7 +31,7 @@ const generateAndVerifyProof = async (inputs, zkeyPath, useWasm, rapidsnarkExePa
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
// verify it
|
|
34
|
-
const isValid = await (0, contracts_1.verifyProof)(r.publicSignals, r.proof,
|
|
34
|
+
const isValid = await (0, contracts_1.verifyProof)(r.publicSignals, r.proof, verifyingKey);
|
|
35
35
|
if (!isValid) {
|
|
36
36
|
throw new Error("Generated an invalid proof");
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../../ts/utils/proofs.ts"],"names":[],"mappings":";;;AAAA,wDAOkC;AAIlC;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,
|
|
1
|
+
{"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../../ts/utils/proofs.ts"],"names":[],"mappings":";;;AAAA,wDAOkC;AAIlC;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,MAAsB,EACtB,QAAgB,EAChB,OAA4B,EAC5B,iBAAqC,EACrC,cAAkC,EAClC,QAA4B,EACT,EAAE;IACrB,IAAI,CAAkB,CAAC;IAEvB,MAAM,YAAY,GAAG,MAAM,IAAA,+BAAmB,EAAC,QAAQ,CAAC,CAAC;IAEzD,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9C,CAAC,GAAG,MAAM,IAAA,gCAAoB,EAAC;YAC7B,MAAM;YACN,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,CAAC,GAAG,MAAM,IAAA,mCAAuB,EAAC;YAChC,MAAM;YACN,QAAQ;YACR,iBAAiB;YACjB,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IAED,YAAY;IACZ,MAAM,OAAO,GAAG,MAAM,IAAA,uBAAW,EAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAE1E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,IAAA,0CAA8B,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC;AAnCW,QAAA,sBAAsB,0BAmCjC"}
|
|
@@ -2,7 +2,7 @@ import type { BigNumberish, Signer } from "ethers";
|
|
|
2
2
|
/**
|
|
3
3
|
* A circuit inputs for the circom circuit
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type TCircuitInputs = Record<string, string | bigint | bigint[] | bigint[][] | string[] | bigint[][][]>;
|
|
6
6
|
/**
|
|
7
7
|
* Circuit parameters
|
|
8
8
|
*/
|
|
@@ -14,7 +14,7 @@ export interface ICircuitParams {
|
|
|
14
14
|
/**
|
|
15
15
|
* The intermediate state tree depth (ballot tree)
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
tallyProcessingStateTreeDepth: number;
|
|
18
18
|
/**
|
|
19
19
|
* The vote option tree depth
|
|
20
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAE/G;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,6BAA6B,EAAE,MAAM,CAAC;IACtC;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,SAAS,EAAE,YAAY,EAAE,EAAE,CAAC;IAC5B,UAAU,EAAE,YAAY,EAAE,EAAE,CAAC;IAC7B,UAAU,EAAE,YAAY,EAAE,EAAE,CAAC;IAC7B,eAAe,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACpC,EAAE,EAAE,YAAY,EAAE,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -13,4 +13,12 @@ export declare const unlinkFile: (filepath: string) => Promise<void>;
|
|
|
13
13
|
* @param ms - the amount of time to sleep in milliseconds
|
|
14
14
|
*/
|
|
15
15
|
export declare const sleep: (ms: number) => Promise<void>;
|
|
16
|
+
declare global {
|
|
17
|
+
interface ITerminatable {
|
|
18
|
+
terminate: () => Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
var curve_bn128: ITerminatable | undefined;
|
|
21
|
+
var curve_bls12381: ITerminatable | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare const cleanThreads: () => Promise<void>;
|
|
16
24
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/utils/utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAO,OAAoC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,CAM/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAIpD,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/utils/utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAO,OAAoC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,CAM/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAIpD,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,aAAa;QACrB,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;KACnC;IAGD,IAAI,WAAW,EAAE,aAAa,GAAG,SAAS,CAAC;IAG3C,IAAI,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC;CAC/C;AAMD,eAAO,MAAM,YAAY,QAAa,OAAO,CAAC,IAAI,CAUjD,CAAC"}
|
package/build/ts/utils/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.sleep = exports.unlinkFile = exports.isArm = void 0;
|
|
6
|
+
exports.cleanThreads = exports.sleep = exports.unlinkFile = exports.isArm = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
/**
|
|
@@ -33,4 +33,17 @@ const sleep = async (ms) => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
exports.sleep = sleep;
|
|
36
|
+
/*
|
|
37
|
+
* https://github.com/iden3/snarkjs/issues/152
|
|
38
|
+
* Need to cleanup the threads to avoid stalling
|
|
39
|
+
*/
|
|
40
|
+
const cleanThreads = async () => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
42
|
+
if (!globalThis) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const curves = ["curve_bn128", "curve_bls12381"];
|
|
46
|
+
await Promise.all(curves.map((curve) => globalThis[curve]?.terminate()).filter(Boolean));
|
|
47
|
+
};
|
|
48
|
+
exports.cleanThreads = cleanThreads;
|
|
36
49
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/utils/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,4CAAoB;AAEpB;;;GAGG;AACI,MAAM,KAAK,GAAG,GAAY,EAAE,CAAC,YAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAAjD,QAAA,KAAK,SAA4C;AAE9D;;;GAGG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAiB,EAAE;IAClE,MAAM,YAAY,GAAG,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAE7C,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,YAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAC;AANW,QAAA,UAAU,cAMrB;AAEF;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EAAE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CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAyC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAC1G,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,YAAY,gBAUvB"}
|
|
@@ -6,5 +6,5 @@ import type { ICheckVerifyingKeysArgs } from "./types";
|
|
|
6
6
|
* @param CheckVerifyingKeysArgs - The arguments for the checkVerifyingKeys command
|
|
7
7
|
* @returns Whether the verifying keys match or not
|
|
8
8
|
*/
|
|
9
|
-
export declare const checkVerifyingKeys: ({ stateTreeDepth,
|
|
9
|
+
export declare const checkVerifyingKeys: ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, messageProcessorZkeyPath, voteTallyZkeyPath, pollJoiningZkeyPath, pollJoinedZkeyPath, verifyingKeysRegistry, signer, mode, }: ICheckVerifyingKeysArgs) => Promise<boolean>;
|
|
10
10
|
//# sourceMappingURL=checkVerifyingKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkVerifyingKeys.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/checkVerifyingKeys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAMvD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAU,
|
|
1
|
+
{"version":3,"file":"checkVerifyingKeys.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/checkVerifyingKeys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAMvD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAU,sNAYtC,uBAAuB,KAAG,OAAO,CAAC,OAAO,CAiE3C,CAAC"}
|
|
@@ -15,50 +15,49 @@ const utils_2 = require("./utils");
|
|
|
15
15
|
* @param CheckVerifyingKeysArgs - The arguments for the checkVerifyingKeys command
|
|
16
16
|
* @returns Whether the verifying keys match or not
|
|
17
17
|
*/
|
|
18
|
-
const checkVerifyingKeys = async ({ stateTreeDepth,
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error("Please provide a
|
|
18
|
+
const checkVerifyingKeys = async ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, messageProcessorZkeyPath, voteTallyZkeyPath, pollJoiningZkeyPath, pollJoinedZkeyPath, verifyingKeysRegistry, signer, mode = contracts_1.EMode.QV, }) => {
|
|
19
|
+
if (!verifyingKeysRegistry) {
|
|
20
|
+
throw new Error("Please provide a VerifyingKeysRegistry contract address");
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
throw new Error("The
|
|
22
|
+
const isVerifyingKeyExists = await (0, utils_1.contractExists)(signer.provider, verifyingKeysRegistry);
|
|
23
|
+
if (!isVerifyingKeyExists) {
|
|
24
|
+
throw new Error("The VerifyingKeysRegistry contract does not exist");
|
|
25
25
|
}
|
|
26
26
|
// we need to ensure that the zkey files exist
|
|
27
|
-
const isProcessMessagesZkeyPathExists = fs_1.default.existsSync(
|
|
27
|
+
const isProcessMessagesZkeyPathExists = fs_1.default.existsSync(messageProcessorZkeyPath);
|
|
28
28
|
if (!isProcessMessagesZkeyPathExists) {
|
|
29
29
|
throw new Error("The provided Process messages zkey does not exist");
|
|
30
30
|
}
|
|
31
|
-
const isTallyVotesZkeyPathExists = fs_1.default.existsSync(
|
|
31
|
+
const isTallyVotesZkeyPathExists = fs_1.default.existsSync(voteTallyZkeyPath);
|
|
32
32
|
if (!isTallyVotesZkeyPathExists) {
|
|
33
33
|
throw new Error("The provided Tally votes zkey does not exist");
|
|
34
34
|
}
|
|
35
35
|
// extract the verification keys from the zkey files
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const { pollJoiningVerifyingKey, pollJoinedVerifyingKey, processVerifyingKey, tallyVerifyingKey } = await (0, utils_2.extractAllVerifyingKeys)({
|
|
37
|
+
messageProcessorZkeyPath,
|
|
38
|
+
voteTallyZkeyPath,
|
|
39
39
|
pollJoiningZkeyPath,
|
|
40
40
|
pollJoinedZkeyPath,
|
|
41
41
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
vkRegistryAddress: vkRegistry,
|
|
42
|
+
const { pollJoiningVerifyingKeyOnChain, pollJoinedVerifyingKeyOnChain, processVerifyingKeyOnChain, tallyVerifyingKeyOnChain, } = await (0, utils_2.getAllOnChainVerifyingKeys)({
|
|
43
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistry,
|
|
45
44
|
signer,
|
|
46
45
|
stateTreeDepth,
|
|
47
46
|
voteOptionTreeDepth,
|
|
48
47
|
messageBatchSize,
|
|
49
|
-
|
|
48
|
+
tallyProcessingStateTreeDepth,
|
|
50
49
|
mode,
|
|
51
50
|
});
|
|
52
|
-
if (!(0, utils_2.
|
|
51
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoiningVerifyingKeyOnChain, pollJoiningVerifyingKey)) {
|
|
53
52
|
throw new Error("Poll verifying keys do not match");
|
|
54
53
|
}
|
|
55
|
-
if (!(0, utils_2.
|
|
54
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoinedVerifyingKeyOnChain, pollJoinedVerifyingKey)) {
|
|
56
55
|
throw new Error("Poll verifying keys do not match");
|
|
57
56
|
}
|
|
58
|
-
if (!(0, utils_2.
|
|
57
|
+
if (!(0, utils_2.compareVerifyingKeys)(processVerifyingKeyOnChain, processVerifyingKey)) {
|
|
59
58
|
throw new Error("Process verifying keys do not match");
|
|
60
59
|
}
|
|
61
|
-
if (!(0, utils_2.
|
|
60
|
+
if (!(0, utils_2.compareVerifyingKeys)(tallyVerifyingKeyOnChain, tallyVerifyingKey)) {
|
|
62
61
|
throw new Error("Tally verifying keys do not match");
|
|
63
62
|
}
|
|
64
63
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkVerifyingKeys.js","sourceRoot":"","sources":["../../../ts/verifyingKeys/checkVerifyingKeys.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAiD;AAEjD,4CAAoB;AAIpB,oCAA0C;AAE1C,
|
|
1
|
+
{"version":3,"file":"checkVerifyingKeys.js","sourceRoot":"","sources":["../../../ts/verifyingKeys/checkVerifyingKeys.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAiD;AAEjD,4CAAoB;AAIpB,oCAA0C;AAE1C,mCAAoG;AAEpG;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,MAAM,EACN,IAAI,GAAG,iBAAK,CAAC,EAAE,GACS,EAAoB,EAAE;IAC9C,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,oBAAoB,GAAG,MAAM,IAAA,sBAAc,EAAC,MAAM,CAAC,QAAS,EAAE,qBAAqB,CAAC,CAAC;IAE3F,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,8CAA8C;IAC9C,MAAM,+BAA+B,GAAG,YAAE,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;IAEhF,IAAI,CAAC,+BAA+B,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,0BAA0B,GAAG,YAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAEpE,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,oDAAoD;IACpD,MAAM,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAC/F,MAAM,IAAA,+BAAuB,EAAC;QAC5B,wBAAwB;QACxB,iBAAiB;QACjB,mBAAmB;QACnB,kBAAkB;KACnB,CAAC,CAAC;IAEL,MAAM,EACJ,8BAA8B,EAC9B,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,GACzB,GAAG,MAAM,IAAA,kCAA0B,EAAC;QACnC,4BAA4B,EAAE,qBAAqB;QACnD,MAAM;QACN,cAAc;QACd,mBAAmB;QACnB,gBAAgB;QAChB,6BAA6B;QAC7B,IAAI;KACL,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,4BAAoB,EAAC,8BAA8B,EAAE,uBAAuB,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,6BAA6B,EAAE,sBAAsB,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,0BAA0B,EAAE,mBAAmB,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,wBAAwB,EAAE,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA7EW,QAAA,kBAAkB,sBA6E7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { checkVerifyingKeys } from "./checkVerifyingKeys";
|
|
2
2
|
export { setVerifyingKeys } from "./setVerifyingKeys";
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
3
|
+
export { getAllOnChainVerifyingKeys, compareVerifyingKeys, extractAllVerifyingKeys, extractVerifyingKeyToFile, } from "./utils";
|
|
4
|
+
export type { IGetAllVerifyingKeysArgs, IMaciVerifyingKeysOnchain, IExtractAllVerifyingKeysArgs, IMaciVerifyingKeys, ISetVerifyingKeysArgs, ICheckVerifyingKeysArgs, } from "./types";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,wBAAwB,EACxB,yBAAyB,EACzB,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,SAAS,CAAC"}
|