@maci-protocol/sdk 0.0.0-ci.00107eb
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/CHANGELOG.md +80 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/build/package.json +65 -0
- package/build/ts/browser/index.d.ts +15 -0
- package/build/ts/browser/index.d.ts.map +1 -0
- package/build/ts/browser/index.js +40 -0
- package/build/ts/browser/index.js.map +1 -0
- 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 +6 -0
- package/build/ts/deploy/index.d.ts.map +1 -0
- package/build/ts/deploy/index.js +12 -0
- package/build/ts/deploy/index.js.map +1 -0
- package/build/ts/deploy/maci.d.ts +8 -0
- package/build/ts/deploy/maci.d.ts.map +1 -0
- package/build/ts/deploy/maci.js +97 -0
- package/build/ts/deploy/maci.js.map +1 -0
- package/build/ts/deploy/poll.d.ts +8 -0
- package/build/ts/deploy/poll.d.ts.map +1 -0
- package/build/ts/deploy/poll.js +112 -0
- package/build/ts/deploy/poll.js.map +1 -0
- package/build/ts/deploy/types.d.ts +225 -0
- package/build/ts/deploy/types.d.ts.map +1 -0
- package/build/ts/deploy/types.js +3 -0
- package/build/ts/deploy/types.js.map +1 -0
- package/build/ts/deploy/utils.d.ts +11 -0
- package/build/ts/deploy/utils.d.ts.map +1 -0
- package/build/ts/deploy/utils.js +22 -0
- package/build/ts/deploy/utils.js.map +1 -0
- 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 +17 -0
- package/build/ts/index.d.ts.map +1 -0
- package/build/ts/index.js +89 -0
- package/build/ts/index.js.map +1 -0
- package/build/ts/maci/index.d.ts +6 -0
- package/build/ts/maci/index.d.ts.map +1 -0
- package/build/ts/maci/index.js +17 -0
- package/build/ts/maci/index.js.map +1 -0
- package/build/ts/maci/merge.d.ts +9 -0
- package/build/ts/maci/merge.d.ts.map +1 -0
- package/build/ts/maci/merge.js +29 -0
- package/build/ts/maci/merge.js.map +1 -0
- package/build/ts/maci/policy.d.ts +53 -0
- package/build/ts/maci/policy.d.ts.map +1 -0
- package/build/ts/maci/policy.js +166 -0
- package/build/ts/maci/policy.js.map +1 -0
- package/build/ts/maci/state.d.ts +8 -0
- package/build/ts/maci/state.d.ts.map +1 -0
- package/build/ts/maci/state.js +82 -0
- package/build/ts/maci/state.js.map +1 -0
- package/build/ts/maci/types.d.ts +208 -0
- package/build/ts/maci/types.d.ts.map +1 -0
- package/build/ts/maci/types.js +20 -0
- package/build/ts/maci/types.js.map +1 -0
- package/build/ts/maciKeys/__tests__/keypair.test.d.ts +2 -0
- package/build/ts/maciKeys/__tests__/keypair.test.d.ts.map +1 -0
- package/build/ts/maciKeys/__tests__/keypair.test.js +24 -0
- package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts +2 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts.map +1 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.js +22 -0
- package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -0
- package/build/ts/maciKeys/index.d.ts +4 -0
- package/build/ts/maciKeys/index.d.ts.map +1 -0
- package/build/ts/maciKeys/index.js +8 -0
- package/build/ts/maciKeys/index.js.map +1 -0
- package/build/ts/maciKeys/keypair.d.ts +9 -0
- package/build/ts/maciKeys/keypair.d.ts.map +1 -0
- package/build/ts/maciKeys/keypair.js +21 -0
- package/build/ts/maciKeys/keypair.js.map +1 -0
- package/build/ts/maciKeys/publicKeys.d.ts +8 -0
- package/build/ts/maciKeys/publicKeys.d.ts.map +1 -0
- package/build/ts/maciKeys/publicKeys.js +23 -0
- package/build/ts/maciKeys/publicKeys.js.map +1 -0
- package/build/ts/maciKeys/types.d.ts +28 -0
- package/build/ts/maciKeys/types.d.ts.map +1 -0
- package/build/ts/maciKeys/types.js +3 -0
- package/build/ts/maciKeys/types.js.map +1 -0
- package/build/ts/poll/index.d.ts +4 -0
- package/build/ts/poll/index.d.ts.map +1 -0
- package/build/ts/poll/index.js +9 -0
- package/build/ts/poll/index.js.map +1 -0
- package/build/ts/poll/poll.d.ts +14 -0
- package/build/ts/poll/poll.d.ts.map +1 -0
- package/build/ts/poll/poll.js +62 -0
- package/build/ts/poll/poll.js.map +1 -0
- package/build/ts/poll/types.d.ts +151 -0
- package/build/ts/poll/types.d.ts.map +1 -0
- package/build/ts/poll/types.js +3 -0
- package/build/ts/poll/types.js.map +1 -0
- package/build/ts/poll/utils.d.ts +9 -0
- package/build/ts/poll/utils.d.ts.map +1 -0
- package/build/ts/poll/utils.js +43 -0
- package/build/ts/poll/utils.js.map +1 -0
- package/build/ts/proof/__tests__/download.test.d.ts +2 -0
- package/build/ts/proof/__tests__/download.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/download.test.js +53 -0
- package/build/ts/proof/__tests__/download.test.js.map +1 -0
- package/build/ts/proof/download.d.ts +9 -0
- package/build/ts/proof/download.d.ts.map +1 -0
- package/build/ts/proof/download.js +47 -0
- package/build/ts/proof/download.js.map +1 -0
- package/build/ts/proof/generate.d.ts +8 -0
- package/build/ts/proof/generate.d.ts.map +1 -0
- package/build/ts/proof/generate.js +133 -0
- package/build/ts/proof/generate.js.map +1 -0
- package/build/ts/proof/index.d.ts +4 -0
- package/build/ts/proof/index.d.ts.map +1 -0
- package/build/ts/proof/index.js +8 -0
- package/build/ts/proof/index.js.map +1 -0
- package/build/ts/proof/prove.d.ts +8 -0
- package/build/ts/proof/prove.d.ts.map +1 -0
- package/build/ts/proof/prove.js +91 -0
- package/build/ts/proof/prove.js.map +1 -0
- package/build/ts/proof/types.d.ts +205 -0
- package/build/ts/proof/types.d.ts.map +1 -0
- package/build/ts/proof/types.js +3 -0
- package/build/ts/proof/types.js.map +1 -0
- 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.d.ts +2 -0
- package/build/ts/relayer/__tests__/messages.test.d.ts.map +1 -0
- package/build/ts/relayer/__tests__/messages.test.js +76 -0
- package/build/ts/relayer/__tests__/messages.test.js.map +1 -0
- package/build/ts/relayer/__tests__/utils.test.d.ts +2 -0
- package/build/ts/relayer/__tests__/utils.test.d.ts.map +1 -0
- package/build/ts/relayer/__tests__/utils.test.js +73 -0
- package/build/ts/relayer/__tests__/utils.test.js.map +1 -0
- package/build/ts/relayer/index.d.ts +3 -0
- package/build/ts/relayer/index.d.ts.map +1 -0
- package/build/ts/relayer/index.js +8 -0
- package/build/ts/relayer/index.js.map +1 -0
- package/build/ts/relayer/messages.d.ts +23 -0
- package/build/ts/relayer/messages.d.ts.map +1 -0
- package/build/ts/relayer/messages.js +66 -0
- package/build/ts/relayer/messages.js.map +1 -0
- package/build/ts/relayer/types.d.ts +168 -0
- package/build/ts/relayer/types.d.ts.map +1 -0
- package/build/ts/relayer/types.js +3 -0
- package/build/ts/relayer/types.js.map +1 -0
- package/build/ts/relayer/utils.d.ts +12 -0
- package/build/ts/relayer/utils.d.ts.map +1 -0
- package/build/ts/relayer/utils.js +37 -0
- package/build/ts/relayer/utils.js.map +1 -0
- 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 +9 -0
- package/build/ts/tally/commitments.d.ts.map +1 -0
- package/build/ts/tally/commitments.js +43 -0
- package/build/ts/tally/commitments.js.map +1 -0
- package/build/ts/tally/index.d.ts +5 -0
- package/build/ts/tally/index.d.ts.map +1 -0
- package/build/ts/tally/index.js +12 -0
- package/build/ts/tally/index.js.map +1 -0
- 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 +219 -0
- package/build/ts/tally/types.d.ts.map +1 -0
- package/build/ts/tally/types.js +3 -0
- package/build/ts/tally/types.js.map +1 -0
- package/build/ts/tally/utils.d.ts +24 -0
- package/build/ts/tally/utils.d.ts.map +1 -0
- package/build/ts/tally/utils.js +50 -0
- package/build/ts/tally/utils.js.map +1 -0
- package/build/ts/tally/verification.d.ts +7 -0
- package/build/ts/tally/verification.d.ts.map +1 -0
- package/build/ts/tally/verification.js +62 -0
- package/build/ts/tally/verification.js.map +1 -0
- package/build/ts/trees/index.d.ts +3 -0
- package/build/ts/trees/index.d.ts.map +1 -0
- package/build/ts/trees/index.js +8 -0
- package/build/ts/trees/index.js.map +1 -0
- package/build/ts/trees/stateTree.d.ts +35 -0
- package/build/ts/trees/stateTree.d.ts.map +1 -0
- package/build/ts/trees/stateTree.js +117 -0
- package/build/ts/trees/stateTree.js.map +1 -0
- package/build/ts/trees/types.d.ts +55 -0
- package/build/ts/trees/types.d.ts.map +1 -0
- package/build/ts/trees/types.js +3 -0
- package/build/ts/trees/types.js.map +1 -0
- package/build/ts/user/index.d.ts +5 -0
- package/build/ts/user/index.d.ts.map +1 -0
- package/build/ts/user/index.js +17 -0
- package/build/ts/user/index.js.map +1 -0
- 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 +460 -0
- package/build/ts/user/types.d.ts.map +1 -0
- package/build/ts/user/types.js +3 -0
- package/build/ts/user/types.js.map +1 -0
- package/build/ts/user/utils.d.ts +88 -0
- package/build/ts/user/utils.d.ts.map +1 -0
- package/build/ts/user/utils.js +258 -0
- package/build/ts/user/utils.js.map +1 -0
- package/build/ts/utils/cid.d.ts +23 -0
- package/build/ts/utils/cid.d.ts.map +1 -0
- package/build/ts/utils/cid.js +72 -0
- package/build/ts/utils/cid.js.map +1 -0
- package/build/ts/utils/constants.d.ts +2 -0
- package/build/ts/utils/constants.d.ts.map +1 -0
- package/build/ts/utils/constants.js +5 -0
- package/build/ts/utils/constants.js.map +1 -0
- package/build/ts/utils/contracts.d.ts +15 -0
- package/build/ts/utils/contracts.d.ts.map +1 -0
- package/build/ts/utils/contracts.js +26 -0
- package/build/ts/utils/contracts.js.map +1 -0
- package/build/ts/utils/files.d.ts +9 -0
- package/build/ts/utils/files.d.ts.map +1 -0
- package/build/ts/utils/files.js +20 -0
- package/build/ts/utils/files.js.map +1 -0
- package/build/ts/utils/formatting.d.ts +8 -0
- package/build/ts/utils/formatting.d.ts.map +1 -0
- package/build/ts/utils/formatting.js +11 -0
- package/build/ts/utils/formatting.js.map +1 -0
- package/build/ts/utils/fundWallet.d.ts +7 -0
- package/build/ts/utils/fundWallet.d.ts.map +1 -0
- package/build/ts/utils/fundWallet.js +20 -0
- package/build/ts/utils/fundWallet.js.map +1 -0
- package/build/ts/utils/index.d.ts +12 -0
- package/build/ts/utils/index.d.ts.map +1 -0
- package/build/ts/utils/index.js +29 -0
- package/build/ts/utils/index.js.map +1 -0
- package/build/ts/utils/params.d.ts +7 -0
- package/build/ts/utils/params.d.ts.map +1 -0
- package/build/ts/utils/params.js +19 -0
- package/build/ts/utils/params.js.map +1 -0
- package/build/ts/utils/proofs.d.ts +13 -0
- package/build/ts/utils/proofs.d.ts.map +1 -0
- package/build/ts/utils/proofs.js +41 -0
- package/build/ts/utils/proofs.js.map +1 -0
- package/build/ts/utils/timeTravel.d.ts +7 -0
- package/build/ts/utils/timeTravel.d.ts.map +1 -0
- package/build/ts/utils/timeTravel.js +14 -0
- package/build/ts/utils/timeTravel.js.map +1 -0
- package/build/ts/utils/trees.d.ts +13 -0
- package/build/ts/utils/trees.d.ts.map +1 -0
- package/build/ts/utils/trees.js +30 -0
- package/build/ts/utils/trees.js.map +1 -0
- package/build/ts/utils/types.d.ts +71 -0
- package/build/ts/utils/types.d.ts.map +1 -0
- package/build/ts/utils/types.js +3 -0
- package/build/ts/utils/types.js.map +1 -0
- package/build/ts/utils/utils.d.ts +29 -0
- package/build/ts/utils/utils.d.ts.map +1 -0
- package/build/ts/utils/utils.js +61 -0
- package/build/ts/utils/utils.js.map +1 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts +10 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts.map +1 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.js +66 -0
- package/build/ts/verifyingKeys/checkVerifyingKeys.js.map +1 -0
- package/build/ts/verifyingKeys/index.d.ts +5 -0
- package/build/ts/verifyingKeys/index.d.ts.map +1 -0
- package/build/ts/verifyingKeys/index.js +13 -0
- package/build/ts/verifyingKeys/index.js.map +1 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts +7 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.d.ts.map +1 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.js +108 -0
- package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -0
- package/build/ts/verifyingKeys/types.d.ts +239 -0
- package/build/ts/verifyingKeys/types.d.ts.map +1 -0
- package/build/ts/verifyingKeys/types.js +3 -0
- package/build/ts/verifyingKeys/types.js.map +1 -0
- package/build/ts/verifyingKeys/utils.d.ts +29 -0
- package/build/ts/verifyingKeys/utils.d.ts.map +1 -0
- package/build/ts/verifyingKeys/utils.js +118 -0
- package/build/ts/verifyingKeys/utils.js.map +1 -0
- package/build/ts/vote/generate.d.ts +8 -0
- package/build/ts/vote/generate.d.ts.map +1 -0
- package/build/ts/vote/generate.js +46 -0
- package/build/ts/vote/generate.js.map +1 -0
- package/build/ts/vote/index.d.ts +7 -0
- package/build/ts/vote/index.d.ts.map +1 -0
- package/build/ts/vote/index.js +17 -0
- package/build/ts/vote/index.js.map +1 -0
- package/build/ts/vote/invalidate.d.ts +13 -0
- package/build/ts/vote/invalidate.d.ts.map +1 -0
- package/build/ts/vote/invalidate.js +44 -0
- package/build/ts/vote/invalidate.js.map +1 -0
- package/build/ts/vote/publish.d.ts +14 -0
- package/build/ts/vote/publish.d.ts.map +1 -0
- package/build/ts/vote/publish.js +88 -0
- package/build/ts/vote/publish.js.map +1 -0
- package/build/ts/vote/submit.d.ts +13 -0
- package/build/ts/vote/submit.d.ts.map +1 -0
- package/build/ts/vote/submit.js +36 -0
- package/build/ts/vote/submit.js.map +1 -0
- package/build/ts/vote/types.d.ts +238 -0
- package/build/ts/vote/types.d.ts.map +1 -0
- package/build/ts/vote/types.js +3 -0
- package/build/ts/vote/types.js.map +1 -0
- package/build/ts/vote/utils.d.ts +16 -0
- package/build/ts/vote/utils.d.ts.map +1 -0
- package/build/ts/vote/utils.js +26 -0
- package/build/ts/vote/utils.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
8
|
+
const core_1 = require("@maci-protocol/core");
|
|
9
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
10
|
+
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const stateTree_1 = require("../trees/stateTree");
|
|
13
|
+
const constants_1 = require("../utils/constants");
|
|
14
|
+
/**
|
|
15
|
+
* Parse the poll joining events from the Poll contract
|
|
16
|
+
*/
|
|
17
|
+
const parsePollJoinEvents = async ({ pollContract, startBlock, currentBlock, pollPublicKey, }) => {
|
|
18
|
+
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
19
|
+
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
20
|
+
const publicKey = pollPublicKey.asArray();
|
|
21
|
+
// eslint-disable-next-line no-await-in-loop
|
|
22
|
+
const newEvents = await pollContract.queryFilter(pollContract.filters.PollJoined(publicKey[0], publicKey[1], undefined, undefined, undefined), block, toBlock);
|
|
23
|
+
if (newEvents.length > 0) {
|
|
24
|
+
const [event] = newEvents;
|
|
25
|
+
return {
|
|
26
|
+
pollStateIndex: event.args[4].toString(),
|
|
27
|
+
voiceCredits: event.args[2].toString(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
pollStateIndex: undefined,
|
|
33
|
+
voiceCredits: undefined,
|
|
34
|
+
};
|
|
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;
|
|
74
|
+
/**
|
|
75
|
+
* Parse the signup events from the MACI contract
|
|
76
|
+
*/
|
|
77
|
+
const parseSignupEvents = async ({ maciContract, startBlock, currentBlock, publicKey, }) => {
|
|
78
|
+
for (let block = startBlock; block <= currentBlock; block += constants_1.BLOCKS_STEP) {
|
|
79
|
+
const toBlock = Math.min(block + constants_1.BLOCKS_STEP - 1, currentBlock);
|
|
80
|
+
// eslint-disable-next-line no-await-in-loop
|
|
81
|
+
const newEvents = await maciContract.queryFilter(maciContract.filters.SignUp(undefined, undefined, publicKey.raw[0], publicKey.raw[1]), block, toBlock);
|
|
82
|
+
if (newEvents.length > 0) {
|
|
83
|
+
const [event] = newEvents;
|
|
84
|
+
return {
|
|
85
|
+
stateIndex: event.args[0].toString(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
stateIndex: undefined,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
exports.parseSignupEvents = parseSignupEvents;
|
|
94
|
+
/**
|
|
95
|
+
* Get state index from maci state leaves or from sign up leaves
|
|
96
|
+
* @param publicKeys Public keys from maci state or sign up tree
|
|
97
|
+
* @param userMaciPublicKey Public key of the maci user
|
|
98
|
+
* @param stateIndex State index from the command
|
|
99
|
+
* @returns State index
|
|
100
|
+
*/
|
|
101
|
+
const getStateIndex = (publicKeys, userMaciPublicKey, stateIndex) => {
|
|
102
|
+
if (!stateIndex) {
|
|
103
|
+
const index = publicKeys.findIndex((key) => key.equals(userMaciPublicKey));
|
|
104
|
+
if (index > 0) {
|
|
105
|
+
return BigInt(index);
|
|
106
|
+
}
|
|
107
|
+
throw new Error("MACI Public key not found");
|
|
108
|
+
}
|
|
109
|
+
return stateIndex;
|
|
110
|
+
};
|
|
111
|
+
exports.getStateIndex = getStateIndex;
|
|
112
|
+
/**
|
|
113
|
+
* Create circuit input for pollJoining
|
|
114
|
+
* @param signUpData Sign up tree and state leaves
|
|
115
|
+
* @param stateTreeDepth Maci state tree depth
|
|
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
|
|
119
|
+
* @param pollId Poll's id
|
|
120
|
+
* @returns stringified circuit inputs
|
|
121
|
+
*/
|
|
122
|
+
const joiningCircuitInputs = (inclusionProof, stateTreeDepth, maciPrivateKey, pollPublicKey, pollId) => {
|
|
123
|
+
// calculate the path elements for the state tree given the original state tree
|
|
124
|
+
const { siblings, index, root: stateRoot } = inclusionProof;
|
|
125
|
+
const siblingsLength = siblings.length;
|
|
126
|
+
for (let i = 0; i < stateTreeDepth; i += 1) {
|
|
127
|
+
if (i >= siblingsLength) {
|
|
128
|
+
siblings[i] = BigInt(0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const siblingsArray = siblings.map((sibling) => [sibling]);
|
|
132
|
+
// Create nullifier from private key
|
|
133
|
+
const inputNullifier = BigInt(maciPrivateKey.asCircuitInputs());
|
|
134
|
+
const nullifier = (0, crypto_1.poseidon)([inputNullifier, pollId]);
|
|
135
|
+
// Set actualStateTreeDepth as number of initial siblings length
|
|
136
|
+
const actualStateTreeDepth = BigInt(siblingsLength);
|
|
137
|
+
// Calculate public input hash from nullifier, credits and current root
|
|
138
|
+
const circuitInputs = {
|
|
139
|
+
privateKey: maciPrivateKey.asCircuitInputs(),
|
|
140
|
+
pollPublicKey: pollPublicKey.asCircuitInputs(),
|
|
141
|
+
siblings: siblingsArray,
|
|
142
|
+
index: BigInt(index),
|
|
143
|
+
nullifier,
|
|
144
|
+
stateRoot,
|
|
145
|
+
actualStateTreeDepth,
|
|
146
|
+
pollId,
|
|
147
|
+
};
|
|
148
|
+
return (0, crypto_1.stringifyBigInts)(circuitInputs);
|
|
149
|
+
};
|
|
150
|
+
exports.joiningCircuitInputs = joiningCircuitInputs;
|
|
151
|
+
/**
|
|
152
|
+
* Get the poll joining circuit inputs from a state file
|
|
153
|
+
* @param stateFile - The path to the state file
|
|
154
|
+
* @returns The poll joining circuit inputs
|
|
155
|
+
*/
|
|
156
|
+
const getPollJoiningCircuitInputsFromStateFile = async ({ stateFile, pollId, stateIndex, userMaciPrivateKey, }) => {
|
|
157
|
+
const file = await fs_1.default.promises.readFile(stateFile);
|
|
158
|
+
const content = JSON.parse(file.toString());
|
|
159
|
+
const maciState = core_1.MaciState.fromJSON(content);
|
|
160
|
+
const poll = maciState.polls.get(pollId);
|
|
161
|
+
const { publicKey: userPublicKey } = new domainobjs_1.Keypair(userMaciPrivateKey);
|
|
162
|
+
const loadedStateIndex = (0, exports.getStateIndex)(maciState.publicKeys, userPublicKey, stateIndex);
|
|
163
|
+
// check < 1 cause index zero is a blank state leaf
|
|
164
|
+
if (loadedStateIndex < 1) {
|
|
165
|
+
throw new Error("Invalid state index");
|
|
166
|
+
}
|
|
167
|
+
poll.updatePoll(BigInt(maciState.publicKeys.length));
|
|
168
|
+
const circuitInputs = poll.joiningCircuitInputs({
|
|
169
|
+
maciPrivateKey: userMaciPrivateKey,
|
|
170
|
+
stateLeafIndex: stateIndex,
|
|
171
|
+
pollPublicKey: userPublicKey,
|
|
172
|
+
});
|
|
173
|
+
return circuitInputs;
|
|
174
|
+
};
|
|
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;
|
|
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);
|
|
248
|
+
if (loadedStateIndex < 1) {
|
|
249
|
+
throw new Error("Invalid state index");
|
|
250
|
+
}
|
|
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);
|
|
256
|
+
};
|
|
257
|
+
exports.getPollJoiningCircuitEvents = getPollJoiningCircuitEvents;
|
|
258
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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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EAAE,UAAU,CAAC,CAAC;IAEzF,IAAI,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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an IPFS CIDv1 to a bytes32-compatible hex string.
|
|
3
|
+
*
|
|
4
|
+
* This function:
|
|
5
|
+
* - Decodes the Base32-encoded CIDv1
|
|
6
|
+
* - Extracts the SHA-256 digest from the multihash
|
|
7
|
+
* - Converts it to a Solidity-compatible `bytes32` format
|
|
8
|
+
*
|
|
9
|
+
* @param hash - The CIDv1 string
|
|
10
|
+
* @returns A `bytes32`-compatible hex string (e.g., `0x...`)
|
|
11
|
+
*/
|
|
12
|
+
export declare const cidToBytes32: (hash: string) => Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a CID (Content Identifier) from an object by encoding the object into JSON and
|
|
15
|
+
* hashing it using the SHA-256 algorithm, and then creating a CID using the Multiformats CID library.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {T} data The input object to be encoded and hashed to generate the CID.
|
|
19
|
+
* @returns A CID generated from the hashed JSON-encoded object.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const createCidFromObject: <T>(data: T) => Promise<string>;
|
|
23
|
+
//# sourceMappingURL=cid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../../../ts/utils/cid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,CAI/D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAU,CAAC,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,MAAM,CAUpE,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createCidFromObject = exports.cidToBytes32 = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Converts an IPFS CIDv1 to a bytes32-compatible hex string.
|
|
39
|
+
*
|
|
40
|
+
* This function:
|
|
41
|
+
* - Decodes the Base32-encoded CIDv1
|
|
42
|
+
* - Extracts the SHA-256 digest from the multihash
|
|
43
|
+
* - Converts it to a Solidity-compatible `bytes32` format
|
|
44
|
+
*
|
|
45
|
+
* @param hash - The CIDv1 string
|
|
46
|
+
* @returns A `bytes32`-compatible hex string (e.g., `0x...`)
|
|
47
|
+
*/
|
|
48
|
+
const cidToBytes32 = async (hash) => {
|
|
49
|
+
const [{ CID }, { ethers }] = await Promise.all([Promise.resolve().then(() => __importStar(require("multiformats/cid"))), Promise.resolve().then(() => __importStar(require("ethers")))]);
|
|
50
|
+
return ethers.hexlify(CID.parse(hash).multihash.digest);
|
|
51
|
+
};
|
|
52
|
+
exports.cidToBytes32 = cidToBytes32;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a CID (Content Identifier) from an object by encoding the object into JSON and
|
|
55
|
+
* hashing it using the SHA-256 algorithm, and then creating a CID using the Multiformats CID library.
|
|
56
|
+
*
|
|
57
|
+
* @template T
|
|
58
|
+
* @param {T} data The input object to be encoded and hashed to generate the CID.
|
|
59
|
+
* @returns A CID generated from the hashed JSON-encoded object.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
const createCidFromObject = async (data) => {
|
|
63
|
+
const [{ CID }, json, { sha256 }] = await Promise.all([
|
|
64
|
+
Promise.resolve().then(() => __importStar(require("multiformats/cid"))),
|
|
65
|
+
Promise.resolve().then(() => __importStar(require("multiformats/codecs/json"))),
|
|
66
|
+
Promise.resolve().then(() => __importStar(require("multiformats/hashes/sha2"))),
|
|
67
|
+
]);
|
|
68
|
+
const hash = await sha256.digest(json.encode(data));
|
|
69
|
+
return CID.create(1, json.code, hash).toString();
|
|
70
|
+
};
|
|
71
|
+
exports.createCidFromObject = createCidFromObject;
|
|
72
|
+
//# sourceMappingURL=cid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../../../ts/utils/cid.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;GAUG;AACI,MAAM,YAAY,GAAG,KAAK,EAAE,IAAY,EAAmB,EAAE;IAClE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,mDAAQ,kBAAkB,uDAAU,QAAQ,IAAE,CAAC,CAAC;IAEhG,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB;AAEF;;;;;;;;GAQG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAK,IAAO,EAAmB,EAAE;IACvE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;0DAC7C,kBAAkB;0DAClB,0BAA0B;0DAC1B,0BAA0B;KAClC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEpD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AACnD,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../ts/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../ts/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Provider } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Small utility function to check whether a contract exists at a given address
|
|
4
|
+
* @param provider - the provider to use to interact with the chain
|
|
5
|
+
* @param address - the address of the contract to check
|
|
6
|
+
* @returns a boolean indicating whether the contract exists
|
|
7
|
+
*/
|
|
8
|
+
export declare const contractExists: (provider: Provider, address: string) => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Small utility to retrieve the current block timestamp from the blockchain
|
|
11
|
+
* @param provider the provider to use to interact with the chain
|
|
12
|
+
* @returns the current block timestamp
|
|
13
|
+
*/
|
|
14
|
+
export declare const currentBlockTimestamp: (provider: Provider) => Promise<number>;
|
|
15
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../ts/utils/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAU,UAAU,QAAQ,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,OAAO,CAGzF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,MAAM,CAK9E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentBlockTimestamp = exports.contractExists = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Small utility function to check whether a contract exists at a given address
|
|
6
|
+
* @param provider - the provider to use to interact with the chain
|
|
7
|
+
* @param address - the address of the contract to check
|
|
8
|
+
* @returns a boolean indicating whether the contract exists
|
|
9
|
+
*/
|
|
10
|
+
const contractExists = async (provider, address) => {
|
|
11
|
+
const code = await provider.getCode(address);
|
|
12
|
+
return code.length > 2;
|
|
13
|
+
};
|
|
14
|
+
exports.contractExists = contractExists;
|
|
15
|
+
/**
|
|
16
|
+
* Small utility to retrieve the current block timestamp from the blockchain
|
|
17
|
+
* @param provider the provider to use to interact with the chain
|
|
18
|
+
* @returns the current block timestamp
|
|
19
|
+
*/
|
|
20
|
+
const currentBlockTimestamp = async (provider) => {
|
|
21
|
+
const blockNum = await provider.getBlockNumber();
|
|
22
|
+
const block = await provider.getBlock(blockNum);
|
|
23
|
+
return Number(block?.timestamp);
|
|
24
|
+
};
|
|
25
|
+
exports.currentBlockTimestamp = currentBlockTimestamp;
|
|
26
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../ts/utils/contracts.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,cAAc,GAAG,KAAK,EAAE,QAAkB,EAAE,OAAe,EAAoB,EAAE;IAC5F,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,QAAkB,EAAmB,EAAE;IACjF,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEhD,OAAO,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAClC,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if an array of paths exist on the local file system
|
|
3
|
+
* @param paths - the array of paths to check
|
|
4
|
+
* @returns an array of boolean and string,
|
|
5
|
+
* where the boolean indicates whether all paths exist, and the string
|
|
6
|
+
* is the path that does not exist
|
|
7
|
+
*/
|
|
8
|
+
export declare const doesPathExist: (paths: string[]) => [boolean, string | null];
|
|
9
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../ts/utils/files.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,KAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAItE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.doesPathExist = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
/**
|
|
9
|
+
* Check if an array of paths exist on the local file system
|
|
10
|
+
* @param paths - the array of paths to check
|
|
11
|
+
* @returns an array of boolean and string,
|
|
12
|
+
* where the boolean indicates whether all paths exist, and the string
|
|
13
|
+
* is the path that does not exist
|
|
14
|
+
*/
|
|
15
|
+
const doesPathExist = (paths) => {
|
|
16
|
+
const notFoundPath = paths.find((path) => !fs_1.default.existsSync(path));
|
|
17
|
+
return notFoundPath ? [false, notFoundPath] : [true, null];
|
|
18
|
+
};
|
|
19
|
+
exports.doesPathExist = doesPathExist;
|
|
20
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../ts/utils/files.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAEpB;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,CAAC,KAAe,EAA4B,EAAE;IACzE,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAEhE,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC,CAAC;AAJW,QAAA,aAAa,iBAIxB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BigNumberish } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Convert a value to its hex representation
|
|
4
|
+
* @param val - the value to convert
|
|
5
|
+
* @returns the value converted as a hex string
|
|
6
|
+
*/
|
|
7
|
+
export declare const asHex: (val: BigNumberish) => string;
|
|
8
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../ts/utils/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,YAAY,KAAG,MAAyC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asHex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a value to its hex representation
|
|
6
|
+
* @param val - the value to convert
|
|
7
|
+
* @returns the value converted as a hex string
|
|
8
|
+
*/
|
|
9
|
+
const asHex = (val) => `0x${BigInt(val).toString(16)}`;
|
|
10
|
+
exports.asHex = asHex;
|
|
11
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../../ts/utils/formatting.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,MAAM,KAAK,GAAG,CAAC,GAAiB,EAAU,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAAvE,QAAA,KAAK,SAAkE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IFundWalletArgs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Fund a new wallet with Ether
|
|
4
|
+
* @param args Fund wallet arguments
|
|
5
|
+
*/
|
|
6
|
+
export declare const fundWallet: ({ amount, address, signer }: IFundWalletArgs) => Promise<string>;
|
|
7
|
+
//# sourceMappingURL=fundWallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fundWallet.d.ts","sourceRoot":"","sources":["../../../ts/utils/fundWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAU,6BAA6B,eAAe,KAAG,OAAO,CAAC,MAAM,CAY7F,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fundWallet = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fund a new wallet with Ether
|
|
6
|
+
* @param args Fund wallet arguments
|
|
7
|
+
*/
|
|
8
|
+
const fundWallet = async ({ amount, address, signer }) => {
|
|
9
|
+
const tx = await signer.sendTransaction({
|
|
10
|
+
to: address,
|
|
11
|
+
value: amount.toString(),
|
|
12
|
+
});
|
|
13
|
+
const receipt = await tx.wait();
|
|
14
|
+
if (receipt?.status !== 1) {
|
|
15
|
+
throw new Error("Transaction failed");
|
|
16
|
+
}
|
|
17
|
+
return receipt.hash;
|
|
18
|
+
};
|
|
19
|
+
exports.fundWallet = fundWallet;
|
|
20
|
+
//# sourceMappingURL=fundWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fundWallet.js","sourceRoot":"","sources":["../../../ts/utils/fundWallet.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAmB,EAAmB,EAAE;IAChG,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;QACtC,EAAE,EAAE,OAAO;QACX,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE;KACzB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;IAEhC,IAAI,OAAO,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CAAC;AAZW,QAAA,UAAU,cAYrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { cidToBytes32, createCidFromObject } from "./cid";
|
|
2
|
+
export { BLOCKS_STEP } from "./constants";
|
|
3
|
+
export { contractExists, currentBlockTimestamp } from "./contracts";
|
|
4
|
+
export { asHex } from "./formatting";
|
|
5
|
+
export { fundWallet } from "./fundWallet";
|
|
6
|
+
export { validateParams } from "./params";
|
|
7
|
+
export { timeTravel } from "./timeTravel";
|
|
8
|
+
export { calculateBinaryTreeDepthFromMaxLeaves, calculateQuinTreeDepthFromMaxLeaves } from "./trees";
|
|
9
|
+
export { isArm, sleep, sleepUntil } from "./utils";
|
|
10
|
+
export { generateAndVerifyProof } from "./proofs";
|
|
11
|
+
export type { ICircuitParams, ISnarkJSVerificationKey, ITimeTravelArgs, IFundWalletArgs } from "./types";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
var cid_1 = require("./cid");
|
|
5
|
+
Object.defineProperty(exports, "cidToBytes32", { enumerable: true, get: function () { return cid_1.cidToBytes32; } });
|
|
6
|
+
Object.defineProperty(exports, "createCidFromObject", { enumerable: true, get: function () { return cid_1.createCidFromObject; } });
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
Object.defineProperty(exports, "BLOCKS_STEP", { enumerable: true, get: function () { return constants_1.BLOCKS_STEP; } });
|
|
9
|
+
var contracts_1 = require("./contracts");
|
|
10
|
+
Object.defineProperty(exports, "contractExists", { enumerable: true, get: function () { return contracts_1.contractExists; } });
|
|
11
|
+
Object.defineProperty(exports, "currentBlockTimestamp", { enumerable: true, get: function () { return contracts_1.currentBlockTimestamp; } });
|
|
12
|
+
var formatting_1 = require("./formatting");
|
|
13
|
+
Object.defineProperty(exports, "asHex", { enumerable: true, get: function () { return formatting_1.asHex; } });
|
|
14
|
+
var fundWallet_1 = require("./fundWallet");
|
|
15
|
+
Object.defineProperty(exports, "fundWallet", { enumerable: true, get: function () { return fundWallet_1.fundWallet; } });
|
|
16
|
+
var params_1 = require("./params");
|
|
17
|
+
Object.defineProperty(exports, "validateParams", { enumerable: true, get: function () { return params_1.validateParams; } });
|
|
18
|
+
var timeTravel_1 = require("./timeTravel");
|
|
19
|
+
Object.defineProperty(exports, "timeTravel", { enumerable: true, get: function () { return timeTravel_1.timeTravel; } });
|
|
20
|
+
var trees_1 = require("./trees");
|
|
21
|
+
Object.defineProperty(exports, "calculateBinaryTreeDepthFromMaxLeaves", { enumerable: true, get: function () { return trees_1.calculateBinaryTreeDepthFromMaxLeaves; } });
|
|
22
|
+
Object.defineProperty(exports, "calculateQuinTreeDepthFromMaxLeaves", { enumerable: true, get: function () { return trees_1.calculateQuinTreeDepthFromMaxLeaves; } });
|
|
23
|
+
var utils_1 = require("./utils");
|
|
24
|
+
Object.defineProperty(exports, "isArm", { enumerable: true, get: function () { return utils_1.isArm; } });
|
|
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; } });
|
|
27
|
+
var proofs_1 = require("./proofs");
|
|
28
|
+
Object.defineProperty(exports, "generateAndVerifyProof", { enumerable: true, get: function () { return proofs_1.generateAndVerifyProof; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,iCAAmD;AAA1C,8FAAA,KAAK,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,mGAAA,UAAU,OAAA;AACjC,mCAAkD;AAAzC,gHAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ICircuitParams } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Validate the circuit parameters
|
|
4
|
+
* @param params - The circuit parameters
|
|
5
|
+
*/
|
|
6
|
+
export declare const validateParams: ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, }: ICircuitParams) => boolean;
|
|
7
|
+
//# sourceMappingURL=params.d.ts.map
|
|
@@ -0,0 +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,2FAK5B,cAAc,KAAG,OAWnB,CAAC"}
|