@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,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateParams = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validate the circuit parameters
|
|
6
|
+
* @param params - The circuit parameters
|
|
7
|
+
*/
|
|
8
|
+
const validateParams = ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, }) => {
|
|
9
|
+
// validate args
|
|
10
|
+
if (stateTreeDepth < 1 || tallyProcessingStateTreeDepth < 1 || voteOptionTreeDepth < 1 || messageBatchSize < 1) {
|
|
11
|
+
throw new Error("Invalid depth or batch size parameters");
|
|
12
|
+
}
|
|
13
|
+
if (stateTreeDepth < tallyProcessingStateTreeDepth) {
|
|
14
|
+
throw new Error("Invalid state tree depth or intermediate state tree depth");
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
exports.validateParams = validateParams;
|
|
19
|
+
//# sourceMappingURL=params.js.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TCircuitInputs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Generate and verify poll proof
|
|
4
|
+
* @param inputs - the inputs to the circuit
|
|
5
|
+
* @param zkeyPath - the path to the zkey
|
|
6
|
+
* @param useWasm - whether we want to use the wasm witness or not
|
|
7
|
+
* @param rapidsnarkExePath - the path to the rapidnsark binary
|
|
8
|
+
* @param witnessExePath - the path to the compiled witness binary
|
|
9
|
+
* @param wasmPath - the path to the wasm witness
|
|
10
|
+
* @returns proof - an array of strings
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateAndVerifyProof: (inputs: TCircuitInputs, zkeyPath: string, useWasm: boolean | undefined, rapidsnarkExePath: string | undefined, witnessExePath: string | undefined, wasmPath: string | undefined) => Promise<string[]>;
|
|
13
|
+
//# sourceMappingURL=proofs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAndVerifyProof = void 0;
|
|
4
|
+
const contracts_1 = require("@maci-protocol/contracts");
|
|
5
|
+
/**
|
|
6
|
+
* Generate and verify poll proof
|
|
7
|
+
* @param inputs - the inputs to the circuit
|
|
8
|
+
* @param zkeyPath - the path to the zkey
|
|
9
|
+
* @param useWasm - whether we want to use the wasm witness or not
|
|
10
|
+
* @param rapidsnarkExePath - the path to the rapidnsark binary
|
|
11
|
+
* @param witnessExePath - the path to the compiled witness binary
|
|
12
|
+
* @param wasmPath - the path to the wasm witness
|
|
13
|
+
* @returns proof - an array of strings
|
|
14
|
+
*/
|
|
15
|
+
const generateAndVerifyProof = async (inputs, zkeyPath, useWasm, rapidsnarkExePath, witnessExePath, wasmPath) => {
|
|
16
|
+
let r;
|
|
17
|
+
const verifyingKey = await (0, contracts_1.extractVerifyingKey)(zkeyPath);
|
|
18
|
+
if (useWasm === true || useWasm === undefined) {
|
|
19
|
+
r = await (0, contracts_1.generateProofSnarkjs)({
|
|
20
|
+
inputs,
|
|
21
|
+
zkeyPath,
|
|
22
|
+
wasmPath,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
r = await (0, contracts_1.generateProofRapidSnark)({
|
|
27
|
+
inputs,
|
|
28
|
+
zkeyPath,
|
|
29
|
+
rapidsnarkExePath,
|
|
30
|
+
witnessExePath,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// verify it
|
|
34
|
+
const isValid = await (0, contracts_1.verifyProof)(r.publicSignals, r.proof, verifyingKey);
|
|
35
|
+
if (!isValid) {
|
|
36
|
+
throw new Error("Generated an invalid proof");
|
|
37
|
+
}
|
|
38
|
+
return (0, contracts_1.formatProofForVerifierContract)(r.proof);
|
|
39
|
+
};
|
|
40
|
+
exports.generateAndVerifyProof = generateAndVerifyProof;
|
|
41
|
+
//# sourceMappingURL=proofs.js.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ITimeTravelArgs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Utility to travel in time when using a local blockchain
|
|
4
|
+
* @param args time travel args
|
|
5
|
+
*/
|
|
6
|
+
export declare const timeTravel: ({ seconds, signer }: ITimeTravelArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=timeTravel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeTravel.d.ts","sourceRoot":"","sources":["../../../ts/utils/timeTravel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAU,qBAAqB,eAAe,KAAG,OAAO,CAAC,IAAI,CAInF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timeTravel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility to travel in time when using a local blockchain
|
|
6
|
+
* @param args time travel args
|
|
7
|
+
*/
|
|
8
|
+
const timeTravel = async ({ seconds, signer }) => {
|
|
9
|
+
// send the instructions to the provider
|
|
10
|
+
await signer.provider.send("evm_increaseTime", [Number(seconds)]);
|
|
11
|
+
await signer.provider.send("evm_mine", []);
|
|
12
|
+
};
|
|
13
|
+
exports.timeTravel = timeTravel;
|
|
14
|
+
//# sourceMappingURL=timeTravel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeTravel.js","sourceRoot":"","sources":["../../../ts/utils/timeTravel.ts"],"names":[],"mappings":";;;AAGA;;;GAGG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAmB,EAAiB,EAAE;IACtF,wCAAwC;IACxC,MAAO,MAAM,CAAC,QAA4B,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvF,MAAO,MAAM,CAAC,QAA4B,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility to calculate the depth of a binary tree
|
|
3
|
+
* @param maxLeaves - the number of leaves in the tree
|
|
4
|
+
* @returns the depth of the tree
|
|
5
|
+
*/
|
|
6
|
+
export declare const calculateBinaryTreeDepthFromMaxLeaves: (maxLeaves: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* Utility to calculate the depth of a quin tree
|
|
9
|
+
* @param maxLeaves the number of leaves in the tree
|
|
10
|
+
* @returns the depth of the tree
|
|
11
|
+
*/
|
|
12
|
+
export declare const calculateQuinTreeDepthFromMaxLeaves: (maxLeaves: number) => number;
|
|
13
|
+
//# sourceMappingURL=trees.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trees.d.ts","sourceRoot":"","sources":["../../../ts/utils/trees.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,GAAI,WAAW,MAAM,KAAG,MAQzE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,GAAI,WAAW,MAAM,KAAG,MAQvE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateQuinTreeDepthFromMaxLeaves = exports.calculateBinaryTreeDepthFromMaxLeaves = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility to calculate the depth of a binary tree
|
|
6
|
+
* @param maxLeaves - the number of leaves in the tree
|
|
7
|
+
* @returns the depth of the tree
|
|
8
|
+
*/
|
|
9
|
+
const calculateBinaryTreeDepthFromMaxLeaves = (maxLeaves) => {
|
|
10
|
+
let result = 0;
|
|
11
|
+
while (2 ** result < maxLeaves) {
|
|
12
|
+
result += 1;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
exports.calculateBinaryTreeDepthFromMaxLeaves = calculateBinaryTreeDepthFromMaxLeaves;
|
|
17
|
+
/**
|
|
18
|
+
* Utility to calculate the depth of a quin tree
|
|
19
|
+
* @param maxLeaves the number of leaves in the tree
|
|
20
|
+
* @returns the depth of the tree
|
|
21
|
+
*/
|
|
22
|
+
const calculateQuinTreeDepthFromMaxLeaves = (maxLeaves) => {
|
|
23
|
+
let result = 0;
|
|
24
|
+
while (5 ** result < maxLeaves) {
|
|
25
|
+
result += 1;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
exports.calculateQuinTreeDepthFromMaxLeaves = calculateQuinTreeDepthFromMaxLeaves;
|
|
30
|
+
//# sourceMappingURL=trees.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trees.js","sourceRoot":"","sources":["../../../ts/utils/trees.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,qCAAqC,GAAG,CAAC,SAAiB,EAAU,EAAE;IACjF,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AARW,QAAA,qCAAqC,yCAQhD;AAEF;;;;GAIG;AACI,MAAM,mCAAmC,GAAG,CAAC,SAAiB,EAAU,EAAE;IAC/E,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AARW,QAAA,mCAAmC,uCAQ9C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { BigNumberish, Signer } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* A circuit inputs for the circom circuit
|
|
4
|
+
*/
|
|
5
|
+
export type TCircuitInputs = Record<string, string | bigint | bigint[] | bigint[][] | string[] | bigint[][][]>;
|
|
6
|
+
/**
|
|
7
|
+
* Circuit parameters
|
|
8
|
+
*/
|
|
9
|
+
export interface ICircuitParams {
|
|
10
|
+
/**
|
|
11
|
+
* The state tree depth
|
|
12
|
+
*/
|
|
13
|
+
stateTreeDepth: number;
|
|
14
|
+
/**
|
|
15
|
+
* The intermediate state tree depth (ballot tree)
|
|
16
|
+
*/
|
|
17
|
+
tallyProcessingStateTreeDepth: number;
|
|
18
|
+
/**
|
|
19
|
+
* The vote option tree depth
|
|
20
|
+
*/
|
|
21
|
+
voteOptionTreeDepth: number;
|
|
22
|
+
/**
|
|
23
|
+
* The message batch size
|
|
24
|
+
*/
|
|
25
|
+
messageBatchSize: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface that represents Verification key
|
|
29
|
+
*/
|
|
30
|
+
export interface ISnarkJSVerificationKey {
|
|
31
|
+
protocol: BigNumberish;
|
|
32
|
+
curve: BigNumberish;
|
|
33
|
+
nPublic: BigNumberish;
|
|
34
|
+
vk_alpha_1: BigNumberish[];
|
|
35
|
+
vk_beta_2: BigNumberish[][];
|
|
36
|
+
vk_gamma_2: BigNumberish[][];
|
|
37
|
+
vk_delta_2: BigNumberish[][];
|
|
38
|
+
vk_alphabeta_12: BigNumberish[][][];
|
|
39
|
+
IC: BigNumberish[][];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Interface for the arguments to the TimeTravel command
|
|
43
|
+
*/
|
|
44
|
+
export interface ITimeTravelArgs {
|
|
45
|
+
/**
|
|
46
|
+
* The number of seconds to time travel
|
|
47
|
+
*/
|
|
48
|
+
seconds: number;
|
|
49
|
+
/**
|
|
50
|
+
* A signer object
|
|
51
|
+
*/
|
|
52
|
+
signer: Signer;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Interface for the arguments to the FundWallet command
|
|
56
|
+
*/
|
|
57
|
+
export interface IFundWalletArgs {
|
|
58
|
+
/**
|
|
59
|
+
* The amount to fund
|
|
60
|
+
*/
|
|
61
|
+
amount: number;
|
|
62
|
+
/**
|
|
63
|
+
* The address of the wallet to fund
|
|
64
|
+
*/
|
|
65
|
+
address: string;
|
|
66
|
+
/**
|
|
67
|
+
* A signer object
|
|
68
|
+
*/
|
|
69
|
+
signer: Signer;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/utils/types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"file":"types.js","sourceRoot":"","sources":["../../../ts/utils/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if we are running on an arm chip
|
|
3
|
+
* @returns whether we are running on an arm chip
|
|
4
|
+
*/
|
|
5
|
+
export declare const isArm: () => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Remove a file
|
|
8
|
+
* @param filepath - the path to the file
|
|
9
|
+
*/
|
|
10
|
+
export declare const unlinkFile: (filepath: string) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Pause the thread for n milliseconds
|
|
13
|
+
* @param ms - the amount of time to sleep in milliseconds
|
|
14
|
+
*/
|
|
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>;
|
|
21
|
+
declare global {
|
|
22
|
+
interface ITerminatable {
|
|
23
|
+
terminate: () => Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
var curve_bn128: ITerminatable | undefined;
|
|
26
|
+
var curve_bls12381: ITerminatable | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare const cleanThreads: () => Promise<void>;
|
|
29
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +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;;;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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.cleanThreads = exports.sleepUntil = exports.sleep = exports.unlinkFile = exports.isArm = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
/**
|
|
10
|
+
* Check if we are running on an arm chip
|
|
11
|
+
* @returns whether we are running on an arm chip
|
|
12
|
+
*/
|
|
13
|
+
const isArm = () => os_1.default.arch().includes("arm");
|
|
14
|
+
exports.isArm = isArm;
|
|
15
|
+
/**
|
|
16
|
+
* Remove a file
|
|
17
|
+
* @param filepath - the path to the file
|
|
18
|
+
*/
|
|
19
|
+
const unlinkFile = async (filepath) => {
|
|
20
|
+
const isFileExists = fs_1.default.existsSync(filepath);
|
|
21
|
+
if (isFileExists) {
|
|
22
|
+
await fs_1.default.promises.unlink(filepath);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.unlinkFile = unlinkFile;
|
|
26
|
+
/**
|
|
27
|
+
* Pause the thread for n milliseconds
|
|
28
|
+
* @param ms - the amount of time to sleep in milliseconds
|
|
29
|
+
*/
|
|
30
|
+
const sleep = async (ms) => {
|
|
31
|
+
await new Promise((resolve) => {
|
|
32
|
+
setTimeout(resolve, ms);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
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;
|
|
48
|
+
/*
|
|
49
|
+
* https://github.com/iden3/snarkjs/issues/152
|
|
50
|
+
* Need to cleanup the threads to avoid stalling
|
|
51
|
+
*/
|
|
52
|
+
const cleanThreads = async () => {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
54
|
+
if (!globalThis) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const curves = ["curve_bn128", "curve_bls12381"];
|
|
58
|
+
await Promise.all(curves.map((curve) => globalThis[curve]?.terminate()).filter(Boolean));
|
|
59
|
+
};
|
|
60
|
+
exports.cleanThreads = cleanThreads;
|
|
61
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +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,CA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./types";
|
|
2
|
+
/**
|
|
3
|
+
* Command to confirm that the verifying keys in the contract match the
|
|
4
|
+
* local ones
|
|
5
|
+
* @note see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing
|
|
6
|
+
* @param CheckVerifyingKeysArgs - The arguments for the checkVerifyingKeys command
|
|
7
|
+
* @returns Whether the verifying keys match or not
|
|
8
|
+
*/
|
|
9
|
+
export declare const checkVerifyingKeys: ({ stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, messageProcessorZkeyPath, voteTallyZkeyPath, pollJoiningZkeyPath, pollJoinedZkeyPath, verifyingKeysRegistry, signer, mode, }: ICheckVerifyingKeysArgs) => Promise<boolean>;
|
|
10
|
+
//# sourceMappingURL=checkVerifyingKeys.d.ts.map
|
|
@@ -0,0 +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,sNAYtC,uBAAuB,KAAG,OAAO,CAAC,OAAO,CAiE3C,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.checkVerifyingKeys = void 0;
|
|
7
|
+
const contracts_1 = require("@maci-protocol/contracts");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const utils_2 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Command to confirm that the verifying keys in the contract match the
|
|
13
|
+
* local ones
|
|
14
|
+
* @note see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing
|
|
15
|
+
* @param CheckVerifyingKeysArgs - The arguments for the checkVerifyingKeys command
|
|
16
|
+
* @returns Whether the verifying keys match or not
|
|
17
|
+
*/
|
|
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
|
+
}
|
|
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
|
+
}
|
|
26
|
+
// we need to ensure that the zkey files exist
|
|
27
|
+
const isProcessMessagesZkeyPathExists = fs_1.default.existsSync(messageProcessorZkeyPath);
|
|
28
|
+
if (!isProcessMessagesZkeyPathExists) {
|
|
29
|
+
throw new Error("The provided Process messages zkey does not exist");
|
|
30
|
+
}
|
|
31
|
+
const isTallyVotesZkeyPathExists = fs_1.default.existsSync(voteTallyZkeyPath);
|
|
32
|
+
if (!isTallyVotesZkeyPathExists) {
|
|
33
|
+
throw new Error("The provided Tally votes zkey does not exist");
|
|
34
|
+
}
|
|
35
|
+
// extract the verification keys from the zkey files
|
|
36
|
+
const { pollJoiningVerifyingKey, pollJoinedVerifyingKey, processVerifyingKey, tallyVerifyingKey } = await (0, utils_2.extractAllVerifyingKeys)({
|
|
37
|
+
messageProcessorZkeyPath,
|
|
38
|
+
voteTallyZkeyPath,
|
|
39
|
+
pollJoiningZkeyPath,
|
|
40
|
+
pollJoinedZkeyPath,
|
|
41
|
+
});
|
|
42
|
+
const { pollJoiningVerifyingKeyOnChain, pollJoinedVerifyingKeyOnChain, processVerifyingKeyOnChain, tallyVerifyingKeyOnChain, } = await (0, utils_2.getAllOnChainVerifyingKeys)({
|
|
43
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistry,
|
|
44
|
+
signer,
|
|
45
|
+
stateTreeDepth,
|
|
46
|
+
voteOptionTreeDepth,
|
|
47
|
+
messageBatchSize,
|
|
48
|
+
tallyProcessingStateTreeDepth,
|
|
49
|
+
mode,
|
|
50
|
+
});
|
|
51
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoiningVerifyingKeyOnChain, pollJoiningVerifyingKey)) {
|
|
52
|
+
throw new Error("Poll verifying keys do not match");
|
|
53
|
+
}
|
|
54
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoinedVerifyingKeyOnChain, pollJoinedVerifyingKey)) {
|
|
55
|
+
throw new Error("Poll verifying keys do not match");
|
|
56
|
+
}
|
|
57
|
+
if (!(0, utils_2.compareVerifyingKeys)(processVerifyingKeyOnChain, processVerifyingKey)) {
|
|
58
|
+
throw new Error("Process verifying keys do not match");
|
|
59
|
+
}
|
|
60
|
+
if (!(0, utils_2.compareVerifyingKeys)(tallyVerifyingKeyOnChain, tallyVerifyingKey)) {
|
|
61
|
+
throw new Error("Tally verifying keys do not match");
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
exports.checkVerifyingKeys = checkVerifyingKeys;
|
|
66
|
+
//# sourceMappingURL=checkVerifyingKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkVerifyingKeys.js","sourceRoot":"","sources":["../../../ts/verifyingKeys/checkVerifyingKeys.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAiD;AAEjD,4CAAoB;AAIpB,oCAA0C;AAE1C,mCAAoG;AAEpG;;;;;;GAMG;AACI,MAAM,kBAAk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N,cAAc;QACd,mBAAmB;QACnB,gBAAgB;QAChB,6BAA6B;QAC7B,IAAI;KACL,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,4BAAoB,EAAC,8BAA8B,EAAE,uBAAuB,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,6BAA6B,EAAE,sBAAsB,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,0BAA0B,EAAE,mBAAmB,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,IAAA,4BAAoB,EAAC,wBAAwB,EAAE,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA7EW,QAAA,kBAAkB,sBA6E7B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { checkVerifyingKeys } from "./checkVerifyingKeys";
|
|
2
|
+
export { setVerifyingKeys } from "./setVerifyingKeys";
|
|
3
|
+
export { getAllOnChainVerifyingKeys, compareVerifyingKeys, extractAllVerifyingKeys, extractVerifyingKeyToFile, } from "./utils";
|
|
4
|
+
export type { IGetAllVerifyingKeysArgs, IMaciVerifyingKeysOnchain, IExtractAllVerifyingKeysArgs, IMaciVerifyingKeys, ISetVerifyingKeysArgs, ICheckVerifyingKeysArgs, } from "./types";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,wBAAwB,EACxB,yBAAyB,EACzB,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractVerifyingKeyToFile = exports.extractAllVerifyingKeys = exports.compareVerifyingKeys = exports.getAllOnChainVerifyingKeys = exports.setVerifyingKeys = exports.checkVerifyingKeys = void 0;
|
|
4
|
+
var checkVerifyingKeys_1 = require("./checkVerifyingKeys");
|
|
5
|
+
Object.defineProperty(exports, "checkVerifyingKeys", { enumerable: true, get: function () { return checkVerifyingKeys_1.checkVerifyingKeys; } });
|
|
6
|
+
var setVerifyingKeys_1 = require("./setVerifyingKeys");
|
|
7
|
+
Object.defineProperty(exports, "setVerifyingKeys", { enumerable: true, get: function () { return setVerifyingKeys_1.setVerifyingKeys; } });
|
|
8
|
+
var utils_1 = require("./utils");
|
|
9
|
+
Object.defineProperty(exports, "getAllOnChainVerifyingKeys", { enumerable: true, get: function () { return utils_1.getAllOnChainVerifyingKeys; } });
|
|
10
|
+
Object.defineProperty(exports, "compareVerifyingKeys", { enumerable: true, get: function () { return utils_1.compareVerifyingKeys; } });
|
|
11
|
+
Object.defineProperty(exports, "extractAllVerifyingKeys", { enumerable: true, get: function () { return utils_1.extractAllVerifyingKeys; } });
|
|
12
|
+
Object.defineProperty(exports, "extractVerifyingKeyToFile", { enumerable: true, get: function () { return utils_1.extractVerifyingKeyToFile; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/verifyingKeys/index.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,iCAKiB;AAJf,mHAAA,0BAA0B,OAAA;AAC1B,6GAAA,oBAAoB,OAAA;AACpB,gHAAA,uBAAuB,OAAA;AACvB,kHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ISetVerifyingKeysArgs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Set the verifying keys on the contract
|
|
4
|
+
* @param args - The arguments for the setVerifyingKeys function
|
|
5
|
+
*/
|
|
6
|
+
export declare const setVerifyingKeys: ({ pollJoiningVerifyingKey, pollJoinedVerifyingKey, processMessagesVerifyingKeys, tallyVotesVerifyingKeys, stateTreeDepth, pollStateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, verifyingKeysRegistryAddress, signer, modes, }: ISetVerifyingKeysArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=setVerifyingKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setVerifyingKeys.d.ts","sourceRoot":"","sources":["../../../ts/verifyingKeys/setVerifyingKeys.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAMrD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAU,oQAapC,qBAAqB,KAAG,OAAO,CAAC,IAAI,CAmItC,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setVerifyingKeys = void 0;
|
|
4
|
+
const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
|
|
5
|
+
const core_1 = require("@maci-protocol/core");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const utils_2 = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* Set the verifying keys on the contract
|
|
10
|
+
* @param args - The arguments for the setVerifyingKeys function
|
|
11
|
+
*/
|
|
12
|
+
const setVerifyingKeys = async ({ pollJoiningVerifyingKey, pollJoinedVerifyingKey, processMessagesVerifyingKeys, tallyVotesVerifyingKeys, stateTreeDepth, pollStateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize, verifyingKeysRegistryAddress, signer, modes, }) => {
|
|
13
|
+
// validate args
|
|
14
|
+
if (stateTreeDepth < 1 || tallyProcessingStateTreeDepth < 1 || voteOptionTreeDepth < 1 || messageBatchSize < 1) {
|
|
15
|
+
throw new Error("Invalid depth or batch size parameters");
|
|
16
|
+
}
|
|
17
|
+
if (stateTreeDepth < tallyProcessingStateTreeDepth) {
|
|
18
|
+
throw new Error("Invalid state tree depth or intermediate state tree depth");
|
|
19
|
+
}
|
|
20
|
+
if (processMessagesVerifyingKeys.length !== modes.length) {
|
|
21
|
+
throw new Error("Number of process messages verifying keys must match number of modes");
|
|
22
|
+
}
|
|
23
|
+
if (tallyVotesVerifyingKeys.length !== modes.length) {
|
|
24
|
+
throw new Error("Number of tally votes verifying keys must match number of modes");
|
|
25
|
+
}
|
|
26
|
+
const isContractExists = await (0, utils_1.contractExists)(signer.provider, verifyingKeysRegistryAddress);
|
|
27
|
+
// ensure we have a contract deployed at the provided address
|
|
28
|
+
if (!isContractExists) {
|
|
29
|
+
throw new Error(`A VerifyingKeysRegistry contract is not deployed at ${verifyingKeysRegistryAddress}`);
|
|
30
|
+
}
|
|
31
|
+
// connect to VerifyingKeysRegistry contract
|
|
32
|
+
const verifyingKeysRegistryContract = typechain_types_1.VerifyingKeysRegistry__factory.connect(verifyingKeysRegistryAddress, signer);
|
|
33
|
+
// check if the poll verifyingKeys were already set
|
|
34
|
+
const pollJoiningVerifyingKeySignature = (0, core_1.generatePollJoiningVerifyingKeySignature)(stateTreeDepth);
|
|
35
|
+
const pollJoinedVerifyingKeySignature = (0, core_1.generatePollJoinedVerifyingKeySignature)(stateTreeDepth);
|
|
36
|
+
const [isPollJoiningVerifyingKeySet, isPollJoinedVerifyingKeySet] = await Promise.all([
|
|
37
|
+
verifyingKeysRegistryContract.isPollJoiningVerifyingKeySet(pollJoiningVerifyingKeySignature),
|
|
38
|
+
verifyingKeysRegistryContract.isPollJoinedVerifyingKeySet(pollJoinedVerifyingKeySignature),
|
|
39
|
+
]);
|
|
40
|
+
if (isPollJoiningVerifyingKeySet) {
|
|
41
|
+
throw new Error("This poll joining verifying key is already set in the contract");
|
|
42
|
+
}
|
|
43
|
+
if (isPollJoinedVerifyingKeySet) {
|
|
44
|
+
throw new Error("This poll joined verifying key is already set in the contract");
|
|
45
|
+
}
|
|
46
|
+
// check if the process messages or tally verifyingKey were already set for each mode
|
|
47
|
+
const processVerifyingKeySignature = (0, core_1.generateProcessVerifyingKeySignature)(stateTreeDepth, voteOptionTreeDepth, messageBatchSize);
|
|
48
|
+
const tallyVerifyingKeySignature = (0, core_1.generateTallyVerifyingKeySignature)(stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth);
|
|
49
|
+
const keyChecks = await Promise.all(modes.map(async (mode) => {
|
|
50
|
+
const [isProcessVerifyingKeySet, isTallyVerifyingKeySet] = await Promise.all([
|
|
51
|
+
verifyingKeysRegistryContract.isProcessVerifyingKeySet(processVerifyingKeySignature, mode),
|
|
52
|
+
verifyingKeysRegistryContract.isTallyVerifyingKeySet(tallyVerifyingKeySignature, mode),
|
|
53
|
+
]);
|
|
54
|
+
return { mode, isProcessVerifyingKeySet, isTallyVerifyingKeySet };
|
|
55
|
+
}));
|
|
56
|
+
keyChecks.forEach(({ mode, isProcessVerifyingKeySet, isTallyVerifyingKeySet }) => {
|
|
57
|
+
if (isProcessVerifyingKeySet) {
|
|
58
|
+
throw new Error(`This process verifying key is already set in the contract for mode ${mode}`);
|
|
59
|
+
}
|
|
60
|
+
if (isTallyVerifyingKeySet) {
|
|
61
|
+
throw new Error(`This tally verifying key is already set in the contract for mode ${mode}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
// set them onchain
|
|
65
|
+
const tx = await verifyingKeysRegistryContract.setVerifyingKeysBatch({
|
|
66
|
+
stateTreeDepth,
|
|
67
|
+
pollStateTreeDepth,
|
|
68
|
+
tallyProcessingStateTreeDepth,
|
|
69
|
+
voteOptionTreeDepth,
|
|
70
|
+
messageBatchSize,
|
|
71
|
+
modes,
|
|
72
|
+
pollJoiningVerifyingKey: pollJoiningVerifyingKey.asContractParam(),
|
|
73
|
+
pollJoinedVerifyingKey: pollJoinedVerifyingKey.asContractParam(),
|
|
74
|
+
processVerifyingKeys: processMessagesVerifyingKeys.map((key) => key.asContractParam()),
|
|
75
|
+
tallyVerifyingKeys: tallyVotesVerifyingKeys.map((key) => key.asContractParam()),
|
|
76
|
+
});
|
|
77
|
+
const receipt = await tx.wait();
|
|
78
|
+
if (receipt?.status !== 1) {
|
|
79
|
+
throw new Error("Set verifying keys transaction failed");
|
|
80
|
+
}
|
|
81
|
+
// Verify that all keys were set correctly
|
|
82
|
+
const [pollJoiningVerifyingKeyOnChain, pollJoinedVerifyingKeyOnChain] = await Promise.all([
|
|
83
|
+
verifyingKeysRegistryContract.getPollJoiningVerifyingKey(stateTreeDepth),
|
|
84
|
+
verifyingKeysRegistryContract.getPollJoinedVerifyingKey(stateTreeDepth),
|
|
85
|
+
]);
|
|
86
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoiningVerifyingKeyOnChain, pollJoiningVerifyingKey)) {
|
|
87
|
+
throw new Error("pollJoiningVerifyingKey mismatch");
|
|
88
|
+
}
|
|
89
|
+
if (!(0, utils_2.compareVerifyingKeys)(pollJoinedVerifyingKeyOnChain, pollJoinedVerifyingKey)) {
|
|
90
|
+
throw new Error("pollJoinedVerifyingKey mismatch");
|
|
91
|
+
}
|
|
92
|
+
for (let i = 0; i < modes.length; i += 1) {
|
|
93
|
+
const mode = modes[i];
|
|
94
|
+
// eslint-disable-next-line no-await-in-loop
|
|
95
|
+
const [processVerifyingKeyOnChain, tallyVerifyingKeyOnChain] = await Promise.all([
|
|
96
|
+
verifyingKeysRegistryContract.getProcessVerifyingKey(stateTreeDepth, voteOptionTreeDepth, messageBatchSize, mode),
|
|
97
|
+
verifyingKeysRegistryContract.getTallyVerifyingKey(stateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, mode),
|
|
98
|
+
]);
|
|
99
|
+
if (!(0, utils_2.compareVerifyingKeys)(processVerifyingKeyOnChain, processMessagesVerifyingKeys[i])) {
|
|
100
|
+
throw new Error("processVerifyingKey mismatch");
|
|
101
|
+
}
|
|
102
|
+
if (!(0, utils_2.compareVerifyingKeys)(tallyVerifyingKeyOnChain, tallyVotesVerifyingKeys[i])) {
|
|
103
|
+
throw new Error("tallyVerifyingKey mismatch");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.setVerifyingKeys = setVerifyingKeys;
|
|
108
|
+
//# sourceMappingURL=setVerifyingKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setVerifyingKeys.js","sourceRoot":"","sources":["../../../ts/verifyingKeys/setVerifyingKeys.ts"],"names":[],"mappings":";;;AACA,8EAA0H;AAC1H,8CAK6B;AAI7B,oCAA0C;AAE1C,mCAA+C;AAE/C;;;GAGG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACrC,uBAAuB,EACvB,sBAAsB,EACtB,4BAA4B,EAC5B,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,EAC5B,MAAM,EACN,KAAK,GACiB,EAAiB,EAAE;IACzC,gBAAgB;IAChB,IAAI,cAAc,GAAG,CAAC,IAAI,6BAA6B,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,IAAI,gBAAg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