@maci-protocol/coordinator 0.0.0-ci.5209133
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 +51 -0
- package/LICENSE +22 -0
- package/README.md +42 -0
- package/build/hardhat.config.cjs +31 -0
- package/build/hardhat.config.cjs.map +1 -0
- package/build/hardhat.config.d.cts +24 -0
- package/build/hardhat.config.d.cts.map +1 -0
- package/build/scripts/generateKeypair.d.ts +2 -0
- package/build/scripts/generateKeypair.d.ts.map +1 -0
- package/build/scripts/generateKeypair.js +25 -0
- package/build/scripts/generateKeypair.js.map +1 -0
- package/build/scripts/generateMaciKeyPair.d.ts +2 -0
- package/build/scripts/generateMaciKeyPair.d.ts.map +1 -0
- package/build/scripts/generateMaciKeyPair.js +3 -0
- package/build/scripts/generateMaciKeyPair.js.map +1 -0
- package/build/scripts/getAuthHeader.d.ts +2 -0
- package/build/scripts/getAuthHeader.d.ts.map +1 -0
- package/build/scripts/getAuthHeader.js +31 -0
- package/build/scripts/getAuthHeader.js.map +1 -0
- package/build/tests/constants.d.ts +8 -0
- package/build/tests/constants.d.ts.map +1 -0
- package/build/tests/constants.js +10 -0
- package/build/tests/constants.js.map +1 -0
- package/build/tests/e2e.aa.test.d.ts +2 -0
- package/build/tests/e2e.aa.test.d.ts.map +1 -0
- package/build/tests/e2e.aa.test.js +103 -0
- package/build/tests/e2e.aa.test.js.map +1 -0
- package/build/tests/e2e.deploy.test.d.ts +2 -0
- package/build/tests/e2e.deploy.test.d.ts.map +1 -0
- package/build/tests/e2e.deploy.test.js +234 -0
- package/build/tests/e2e.deploy.test.js.map +1 -0
- package/build/tests/utils.d.ts +14 -0
- package/build/tests/utils.d.ts.map +1 -0
- package/build/tests/utils.js +44 -0
- package/build/tests/utils.js.map +1 -0
- package/build/ts/app.module.d.ts +3 -0
- package/build/ts/app.module.d.ts.map +1 -0
- package/build/ts/app.module.js +36 -0
- package/build/ts/app.module.js.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts +44 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.js +96 -0
- package/build/ts/auth/AccountSignatureGuard.service.js.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts +2 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js +113 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js.map +1 -0
- package/build/ts/common/__tests__/common.test.d.ts +2 -0
- package/build/ts/common/__tests__/common.test.d.ts.map +1 -0
- package/build/ts/common/__tests__/common.test.js +79 -0
- package/build/ts/common/__tests__/common.test.js.map +1 -0
- package/build/ts/common/accountAbstraction.d.ts +55 -0
- package/build/ts/common/accountAbstraction.d.ts.map +1 -0
- package/build/ts/common/accountAbstraction.js +110 -0
- package/build/ts/common/accountAbstraction.js.map +1 -0
- package/build/ts/common/errors.d.ts +33 -0
- package/build/ts/common/errors.d.ts.map +1 -0
- package/build/ts/common/errors.js +34 -0
- package/build/ts/common/errors.js.map +1 -0
- package/build/ts/common/index.d.ts +4 -0
- package/build/ts/common/index.d.ts.map +1 -0
- package/build/ts/common/index.js +4 -0
- package/build/ts/common/index.js.map +1 -0
- package/build/ts/common/networks.d.ts +29 -0
- package/build/ts/common/networks.d.ts.map +1 -0
- package/build/ts/common/networks.js +70 -0
- package/build/ts/common/networks.js.map +1 -0
- package/build/ts/common/types.d.ts +9 -0
- package/build/ts/common/types.d.ts.map +1 -0
- package/build/ts/common/types.js +2 -0
- package/build/ts/common/types.js.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts +2 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js +26 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js.map +1 -0
- package/build/ts/crypto/crypto.module.d.ts +3 -0
- package/build/ts/crypto/crypto.module.d.ts.map +1 -0
- package/build/ts/crypto/crypto.module.js +18 -0
- package/build/ts/crypto/crypto.module.js.map +1 -0
- package/build/ts/crypto/crypto.service.d.ts +31 -0
- package/build/ts/crypto/crypto.service.d.ts.map +1 -0
- package/build/ts/crypto/crypto.service.js +68 -0
- package/build/ts/crypto/crypto.service.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js +84 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js +425 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -0
- package/build/ts/deployer/__tests__/utils.d.ts +36 -0
- package/build/ts/deployer/__tests__/utils.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/utils.js +96 -0
- package/build/ts/deployer/__tests__/utils.js.map +1 -0
- package/build/ts/deployer/constants.d.ts +13 -0
- package/build/ts/deployer/constants.d.ts.map +1 -0
- package/build/ts/deployer/constants.js +13 -0
- package/build/ts/deployer/constants.js.map +1 -0
- package/build/ts/deployer/deployer.controller.d.ts +34 -0
- package/build/ts/deployer/deployer.controller.d.ts.map +1 -0
- package/build/ts/deployer/deployer.controller.js +89 -0
- package/build/ts/deployer/deployer.controller.js.map +1 -0
- package/build/ts/deployer/deployer.module.d.ts +3 -0
- package/build/ts/deployer/deployer.module.d.ts.map +1 -0
- package/build/ts/deployer/deployer.module.js +23 -0
- package/build/ts/deployer/deployer.module.js.map +1 -0
- package/build/ts/deployer/deployer.service.d.ts +112 -0
- package/build/ts/deployer/deployer.service.d.ts.map +1 -0
- package/build/ts/deployer/deployer.service.js +628 -0
- package/build/ts/deployer/deployer.service.js.map +1 -0
- package/build/ts/deployer/dto.d.ts +46 -0
- package/build/ts/deployer/dto.d.ts.map +1 -0
- package/build/ts/deployer/dto.js +117 -0
- package/build/ts/deployer/dto.js.map +1 -0
- package/build/ts/deployer/types.d.ts +306 -0
- package/build/ts/deployer/types.d.ts.map +1 -0
- package/build/ts/deployer/types.js +2 -0
- package/build/ts/deployer/types.js.map +1 -0
- package/build/ts/deployer/utils.d.ts +8 -0
- package/build/ts/deployer/utils.d.ts.map +1 -0
- package/build/ts/deployer/utils.js +9 -0
- package/build/ts/deployer/utils.js.map +1 -0
- package/build/ts/file/__tests__/file.service.test.d.ts +2 -0
- package/build/ts/file/__tests__/file.service.test.d.ts.map +1 -0
- package/build/ts/file/__tests__/file.service.test.js +76 -0
- package/build/ts/file/__tests__/file.service.test.js.map +1 -0
- package/build/ts/file/file.module.d.ts +3 -0
- package/build/ts/file/file.module.d.ts.map +1 -0
- package/build/ts/file/file.module.js +18 -0
- package/build/ts/file/file.module.js.map +1 -0
- package/build/ts/file/file.service.d.ts +62 -0
- package/build/ts/file/file.service.d.ts.map +1 -0
- package/build/ts/file/file.service.js +115 -0
- package/build/ts/file/file.service.js.map +1 -0
- package/build/ts/file/types.d.ts +36 -0
- package/build/ts/file/types.d.ts.map +1 -0
- package/build/ts/file/types.js +2 -0
- package/build/ts/file/types.js.map +1 -0
- package/build/ts/jest/setup.d.ts +8 -0
- package/build/ts/jest/setup.d.ts.map +1 -0
- package/build/ts/jest/setup.js +2 -0
- package/build/ts/jest/setup.js.map +1 -0
- package/build/ts/jest/transform.d.ts +8 -0
- package/build/ts/jest/transform.d.ts.map +1 -0
- package/build/ts/jest/transform.js +10 -0
- package/build/ts/jest/transform.js.map +1 -0
- package/build/ts/main.d.ts +2 -0
- package/build/ts/main.d.ts.map +1 -0
- package/build/ts/main.js +46 -0
- package/build/ts/main.js.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.js +89 -0
- package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js +61 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.js +128 -0
- package/build/ts/proof/__tests__/proof.service.test.js.map +1 -0
- package/build/ts/proof/dto.d.ts +73 -0
- package/build/ts/proof/dto.d.ts.map +1 -0
- package/build/ts/proof/dto.js +255 -0
- package/build/ts/proof/dto.js.map +1 -0
- package/build/ts/proof/proof.controller.d.ts +46 -0
- package/build/ts/proof/proof.controller.d.ts.map +1 -0
- package/build/ts/proof/proof.controller.js +135 -0
- package/build/ts/proof/proof.controller.js.map +1 -0
- package/build/ts/proof/proof.gateway.d.ts +35 -0
- package/build/ts/proof/proof.gateway.d.ts.map +1 -0
- package/build/ts/proof/proof.gateway.js +93 -0
- package/build/ts/proof/proof.gateway.js.map +1 -0
- package/build/ts/proof/proof.module.d.ts +3 -0
- package/build/ts/proof/proof.module.d.ts.map +1 -0
- package/build/ts/proof/proof.module.js +24 -0
- package/build/ts/proof/proof.module.js.map +1 -0
- package/build/ts/proof/proof.service.d.ts +54 -0
- package/build/ts/proof/proof.service.d.ts.map +1 -0
- package/build/ts/proof/proof.service.js +246 -0
- package/build/ts/proof/proof.service.js.map +1 -0
- package/build/ts/proof/types.d.ts +140 -0
- package/build/ts/proof/types.d.ts.map +1 -0
- package/build/ts/proof/types.js +11 -0
- package/build/ts/proof/types.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js +44 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js +61 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts +25 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.js +64 -0
- package/build/ts/sessionKeys/__tests__/utils.js.map +1 -0
- package/build/ts/sessionKeys/dto.d.ts +11 -0
- package/build/ts/sessionKeys/dto.d.ts.map +1 -0
- package/build/ts/sessionKeys/dto.js +29 -0
- package/build/ts/sessionKeys/dto.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts +26 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js +74 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts +3 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.js +23 -0
- package/build/ts/sessionKeys/sessionKeys.module.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts +50 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.js +104 -0
- package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -0
- package/build/ts/sessionKeys/types.d.ts +11 -0
- package/build/ts/sessionKeys/types.d.ts.map +1 -0
- package/build/ts/sessionKeys/types.js +2 -0
- package/build/ts/sessionKeys/types.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js +50 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js +83 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js +58 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js.map +1 -0
- package/build/ts/subgraph/dto.d.ts +27 -0
- package/build/ts/subgraph/dto.d.ts.map +1 -0
- package/build/ts/subgraph/dto.js +83 -0
- package/build/ts/subgraph/dto.js.map +1 -0
- package/build/ts/subgraph/subgraph.controller.d.ts +24 -0
- package/build/ts/subgraph/subgraph.controller.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.controller.js +66 -0
- package/build/ts/subgraph/subgraph.controller.js.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts +35 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.js +93 -0
- package/build/ts/subgraph/subgraph.gateway.js.map +1 -0
- package/build/ts/subgraph/subgraph.module.d.ts +3 -0
- package/build/ts/subgraph/subgraph.module.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.module.js +23 -0
- package/build/ts/subgraph/subgraph.module.js.map +1 -0
- package/build/ts/subgraph/subgraph.service.d.ts +20 -0
- package/build/ts/subgraph/subgraph.service.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.service.js +106 -0
- package/build/ts/subgraph/subgraph.service.js.map +1 -0
- package/build/ts/subgraph/types.d.ts +93 -0
- package/build/ts/subgraph/types.d.ts.map +1 -0
- package/build/ts/subgraph/types.js +24 -0
- package/build/ts/subgraph/types.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Keypair, PrivKey } from "@maci-protocol/domainobjs";
|
|
2
|
+
import { Deployment, ProofGenerator } from "@maci-protocol/sdk";
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import { zeroAddress } from "viem";
|
|
5
|
+
import { ErrorCodes } from "../../common";
|
|
6
|
+
import { FileService } from "../../file/file.service";
|
|
7
|
+
import { SessionKeysService } from "../../sessionKeys/sessionKeys.service";
|
|
8
|
+
import { ProofGeneratorService } from "../proof.service";
|
|
9
|
+
dotenv.config();
|
|
10
|
+
jest.mock("hardhat", () => ({
|
|
11
|
+
network: {
|
|
12
|
+
name: "localhost",
|
|
13
|
+
config: {
|
|
14
|
+
chain: { id: 0x1 },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
jest.mock("@maci-protocol/contracts", () => ({
|
|
19
|
+
...jest.requireActual("@maci-protocol/contracts"),
|
|
20
|
+
Deployment: {
|
|
21
|
+
getInstance: jest.fn(),
|
|
22
|
+
},
|
|
23
|
+
ProofGenerator: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
jest.mock("../../crypto/crypto.service", () => ({
|
|
26
|
+
CryptoService: {
|
|
27
|
+
getInstance: jest.fn(),
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
describe("ProofGeneratorService", () => {
|
|
31
|
+
const defaultProofArgs = {
|
|
32
|
+
poll: 1,
|
|
33
|
+
maciContractAddress: zeroAddress,
|
|
34
|
+
tallyContractAddress: zeroAddress,
|
|
35
|
+
useQuadraticVoting: false,
|
|
36
|
+
encryptedCoordinatorPrivateKey: "siO9W/g7jNVXs9tOUv/pffrcqYdMlgdXw7nSSlqM1q1UvHGSSbhtLJpeT+nJKW7/+xrBTgI0wB866DSkg8Rgr8zD+POUMiKPrGqAO/XhrcmRDL+COURFNDRh9WGeAua6hdiNoufQYvXPl1iWyIYidSDbfmC2wR6F9vVkhg/6KDZyw8Wlr6LUh0RYT+hUHEwwGbz7MeqZJcJQSTpECPF5pnk8NTHL2W/XThaewB4n4HYqjDUbYLmBDLYWsDDMgoPo709a309rTq3uEe0YBgVF8g9aGxucTDhz+/LYYzqaeSxclUwen9Z4BGZjiDSPBZfooOEQEEwIJlViQ2kl1VeOKAmkiWEUVfItivmNbC/PNZchklmfFsGpiu4DT9UU9YVBN2OTcFYHHsslcaqrR7SuesqjluaGjG46oYEmfQlkZ4gXhavdWXw2ant+Tv6HRo4trqjoD1e3jUkN6gJMWomxOeRBTg0czBZlz/IwUtTpBHcKhi3EqGQo8OuQtWww+Ts7ySmeoONuovYUsIAppNuOubfUxvFJoTr2vKbWNAiYetw09kddkjmBe+S8A5PUiFOi262mfc7g5wJwPPP7wpTBY0Fya+2BCPzXqRLMOtNI+1tW3/UQLZYvEY8J0TxmhoAGZaRn8FKaosatRxDZTQS6QUNmKxpmUspkRKzTXN5lznM=",
|
|
37
|
+
};
|
|
38
|
+
let mockContract = {
|
|
39
|
+
polls: jest.fn(),
|
|
40
|
+
getMainRoot: jest.fn(),
|
|
41
|
+
treeDepths: jest.fn(),
|
|
42
|
+
extContracts: jest.fn(),
|
|
43
|
+
stateMerged: jest.fn(),
|
|
44
|
+
coordinatorPubKey: jest.fn(),
|
|
45
|
+
};
|
|
46
|
+
let defaultProofGenerator = {
|
|
47
|
+
generateMpProofs: jest.fn(),
|
|
48
|
+
generateTallyProofs: jest.fn(),
|
|
49
|
+
merge: jest.fn(),
|
|
50
|
+
};
|
|
51
|
+
const defaultCryptoService = {
|
|
52
|
+
decrypt: jest.fn(),
|
|
53
|
+
};
|
|
54
|
+
const defaultDeploymentService = {
|
|
55
|
+
setHre: jest.fn(),
|
|
56
|
+
getDeployer: jest.fn(() => Promise.resolve({})),
|
|
57
|
+
getContract: jest.fn(() => Promise.resolve(mockContract)),
|
|
58
|
+
};
|
|
59
|
+
const fileService = new FileService();
|
|
60
|
+
const sessionKeysService = new SessionKeysService(fileService);
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
mockContract = {
|
|
63
|
+
polls: jest.fn(() => Promise.resolve({ poll: zeroAddress.replace("0x0", "0x1"), messageProcessor: zeroAddress, tally: zeroAddress })),
|
|
64
|
+
getMainRoot: jest.fn(() => Promise.resolve(1n)),
|
|
65
|
+
treeDepths: jest.fn(() => Promise.resolve([1, 2, 3])),
|
|
66
|
+
extContracts: jest.fn(() => Promise.resolve({ messageAq: zeroAddress })),
|
|
67
|
+
stateMerged: jest.fn(() => Promise.resolve(true)),
|
|
68
|
+
coordinatorPubKey: jest.fn(() => Promise.resolve({
|
|
69
|
+
x: 21424602586933317770306541383681754745261216801634012235464162098738462892814n,
|
|
70
|
+
y: 11917647526382221762393892566678210317414189429046519403585863973939713533473n,
|
|
71
|
+
})),
|
|
72
|
+
};
|
|
73
|
+
defaultProofGenerator = {
|
|
74
|
+
generateMpProofs: jest.fn(() => Promise.resolve([1])),
|
|
75
|
+
generateTallyProofs: jest.fn(() => Promise.resolve({ proofs: [1], tallyData: {} })),
|
|
76
|
+
merge: jest.fn(() => Promise.resolve(true)),
|
|
77
|
+
};
|
|
78
|
+
defaultCryptoService.decrypt = jest.fn(() => "macisk.6d5efa8ebc6f7a6ee3e9bf573346af2df29b007b29ef420c030aa4a7f3410182");
|
|
79
|
+
Deployment.getInstance.mockReturnValue(defaultDeploymentService);
|
|
80
|
+
ProofGenerator.mockReturnValue(defaultProofGenerator);
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
ProofGenerator.prepareState = jest.fn(() => Promise.resolve({
|
|
84
|
+
polls: new Map([[1n, {}]]),
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
jest.clearAllMocks();
|
|
89
|
+
});
|
|
90
|
+
test("should throw error if state is not merged yet", async () => {
|
|
91
|
+
mockContract.stateMerged.mockResolvedValue(false);
|
|
92
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
93
|
+
await expect(service.generate(defaultProofArgs)).rejects.toThrow(ErrorCodes.NOT_MERGED_STATE_TREE.toString());
|
|
94
|
+
});
|
|
95
|
+
test("should throw error if private key is wrong", async () => {
|
|
96
|
+
const keypair = new Keypair(new PrivKey(0n));
|
|
97
|
+
mockContract.coordinatorPubKey.mockResolvedValue(keypair.pubKey.asContractParam());
|
|
98
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
99
|
+
await expect(service.generate(defaultProofArgs)).rejects.toThrow(ErrorCodes.PRIVATE_KEY_MISMATCH.toString());
|
|
100
|
+
});
|
|
101
|
+
test("should throw error if poll is not found", async () => {
|
|
102
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
103
|
+
await expect(service.generate({ ...defaultProofArgs, poll: 2 })).rejects.toThrow(ErrorCodes.POLL_NOT_FOUND.toString());
|
|
104
|
+
});
|
|
105
|
+
test("should throw error if poll is not found in maci contract", async () => {
|
|
106
|
+
mockContract.polls.mockResolvedValue({ poll: zeroAddress });
|
|
107
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
108
|
+
await expect(service.generate({ ...defaultProofArgs, poll: 2 })).rejects.toThrow(ErrorCodes.POLL_NOT_FOUND.toString());
|
|
109
|
+
});
|
|
110
|
+
test("should throw error if coordinator key cannot be decrypted", async () => {
|
|
111
|
+
defaultCryptoService.decrypt.mockReturnValue("unknown");
|
|
112
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
113
|
+
await expect(service.generate({ ...defaultProofArgs, encryptedCoordinatorPrivateKey: "unknown" })).rejects.toThrow("Cannot convert 0x to a BigInt");
|
|
114
|
+
});
|
|
115
|
+
test("should generate proofs properly for NonQv", async () => {
|
|
116
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
117
|
+
const data = await service.generate(defaultProofArgs);
|
|
118
|
+
expect(data.processProofs).toHaveLength(1);
|
|
119
|
+
expect(data.tallyProofs).toHaveLength(1);
|
|
120
|
+
});
|
|
121
|
+
test("should generate proofs properly for Qv", async () => {
|
|
122
|
+
const service = new ProofGeneratorService(defaultCryptoService, fileService, sessionKeysService);
|
|
123
|
+
const data = await service.generate({ ...defaultProofArgs, useQuadraticVoting: true });
|
|
124
|
+
expect(data.processProofs).toHaveLength(1);
|
|
125
|
+
expect(data.tallyProofs).toHaveLength(1);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=proof.service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.service.test.js","sourceRoot":"","sources":["../../../../ts/proof/__tests__/proof.service.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAInC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAY,EAAE,CAAC,CAAC;IACnC,OAAO,EAAE;QACP,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE;YACN,KAAK,EAAE,EAAE,EAAE,EAA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M,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,gBAAgB,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;QAEvF,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
import { ESupportedNetworks } from "../common";
|
|
3
|
+
/**
|
|
4
|
+
* Data transfer object for generate proof
|
|
5
|
+
*/
|
|
6
|
+
export declare class GenerateProofDto {
|
|
7
|
+
/**
|
|
8
|
+
* Poll id
|
|
9
|
+
*/
|
|
10
|
+
poll: number;
|
|
11
|
+
/**
|
|
12
|
+
* Maci contract address
|
|
13
|
+
*/
|
|
14
|
+
maciContractAddress: string;
|
|
15
|
+
/**
|
|
16
|
+
* Tally contract address
|
|
17
|
+
*/
|
|
18
|
+
tallyContractAddress: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to use Qv or NonQv
|
|
21
|
+
*/
|
|
22
|
+
useQuadraticVoting: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypted coordinator private key with RSA public key (see .env.example)
|
|
25
|
+
*/
|
|
26
|
+
encryptedCoordinatorPrivateKey: string;
|
|
27
|
+
/**
|
|
28
|
+
* Start block for event processing
|
|
29
|
+
*/
|
|
30
|
+
startBlock?: number;
|
|
31
|
+
/**
|
|
32
|
+
* End block for event processing
|
|
33
|
+
*/
|
|
34
|
+
endBlock?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Blocks per batch for event processing
|
|
37
|
+
*/
|
|
38
|
+
blocksPerBatch?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Data transfer object for merge trees
|
|
42
|
+
*/
|
|
43
|
+
export declare class MergeTreesDto {
|
|
44
|
+
/**
|
|
45
|
+
* Poll id
|
|
46
|
+
*/
|
|
47
|
+
poll: number;
|
|
48
|
+
maciContractAddress: string;
|
|
49
|
+
sessionKeyAddress: string;
|
|
50
|
+
approval: string;
|
|
51
|
+
/**
|
|
52
|
+
* Chain Name
|
|
53
|
+
*/
|
|
54
|
+
chain: ESupportedNetworks;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Data transfer object for submit proofs on-chain
|
|
58
|
+
*/
|
|
59
|
+
export declare class SubmitProofsDto {
|
|
60
|
+
/**
|
|
61
|
+
* Poll id
|
|
62
|
+
*/
|
|
63
|
+
pollId: number;
|
|
64
|
+
maciContractAddress: Hex;
|
|
65
|
+
tallyContractAddress: Hex;
|
|
66
|
+
sessionKeyAddress: Hex;
|
|
67
|
+
approval: string;
|
|
68
|
+
/**
|
|
69
|
+
* Chain Name
|
|
70
|
+
*/
|
|
71
|
+
chain: ESupportedNetworks;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../../../ts/proof/dto.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IAQH,IAAI,EAAG,MAAM,CAAC;IAEd;;OAEG;IAMH,mBAAmB,EAAG,MAAM,CAAC;IAE7B;;OAEG;IAMH,oBAAoB,EAAG,MAAM,CAAC;IAE9B;;OAEG;IAMH,kBAAkB,EAAG,OAAO,CAAC;IAE7B;;OAEG;IASH,8BAA8B,EAAG,MAAM,CAAC;IAExC;;OAEG;IASH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IASH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IAWH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB;;OAEG;IAQH,IAAI,EAAG,MAAM,CAAC;IAOd,mBAAmB,EAAG,MAAM,CAAC;IAO7B,iBAAiB,EAAG,MAAM,CAAC;IAO3B,QAAQ,EAAG,MAAM,CAAC;IAElB;;OAEG;IAMH,KAAK,EAAG,kBAAkB,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IAQH,MAAM,EAAG,MAAM,CAAC;IAOhB,mBAAmB,EAAG,GAAG,CAAC;IAO1B,oBAAoB,EAAG,GAAG,CAAC;IAO3B,iBAAiB,EAAG,GAAG,CAAC;IAOxB,QAAQ,EAAG,MAAM,CAAC;IAElB;;OAEG;IAMH,KAAK,EAAG,kBAAkB,CAAC;CAC5B"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { ApiProperty } from "@nestjs/swagger";
|
|
11
|
+
import { IsBoolean, IsEnum, IsEthereumAddress, IsInt, IsOptional, IsString, Length, Max, Min } from "class-validator";
|
|
12
|
+
import { ESupportedNetworks } from "../common";
|
|
13
|
+
/**
|
|
14
|
+
* Data transfer object for generate proof
|
|
15
|
+
*/
|
|
16
|
+
export class GenerateProofDto {
|
|
17
|
+
/**
|
|
18
|
+
* Poll id
|
|
19
|
+
*/
|
|
20
|
+
poll;
|
|
21
|
+
/**
|
|
22
|
+
* Maci contract address
|
|
23
|
+
*/
|
|
24
|
+
maciContractAddress;
|
|
25
|
+
/**
|
|
26
|
+
* Tally contract address
|
|
27
|
+
*/
|
|
28
|
+
tallyContractAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to use Qv or NonQv
|
|
31
|
+
*/
|
|
32
|
+
useQuadraticVoting;
|
|
33
|
+
/**
|
|
34
|
+
* Encrypted coordinator private key with RSA public key (see .env.example)
|
|
35
|
+
*/
|
|
36
|
+
encryptedCoordinatorPrivateKey;
|
|
37
|
+
/**
|
|
38
|
+
* Start block for event processing
|
|
39
|
+
*/
|
|
40
|
+
startBlock;
|
|
41
|
+
/**
|
|
42
|
+
* End block for event processing
|
|
43
|
+
*/
|
|
44
|
+
endBlock;
|
|
45
|
+
/**
|
|
46
|
+
* Blocks per batch for event processing
|
|
47
|
+
*/
|
|
48
|
+
blocksPerBatch;
|
|
49
|
+
}
|
|
50
|
+
__decorate([
|
|
51
|
+
ApiProperty({
|
|
52
|
+
description: "Poll id",
|
|
53
|
+
minimum: 0,
|
|
54
|
+
type: Number,
|
|
55
|
+
}),
|
|
56
|
+
IsInt(),
|
|
57
|
+
Min(0),
|
|
58
|
+
__metadata("design:type", Number)
|
|
59
|
+
], GenerateProofDto.prototype, "poll", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
ApiProperty({
|
|
62
|
+
description: "MACI contract address",
|
|
63
|
+
type: String,
|
|
64
|
+
}),
|
|
65
|
+
IsEthereumAddress(),
|
|
66
|
+
__metadata("design:type", String)
|
|
67
|
+
], GenerateProofDto.prototype, "maciContractAddress", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
ApiProperty({
|
|
70
|
+
description: "Tally contract address",
|
|
71
|
+
type: String,
|
|
72
|
+
}),
|
|
73
|
+
IsEthereumAddress(),
|
|
74
|
+
__metadata("design:type", String)
|
|
75
|
+
], GenerateProofDto.prototype, "tallyContractAddress", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
ApiProperty({
|
|
78
|
+
description: "Whether to use quadratic voting or not",
|
|
79
|
+
type: Boolean,
|
|
80
|
+
}),
|
|
81
|
+
IsBoolean(),
|
|
82
|
+
__metadata("design:type", Boolean)
|
|
83
|
+
], GenerateProofDto.prototype, "useQuadraticVoting", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
ApiProperty({
|
|
86
|
+
description: "Encrypted coordinator private key with RSA public key (see README.md)",
|
|
87
|
+
minimum: 1,
|
|
88
|
+
maximum: 1024,
|
|
89
|
+
type: String,
|
|
90
|
+
}),
|
|
91
|
+
IsString(),
|
|
92
|
+
Length(1, 1024),
|
|
93
|
+
__metadata("design:type", String)
|
|
94
|
+
], GenerateProofDto.prototype, "encryptedCoordinatorPrivateKey", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
ApiProperty({
|
|
97
|
+
description: "Start block for event parsing",
|
|
98
|
+
minimum: 0,
|
|
99
|
+
type: Number,
|
|
100
|
+
}),
|
|
101
|
+
IsInt(),
|
|
102
|
+
Min(0),
|
|
103
|
+
IsOptional(),
|
|
104
|
+
__metadata("design:type", Number)
|
|
105
|
+
], GenerateProofDto.prototype, "startBlock", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
ApiProperty({
|
|
108
|
+
description: "End block for event parsing",
|
|
109
|
+
minimum: 0,
|
|
110
|
+
type: Number,
|
|
111
|
+
}),
|
|
112
|
+
IsInt(),
|
|
113
|
+
Min(0),
|
|
114
|
+
IsOptional(),
|
|
115
|
+
__metadata("design:type", Number)
|
|
116
|
+
], GenerateProofDto.prototype, "endBlock", void 0);
|
|
117
|
+
__decorate([
|
|
118
|
+
ApiProperty({
|
|
119
|
+
description: "Blocks per batch for event parsing",
|
|
120
|
+
minimum: 1,
|
|
121
|
+
maximum: 1000,
|
|
122
|
+
type: Number,
|
|
123
|
+
}),
|
|
124
|
+
IsInt(),
|
|
125
|
+
Min(1),
|
|
126
|
+
Max(1000),
|
|
127
|
+
IsOptional(),
|
|
128
|
+
__metadata("design:type", Number)
|
|
129
|
+
], GenerateProofDto.prototype, "blocksPerBatch", void 0);
|
|
130
|
+
/**
|
|
131
|
+
* Data transfer object for merge trees
|
|
132
|
+
*/
|
|
133
|
+
export class MergeTreesDto {
|
|
134
|
+
/**
|
|
135
|
+
* Poll id
|
|
136
|
+
*/
|
|
137
|
+
poll;
|
|
138
|
+
maciContractAddress;
|
|
139
|
+
sessionKeyAddress;
|
|
140
|
+
approval;
|
|
141
|
+
/**
|
|
142
|
+
* Chain Name
|
|
143
|
+
*/
|
|
144
|
+
chain;
|
|
145
|
+
}
|
|
146
|
+
__decorate([
|
|
147
|
+
ApiProperty({
|
|
148
|
+
description: "Poll id",
|
|
149
|
+
minimum: 0,
|
|
150
|
+
type: Number,
|
|
151
|
+
}),
|
|
152
|
+
IsInt(),
|
|
153
|
+
Min(0),
|
|
154
|
+
__metadata("design:type", Number)
|
|
155
|
+
], MergeTreesDto.prototype, "poll", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
ApiProperty({
|
|
158
|
+
description: "MACI contract address",
|
|
159
|
+
type: String,
|
|
160
|
+
}),
|
|
161
|
+
IsEthereumAddress(),
|
|
162
|
+
__metadata("design:type", String)
|
|
163
|
+
], MergeTreesDto.prototype, "maciContractAddress", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
ApiProperty({
|
|
166
|
+
description: "Session key address",
|
|
167
|
+
type: String,
|
|
168
|
+
}),
|
|
169
|
+
IsEthereumAddress(),
|
|
170
|
+
__metadata("design:type", String)
|
|
171
|
+
], MergeTreesDto.prototype, "sessionKeyAddress", void 0);
|
|
172
|
+
__decorate([
|
|
173
|
+
ApiProperty({
|
|
174
|
+
description: "Approval",
|
|
175
|
+
type: String,
|
|
176
|
+
}),
|
|
177
|
+
IsString(),
|
|
178
|
+
__metadata("design:type", String)
|
|
179
|
+
], MergeTreesDto.prototype, "approval", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
ApiProperty({
|
|
182
|
+
description: "Chain to which to deploy the contract(s)",
|
|
183
|
+
enum: ESupportedNetworks,
|
|
184
|
+
}),
|
|
185
|
+
IsEnum(ESupportedNetworks),
|
|
186
|
+
__metadata("design:type", String)
|
|
187
|
+
], MergeTreesDto.prototype, "chain", void 0);
|
|
188
|
+
/**
|
|
189
|
+
* Data transfer object for submit proofs on-chain
|
|
190
|
+
*/
|
|
191
|
+
export class SubmitProofsDto {
|
|
192
|
+
/**
|
|
193
|
+
* Poll id
|
|
194
|
+
*/
|
|
195
|
+
pollId;
|
|
196
|
+
maciContractAddress;
|
|
197
|
+
tallyContractAddress;
|
|
198
|
+
sessionKeyAddress;
|
|
199
|
+
approval;
|
|
200
|
+
/**
|
|
201
|
+
* Chain Name
|
|
202
|
+
*/
|
|
203
|
+
chain;
|
|
204
|
+
}
|
|
205
|
+
__decorate([
|
|
206
|
+
ApiProperty({
|
|
207
|
+
description: "Poll id",
|
|
208
|
+
minimum: 0,
|
|
209
|
+
type: Number,
|
|
210
|
+
}),
|
|
211
|
+
IsInt(),
|
|
212
|
+
Min(0),
|
|
213
|
+
__metadata("design:type", Number)
|
|
214
|
+
], SubmitProofsDto.prototype, "pollId", void 0);
|
|
215
|
+
__decorate([
|
|
216
|
+
ApiProperty({
|
|
217
|
+
description: "MACI contract address",
|
|
218
|
+
type: String,
|
|
219
|
+
}),
|
|
220
|
+
IsEthereumAddress(),
|
|
221
|
+
__metadata("design:type", String)
|
|
222
|
+
], SubmitProofsDto.prototype, "maciContractAddress", void 0);
|
|
223
|
+
__decorate([
|
|
224
|
+
ApiProperty({
|
|
225
|
+
description: "Tally contract address",
|
|
226
|
+
type: String,
|
|
227
|
+
}),
|
|
228
|
+
IsEthereumAddress(),
|
|
229
|
+
__metadata("design:type", String)
|
|
230
|
+
], SubmitProofsDto.prototype, "tallyContractAddress", void 0);
|
|
231
|
+
__decorate([
|
|
232
|
+
ApiProperty({
|
|
233
|
+
description: "Session key address",
|
|
234
|
+
type: String,
|
|
235
|
+
}),
|
|
236
|
+
IsEthereumAddress(),
|
|
237
|
+
__metadata("design:type", String)
|
|
238
|
+
], SubmitProofsDto.prototype, "sessionKeyAddress", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
ApiProperty({
|
|
241
|
+
description: "Approval",
|
|
242
|
+
type: String,
|
|
243
|
+
}),
|
|
244
|
+
IsString(),
|
|
245
|
+
__metadata("design:type", String)
|
|
246
|
+
], SubmitProofsDto.prototype, "approval", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
ApiProperty({
|
|
249
|
+
description: "Chain to which to deploy the contract(s)",
|
|
250
|
+
enum: ESupportedNetworks,
|
|
251
|
+
}),
|
|
252
|
+
IsEnum(ESupportedNetworks),
|
|
253
|
+
__metadata("design:type", String)
|
|
254
|
+
], SubmitProofsDto.prototype, "chain", void 0);
|
|
255
|
+
//# sourceMappingURL=dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto.js","sourceRoot":"","sources":["../../../ts/proof/dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAItH,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IAQH,IAAI,CAAU;IAEd;;OAEG;IAMH,mBAAmB,CAAU;IAE7B;;OAEG;IAMH,oBAAoB,CAAU;IAE9B;;OAEG;IAMH,kBAAkB,CA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I,EAAE,MAAM;KACb,CAAC;IACD,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;;+CACS;AAOhB;IALC,WAAW,CAAC;QACX,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE,MAAM;KACb,CAAC;IACD,iBAAiB,EAAE;;4DACM;AAO1B;IALC,WAAW,CAAC;QACX,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,MAAM;KACb,CAAC;IACD,iBAAiB,EAAE;;6DACO;AAO3B;IALC,WAAW,CAAC;QACX,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,MAAM;KACb,CAAC;IACD,iBAAiB,EAAE;;0DACI;AAOxB;IALC,WAAW,CAAC;QACX,WAAW,EAAE,UAAU;QACvB,IAAI,EAAE,MAAM;KACb,CAAC;IACD,QAAQ,EAAE;;iDACO;AAUlB;IALC,WAAW,CAAC;QACX,WAAW,EAAE,0CAA0C;QACvD,IAAI,EAAE,kBAAkB;KACzB,CAAC;IACD,MAAM,CAAC,kBAAkB,CAAC;;8CACA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IGenerateData, IMergeArgs } from "./types";
|
|
2
|
+
import type { IGetPublicKeyData } from "../file/types";
|
|
3
|
+
import { FileService } from "../file/file.service";
|
|
4
|
+
import { GenerateProofDto, SubmitProofsDto } from "./dto";
|
|
5
|
+
import { ProofGeneratorService } from "./proof.service";
|
|
6
|
+
export declare class ProofController {
|
|
7
|
+
private readonly proofGeneratorService;
|
|
8
|
+
private readonly fileService;
|
|
9
|
+
/**
|
|
10
|
+
* Logger
|
|
11
|
+
*/
|
|
12
|
+
private readonly logger;
|
|
13
|
+
/**
|
|
14
|
+
* Initialize ProofController
|
|
15
|
+
*
|
|
16
|
+
* @param proofGeneratorService - proof generator service
|
|
17
|
+
* @param fileService - file service
|
|
18
|
+
*/
|
|
19
|
+
constructor(proofGeneratorService: ProofGeneratorService, fileService: FileService);
|
|
20
|
+
/**
|
|
21
|
+
* Generate proofs api method
|
|
22
|
+
*
|
|
23
|
+
* @param args - generate proof dto
|
|
24
|
+
* @returns generated proofs and tally data
|
|
25
|
+
*/
|
|
26
|
+
generate(args: GenerateProofDto): Promise<IGenerateData>;
|
|
27
|
+
/**
|
|
28
|
+
* Merge trees api method
|
|
29
|
+
*
|
|
30
|
+
* @param args - merge args
|
|
31
|
+
* @returns whether the trees were successfully merged
|
|
32
|
+
*/
|
|
33
|
+
merge(args: IMergeArgs): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Submit proofs on-chain api method
|
|
36
|
+
* @param args - submit proofs on-chain args
|
|
37
|
+
*/
|
|
38
|
+
submit(args: SubmitProofsDto): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Get RSA public key for authorization setup
|
|
41
|
+
*
|
|
42
|
+
* @returns RSA public key
|
|
43
|
+
*/
|
|
44
|
+
getPublicKey(): Promise<IGetPublicKeyData>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=proof.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.controller.d.ts","sourceRoot":"","sources":["../../../ts/proof/proof.controller.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAiB,eAAe,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,qBAIa,eAAe;IAaxB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAb9B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAE3D;;;;;OAKG;gBAEgB,qBAAqB,EAAE,qBAAqB,EAC5C,WAAW,EAAE,WAAW;IAG3C;;;;;OAKG;IAMG,QAAQ,CAAS,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAOtE;;;;;OAKG;IAMG,KAAK,CAAS,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAOvD;;;OAGG;IAMG,MAAM,CAAS,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAO7D;;;;OAIG;IAKG,YAAY,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAMjD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var ProofController_1;
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
15
|
+
import { Body, Controller, Get, HttpException, HttpStatus, Logger, Post, UseGuards } from "@nestjs/common";
|
|
16
|
+
import { ApiBearerAuth, ApiBody, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
17
|
+
import { AccountSignatureGuard, Public } from "../auth/AccountSignatureGuard.service";
|
|
18
|
+
import { FileService } from "../file/file.service";
|
|
19
|
+
import { GenerateProofDto, MergeTreesDto, SubmitProofsDto } from "./dto";
|
|
20
|
+
import { ProofGeneratorService } from "./proof.service";
|
|
21
|
+
let ProofController = ProofController_1 = class ProofController {
|
|
22
|
+
proofGeneratorService;
|
|
23
|
+
fileService;
|
|
24
|
+
/**
|
|
25
|
+
* Logger
|
|
26
|
+
*/
|
|
27
|
+
logger = new Logger(ProofController_1.name);
|
|
28
|
+
/**
|
|
29
|
+
* Initialize ProofController
|
|
30
|
+
*
|
|
31
|
+
* @param proofGeneratorService - proof generator service
|
|
32
|
+
* @param fileService - file service
|
|
33
|
+
*/
|
|
34
|
+
constructor(proofGeneratorService, fileService) {
|
|
35
|
+
this.proofGeneratorService = proofGeneratorService;
|
|
36
|
+
this.fileService = fileService;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate proofs api method
|
|
40
|
+
*
|
|
41
|
+
* @param args - generate proof dto
|
|
42
|
+
* @returns generated proofs and tally data
|
|
43
|
+
*/
|
|
44
|
+
async generate(args) {
|
|
45
|
+
return this.proofGeneratorService.generate(args).catch((error) => {
|
|
46
|
+
this.logger.error(`Error:`, error);
|
|
47
|
+
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Merge trees api method
|
|
52
|
+
*
|
|
53
|
+
* @param args - merge args
|
|
54
|
+
* @returns whether the trees were successfully merged
|
|
55
|
+
*/
|
|
56
|
+
async merge(args) {
|
|
57
|
+
return this.proofGeneratorService.merge(args).catch((error) => {
|
|
58
|
+
this.logger.error(`Error:`, error);
|
|
59
|
+
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Submit proofs on-chain api method
|
|
64
|
+
* @param args - submit proofs on-chain args
|
|
65
|
+
*/
|
|
66
|
+
async submit(args) {
|
|
67
|
+
return this.proofGeneratorService.submit(args).catch((error) => {
|
|
68
|
+
this.logger.error(`Error:`, error);
|
|
69
|
+
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get RSA public key for authorization setup
|
|
74
|
+
*
|
|
75
|
+
* @returns RSA public key
|
|
76
|
+
*/
|
|
77
|
+
async getPublicKey() {
|
|
78
|
+
return this.fileService.getPublicKey().catch((error) => {
|
|
79
|
+
this.logger.error(`Error:`, error);
|
|
80
|
+
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
__decorate([
|
|
85
|
+
ApiBody({ type: GenerateProofDto }),
|
|
86
|
+
ApiResponse({ status: HttpStatus.CREATED, description: "The proofs have been successfully generated" }),
|
|
87
|
+
ApiResponse({ status: HttpStatus.FORBIDDEN, description: "Forbidden" }),
|
|
88
|
+
ApiResponse({ status: HttpStatus.BAD_REQUEST, description: "BadRequest" }),
|
|
89
|
+
Post("generate"),
|
|
90
|
+
__param(0, Body()),
|
|
91
|
+
__metadata("design:type", Function),
|
|
92
|
+
__metadata("design:paramtypes", [GenerateProofDto]),
|
|
93
|
+
__metadata("design:returntype", Promise)
|
|
94
|
+
], ProofController.prototype, "generate", null);
|
|
95
|
+
__decorate([
|
|
96
|
+
ApiBody({ type: MergeTreesDto }),
|
|
97
|
+
ApiResponse({ status: HttpStatus.CREATED, description: "The proofs have been successfully merged" }),
|
|
98
|
+
ApiResponse({ status: HttpStatus.FORBIDDEN, description: "Forbidden" }),
|
|
99
|
+
ApiResponse({ status: HttpStatus.BAD_REQUEST, description: "BadRequest" }),
|
|
100
|
+
Post("merge"),
|
|
101
|
+
__param(0, Body()),
|
|
102
|
+
__metadata("design:type", Function),
|
|
103
|
+
__metadata("design:paramtypes", [Object]),
|
|
104
|
+
__metadata("design:returntype", Promise)
|
|
105
|
+
], ProofController.prototype, "merge", null);
|
|
106
|
+
__decorate([
|
|
107
|
+
ApiBody({ type: SubmitProofsDto }),
|
|
108
|
+
ApiResponse({ status: HttpStatus.CREATED, description: "The proofs have been successfully submitted" }),
|
|
109
|
+
ApiResponse({ status: HttpStatus.FORBIDDEN, description: "Forbidden" }),
|
|
110
|
+
ApiResponse({ status: HttpStatus.BAD_REQUEST, description: "BadRequest" }),
|
|
111
|
+
Post("submit"),
|
|
112
|
+
__param(0, Body()),
|
|
113
|
+
__metadata("design:type", Function),
|
|
114
|
+
__metadata("design:paramtypes", [SubmitProofsDto]),
|
|
115
|
+
__metadata("design:returntype", Promise)
|
|
116
|
+
], ProofController.prototype, "submit", null);
|
|
117
|
+
__decorate([
|
|
118
|
+
ApiResponse({ status: HttpStatus.OK, description: "Public key was successfully returned" }),
|
|
119
|
+
ApiResponse({ status: HttpStatus.BAD_REQUEST, description: "BadRequest" }),
|
|
120
|
+
Public(),
|
|
121
|
+
Get("publicKey"),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", []),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], ProofController.prototype, "getPublicKey", null);
|
|
126
|
+
ProofController = ProofController_1 = __decorate([
|
|
127
|
+
ApiTags("v1/proof"),
|
|
128
|
+
ApiBearerAuth(),
|
|
129
|
+
Controller("v1/proof"),
|
|
130
|
+
UseGuards(AccountSignatureGuard),
|
|
131
|
+
__metadata("design:paramtypes", [ProofGeneratorService,
|
|
132
|
+
FileService])
|
|
133
|
+
], ProofController);
|
|
134
|
+
export { ProofController };
|
|
135
|
+
//# sourceMappingURL=proof.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.controller.js","sourceRoot":"","sources":["../../../ts/proof/proof.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAAiD;AACjD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE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