@maci-protocol/sdk 0.0.0-ci.f433bba → 0.0.0-ci.f446b8f
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 +22 -20
- 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.d.ts +1 -1
- package/build/ts/deploy/maci.d.ts.map +1 -1
- package/build/ts/deploy/maci.js +18 -8
- 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 +10 -11
- package/build/ts/deploy/poll.js.map +1 -1
- package/build/ts/deploy/types.d.ts +28 -15
- 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/policy.d.ts +13 -1
- package/build/ts/maci/policy.d.ts.map +1 -1
- package/build/ts/maci/policy.js +40 -1
- package/build/ts/maci/policy.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 +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 +9 -9
- 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/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 -10
- 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 -12
- 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 -27
- 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 +92 -58
- 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/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.getFirstSignUpBlockNumber = 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");
|
|
@@ -17,13 +17,13 @@ const constants_1 = require("../utils/constants");
|
|
|
17
17
|
const parsePollJoinEvents = async ({ pollContract, startBlock, currentBlock, pollPublicKey, }) => {
|
|
18
18
|
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
19
19
|
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
20
|
-
const
|
|
20
|
+
const publicKey = pollPublicKey.asArray();
|
|
21
21
|
// eslint-disable-next-line no-await-in-loop
|
|
22
|
-
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);
|
|
23
23
|
if (newEvents.length > 0) {
|
|
24
24
|
const [event] = newEvents;
|
|
25
25
|
return {
|
|
26
|
-
pollStateIndex: event.args[
|
|
26
|
+
pollStateIndex: event.args[4].toString(),
|
|
27
27
|
voiceCredits: event.args[2].toString(),
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -39,11 +39,11 @@ exports.parsePollJoinEvents = parsePollJoinEvents;
|
|
|
39
39
|
* @param {IJoinedUserArgs} - The arguments for the join check command
|
|
40
40
|
* @returns user joined or not and poll state index, voice credit balance
|
|
41
41
|
*/
|
|
42
|
-
const getJoinedUserData = async ({ maciAddress, pollId,
|
|
42
|
+
const getJoinedUserData = async ({ maciAddress, pollId, pollPublicKey: serializedPollPublicKey, signer, startBlock, }) => {
|
|
43
43
|
const maciContract = typechain_types_1.MACI__factory.connect(maciAddress, signer);
|
|
44
44
|
const pollContracts = await maciContract.getPoll(pollId);
|
|
45
45
|
const pollContract = typechain_types_1.Poll__factory.connect(pollContracts.poll, signer);
|
|
46
|
-
const pollPublicKey = domainobjs_1.
|
|
46
|
+
const pollPublicKey = domainobjs_1.PublicKey.deserialize(serializedPollPublicKey);
|
|
47
47
|
const startBlockNumber = startBlock || 0;
|
|
48
48
|
const currentBlock = await signer.provider.getBlockNumber();
|
|
49
49
|
const { pollStateIndex, voiceCredits } = await (0, exports.parsePollJoinEvents)({
|
|
@@ -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,45 +113,33 @@ 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
|
|
119
|
-
* @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
|
|
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
|
-
// The index must be converted to a list of indices, 1 for each tree level.
|
|
130
|
-
// The circuit tree depth is this.stateTreeDepth, so the number of siblings must be this.stateTreeDepth,
|
|
131
|
-
// even if the tree depth is actually 3. The missing siblings can be set to 0, as they
|
|
132
|
-
// won't be used to calculate the root in the circuit.
|
|
133
|
-
const indices = [];
|
|
134
126
|
for (let i = 0; i < stateTreeDepth; i += 1) {
|
|
135
|
-
// eslint-disable-next-line no-bitwise
|
|
136
|
-
indices.push(BigInt((index >> i) & 1));
|
|
137
127
|
if (i >= siblingsLength) {
|
|
138
128
|
siblings[i] = BigInt(0);
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
131
|
const siblingsArray = siblings.map((sibling) => [sibling]);
|
|
142
132
|
// Create nullifier from private key
|
|
143
|
-
const inputNullifier = BigInt(
|
|
133
|
+
const inputNullifier = BigInt(maciPrivateKey.asCircuitInputs());
|
|
144
134
|
const nullifier = (0, crypto_1.poseidon)([inputNullifier, pollId]);
|
|
145
|
-
// Get pll state tree's root
|
|
146
|
-
const stateRoot = stateTree.root;
|
|
147
135
|
// Set actualStateTreeDepth as number of initial siblings length
|
|
148
136
|
const actualStateTreeDepth = BigInt(siblingsLength);
|
|
149
137
|
// Calculate public input hash from nullifier, credits and current root
|
|
150
138
|
const circuitInputs = {
|
|
151
|
-
|
|
152
|
-
|
|
139
|
+
privateKey: maciPrivateKey.asCircuitInputs(),
|
|
140
|
+
pollPublicKey: pollPublicKey.asCircuitInputs(),
|
|
153
141
|
siblings: siblingsArray,
|
|
154
|
-
|
|
142
|
+
index: BigInt(index),
|
|
155
143
|
nullifier,
|
|
156
144
|
stateRoot,
|
|
157
145
|
actualStateTreeDepth,
|
|
@@ -165,26 +153,77 @@ exports.joiningCircuitInputs = joiningCircuitInputs;
|
|
|
165
153
|
* @param stateFile - The path to the state file
|
|
166
154
|
* @returns The poll joining circuit inputs
|
|
167
155
|
*/
|
|
168
|
-
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex,
|
|
156
|
+
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex, userMaciPrivateKey, }) => {
|
|
169
157
|
const file = await fs_1.default.promises.readFile(stateFile);
|
|
170
158
|
const content = JSON.parse(file.toString());
|
|
171
159
|
const maciState = core_1.MaciState.fromJSON(content);
|
|
172
160
|
const poll = maciState.polls.get(pollId);
|
|
173
|
-
const {
|
|
174
|
-
const loadedStateIndex = (0, exports.getStateIndex)(maciState.
|
|
161
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
162
|
+
const loadedStateIndex = (0, exports.getStateIndex)(maciState.publicKeys, userPublicKey, stateIndex);
|
|
175
163
|
// check < 1 cause index zero is a blank state leaf
|
|
176
164
|
if (loadedStateIndex < 1) {
|
|
177
165
|
throw new Error("Invalid state index");
|
|
178
166
|
}
|
|
179
|
-
poll.updatePoll(BigInt(maciState.
|
|
167
|
+
poll.updatePoll(BigInt(maciState.publicKeys.length));
|
|
180
168
|
const circuitInputs = poll.joiningCircuitInputs({
|
|
181
|
-
|
|
169
|
+
maciPrivateKey: userMaciPrivateKey,
|
|
182
170
|
stateLeafIndex: stateIndex,
|
|
183
|
-
|
|
171
|
+
pollPublicKey: userPublicKey,
|
|
184
172
|
});
|
|
185
173
|
return circuitInputs;
|
|
186
174
|
};
|
|
187
175
|
exports.getPollJoiningCircuitInputsFromStateFile = getPollJoiningCircuitInputsFromStateFile;
|
|
176
|
+
/**
|
|
177
|
+
* Get the block number when the first SignUp event was emitted
|
|
178
|
+
* @param maciContract - The MACI contract to fetch events from
|
|
179
|
+
* @param startBlock - The block number to start searching from (optional)
|
|
180
|
+
* @returns The block number when the first SignUp event was emitted
|
|
181
|
+
*/
|
|
182
|
+
const getFirstSignUpBlockNumber = async (maciContract, startBlock) => {
|
|
183
|
+
if (startBlock) {
|
|
184
|
+
return startBlock;
|
|
185
|
+
}
|
|
186
|
+
return maciContract.queryFilter(maciContract.filters.SignUp(), 0).then((events) => events[0]?.blockNumber ?? 0);
|
|
187
|
+
};
|
|
188
|
+
exports.getFirstSignUpBlockNumber = getFirstSignUpBlockNumber;
|
|
189
|
+
/**
|
|
190
|
+
* Generate MACI's state tree from the MACI contract
|
|
191
|
+
* @param {IGenerateMaciStateTreeArgs} args - The arguments for the generate maci state tree command
|
|
192
|
+
* @returns The MACI's state tree
|
|
193
|
+
*/
|
|
194
|
+
const generateMaciStateTree = async ({ maciContractAddress, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
195
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciContractAddress, signer);
|
|
196
|
+
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
197
|
+
const fromBlock = await (0, exports.getFirstSignUpBlockNumber)(maciContract, startBlock);
|
|
198
|
+
return (0, stateTree_1.generateSignUpTree)({
|
|
199
|
+
provider: signer.provider,
|
|
200
|
+
address: await maciContract.getAddress(),
|
|
201
|
+
blocksPerRequest: blocksPerBatch || 50,
|
|
202
|
+
fromBlock,
|
|
203
|
+
endBlock,
|
|
204
|
+
sleepAmount: 0,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
exports.generateMaciStateTree = generateMaciStateTree;
|
|
208
|
+
/**
|
|
209
|
+
* Generate MACI's state tree from the MACI contract with a given end key
|
|
210
|
+
* @param {IGenerateMaciStateTreeWithEndKeyArgs} args - The arguments for the generate maci state tree command
|
|
211
|
+
* @returns The MACI's state tree
|
|
212
|
+
*/
|
|
213
|
+
const generateMaciStateTreeWithEndKey = async ({ maciContractAddress, signer, startBlock, endBlock, blocksPerBatch, userPublicKey, }) => {
|
|
214
|
+
const maciContract = typechain_types_1.MACI__factory.connect(maciContractAddress, signer);
|
|
215
|
+
// build an off-chain representation of the MACI contract using data in the contract storage
|
|
216
|
+
const fromBlock = await (0, exports.getFirstSignUpBlockNumber)(maciContract, startBlock);
|
|
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;
|
|
188
227
|
/**
|
|
189
228
|
* Get the poll joining circuit events from a state file
|
|
190
229
|
* @param maciContract - The MACI contract
|
|
@@ -192,33 +231,28 @@ exports.getPollJoiningCircuitInputsFromStateFile = getPollJoiningCircuitInputsFr
|
|
|
192
231
|
* @param signer - The signer
|
|
193
232
|
* @returns The poll joining circuit events
|
|
194
233
|
*/
|
|
195
|
-
const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId,
|
|
196
|
-
|
|
197
|
-
const [defaultStartBlockSignup, defaultStartBlockPoll, stateTreeDepth] = await Promise.all([
|
|
198
|
-
maciContract
|
|
199
|
-
.queryFilter(maciContract.filters.SignUp(), startBlock ?? 0)
|
|
200
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
201
|
-
maciContract
|
|
202
|
-
.queryFilter(maciContract.filters.DeployPoll(), startBlock ?? 0)
|
|
203
|
-
.then((events) => events[0]?.blockNumber ?? 0),
|
|
234
|
+
const getPollJoiningCircuitEvents = async ({ maciContract, stateIndex, pollId, userMaciPrivateKey, signer, startBlock, endBlock, blocksPerBatch, }) => {
|
|
235
|
+
const [stateTreeDepth, maciContractAddress] = await Promise.all([
|
|
204
236
|
maciContract.stateTreeDepth(),
|
|
237
|
+
maciContract.getAddress(),
|
|
205
238
|
]);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
address: await maciContract.getAddress(),
|
|
211
|
-
blocksPerRequest: blocksPerBatch || 50,
|
|
212
|
-
fromBlock,
|
|
239
|
+
const signUpData = await (0, exports.generateMaciStateTree)({
|
|
240
|
+
maciContractAddress,
|
|
241
|
+
signer,
|
|
242
|
+
startBlock,
|
|
213
243
|
endBlock,
|
|
214
|
-
|
|
244
|
+
blocksPerBatch,
|
|
215
245
|
});
|
|
216
|
-
const {
|
|
217
|
-
const loadedStateIndex = (0, exports.getStateIndex)(signUpData.
|
|
246
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
247
|
+
const loadedStateIndex = (0, exports.getStateIndex)(signUpData.publicKeys, userPublicKey, stateIndex);
|
|
218
248
|
if (loadedStateIndex < 1) {
|
|
219
249
|
throw new Error("Invalid state index");
|
|
220
250
|
}
|
|
221
|
-
|
|
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);
|
|
222
256
|
};
|
|
223
257
|
exports.getPollJoiningCircuitEvents = getPollJoiningCircuitEvents;
|
|
224
258
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/user/utils.ts"],"names":[],"mappings":";;;;;;AAAA,8EAIkD;AAClD,8CAAqE;AACrE,kDAAmE;AACnE,0DAAgF;AAEhF,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,SAAS,GAAG,MAAM,YAAY,CAAC,WAAW,CAC9C,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,EAC5F,KAAK,EACL,OAAO,CACR,CAAC;QAEF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;YAE1B,OAAO;gBACL,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;gBACxC,YAAY,EAAE,KAAK,CAAC,IAAI,CA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AI,gBAAiB,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;IAE7C,+EAA+E;IAC/E,MAAM,cAAc,GAAG,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEzE,OAAO,IAAA,4BAAoB,EACzB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,MAAM,CACsB,CAAC;AACjC,CAAC,CAAC;AA3CW,QAAA,2BAA2B,+BA2CtC"}
|
|
@@ -6,7 +6,7 @@ export { fundWallet } from "./fundWallet";
|
|
|
6
6
|
export { validateParams } from "./params";
|
|
7
7
|
export { timeTravel } from "./timeTravel";
|
|
8
8
|
export { calculateBinaryTreeDepthFromMaxLeaves, calculateQuinTreeDepthFromMaxLeaves } from "./trees";
|
|
9
|
-
export { isArm, sleep } from "./utils";
|
|
9
|
+
export { isArm, sleep, sleepUntil } from "./utils";
|
|
10
10
|
export { generateAndVerifyProof } from "./proofs";
|
|
11
11
|
export type { ICircuitParams, ISnarkJSVerificationKey, ITimeTravelArgs, IFundWalletArgs } from "./types";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,qCAAqC,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,qCAAqC,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
package/build/ts/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateAndVerifyProof = exports.sleep = exports.isArm = exports.calculateQuinTreeDepthFromMaxLeaves = exports.calculateBinaryTreeDepthFromMaxLeaves = exports.timeTravel = exports.validateParams = exports.fundWallet = exports.asHex = exports.currentBlockTimestamp = exports.contractExists = exports.BLOCKS_STEP = exports.createCidFromObject = exports.cidToBytes32 = void 0;
|
|
3
|
+
exports.generateAndVerifyProof = exports.sleepUntil = exports.sleep = exports.isArm = exports.calculateQuinTreeDepthFromMaxLeaves = exports.calculateBinaryTreeDepthFromMaxLeaves = exports.timeTravel = exports.validateParams = exports.fundWallet = exports.asHex = exports.currentBlockTimestamp = exports.contractExists = exports.BLOCKS_STEP = exports.createCidFromObject = exports.cidToBytes32 = void 0;
|
|
4
4
|
var cid_1 = require("./cid");
|
|
5
5
|
Object.defineProperty(exports, "cidToBytes32", { enumerable: true, get: function () { return cid_1.cidToBytes32; } });
|
|
6
6
|
Object.defineProperty(exports, "createCidFromObject", { enumerable: true, get: function () { return cid_1.createCidFromObject; } });
|
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "calculateQuinTreeDepthFromMaxLeaves", { enumerab
|
|
|
23
23
|
var utils_1 = require("./utils");
|
|
24
24
|
Object.defineProperty(exports, "isArm", { enumerable: true, get: function () { return utils_1.isArm; } });
|
|
25
25
|
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
|
|
26
|
+
Object.defineProperty(exports, "sleepUntil", { enumerable: true, get: function () { return utils_1.sleepUntil; } });
|
|
26
27
|
var proofs_1 = require("./proofs");
|
|
27
28
|
Object.defineProperty(exports, "generateAndVerifyProof", { enumerable: true, get: function () { return proofs_1.generateAndVerifyProof; } });
|
|
28
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/utils/index.ts"],"names":[],"mappings":";;;AAAA,6BAA0D;AAAjD,mGAAA,YAAY,OAAA;AAAE,0GAAA,mBAAmB,OAAA;AAC1C,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,yCAAoE;AAA3D,2GAAA,cAAc,OAAA;AAAE,kHAAA,qBAAqB,OAAA;AAC9C,2CAAqC;AAA5B,mGAAA,KAAK,OAAA;AACd,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,iCAAqG;AAA5F,8HAAA,qCAAqC,OAAA;AAAE,4HAAA,mCAAmC,OAAA;AACnF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/utils/index.ts"],"names":[],"mappings":";;;AAAA,6BAA0D;AAAjD,mGAAA,YAAY,OAAA;AAAE,0GAAA,mBAAmB,OAAA;AAC1C,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,yCAAoE;AAA3D,2GAAA,cAAc,OAAA;AAAE,kHAAA,qBAAqB,OAAA;AAC9C,2CAAqC;AAA5B,mGAAA,KAAK,OAAA;AACd,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,iCAAqG;AAA5F,8HAAA,qCAAqC,OAAA;AAAE,4HAAA,mCAAmC,OAAA;AACnF,iCAAmD;AAA1C,8FAAA,KAAK,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,mGAAA,UAAU,OAAA;AACjC,mCAAkD;AAAzC,gHAAA,sBAAsB,OAAA"}
|
|
@@ -3,5 +3,5 @@ import type { ICircuitParams } from "./types";
|
|
|
3
3
|
* 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,6 +13,11 @@ 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
|
+
/**
|
|
17
|
+
* Pause until a specific timestamp
|
|
18
|
+
* @param timestamp - the timestamp to wait for in milliseconds
|
|
19
|
+
*/
|
|
20
|
+
export declare const sleepUntil: (timestamp: number) => Promise<void>;
|
|
16
21
|
declare global {
|
|
17
22
|
interface ITerminatable {
|
|
18
23
|
terminate: () => Promise<unknown>;
|
|
@@ -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;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"}
|
|
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;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAOhE,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.cleanThreads = exports.sleep = exports.unlinkFile = exports.isArm = void 0;
|
|
6
|
+
exports.cleanThreads = exports.sleepUntil = 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,6 +33,18 @@ const sleep = async (ms) => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
exports.sleep = sleep;
|
|
36
|
+
/**
|
|
37
|
+
* Pause until a specific timestamp
|
|
38
|
+
* @param timestamp - the timestamp to wait for in milliseconds
|
|
39
|
+
*/
|
|
40
|
+
const sleepUntil = async (timestamp) => {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
const msToWait = timestamp - now;
|
|
43
|
+
if (msToWait > 0) {
|
|
44
|
+
await (0, exports.sleep)(msToWait);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.sleepUntil = sleepUntil;
|
|
36
48
|
/*
|
|
37
49
|
* https://github.com/iden3/snarkjs/issues/152
|
|
38
50
|
* Need to cleanup the threads to avoid stalling
|
|
@@ -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,EAAU,EAAiB,EAAE;IAC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AC,CAAC,OAAO,EAAE,EAAE;QAC5B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,KAAK,SAIhB;AAEF;;;GAGG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,SAAiB,EAAiB,EAAE;IACnE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,SAAS,GAAG,GAAG,CAAC;IAEjC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;AACH,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAcF;;;GAGG;AACI,MAAM,YAAY,GAAG,KAAK,IAAmB,EAAE;IACpD,uEAAuE;IACvE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;IACjD,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,GAAG,CAAC,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;
|