@maci-protocol/coordinator 0.0.0-ci.533e19d → 0.0.0-ci.54209f1

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.
Files changed (128) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +31 -6
  3. package/build/hardhat.config.cjs +3 -0
  4. package/build/hardhat.config.cjs.map +1 -1
  5. package/build/hardhat.config.d.cts +3 -0
  6. package/build/scripts/generateMaciKeyPair.js +2 -2
  7. package/build/scripts/generateMaciKeyPair.js.map +1 -1
  8. package/build/tests/constants.d.ts +0 -1
  9. package/build/tests/constants.d.ts.map +1 -1
  10. package/build/tests/constants.js +0 -1
  11. package/build/tests/constants.js.map +1 -1
  12. package/build/tests/e2e.aa.test.js +18 -25
  13. package/build/tests/e2e.aa.test.js.map +1 -1
  14. package/build/tests/e2e.deploy.test.js +135 -82
  15. package/build/tests/e2e.deploy.test.js.map +1 -1
  16. package/build/tests/utils.d.ts +6 -0
  17. package/build/tests/utils.d.ts.map +1 -1
  18. package/build/tests/utils.js +12 -3
  19. package/build/tests/utils.js.map +1 -1
  20. package/build/ts/app.module.d.ts.map +1 -1
  21. package/build/ts/app.module.js +2 -0
  22. package/build/ts/app.module.js.map +1 -1
  23. package/build/ts/common/__tests__/common.test.js +9 -13
  24. package/build/ts/common/__tests__/common.test.js.map +1 -1
  25. package/build/ts/common/accountAbstraction.d.ts +2 -19
  26. package/build/ts/common/accountAbstraction.d.ts.map +1 -1
  27. package/build/ts/common/accountAbstraction.js +15 -44
  28. package/build/ts/common/accountAbstraction.js.map +1 -1
  29. package/build/ts/common/chain.d.ts +16 -0
  30. package/build/ts/common/chain.d.ts.map +1 -0
  31. package/build/ts/common/chain.js +31 -0
  32. package/build/ts/common/chain.js.map +1 -0
  33. package/build/ts/common/coordinatorKeypair.d.ts +7 -0
  34. package/build/ts/common/coordinatorKeypair.d.ts.map +1 -0
  35. package/build/ts/common/coordinatorKeypair.js +14 -0
  36. package/build/ts/common/coordinatorKeypair.js.map +1 -0
  37. package/build/ts/common/errors.d.ts +17 -18
  38. package/build/ts/common/errors.d.ts.map +1 -1
  39. package/build/ts/common/errors.js +17 -18
  40. package/build/ts/common/errors.js.map +1 -1
  41. package/build/ts/common/index.d.ts +2 -0
  42. package/build/ts/common/index.d.ts.map +1 -1
  43. package/build/ts/common/index.js +2 -0
  44. package/build/ts/common/index.js.map +1 -1
  45. package/build/ts/common/types.d.ts +2 -3
  46. package/build/ts/common/types.d.ts.map +1 -1
  47. package/build/ts/deployer/__tests__/deployer.service.test.js +30 -289
  48. package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -1
  49. package/build/ts/deployer/__tests__/utils.d.ts +27 -1
  50. package/build/ts/deployer/__tests__/utils.d.ts.map +1 -1
  51. package/build/ts/deployer/__tests__/utils.js +42 -11
  52. package/build/ts/deployer/__tests__/utils.js.map +1 -1
  53. package/build/ts/deployer/deployer.service.d.ts +17 -53
  54. package/build/ts/deployer/deployer.service.d.ts.map +1 -1
  55. package/build/ts/deployer/deployer.service.js +178 -447
  56. package/build/ts/deployer/deployer.service.js.map +1 -1
  57. package/build/ts/deployer/dto.d.ts +4 -4
  58. package/build/ts/deployer/dto.d.ts.map +1 -1
  59. package/build/ts/deployer/dto.js +9 -1
  60. package/build/ts/deployer/dto.js.map +1 -1
  61. package/build/ts/deployer/types.d.ts +74 -26
  62. package/build/ts/deployer/types.d.ts.map +1 -1
  63. package/build/ts/file/__tests__/file.service.test.js +12 -11
  64. package/build/ts/file/__tests__/file.service.test.js.map +1 -1
  65. package/build/ts/file/file.service.d.ts +4 -3
  66. package/build/ts/file/file.service.d.ts.map +1 -1
  67. package/build/ts/file/file.service.js +14 -9
  68. package/build/ts/file/file.service.js.map +1 -1
  69. package/build/ts/file/types.d.ts +2 -2
  70. package/build/ts/file/types.d.ts.map +1 -1
  71. package/build/ts/health/__tests__/health.controller.test.d.ts +2 -0
  72. package/build/ts/health/__tests__/health.controller.test.d.ts.map +1 -0
  73. package/build/ts/health/__tests__/health.controller.test.js +22 -0
  74. package/build/ts/health/__tests__/health.controller.test.js.map +1 -0
  75. package/build/ts/health/__tests__/health.service.test.d.ts +2 -0
  76. package/build/ts/health/__tests__/health.service.test.d.ts.map +1 -0
  77. package/build/ts/health/__tests__/health.service.test.js +77 -0
  78. package/build/ts/health/__tests__/health.service.test.js.map +1 -0
  79. package/build/ts/health/health.controller.d.ts +16 -0
  80. package/build/ts/health/health.controller.d.ts.map +1 -0
  81. package/build/ts/health/health.controller.js +43 -0
  82. package/build/ts/health/health.controller.js.map +1 -0
  83. package/build/ts/health/health.module.d.ts +3 -0
  84. package/build/ts/health/health.module.d.ts.map +1 -0
  85. package/build/ts/health/health.module.js +21 -0
  86. package/build/ts/health/health.module.js.map +1 -0
  87. package/build/ts/health/health.service.d.ts +35 -0
  88. package/build/ts/health/health.service.d.ts.map +1 -0
  89. package/build/ts/health/health.service.js +169 -0
  90. package/build/ts/health/health.service.js.map +1 -0
  91. package/build/ts/health/types.d.ts +79 -0
  92. package/build/ts/health/types.d.ts.map +1 -0
  93. package/build/ts/health/types.js +2 -0
  94. package/build/ts/health/types.js.map +1 -0
  95. package/build/ts/proof/__tests__/proof.controller.test.js +5 -3
  96. package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -1
  97. package/build/ts/proof/__tests__/proof.gateway.test.js +6 -3
  98. package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -1
  99. package/build/ts/proof/__tests__/proof.service.test.js +18 -31
  100. package/build/ts/proof/__tests__/proof.service.test.js.map +1 -1
  101. package/build/ts/proof/dto.d.ts +13 -15
  102. package/build/ts/proof/dto.d.ts.map +1 -1
  103. package/build/ts/proof/dto.js +51 -44
  104. package/build/ts/proof/dto.js.map +1 -1
  105. package/build/ts/proof/proof.controller.d.ts +3 -2
  106. package/build/ts/proof/proof.controller.d.ts.map +1 -1
  107. package/build/ts/proof/proof.controller.js +1 -4
  108. package/build/ts/proof/proof.controller.js.map +1 -1
  109. package/build/ts/proof/proof.service.d.ts +4 -6
  110. package/build/ts/proof/proof.service.d.ts.map +1 -1
  111. package/build/ts/proof/proof.service.js +48 -130
  112. package/build/ts/proof/proof.service.js.map +1 -1
  113. package/build/ts/proof/types.d.ts +19 -14
  114. package/build/ts/proof/types.d.ts.map +1 -1
  115. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts +53 -0
  116. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts.map +1 -0
  117. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js +105 -0
  118. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js.map +1 -0
  119. package/build/ts/sessionKeys/sessionKeys.service.d.ts +13 -2
  120. package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -1
  121. package/build/ts/sessionKeys/sessionKeys.service.js +22 -4
  122. package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -1
  123. package/build/tsconfig.build.tsbuildinfo +1 -1
  124. package/package.json +36 -36
  125. package/build/ts/deployer/utils.d.ts +0 -8
  126. package/build/ts/deployer/utils.d.ts.map +0 -1
  127. package/build/ts/deployer/utils.js +0 -9
  128. package/build/ts/deployer/utils.js.map +0 -1
package/LICENSE CHANGED
@@ -1,7 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Barry WhiteHat, Kendrick Tan, Kobi Gurkan, Kirill Goncharov
4
- Cory Dickson, Han Jian, Chih-Cheng Liang, and Koh Wei Jie
3
+ Copyright (c) 2025 Ethereum Foundation
5
4
 
6
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,16 +2,23 @@
2
2
 
3
3
  Please refer to [Offchain relayer service documentation](https://maci.pse.dev/docs/category/offchain-relayer) for more information.
4
4
 
5
+ ## Requirements
6
+
7
+ 1. [Node.js](https://nodejs.org/en) version 20.0.0.
8
+ 2. [pnpm](https://pnpm.io/installation) package manager.
9
+ 3. [rapidsnark](https://github.com/iden3/rapidsnark) program.
10
+
5
11
  ## Instructions
6
12
 
7
13
  1. Add `.env` file (see `.env.example`).
8
- 2. Generate RSA key pair with `pnpm run generate-keypair`.
9
- 3. Download zkey files using `pnpm run download-zkeys:{type}` (only test type is available for now).
10
- 4. Make sure you copied RSA public key to your application. This will be needed for encrypting `Authorization` header and coordinator private key for proof generation. Also it can be accessed through API method `GET v1/proof/publicKey`.
11
- 5. Run `pnpm run start` to run the service.
12
- 6. All API calls must be called with `Authorization` header, where the value is encrypted with RSA public key you generated before. Header value contains message signature and message digest created by `COORDINATOR_ADDRESSES`. The format is `publicEncrypt({signature}:{digest})`.
14
+ 2. Remember to set up the rapidsnark file variable.
15
+ 3. Generate RSA key pair with `pnpm run generate-keypair`.
16
+ 4. Download zkey files using `pnpm run download-zkeys:{type}` (only test type is available for now).
17
+ 5. Make sure you copied RSA public key to your application. This will be needed for encrypting `Authorization` header and coordinator private key for proof generation. Also it can be accessed through API method `GET v1/proof/publicKey`.
18
+ 6. Run `pnpm run start` to run the service.
19
+ 7. All API calls must be called with `Authorization` header, where the value is encrypted with RSA public key you generated before. Header value contains message signature and message digest created by `COORDINATOR_ADDRESSES`. The format is `publicEncrypt({signature}:{digest})`.
13
20
  Make sure you set `COORDINATOR_ADDRESSES` env variable and sign any message with the addresses from your application (see [AccountSignatureGuard](./ts/auth/AccountSignatureGuard.service.ts)).
14
- 7. Proofs can be generated with `POST v1/proof/generate` API method or with Websockets (see [dto spec](./ts/proof/dto.ts), [controller](./ts/app.controller.ts) and [wsgateway](./ts/events/events.gateway.ts)).
21
+ 8. Proofs can be generated with `POST v1/proof/generate` API method or with Websockets (see [dto spec](./ts/proof/dto.ts), [controller](./ts/app.controller.ts) and [wsgateway](./ts/events/events.gateway.ts)).
15
22
 
16
23
  ## Subgraph deployment
17
24
 
@@ -40,3 +47,21 @@ After deployment, subgraph url will be available in studio dashboard and you can
40
47
  ```
41
48
  https://api.studio.thegraph.com/.../{SUBGRAPH_NAME}/version/latest
42
49
  ```
50
+
51
+ ## Docker
52
+
53
+ Remember to run it from the monorepo root directory.
54
+
55
+ ```bash
56
+ # Build docker
57
+ docker compose -f apps/coordinator/docker-compose.yml build
58
+
59
+ # Run container detached
60
+ docker compose -f apps/coordinator/docker-compose.yml up -d
61
+
62
+ # Enter the container
63
+ docker compose -f apps/coordinator/docker-compose.yml exec coordinator-service /bin/sh
64
+
65
+ # Stop container
66
+ docker compose -f apps/coordinator/docker-compose.yml down
67
+ ```
@@ -23,6 +23,9 @@ module.exports = {
23
23
  loggingEnabled: false,
24
24
  },
25
25
  },
26
+ solidity: {
27
+ version: "0.8.28",
28
+ },
26
29
  paths: {
27
30
  sources: path.resolve(__dirname, parentDir, "./node_modules/@maci-protocol/sdk/node_modules/@maci-protocol/contracts/contracts"),
28
31
  artifacts: path.resolve(__dirname, parentDir, "./node_modules/@maci-protocol/sdk/node_modules/@maci-protocol/contracts/artifacts"),
@@ -1 +1 @@
1
- {"version":3,"file":"hardhat.config.cjs","sourceRoot":"","sources":["../hardhat.config.cjs"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1D,MAAM,aAAa,GAAG,6DAA6D,CAAC;AAEpF,MAAM,CAAC,OAAO,GAAG;IACf,cAAc,EAAE,SAAS;IACzB,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,uBAAuB;YAC/D,QAAQ,EAAE;gBACR,QAAQ,EAAE,aAAa;gBACvB,IAAI,EA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B,SAAS,EACT,SAAS,EACT,mFAAmF,CACpF;QACD,SAAS,EAAE,IAAI,CAAC,OAAO,CACrB,SAAS,EACT,SAAS,EACT,mFAAmF,CACpF;KACF;CACF,CAAC"}
@@ -16,6 +16,9 @@ export namespace networks {
16
16
  export { loggingEnabled_1 as loggingEnabled };
17
17
  }
18
18
  }
19
+ export namespace solidity {
20
+ let version: string;
21
+ }
19
22
  export namespace paths {
20
23
  let sources: string;
21
24
  let artifacts: string;
@@ -1,3 +1,3 @@
1
- import { genKeypair } from "@maci-protocol/crypto";
2
- genKeypair();
1
+ import { generateKeypair } from "@maci-protocol/crypto";
2
+ generateKeypair();
3
3
  //# sourceMappingURL=generateMaciKeyPair.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateMaciKeyPair.js","sourceRoot":"","sources":["../../scripts/generateMaciKeyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"generateMaciKeyPair.js","sourceRoot":"","sources":["../../scripts/generateMaciKeyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,eAAe,EAAE,CAAC"}
@@ -4,5 +4,4 @@ export declare const testPollJoiningWitnessPath = "./zkeys/PollJoining_10_test/P
4
4
  export declare const testRapidsnarkPath: string;
5
5
  export declare const zeroUint256Encoded: string;
6
6
  export declare const oneUint256Encoded: string;
7
- export declare const pollDuration = 10;
8
7
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../tests/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,2DAA2D,CAAC;AAChG,eAAO,MAAM,uBAAuB,gFAAgF,CAAC;AACrH,eAAO,MAAM,0BAA0B,4EAA4E,CAAC;AACpH,eAAO,MAAM,kBAAkB,QAAyC,CAAC;AAEzE,eAAO,MAAM,kBAAkB,QAAsD,CAAC;AACtF,eAAO,MAAM,iBAAiB,QAAsD,CAAC;AAErF,eAAO,MAAM,YAAY,KAAK,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../tests/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,2DAA2D,CAAC;AAChG,eAAO,MAAM,uBAAuB,gFAAgF,CAAC;AACrH,eAAO,MAAM,0BAA0B,4EAA4E,CAAC;AACpH,eAAO,MAAM,kBAAkB,QAAyC,CAAC;AAEzE,eAAO,MAAM,kBAAkB,QAAsD,CAAC;AACtF,eAAO,MAAM,iBAAiB,QAAsD,CAAC"}
@@ -6,5 +6,4 @@ export const testPollJoiningWitnessPath = "./zkeys/PollJoining_10_test/PollJoini
6
6
  export const testRapidsnarkPath = `${homedir()}/rapidsnark/build/prover`;
7
7
  export const zeroUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [0]);
8
8
  export const oneUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [1]);
9
- export const pollDuration = 10; // 100 seconds (added to unix timestamp of start date)
10
9
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../tests/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,MAAM,CAAC,MAAM,uBAAuB,GAAG,wDAAwD,CAAC;AAChG,MAAM,CAAC,MAAM,uBAAuB,GAAG,6EAA6E,CAAC;AACrH,MAAM,CAAC,MAAM,0BAA0B,GAAG,yEAAyE,CAAC;AACpH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,OAAO,EAAE,0BAA0B,CAAC;AAEzE,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAErF,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC,CAAC,sDAAsD"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../tests/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,MAAM,CAAC,MAAM,uBAAuB,GAAG,wDAAwD,CAAC;AAChG,MAAM,CAAC,MAAM,uBAAuB,GAAG,6EAA6E,CAAC;AACrH,MAAM,CAAC,MAAM,0BAA0B,GAAG,yEAAyE,CAAC;AACpH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,OAAO,EAAE,0BAA0B,CAAC;AAEzE,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
+ import { sleep } from "@maci-protocol/sdk";
1
2
  import { zeroAddress } from "viem";
2
3
  import { ErrorCodes, ESupportedNetworks } from "../ts/common";
3
- import { CryptoService } from "../ts/crypto/crypto.service";
4
4
  import { testMaciDeploymentConfig, testPollDeploymentConfig } from "../ts/deployer/__tests__/utils";
5
5
  import { DeployerService } from "../ts/deployer/deployer.service";
6
6
  import { FileService } from "../ts/file/file.service";
@@ -10,68 +10,61 @@ import { SessionKeysService } from "../ts/sessionKeys/sessionKeys.service";
10
10
  describe("E2E Account Abstraction Tests", () => {
11
11
  const fileService = new FileService();
12
12
  const sessionKeyService = new SessionKeysService(fileService);
13
- const cryptoService = new CryptoService();
14
- const proofService = new ProofGeneratorService(cryptoService, fileService, sessionKeyService);
13
+ const proofService = new ProofGeneratorService(fileService, sessionKeyService);
15
14
  const deployerService = new DeployerService(sessionKeyService, fileService);
16
15
  // using an already deployed maci contract
17
- const maciContract = "0xf281870519822f302B13c07252d0f6A71E8D023e";
18
- const pollId = 2;
16
+ let maciContract = "";
17
+ let pollId;
19
18
  let approval;
20
19
  let sessionKeyAddress;
21
20
  beforeAll(async () => {
22
- approval = await generateApproval(sessionKeyAddress);
23
21
  sessionKeyAddress = (await sessionKeyService.generateSessionKey()).sessionKeyAddress;
22
+ approval = await generateApproval(sessionKeyAddress);
24
23
  });
25
24
  describe("deploy", () => {
26
25
  describe("deployMaci", () => {
27
26
  it("should deploy all maci related contracts", async () => {
28
27
  const { address: maciAddress } = await deployerService.deployMaci({
29
- approval,
30
- sessionKeyAddress,
31
28
  chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
32
29
  config: testMaciDeploymentConfig,
33
30
  });
31
+ maciContract = maciAddress;
34
32
  expect(maciAddress).not.toBe(zeroAddress);
35
33
  });
36
34
  });
37
35
  describe("deployPoll", () => {
38
36
  it("should deploy a poll", async () => {
39
- // Serialize the config with the custom serializer
40
- const serializedConfig = JSON.stringify(testPollDeploymentConfig);
41
- const pollConfig = JSON.parse(serializedConfig);
42
37
  const { pollId: poll } = await deployerService.deployPoll({
43
- approval,
44
- sessionKeyAddress,
45
38
  chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
46
- config: pollConfig,
39
+ config: {
40
+ ...testPollDeploymentConfig,
41
+ startDate: Math.floor(Date.now() / 1000) + 50,
42
+ endDate: Math.floor(Date.now() / 1000) + 85,
43
+ },
47
44
  });
48
45
  expect(poll).toBeDefined();
46
+ pollId = Number.parseInt(poll, 10);
49
47
  });
50
48
  });
51
49
  });
52
50
  describe("merge", () => {
53
51
  test("should return true when there are no errors", async () => {
54
- const { sessionKeyAddress: sessionKey } = await sessionKeyService.generateSessionKey();
55
- const generatedApproval = await generateApproval(sessionKey);
52
+ // wait until we can complete a poll
53
+ await sleep(90 * 1000); // 50 start + 35 end + 5 seconds of grace time
56
54
  const merged = await proofService.merge({
57
55
  maciContractAddress: maciContract,
58
56
  pollId,
59
- sessionKeyAddress: sessionKey,
60
- approval: generatedApproval,
61
57
  chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
62
58
  });
63
59
  expect(merged).toBe(true);
64
60
  });
65
61
  test("should throw when given an invalid pollId", async () => {
66
- const { sessionKeyAddress: sessionKey } = await sessionKeyService.generateSessionKey();
67
- const generatedApproval = await generateApproval(sessionKey);
62
+ const invalidPollId = 50000;
68
63
  await expect(proofService.merge({
69
64
  maciContractAddress: maciContract,
70
- pollId: 50000,
71
- sessionKeyAddress: sessionKey,
72
- approval: generatedApproval,
65
+ pollId: invalidPollId,
73
66
  chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
74
- })).rejects.toThrow(ErrorCodes.POLL_NOT_FOUND.toString());
67
+ })).rejects.toThrow(`MACI contract doesn't have any deployed poll ${invalidPollId}`);
75
68
  });
76
69
  });
77
70
  describe("sessionKeys", () => {
@@ -82,7 +75,7 @@ describe("E2E Account Abstraction Tests", () => {
82
75
  expect(client.key).toBe("Account");
83
76
  expect(client.account.address).not.toBe(zeroAddress);
84
77
  expect(client.account.kernelVersion).toBe(KERNEL_VERSION);
85
- expect(client.account.entryPoint).toBe(ENTRY_POINT);
78
+ expect(client.account.entryPoint.version).toBe(ENTRY_POINT.version);
86
79
  // this is an account with limited permissions so no sudo validator
87
80
  expect(client.account.kernelPluginManager.address).toBe(zeroAddress);
88
81
  expect(client.account.kernelPluginManager.sudoValidator).toBe(undefined);
@@ -1 +1 @@
1
- {"version":3,"file":"e2e.aa.test.js","sourceRoot":"","sources":["../../tests/e2e.aa.test.ts"],"names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test.ts
2
- import { genRandomSalt } from "@maci-protocol/crypto";
3
1
  import { Keypair } from "@maci-protocol/domainobjs";
4
- import { joinPoll, publish, signup, sleep } from "@maci-protocol/sdk";
2
+ import { ContractStorage, isArm, joinPoll, signup, sleep } from "@maci-protocol/sdk";
5
3
  import { ValidationPipe } from "@nestjs/common";
6
4
  import { Test } from "@nestjs/testing";
7
5
  import dotenv from "dotenv";
8
- import hardhat from "hardhat";
9
6
  import { io } from "socket.io-client";
10
7
  import { zeroAddress } from "viem";
8
+ import path from "path";
11
9
  import { AppModule } from "../ts/app.module";
12
- import { ESupportedNetworks } from "../ts/common";
10
+ import { ESupportedNetworks, getSigner } from "../ts/common";
13
11
  import { getPublicClient } from "../ts/common/accountAbstraction";
14
- import { testMaciDeploymentConfig, testPollDeploymentConfig } from "../ts/deployer/__tests__/utils";
12
+ import { pollDuration, pollStartDateExtraSeconds, testMaciDeploymentConfig, testPollDeploymentConfig, } from "../ts/deployer/__tests__/utils";
13
+ import { DeployerModule } from "../ts/deployer/deployer.module";
15
14
  import { FileModule } from "../ts/file/file.module";
16
- import { generateApproval, getKernelAccount } from "../ts/sessionKeys/__tests__/utils";
17
- import { pollDuration, pollJoiningTestZkeyPath, testPollJoiningWasmPath, testPollJoiningWitnessPath, testRapidsnarkPath, zeroUint256Encoded, } from "./constants";
15
+ import { ProofModule } from "../ts/proof/proof.module";
16
+ import { getKernelAccount } from "../ts/sessionKeys/__tests__/utils";
17
+ import { SessionKeysModule } from "../ts/sessionKeys/sessionKeys.module";
18
+ import { pollJoiningTestZkeyPath, testPollJoiningWasmPath, testPollJoiningWitnessPath, testRapidsnarkPath, zeroUint256Encoded, } from "./constants";
18
19
  import { getAuthorizationHeader, rechargeGasIfNeeded } from "./utils";
19
20
  dotenv.config();
20
- const LOCALHOST = "http://localhost:3000";
21
+ jest.setTimeout(700000); // Sets timeout to 700 seconds
22
+ const PORT = process.env.COORDINATOR_PORT || 3000;
23
+ const TEST_URL = `http://localhost:${PORT}/v1`;
24
+ const CHAIN = ESupportedNetworks.OPTIMISM_SEPOLIA;
25
+ const REGEX_SUBGRAPH = /^https:\/\/api\.studio\.thegraph\.com\/query\/\d+\/maci-subgraph\/v0\.0\.\d+$/;
21
26
  const NUM_USERS = 1;
22
- const voteOptions = {
27
+ const VOTE_OPTIONS = {
23
28
  "0": 0,
24
29
  "1": 0,
25
30
  };
26
31
  describe("E2E Deployment Tests", () => {
27
32
  let signer;
28
33
  let encryptedHeader;
29
- let coordinatorKeypair;
30
34
  let sessionKeyAddress;
31
- let approval;
32
35
  let app;
33
36
  let socket;
34
- const publicClient = getPublicClient(ESupportedNetworks.OPTIMISM_SEPOLIA);
37
+ const publicClient = getPublicClient(CHAIN);
35
38
  let maciAddress;
39
+ let maciCreatedAt;
36
40
  let pollId;
37
41
  // set up coordinator address
38
42
  beforeAll(async () => {
39
- [signer] = await hardhat.ethers.getSigners();
43
+ signer = getSigner(CHAIN);
40
44
  encryptedHeader = await getAuthorizationHeader(signer);
41
- coordinatorKeypair = new Keypair();
42
45
  process.env.COORDINATOR_ADDRESSES = await signer.getAddress();
43
46
  await rechargeGasIfNeeded(process.env.COORDINATOR_ADDRESSES, "0.007", "0.007");
44
47
  });
45
48
  // set up NestJS app
46
49
  beforeAll(async () => {
47
50
  const moduleFixture = await Test.createTestingModule({
48
- imports: [AppModule, FileModule],
51
+ imports: [AppModule, FileModule, DeployerModule, ProofModule, SessionKeysModule],
49
52
  }).compile();
50
53
  app = moduleFixture.createNestApplication();
51
54
  app.useGlobalPipes(new ValidationPipe({ transform: true }));
52
55
  await app.init();
53
- await app.listen(3000);
56
+ await app.listen(PORT);
54
57
  });
55
58
  afterAll(async () => {
56
59
  await app.close();
60
+ const storageInstance = ContractStorage.getInstance(path.join(process.cwd(), "deployed-contracts.json"));
61
+ storageInstance.cleanup(CHAIN);
57
62
  });
58
63
  // set up auth header in WS connection
59
64
  beforeEach(async () => {
@@ -75,8 +80,25 @@ describe("E2E Deployment Tests", () => {
75
80
  socket.disconnect();
76
81
  });
77
82
  // run tests
83
+ test("should return true in the health check", async () => {
84
+ const response = await fetch(`${TEST_URL}/health/check`, { method: "GET" });
85
+ const body = (await response.json());
86
+ expect(response.status).toBe(200);
87
+ expect(body.rapidsnark.rapidsnarkIsExecutable).toBe(true);
88
+ expect(body.zkeysDirectory.zkeysDirectoryExists).toBe(true);
89
+ expect(body.coordinatorWalletFunds.address).not.toBe(zeroAddress);
90
+ });
91
+ test("should retrieve RSA public key", async () => {
92
+ const response = await fetch(`${TEST_URL}/proof/publicKey`, {
93
+ method: "GET",
94
+ });
95
+ const body = (await response.json());
96
+ expect(response.status).toBe(200);
97
+ expect(body.publicKey).toBeDefined();
98
+ // this RSA should be used in the encrypted auth header
99
+ });
78
100
  test("should retrieve the session key address", async () => {
79
- const response = await fetch(`${LOCALHOST}/v1/session-keys/generate`, {
101
+ const response = await fetch(`${TEST_URL}/session-keys/generate`, {
80
102
  method: "GET",
81
103
  headers: {
82
104
  Authorization: encryptedHeader,
@@ -87,25 +109,26 @@ describe("E2E Deployment Tests", () => {
87
109
  expect(body.sessionKeyAddress).not.toBe(zeroAddress);
88
110
  // save them for next tests
89
111
  sessionKeyAddress = body.sessionKeyAddress;
90
- approval = await generateApproval(sessionKeyAddress);
91
112
  const sessionKeyAccount = await getKernelAccount(sessionKeyAddress);
92
113
  await rechargeGasIfNeeded(sessionKeyAccount.address, "0.03", "0.03");
93
114
  });
94
115
  test("should deploy MACI correctly", async () => {
95
116
  const config = testMaciDeploymentConfig;
96
- config.VkRegistry.args.stateTreeDepth = config.VkRegistry.args.stateTreeDepth.toString();
97
- config.VkRegistry.args.intStateTreeDepth = config.VkRegistry.args.intStateTreeDepth.toString();
98
- config.VkRegistry.args.voteOptionTreeDepth = config.VkRegistry.args.voteOptionTreeDepth.toString();
99
- const response = await fetch(`${LOCALHOST}/v1/deploy/maci`, {
117
+ config.VerifyingKeysRegistry.args.stateTreeDepth = config.VerifyingKeysRegistry.args.stateTreeDepth.toString();
118
+ config.VerifyingKeysRegistry.args.pollStateTreeDepth =
119
+ config.VerifyingKeysRegistry.args.pollStateTreeDepth.toString();
120
+ config.VerifyingKeysRegistry.args.tallyProcessingStateTreeDepth =
121
+ config.VerifyingKeysRegistry.args.tallyProcessingStateTreeDepth.toString();
122
+ config.VerifyingKeysRegistry.args.voteOptionTreeDepth =
123
+ config.VerifyingKeysRegistry.args.voteOptionTreeDepth.toString();
124
+ const response = await fetch(`${TEST_URL}/deploy/maci`, {
100
125
  method: "POST",
101
126
  headers: {
102
127
  Authorization: encryptedHeader,
103
128
  "Content-Type": "application/json",
104
129
  },
105
130
  body: JSON.stringify({
106
- approval,
107
- sessionKeyAddress,
108
- chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
131
+ chain: CHAIN,
109
132
  config,
110
133
  }),
111
134
  });
@@ -113,25 +136,24 @@ describe("E2E Deployment Tests", () => {
113
136
  expect(response.status).toBe(201);
114
137
  expect(body.address).not.toBe(zeroAddress);
115
138
  // save them for next tests
139
+ const blockNumber = await publicClient.getBlockNumber();
140
+ maciCreatedAt = blockNumber;
116
141
  maciAddress = body.address;
117
142
  });
118
143
  test("should deploy a poll correctly", async () => {
119
144
  const config = testPollDeploymentConfig;
120
- config.coordinatorPubkey = coordinatorKeypair.pubKey.serialize();
121
145
  config.voteOptions = config.voteOptions.toString();
122
- const startDate = Math.floor(Date.now() / 1000) + 10;
146
+ const startDate = Math.floor(Date.now() / 1000) + pollStartDateExtraSeconds;
123
147
  config.startDate = startDate;
124
148
  config.endDate = startDate + pollDuration;
125
- const response = await fetch(`${LOCALHOST}/v1/deploy/poll`, {
149
+ const response = await fetch(`${TEST_URL}/deploy/poll`, {
126
150
  method: "POST",
127
151
  headers: {
128
152
  Authorization: encryptedHeader,
129
153
  "Content-Type": "application/json",
130
154
  },
131
155
  body: JSON.stringify({
132
- approval,
133
- sessionKeyAddress,
134
- chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
156
+ chain: CHAIN,
135
157
  config,
136
158
  }),
137
159
  });
@@ -141,41 +163,19 @@ describe("E2E Deployment Tests", () => {
141
163
  // save them for next tests
142
164
  pollId = BigInt(body.pollId);
143
165
  });
144
- test("should deploy a subgraph correctly", async () => {
145
- const blockNumber = Number(await publicClient.getBlockNumber());
146
- const response = await fetch(`${LOCALHOST}/v1/subgraph/deploy`, {
147
- method: "POST",
148
- headers: {
149
- Authorization: encryptedHeader,
150
- "Content-Type": "application/json",
151
- },
152
- body: JSON.stringify({
153
- maciContractAddress: maciAddress,
154
- startBlock: blockNumber,
155
- network: ESupportedNetworks.OPTIMISM_SEPOLIA,
156
- name: process.env.SUBGRAPH_NAME,
157
- tag: `v0.0.${blockNumber}`, // different versions per test using block number
158
- }),
159
- });
160
- const body = (await response.json());
161
- const { url } = body;
162
- const regex = /^https:\/\/api\.studio\.thegraph\.com\/query\/\d+\/maci-subgraph\/v0\.0\.\d+$/;
163
- expect(response.status).toBe(201);
164
- expect(body.url).toBeDefined();
165
- expect(regex.test(url)).toBe(true);
166
- });
167
166
  test("should allow voting on a poll", async () => {
167
+ await sleep(pollStartDateExtraSeconds * 1000);
168
168
  for (let i = 0; i < NUM_USERS; i += 1) {
169
169
  const keypairUser = new Keypair();
170
- const pubkeyUser = keypairUser.pubKey.serialize();
171
- const privkeyUser = keypairUser.privKey.serialize();
170
+ const userPublicKey = keypairUser.publicKey.serialize();
171
+ const userPrivateKey = keypairUser.privateKey.serialize();
172
172
  const vote = i % 2;
173
- voteOptions[String(vote)] += 1;
173
+ VOTE_OPTIONS[String(vote)] += 1;
174
174
  // user signs up to MACI
175
175
  // eslint-disable-next-line no-await-in-loop
176
176
  await signup({
177
177
  maciAddress,
178
- maciPubKey: pubkeyUser,
178
+ maciPublicKey: userPublicKey,
179
179
  sgData: zeroUint256Encoded,
180
180
  signer,
181
181
  });
@@ -183,38 +183,51 @@ describe("E2E Deployment Tests", () => {
183
183
  // eslint-disable-next-line no-await-in-loop
184
184
  await joinPoll({
185
185
  maciAddress,
186
- privateKey: privkeyUser,
187
- stateIndex: 1n,
186
+ privateKey: userPrivateKey,
188
187
  pollId: BigInt(pollId),
189
188
  pollJoiningZkey: pollJoiningTestZkeyPath,
190
189
  useWasm: true,
191
190
  pollWasm: testPollJoiningWasmPath,
192
- pollWitgen: testPollJoiningWitnessPath,
191
+ pollWitnessGenerator: testPollJoiningWitnessPath,
193
192
  rapidsnark: testRapidsnarkPath,
194
193
  sgDataArg: zeroUint256Encoded,
195
194
  ivcpDataArg: zeroUint256Encoded,
196
195
  signer,
197
196
  });
198
- // user publishes a vote
199
- // eslint-disable-next-line no-await-in-loop
200
- const publishData = await publish({
201
- pubkey: pubkeyUser,
202
- stateIndex: 1n,
203
- voteOptionIndex: BigInt(vote),
204
- nonce: 1n,
205
- pollId: BigInt(pollId),
206
- newVoteWeight: 1n,
207
- maciAddress,
208
- salt: genRandomSalt(),
209
- privateKey: privkeyUser,
210
- signer,
211
- });
212
- expect(publishData.hash).not.toBe(zeroAddress);
213
197
  }
214
198
  });
199
+ test("should deploy a subgraph correctly", async () => {
200
+ const response = await fetch(`${TEST_URL}/subgraph/deploy`, {
201
+ method: "POST",
202
+ headers: {
203
+ Authorization: encryptedHeader,
204
+ "Content-Type": "application/json",
205
+ },
206
+ body: JSON.stringify({
207
+ maciContractAddress: maciAddress,
208
+ startBlock: Number(maciCreatedAt),
209
+ network: CHAIN,
210
+ name: process.env.SUBGRAPH_NAME,
211
+ tag: `v0.0.${maciCreatedAt}`, // different versions per test using block number
212
+ }),
213
+ });
214
+ const body = await response.json();
215
+ if (response.status === 400) {
216
+ const errorMessage = body.message;
217
+ if (errorMessage.includes("api.thegraph.com | 502: Bad gateway")) {
218
+ // eslint-disable-next-line no-console
219
+ console.info("It looks like there was a problem with The Graph endpoint. We are passing this test.");
220
+ return;
221
+ }
222
+ }
223
+ const { url } = body;
224
+ expect(response.status).toBe(201);
225
+ expect(url).toBeDefined();
226
+ expect(REGEX_SUBGRAPH.test(url)).toBe(true);
227
+ });
215
228
  test("should merge correctly", async () => {
216
- await sleep(10000);
217
- const response = await fetch(`${LOCALHOST}/v1/proof/merge`, {
229
+ await sleep(pollDuration * 1000);
230
+ const response = await fetch(`${TEST_URL}/proof/merge`, {
218
231
  method: "POST",
219
232
  headers: {
220
233
  Authorization: encryptedHeader,
@@ -223,9 +236,49 @@ describe("E2E Deployment Tests", () => {
223
236
  body: JSON.stringify({
224
237
  maciContractAddress: maciAddress,
225
238
  pollId: Number(pollId),
226
- approval,
227
- sessionKeyAddress,
228
- chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
239
+ chain: CHAIN,
240
+ }),
241
+ });
242
+ expect(response.status).toBe(201);
243
+ });
244
+ test("should generate proofs correctly", async () => {
245
+ const useWasm = isArm(); // Use WASM on ARM devices, otherwise use rapidsnark
246
+ const response = await fetch(`${TEST_URL}/proof/generate`, {
247
+ method: "POST",
248
+ headers: {
249
+ Authorization: encryptedHeader,
250
+ "Content-Type": "application/json",
251
+ },
252
+ body: JSON.stringify({
253
+ poll: Number(pollId),
254
+ maciContractAddress: maciAddress,
255
+ mode: testPollDeploymentConfig.mode,
256
+ startBlock: Number(maciCreatedAt),
257
+ blocksPerBatch: 500,
258
+ chain: CHAIN,
259
+ useWasm,
260
+ }),
261
+ });
262
+ const body = (await response.json());
263
+ expect(response.status).toBe(201);
264
+ expect(body.processProofs).toBeDefined();
265
+ expect(body.processProofs.length).toBeGreaterThan(0);
266
+ expect(body.tallyProofs).toBeDefined();
267
+ expect(body.tallyProofs.length).toBeGreaterThan(0);
268
+ expect(body.tallyData).toBeDefined();
269
+ expect(body.tallyData.results).toBeDefined();
270
+ });
271
+ test("should submit results on-chain correctly", async () => {
272
+ const response = await fetch(`${TEST_URL}/proof/submit`, {
273
+ method: "POST",
274
+ headers: {
275
+ Authorization: encryptedHeader,
276
+ "Content-Type": "application/json",
277
+ },
278
+ body: JSON.stringify({
279
+ pollId: Number(pollId),
280
+ maciContractAddress: maciAddress,
281
+ chain: CHAIN,
229
282
  }),
230
283
  });
231
284
  expect(response.status).toBe(201);