@maci-protocol/coordinator 0.0.0-ci.01622be

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 (261) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/build/hardhat.config.cjs +34 -0
  5. package/build/hardhat.config.cjs.map +1 -0
  6. package/build/hardhat.config.d.cts +27 -0
  7. package/build/hardhat.config.d.cts.map +1 -0
  8. package/build/scripts/generateKeypair.d.ts +2 -0
  9. package/build/scripts/generateKeypair.d.ts.map +1 -0
  10. package/build/scripts/generateKeypair.js +25 -0
  11. package/build/scripts/generateKeypair.js.map +1 -0
  12. package/build/scripts/generateMaciKeyPair.d.ts +2 -0
  13. package/build/scripts/generateMaciKeyPair.d.ts.map +1 -0
  14. package/build/scripts/generateMaciKeyPair.js +3 -0
  15. package/build/scripts/generateMaciKeyPair.js.map +1 -0
  16. package/build/scripts/getAuthHeader.d.ts +2 -0
  17. package/build/scripts/getAuthHeader.d.ts.map +1 -0
  18. package/build/scripts/getAuthHeader.js +31 -0
  19. package/build/scripts/getAuthHeader.js.map +1 -0
  20. package/build/tests/constants.d.ts +7 -0
  21. package/build/tests/constants.d.ts.map +1 -0
  22. package/build/tests/constants.js +9 -0
  23. package/build/tests/constants.js.map +1 -0
  24. package/build/tests/e2e.aa.test.d.ts +2 -0
  25. package/build/tests/e2e.aa.test.d.ts.map +1 -0
  26. package/build/tests/e2e.aa.test.js +106 -0
  27. package/build/tests/e2e.aa.test.js.map +1 -0
  28. package/build/tests/e2e.deploy.test.d.ts +2 -0
  29. package/build/tests/e2e.deploy.test.d.ts.map +1 -0
  30. package/build/tests/e2e.deploy.test.js +282 -0
  31. package/build/tests/e2e.deploy.test.js.map +1 -0
  32. package/build/tests/utils.d.ts +20 -0
  33. package/build/tests/utils.d.ts.map +1 -0
  34. package/build/tests/utils.js +53 -0
  35. package/build/tests/utils.js.map +1 -0
  36. package/build/ts/app.module.d.ts +3 -0
  37. package/build/ts/app.module.d.ts.map +1 -0
  38. package/build/ts/app.module.js +36 -0
  39. package/build/ts/app.module.js.map +1 -0
  40. package/build/ts/auth/AccountSignatureGuard.service.d.ts +44 -0
  41. package/build/ts/auth/AccountSignatureGuard.service.d.ts.map +1 -0
  42. package/build/ts/auth/AccountSignatureGuard.service.js +96 -0
  43. package/build/ts/auth/AccountSignatureGuard.service.js.map +1 -0
  44. package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts +2 -0
  45. package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts.map +1 -0
  46. package/build/ts/auth/__tests__/AccountSignatureGuard.test.js +113 -0
  47. package/build/ts/auth/__tests__/AccountSignatureGuard.test.js.map +1 -0
  48. package/build/ts/common/__tests__/common.test.d.ts +2 -0
  49. package/build/ts/common/__tests__/common.test.d.ts.map +1 -0
  50. package/build/ts/common/__tests__/common.test.js +75 -0
  51. package/build/ts/common/__tests__/common.test.js.map +1 -0
  52. package/build/ts/common/accountAbstraction.d.ts +38 -0
  53. package/build/ts/common/accountAbstraction.d.ts.map +1 -0
  54. package/build/ts/common/accountAbstraction.js +81 -0
  55. package/build/ts/common/accountAbstraction.js.map +1 -0
  56. package/build/ts/common/chain.d.ts +16 -0
  57. package/build/ts/common/chain.d.ts.map +1 -0
  58. package/build/ts/common/chain.js +35 -0
  59. package/build/ts/common/chain.js.map +1 -0
  60. package/build/ts/common/errors.d.ts +32 -0
  61. package/build/ts/common/errors.d.ts.map +1 -0
  62. package/build/ts/common/errors.js +33 -0
  63. package/build/ts/common/errors.js.map +1 -0
  64. package/build/ts/common/index.d.ts +6 -0
  65. package/build/ts/common/index.d.ts.map +1 -0
  66. package/build/ts/common/index.js +6 -0
  67. package/build/ts/common/index.js.map +1 -0
  68. package/build/ts/common/networks.d.ts +29 -0
  69. package/build/ts/common/networks.d.ts.map +1 -0
  70. package/build/ts/common/networks.js +70 -0
  71. package/build/ts/common/networks.js.map +1 -0
  72. package/build/ts/common/types.d.ts +8 -0
  73. package/build/ts/common/types.d.ts.map +1 -0
  74. package/build/ts/common/types.js +2 -0
  75. package/build/ts/common/types.js.map +1 -0
  76. package/build/ts/crypto/__tests__/crypto.service.test.d.ts +2 -0
  77. package/build/ts/crypto/__tests__/crypto.service.test.d.ts.map +1 -0
  78. package/build/ts/crypto/__tests__/crypto.service.test.js +26 -0
  79. package/build/ts/crypto/__tests__/crypto.service.test.js.map +1 -0
  80. package/build/ts/crypto/crypto.module.d.ts +3 -0
  81. package/build/ts/crypto/crypto.module.d.ts.map +1 -0
  82. package/build/ts/crypto/crypto.module.js +18 -0
  83. package/build/ts/crypto/crypto.module.js.map +1 -0
  84. package/build/ts/crypto/crypto.service.d.ts +31 -0
  85. package/build/ts/crypto/crypto.service.d.ts.map +1 -0
  86. package/build/ts/crypto/crypto.service.js +68 -0
  87. package/build/ts/crypto/crypto.service.js.map +1 -0
  88. package/build/ts/deployer/__tests__/deployer.controller.test.d.ts +2 -0
  89. package/build/ts/deployer/__tests__/deployer.controller.test.d.ts.map +1 -0
  90. package/build/ts/deployer/__tests__/deployer.controller.test.js +84 -0
  91. package/build/ts/deployer/__tests__/deployer.controller.test.js.map +1 -0
  92. package/build/ts/deployer/__tests__/deployer.service.test.d.ts +2 -0
  93. package/build/ts/deployer/__tests__/deployer.service.test.d.ts.map +1 -0
  94. package/build/ts/deployer/__tests__/deployer.service.test.js +166 -0
  95. package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -0
  96. package/build/ts/deployer/__tests__/utils.d.ts +65 -0
  97. package/build/ts/deployer/__tests__/utils.d.ts.map +1 -0
  98. package/build/ts/deployer/__tests__/utils.js +131 -0
  99. package/build/ts/deployer/__tests__/utils.js.map +1 -0
  100. package/build/ts/deployer/constants.d.ts +13 -0
  101. package/build/ts/deployer/constants.d.ts.map +1 -0
  102. package/build/ts/deployer/constants.js +13 -0
  103. package/build/ts/deployer/constants.js.map +1 -0
  104. package/build/ts/deployer/deployer.controller.d.ts +34 -0
  105. package/build/ts/deployer/deployer.controller.d.ts.map +1 -0
  106. package/build/ts/deployer/deployer.controller.js +89 -0
  107. package/build/ts/deployer/deployer.controller.js.map +1 -0
  108. package/build/ts/deployer/deployer.module.d.ts +3 -0
  109. package/build/ts/deployer/deployer.module.d.ts.map +1 -0
  110. package/build/ts/deployer/deployer.module.js +23 -0
  111. package/build/ts/deployer/deployer.module.js.map +1 -0
  112. package/build/ts/deployer/deployer.service.d.ts +76 -0
  113. package/build/ts/deployer/deployer.service.d.ts.map +1 -0
  114. package/build/ts/deployer/deployer.service.js +341 -0
  115. package/build/ts/deployer/deployer.service.js.map +1 -0
  116. package/build/ts/deployer/dto.d.ts +46 -0
  117. package/build/ts/deployer/dto.d.ts.map +1 -0
  118. package/build/ts/deployer/dto.js +125 -0
  119. package/build/ts/deployer/dto.js.map +1 -0
  120. package/build/ts/deployer/types.d.ts +344 -0
  121. package/build/ts/deployer/types.d.ts.map +1 -0
  122. package/build/ts/deployer/types.js +2 -0
  123. package/build/ts/deployer/types.js.map +1 -0
  124. package/build/ts/file/__tests__/file.service.test.d.ts +2 -0
  125. package/build/ts/file/__tests__/file.service.test.d.ts.map +1 -0
  126. package/build/ts/file/__tests__/file.service.test.js +77 -0
  127. package/build/ts/file/__tests__/file.service.test.js.map +1 -0
  128. package/build/ts/file/file.module.d.ts +3 -0
  129. package/build/ts/file/file.module.d.ts.map +1 -0
  130. package/build/ts/file/file.module.js +18 -0
  131. package/build/ts/file/file.module.js.map +1 -0
  132. package/build/ts/file/file.service.d.ts +63 -0
  133. package/build/ts/file/file.service.d.ts.map +1 -0
  134. package/build/ts/file/file.service.js +120 -0
  135. package/build/ts/file/file.service.js.map +1 -0
  136. package/build/ts/file/types.d.ts +36 -0
  137. package/build/ts/file/types.d.ts.map +1 -0
  138. package/build/ts/file/types.js +2 -0
  139. package/build/ts/file/types.js.map +1 -0
  140. package/build/ts/jest/setup.d.ts +8 -0
  141. package/build/ts/jest/setup.d.ts.map +1 -0
  142. package/build/ts/jest/setup.js +2 -0
  143. package/build/ts/jest/setup.js.map +1 -0
  144. package/build/ts/jest/transform.d.ts +8 -0
  145. package/build/ts/jest/transform.d.ts.map +1 -0
  146. package/build/ts/jest/transform.js +10 -0
  147. package/build/ts/jest/transform.js.map +1 -0
  148. package/build/ts/main.d.ts +2 -0
  149. package/build/ts/main.d.ts.map +1 -0
  150. package/build/ts/main.js +46 -0
  151. package/build/ts/main.js.map +1 -0
  152. package/build/ts/proof/__tests__/proof.controller.test.d.ts +2 -0
  153. package/build/ts/proof/__tests__/proof.controller.test.d.ts.map +1 -0
  154. package/build/ts/proof/__tests__/proof.controller.test.js +92 -0
  155. package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -0
  156. package/build/ts/proof/__tests__/proof.gateway.test.d.ts +2 -0
  157. package/build/ts/proof/__tests__/proof.gateway.test.d.ts.map +1 -0
  158. package/build/ts/proof/__tests__/proof.gateway.test.js +65 -0
  159. package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -0
  160. package/build/ts/proof/__tests__/proof.service.test.d.ts +2 -0
  161. package/build/ts/proof/__tests__/proof.service.test.d.ts.map +1 -0
  162. package/build/ts/proof/__tests__/proof.service.test.js +130 -0
  163. package/build/ts/proof/__tests__/proof.service.test.js.map +1 -0
  164. package/build/ts/proof/dto.d.ts +75 -0
  165. package/build/ts/proof/dto.d.ts.map +1 -0
  166. package/build/ts/proof/dto.js +277 -0
  167. package/build/ts/proof/dto.js.map +1 -0
  168. package/build/ts/proof/proof.controller.d.ts +47 -0
  169. package/build/ts/proof/proof.controller.d.ts.map +1 -0
  170. package/build/ts/proof/proof.controller.js +135 -0
  171. package/build/ts/proof/proof.controller.js.map +1 -0
  172. package/build/ts/proof/proof.gateway.d.ts +35 -0
  173. package/build/ts/proof/proof.gateway.d.ts.map +1 -0
  174. package/build/ts/proof/proof.gateway.js +93 -0
  175. package/build/ts/proof/proof.gateway.js.map +1 -0
  176. package/build/ts/proof/proof.module.d.ts +3 -0
  177. package/build/ts/proof/proof.module.d.ts.map +1 -0
  178. package/build/ts/proof/proof.module.js +24 -0
  179. package/build/ts/proof/proof.module.js.map +1 -0
  180. package/build/ts/proof/proof.service.d.ts +54 -0
  181. package/build/ts/proof/proof.service.d.ts.map +1 -0
  182. package/build/ts/proof/proof.service.js +166 -0
  183. package/build/ts/proof/proof.service.js.map +1 -0
  184. package/build/ts/proof/types.d.ts +148 -0
  185. package/build/ts/proof/types.d.ts.map +1 -0
  186. package/build/ts/proof/types.js +11 -0
  187. package/build/ts/proof/types.js.map +1 -0
  188. package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts +2 -0
  189. package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts.map +1 -0
  190. package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js +44 -0
  191. package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js.map +1 -0
  192. package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts +2 -0
  193. package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts.map +1 -0
  194. package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js +61 -0
  195. package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js.map +1 -0
  196. package/build/ts/sessionKeys/__tests__/utils.d.ts +25 -0
  197. package/build/ts/sessionKeys/__tests__/utils.d.ts.map +1 -0
  198. package/build/ts/sessionKeys/__tests__/utils.js +64 -0
  199. package/build/ts/sessionKeys/__tests__/utils.js.map +1 -0
  200. package/build/ts/sessionKeys/dto.d.ts +11 -0
  201. package/build/ts/sessionKeys/dto.d.ts.map +1 -0
  202. package/build/ts/sessionKeys/dto.js +29 -0
  203. package/build/ts/sessionKeys/dto.js.map +1 -0
  204. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts +53 -0
  205. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts.map +1 -0
  206. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js +105 -0
  207. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js.map +1 -0
  208. package/build/ts/sessionKeys/sessionKeys.controller.d.ts +26 -0
  209. package/build/ts/sessionKeys/sessionKeys.controller.d.ts.map +1 -0
  210. package/build/ts/sessionKeys/sessionKeys.controller.js +74 -0
  211. package/build/ts/sessionKeys/sessionKeys.controller.js.map +1 -0
  212. package/build/ts/sessionKeys/sessionKeys.module.d.ts +3 -0
  213. package/build/ts/sessionKeys/sessionKeys.module.d.ts.map +1 -0
  214. package/build/ts/sessionKeys/sessionKeys.module.js +23 -0
  215. package/build/ts/sessionKeys/sessionKeys.module.js.map +1 -0
  216. package/build/ts/sessionKeys/sessionKeys.service.d.ts +61 -0
  217. package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -0
  218. package/build/ts/sessionKeys/sessionKeys.service.js +122 -0
  219. package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -0
  220. package/build/ts/sessionKeys/types.d.ts +11 -0
  221. package/build/ts/sessionKeys/types.d.ts.map +1 -0
  222. package/build/ts/sessionKeys/types.js +2 -0
  223. package/build/ts/sessionKeys/types.js.map +1 -0
  224. package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts +2 -0
  225. package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts.map +1 -0
  226. package/build/ts/subgraph/__tests__/subgraph.controller.test.js +50 -0
  227. package/build/ts/subgraph/__tests__/subgraph.controller.test.js.map +1 -0
  228. package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts +2 -0
  229. package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts.map +1 -0
  230. package/build/ts/subgraph/__tests__/subgraph.gateway.test.js +83 -0
  231. package/build/ts/subgraph/__tests__/subgraph.gateway.test.js.map +1 -0
  232. package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts +2 -0
  233. package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts.map +1 -0
  234. package/build/ts/subgraph/__tests__/subgraph.service.test.js +58 -0
  235. package/build/ts/subgraph/__tests__/subgraph.service.test.js.map +1 -0
  236. package/build/ts/subgraph/dto.d.ts +27 -0
  237. package/build/ts/subgraph/dto.d.ts.map +1 -0
  238. package/build/ts/subgraph/dto.js +83 -0
  239. package/build/ts/subgraph/dto.js.map +1 -0
  240. package/build/ts/subgraph/subgraph.controller.d.ts +24 -0
  241. package/build/ts/subgraph/subgraph.controller.d.ts.map +1 -0
  242. package/build/ts/subgraph/subgraph.controller.js +66 -0
  243. package/build/ts/subgraph/subgraph.controller.js.map +1 -0
  244. package/build/ts/subgraph/subgraph.gateway.d.ts +35 -0
  245. package/build/ts/subgraph/subgraph.gateway.d.ts.map +1 -0
  246. package/build/ts/subgraph/subgraph.gateway.js +93 -0
  247. package/build/ts/subgraph/subgraph.gateway.js.map +1 -0
  248. package/build/ts/subgraph/subgraph.module.d.ts +3 -0
  249. package/build/ts/subgraph/subgraph.module.d.ts.map +1 -0
  250. package/build/ts/subgraph/subgraph.module.js +23 -0
  251. package/build/ts/subgraph/subgraph.module.js.map +1 -0
  252. package/build/ts/subgraph/subgraph.service.d.ts +20 -0
  253. package/build/ts/subgraph/subgraph.service.d.ts.map +1 -0
  254. package/build/ts/subgraph/subgraph.service.js +106 -0
  255. package/build/ts/subgraph/subgraph.service.js.map +1 -0
  256. package/build/ts/subgraph/types.d.ts +93 -0
  257. package/build/ts/subgraph/types.d.ts.map +1 -0
  258. package/build/ts/subgraph/types.js +24 -0
  259. package/build/ts/subgraph/types.js.map +1 -0
  260. package/build/tsconfig.build.tsbuildinfo +1 -0
  261. package/package.json +125 -0
@@ -0,0 +1,282 @@
1
+ import { Keypair } from "@maci-protocol/domainobjs";
2
+ import { ContractStorage, joinPoll, signup, sleep } from "@maci-protocol/sdk";
3
+ import { ValidationPipe } from "@nestjs/common";
4
+ import { Test } from "@nestjs/testing";
5
+ import dotenv from "dotenv";
6
+ import { io } from "socket.io-client";
7
+ import { zeroAddress } from "viem";
8
+ import path from "path";
9
+ import { AppModule } from "../ts/app.module";
10
+ import { ESupportedNetworks, getSigner } from "../ts/common";
11
+ import { getPublicClient } from "../ts/common/accountAbstraction";
12
+ import { coordinatorMACIKeypair, pollStartDateExtraSeconds, testMaciDeploymentConfig, testPollDeploymentConfig, } from "../ts/deployer/__tests__/utils";
13
+ import { DeployerModule } from "../ts/deployer/deployer.module";
14
+ import { FileModule } from "../ts/file/file.module";
15
+ import { ProofModule } from "../ts/proof/proof.module";
16
+ import { generateApproval, getKernelAccount } from "../ts/sessionKeys/__tests__/utils";
17
+ import { SessionKeysModule } from "../ts/sessionKeys/sessionKeys.module";
18
+ import { pollJoiningTestZkeyPath, testPollJoiningWasmPath, testPollJoiningWitnessPath, testRapidsnarkPath, zeroUint256Encoded, } from "./constants";
19
+ import { encryptWithCoordinatorRSAPublicKey, getAuthorizationHeader, rechargeGasIfNeeded } from "./utils";
20
+ dotenv.config();
21
+ jest.setTimeout(700000); // Sets timeout to 700 seconds
22
+ const TEST_URL = "http://localhost:3000/v1";
23
+ const CHAIN = ESupportedNetworks.OPTIMISM_SEPOLIA;
24
+ const REGEX_SUBGRAPH = /^https:\/\/api\.studio\.thegraph\.com\/query\/\d+\/maci-subgraph\/v0\.0\.\d+$/;
25
+ const NUM_USERS = 1;
26
+ const VOTE_OPTIONS = {
27
+ "0": 0,
28
+ "1": 0,
29
+ };
30
+ describe("E2E Deployment Tests", () => {
31
+ let signer;
32
+ let encryptedHeader;
33
+ let sessionKeyAddress;
34
+ let approval;
35
+ let app;
36
+ let socket;
37
+ const publicClient = getPublicClient(CHAIN);
38
+ let maciAddress;
39
+ let pollId;
40
+ const pollDuration = 600;
41
+ // set up coordinator address
42
+ beforeAll(async () => {
43
+ signer = getSigner(CHAIN);
44
+ encryptedHeader = await getAuthorizationHeader(signer);
45
+ process.env.COORDINATOR_ADDRESSES = await signer.getAddress();
46
+ await rechargeGasIfNeeded(process.env.COORDINATOR_ADDRESSES, "0.007", "0.007");
47
+ });
48
+ // set up NestJS app
49
+ beforeAll(async () => {
50
+ const moduleFixture = await Test.createTestingModule({
51
+ imports: [AppModule, FileModule, DeployerModule, ProofModule, SessionKeysModule],
52
+ }).compile();
53
+ app = moduleFixture.createNestApplication();
54
+ app.useGlobalPipes(new ValidationPipe({ transform: true }));
55
+ await app.init();
56
+ await app.listen(3000);
57
+ });
58
+ afterAll(async () => {
59
+ await app.close();
60
+ const storageInstance = ContractStorage.getInstance(path.join(process.cwd(), "deployed-contracts.json"));
61
+ storageInstance.cleanup(CHAIN);
62
+ });
63
+ // set up auth header in WS connection
64
+ beforeEach(async () => {
65
+ const authorization = await getAuthorizationHeader(signer);
66
+ await new Promise((resolve) => {
67
+ app.getUrl().then((url) => {
68
+ socket = io(url, {
69
+ extraHeaders: {
70
+ authorization,
71
+ },
72
+ });
73
+ socket.on("connect", () => {
74
+ resolve(true);
75
+ });
76
+ });
77
+ });
78
+ });
79
+ afterEach(() => {
80
+ socket.disconnect();
81
+ });
82
+ // run tests
83
+ test("should retrieve RSA public key", async () => {
84
+ const response = await fetch(`${TEST_URL}/proof/publicKey`, {
85
+ method: "GET",
86
+ });
87
+ const body = (await response.json());
88
+ expect(response.status).toBe(200);
89
+ expect(body.publicKey).toBeDefined();
90
+ // this RSA should be used in the encrypted auth header and the encrypted coordinator maci private key
91
+ });
92
+ test("should retrieve the session key address", async () => {
93
+ const response = await fetch(`${TEST_URL}/session-keys/generate`, {
94
+ method: "GET",
95
+ headers: {
96
+ Authorization: encryptedHeader,
97
+ },
98
+ });
99
+ const body = (await response.json());
100
+ expect(response.status).toBe(200);
101
+ expect(body.sessionKeyAddress).not.toBe(zeroAddress);
102
+ // save them for next tests
103
+ sessionKeyAddress = body.sessionKeyAddress;
104
+ approval = await generateApproval(sessionKeyAddress);
105
+ const sessionKeyAccount = await getKernelAccount(sessionKeyAddress);
106
+ await rechargeGasIfNeeded(sessionKeyAccount.address, "0.03", "0.03");
107
+ });
108
+ test("should deploy MACI correctly", async () => {
109
+ const config = testMaciDeploymentConfig;
110
+ config.VerifyingKeysRegistry.args.stateTreeDepth = config.VerifyingKeysRegistry.args.stateTreeDepth.toString();
111
+ config.VerifyingKeysRegistry.args.pollStateTreeDepth =
112
+ config.VerifyingKeysRegistry.args.pollStateTreeDepth.toString();
113
+ config.VerifyingKeysRegistry.args.tallyProcessingStateTreeDepth =
114
+ config.VerifyingKeysRegistry.args.tallyProcessingStateTreeDepth.toString();
115
+ config.VerifyingKeysRegistry.args.voteOptionTreeDepth =
116
+ config.VerifyingKeysRegistry.args.voteOptionTreeDepth.toString();
117
+ const response = await fetch(`${TEST_URL}/deploy/maci`, {
118
+ method: "POST",
119
+ headers: {
120
+ Authorization: encryptedHeader,
121
+ "Content-Type": "application/json",
122
+ },
123
+ body: JSON.stringify({
124
+ approval,
125
+ sessionKeyAddress,
126
+ chain: CHAIN,
127
+ config,
128
+ }),
129
+ });
130
+ const body = (await response.json());
131
+ expect(response.status).toBe(201);
132
+ expect(body.address).not.toBe(zeroAddress);
133
+ // save them for next tests
134
+ maciAddress = body.address;
135
+ });
136
+ test("should deploy a poll correctly", async () => {
137
+ const config = testPollDeploymentConfig;
138
+ config.voteOptions = config.voteOptions.toString();
139
+ const startDate = Math.floor(Date.now() / 1000) + pollStartDateExtraSeconds;
140
+ config.startDate = startDate;
141
+ config.endDate = startDate + pollDuration;
142
+ const response = await fetch(`${TEST_URL}/deploy/poll`, {
143
+ method: "POST",
144
+ headers: {
145
+ Authorization: encryptedHeader,
146
+ "Content-Type": "application/json",
147
+ },
148
+ body: JSON.stringify({
149
+ chain: CHAIN,
150
+ config,
151
+ }),
152
+ });
153
+ const body = (await response.json());
154
+ expect(response.status).toBe(201);
155
+ expect(body.pollId).toBeDefined();
156
+ // save them for next tests
157
+ pollId = BigInt(body.pollId);
158
+ });
159
+ test("should allow voting on a poll", async () => {
160
+ await sleep(pollStartDateExtraSeconds * 1000);
161
+ for (let i = 0; i < NUM_USERS; i += 1) {
162
+ const keypairUser = new Keypair();
163
+ const userPublicKey = keypairUser.publicKey.serialize();
164
+ const userPrivateKey = keypairUser.privateKey.serialize();
165
+ const vote = i % 2;
166
+ VOTE_OPTIONS[String(vote)] += 1;
167
+ // user signs up to MACI
168
+ // eslint-disable-next-line no-await-in-loop
169
+ await signup({
170
+ maciAddress,
171
+ maciPublicKey: userPublicKey,
172
+ sgData: zeroUint256Encoded,
173
+ signer,
174
+ });
175
+ // user joins the poll
176
+ // eslint-disable-next-line no-await-in-loop
177
+ await joinPoll({
178
+ maciAddress,
179
+ privateKey: userPrivateKey,
180
+ stateIndex: 1n,
181
+ pollId: BigInt(pollId),
182
+ pollJoiningZkey: pollJoiningTestZkeyPath,
183
+ useWasm: true,
184
+ pollWasm: testPollJoiningWasmPath,
185
+ pollWitgen: testPollJoiningWitnessPath,
186
+ rapidsnark: testRapidsnarkPath,
187
+ sgDataArg: zeroUint256Encoded,
188
+ ivcpDataArg: zeroUint256Encoded,
189
+ signer,
190
+ });
191
+ }
192
+ });
193
+ test("should deploy a subgraph correctly", async () => {
194
+ const blockNumber = await publicClient.getBlockNumber();
195
+ const response = await fetch(`${TEST_URL}/subgraph/deploy`, {
196
+ method: "POST",
197
+ headers: {
198
+ Authorization: encryptedHeader,
199
+ "Content-Type": "application/json",
200
+ },
201
+ body: JSON.stringify({
202
+ maciContractAddress: maciAddress,
203
+ startBlock: Number(blockNumber),
204
+ network: CHAIN,
205
+ name: process.env.SUBGRAPH_NAME,
206
+ tag: `v0.0.${blockNumber}`, // different versions per test using block number
207
+ }),
208
+ });
209
+ const body = (await response.json());
210
+ const { url } = body;
211
+ expect(response.status).toBe(201);
212
+ expect(body.url).toBeDefined();
213
+ expect(REGEX_SUBGRAPH.test(url)).toBe(true);
214
+ });
215
+ test("should merge correctly", async () => {
216
+ await sleep(pollDuration * 2000);
217
+ const response = await fetch(`${TEST_URL}/proof/merge`, {
218
+ method: "POST",
219
+ headers: {
220
+ Authorization: encryptedHeader,
221
+ "Content-Type": "application/json",
222
+ },
223
+ body: JSON.stringify({
224
+ maciContractAddress: maciAddress,
225
+ pollId: Number(pollId),
226
+ approval,
227
+ sessionKeyAddress,
228
+ chain: CHAIN,
229
+ }),
230
+ });
231
+ expect(response.status).toBe(201);
232
+ });
233
+ test("should generate proofs correctly", async () => {
234
+ const blockNumber = await publicClient.getBlockNumber();
235
+ const encryptedCoordinatorPrivateKey = await encryptWithCoordinatorRSAPublicKey(coordinatorMACIKeypair.privateKey.serialize());
236
+ const response = await fetch(`${TEST_URL}/proof/generate`, {
237
+ method: "POST",
238
+ headers: {
239
+ Authorization: encryptedHeader,
240
+ "Content-Type": "application/json",
241
+ },
242
+ body: JSON.stringify({
243
+ poll: Number(pollId),
244
+ maciContractAddress: maciAddress,
245
+ mode: testPollDeploymentConfig.mode,
246
+ encryptedCoordinatorPrivateKey,
247
+ startBlock: Number(blockNumber) - 100,
248
+ endBlock: Number(blockNumber) + 100,
249
+ blocksPerBatch: 20,
250
+ approval,
251
+ sessionKeyAddress,
252
+ chain: CHAIN,
253
+ }),
254
+ });
255
+ const body = (await response.json());
256
+ expect(response.status).toBe(201);
257
+ expect(body.processProofs).toBeDefined();
258
+ expect(body.processProofs.length).toBeGreaterThan(0);
259
+ expect(body.tallyProofs).toBeDefined();
260
+ expect(body.tallyProofs.length).toBeGreaterThan(0);
261
+ expect(body.tallyData).toBeDefined();
262
+ expect(body.tallyData.results).toBeDefined();
263
+ });
264
+ test("should submit results on-chain correctly", async () => {
265
+ const response = await fetch(`${TEST_URL}/proof/submit`, {
266
+ method: "POST",
267
+ headers: {
268
+ Authorization: encryptedHeader,
269
+ "Content-Type": "application/json",
270
+ },
271
+ body: JSON.stringify({
272
+ pollId: Number(pollId),
273
+ maciContractAddress: maciAddress,
274
+ approval,
275
+ sessionKeyAddress,
276
+ chain: CHAIN,
277
+ }),
278
+ });
279
+ expect(response.status).toBe(201);
280
+ });
281
+ });
282
+ //# sourceMappingURL=e2e.deploy.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e2e.deploy.test.js","sourceRoot":"","sources":["../../tests/e2e.deploy.test.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G,MAAM,KAAK,CAAC,GAAG,QAAQ,eAAe,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,eAAe;gBAC9B,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;gBACtB,mBAAmB,EAAE,WAAW;gBAChC,QAAQ;gBACR,iBAAiB;gBACjB,KAAK,EAAE,KAAK;aACQ,CAAC;SACxB,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type Signer } from "ethers";
2
+ import { Hex } from "viem";
3
+ /**
4
+ * Encrypt a message using the coordinator's public key
5
+ * @param message to encrypt
6
+ * @returns encrypted message (ciphertext)
7
+ */
8
+ export declare const encryptWithCoordinatorRSAPublicKey: (message: string) => Promise<string>;
9
+ /**
10
+ * Sign a message with a wallet and encrypt it using the coordinator's public key
11
+ * @param signer
12
+ * @returns Authorization header
13
+ */
14
+ export declare const getAuthorizationHeader: (signer: Signer) => Promise<string>;
15
+ /**
16
+ * Reloads with ETH in case the smart account is out of gas (less than 0.05)
17
+ * @param sessionKeyAddress
18
+ */
19
+ export declare const rechargeGasIfNeeded: (address: Hex, minimumValueOfEther: string, valueToSendOfEther: string) => Promise<void>;
20
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../tests/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAmC,GAAG,EAAoB,MAAM,MAAM,CAAC;AAY9E;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAIxF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAK3E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,GAAG,EACZ,qBAAqB,MAAM,EAC3B,oBAAoB,MAAM,KACzB,OAAO,CAAC,IAAI,CAgBd,CAAC"}
@@ -0,0 +1,53 @@
1
+ import dotenv from "dotenv";
2
+ import { getBytes, hashMessage } from "ethers";
3
+ import { createWalletClient, formatEther, http, parseEther } from "viem";
4
+ import { privateKeyToAccount } from "viem/accounts";
5
+ import { optimismSepolia } from "viem/chains";
6
+ import fs from "fs";
7
+ import { ESupportedNetworks } from "../ts/common";
8
+ import { getPublicClient } from "../ts/common/accountAbstraction";
9
+ import { CryptoService } from "../ts/crypto/crypto.service";
10
+ dotenv.config();
11
+ /**
12
+ * Encrypt a message using the coordinator's public key
13
+ * @param message to encrypt
14
+ * @returns encrypted message (ciphertext)
15
+ */
16
+ export const encryptWithCoordinatorRSAPublicKey = async (message) => {
17
+ const cryptoService = new CryptoService();
18
+ const publicKey = await fs.promises.readFile(process.env.COORDINATOR_PUBLIC_KEY_PATH);
19
+ return cryptoService.encrypt(publicKey, message);
20
+ };
21
+ /**
22
+ * Sign a message with a wallet and encrypt it using the coordinator's public key
23
+ * @param signer
24
+ * @returns Authorization header
25
+ */
26
+ export const getAuthorizationHeader = async (signer) => {
27
+ const signature = await signer.signMessage("message");
28
+ const digest = Buffer.from(getBytes(hashMessage("message"))).toString("hex");
29
+ const encrypted = await encryptWithCoordinatorRSAPublicKey(`${signature}:${digest}`);
30
+ return `Bearer ${encrypted}`;
31
+ };
32
+ /**
33
+ * Reloads with ETH in case the smart account is out of gas (less than 0.05)
34
+ * @param sessionKeyAddress
35
+ */
36
+ export const rechargeGasIfNeeded = async (address, minimumValueOfEther, valueToSendOfEther) => {
37
+ const publicClient = getPublicClient(ESupportedNetworks.OPTIMISM_SEPOLIA);
38
+ const balance = await publicClient.getBalance({ address });
39
+ const balanceAsEther = formatEther(balance);
40
+ if (balanceAsEther <= minimumValueOfEther) {
41
+ const testAccount = privateKeyToAccount(process.env.TEST_PRIVATE_KEY);
42
+ const walletClient = createWalletClient({
43
+ chain: optimismSepolia,
44
+ transport: http(),
45
+ });
46
+ await walletClient.sendTransaction({
47
+ account: testAccount,
48
+ to: address,
49
+ value: parseEther(valueToSendOfEther),
50
+ });
51
+ }
52
+ };
53
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../tests/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAe,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAO,IAAI,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB;;;;GAIG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,KAAK,EAAE,OAAe,EAAmB,EAAE;IAC3F,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA4B,CAAC,CAAC;IACvF,OAAO,aAAa,CAAC,OAAO,CAAC,SAAS,EA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
1
+ export declare class AppModule {
2
+ }
3
+ //# sourceMappingURL=app.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.module.d.ts","sourceRoot":"","sources":["../../ts/app.module.ts"],"names":[],"mappings":"AAUA,qBAgBa,SAAS;CAAG"}
@@ -0,0 +1,36 @@
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
+ import { Module } from "@nestjs/common";
8
+ import { ThrottlerModule } from "@nestjs/throttler";
9
+ import { CryptoModule } from "./crypto/crypto.module";
10
+ import { DeployerModule } from "./deployer/deployer.module";
11
+ import { FileModule } from "./file/file.module";
12
+ import { ProofModule } from "./proof/proof.module";
13
+ import { SessionKeysModule } from "./sessionKeys/sessionKeys.module";
14
+ import { SubgraphModule } from "./subgraph/subgraph.module";
15
+ let AppModule = class AppModule {
16
+ };
17
+ AppModule = __decorate([
18
+ Module({
19
+ imports: [
20
+ ThrottlerModule.forRoot([
21
+ {
22
+ ttl: Number(process.env.TTL),
23
+ limit: Number(process.env.LIMIT),
24
+ },
25
+ ]),
26
+ FileModule,
27
+ CryptoModule,
28
+ SubgraphModule,
29
+ ProofModule,
30
+ SessionKeysModule,
31
+ DeployerModule,
32
+ ],
33
+ })
34
+ ], AppModule);
35
+ export { AppModule };
36
+ //# sourceMappingURL=app.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../ts/app.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAkBrD,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IAhBrB,MAAM,CAAC;QACN,OAAO,EAAE;YACP,eAAe,CAAC,OAAO,CAAC;gBACtB;oBACE,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;oBAC5B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;iBACjC;aACF,CAAC;YACF,UAAU;YACV,YAAY;YACZ,cAAc;YACd,WAAW;YACX,iBAAiB;YACjB,cAAc;SACf;KACF,CAAC;GACW,SAAS,CAAG"}
@@ -0,0 +1,44 @@
1
+ import { type CanActivate, type ExecutionContext, type CustomDecorator } from "@nestjs/common";
2
+ import { Reflector } from "@nestjs/core";
3
+ import { CryptoService } from "../crypto/crypto.service";
4
+ /**
5
+ * Public metadata key
6
+ */
7
+ export declare const PUBLIC_METADATA_KEY = "isPublic";
8
+ /**
9
+ * Public decorator to by-pass auth checks
10
+ *
11
+ * @returns public decorator
12
+ */
13
+ export declare const Public: () => CustomDecorator;
14
+ /**
15
+ * AccountSignatureGuard is responsible for protecting calling controller and websocket gateway functions.
16
+ * If account address is not added to .env file, you will not be allowed to call any API methods.
17
+ * Make sure you send `Authorization: Bearer encrypt({signature}:{digest})` header where:
18
+ * 1. encrypt - RSA public encryption.
19
+ * 2. signature - eth wallet signature for any message
20
+ * 3. digest - hex representation of message digest
21
+ *
22
+ * ```
23
+ * const signature = await signer.signMessage("message");
24
+ * const digest = Buffer.from(getBytes(hashMessage("message"))).toString("hex");
25
+ * ```
26
+ * See tests for more details about authorization.
27
+ */
28
+ export declare class AccountSignatureGuard implements CanActivate {
29
+ private readonly cryptoService;
30
+ private readonly reflector;
31
+ /**
32
+ * Logger
33
+ */
34
+ private readonly logger;
35
+ constructor(cryptoService: CryptoService, reflector: Reflector);
36
+ /**
37
+ * This function should return a boolean, indicating whether the request is allowed or not based on message signature and digest.
38
+ *
39
+ * @param ctx - execution context
40
+ * @returns whether the request is allowed or not
41
+ */
42
+ canActivate(ctx: ExecutionContext): Promise<boolean>;
43
+ }
44
+ //# sourceMappingURL=AccountSignatureGuard.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountSignatureGuard.service.d.ts","sourceRoot":"","sources":["../../../ts/auth/AccountSignatureGuard.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAGhB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAO,eAAyD,CAAC;AAEpF;;;;;;;;;;;;;GAaG;AACH,qBACa,qBAAsB,YAAW,WAAW;IAOrD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAP5B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAGb,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS;IAKvC;;;;;OAKG;IACG,WAAW,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAqC3D"}
@@ -0,0 +1,96 @@
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 AccountSignatureGuard_1;
11
+ import { Logger, Injectable, SetMetadata, } from "@nestjs/common";
12
+ import { Reflector } from "@nestjs/core";
13
+ import { ethers } from "ethers";
14
+ import fs from "fs";
15
+ import path from "path";
16
+ import { CryptoService } from "../crypto/crypto.service";
17
+ /**
18
+ * Public metadata key
19
+ */
20
+ export const PUBLIC_METADATA_KEY = "isPublic";
21
+ /**
22
+ * Public decorator to by-pass auth checks
23
+ *
24
+ * @returns public decorator
25
+ */
26
+ export const Public = () => SetMetadata(PUBLIC_METADATA_KEY, true);
27
+ /**
28
+ * AccountSignatureGuard is responsible for protecting calling controller and websocket gateway functions.
29
+ * If account address is not added to .env file, you will not be allowed to call any API methods.
30
+ * Make sure you send `Authorization: Bearer encrypt({signature}:{digest})` header where:
31
+ * 1. encrypt - RSA public encryption.
32
+ * 2. signature - eth wallet signature for any message
33
+ * 3. digest - hex representation of message digest
34
+ *
35
+ * ```
36
+ * const signature = await signer.signMessage("message");
37
+ * const digest = Buffer.from(getBytes(hashMessage("message"))).toString("hex");
38
+ * ```
39
+ * See tests for more details about authorization.
40
+ */
41
+ let AccountSignatureGuard = AccountSignatureGuard_1 = class AccountSignatureGuard {
42
+ cryptoService;
43
+ reflector;
44
+ /**
45
+ * Logger
46
+ */
47
+ logger;
48
+ constructor(cryptoService, reflector) {
49
+ this.cryptoService = cryptoService;
50
+ this.reflector = reflector;
51
+ this.logger = new Logger(AccountSignatureGuard_1.name);
52
+ }
53
+ /**
54
+ * This function should return a boolean, indicating whether the request is allowed or not based on message signature and digest.
55
+ *
56
+ * @param ctx - execution context
57
+ * @returns whether the request is allowed or not
58
+ */
59
+ async canActivate(ctx) {
60
+ try {
61
+ const isPublic = this.reflector.get(PUBLIC_METADATA_KEY, ctx.getHandler());
62
+ if (isPublic) {
63
+ return true;
64
+ }
65
+ const request = ctx.switchToHttp().getRequest();
66
+ const socket = ctx.switchToWs().getClient();
67
+ const encryptedHeader = socket.handshake?.headers.authorization || request.headers?.authorization;
68
+ if (!encryptedHeader) {
69
+ this.logger.warn("No authorization header");
70
+ return false;
71
+ }
72
+ const privateKey = await fs.promises.readFile(path.resolve(process.env.COORDINATOR_PRIVATE_KEY_PATH));
73
+ const [signature, digest] = this.cryptoService
74
+ .decrypt(privateKey, encryptedHeader.replace("Bearer", "").trim())
75
+ .split(":");
76
+ if (!signature || !digest) {
77
+ this.logger.warn("No signature or digest");
78
+ return false;
79
+ }
80
+ const address = ethers.recoverAddress(Buffer.from(digest, "hex"), signature).toLowerCase();
81
+ const coordinatorAddress = process.env.COORDINATOR_ADDRESSES?.split(",").map((value) => value.toLowerCase()) ?? [];
82
+ return coordinatorAddress.includes(address);
83
+ }
84
+ catch (error) {
85
+ this.logger.error("Error", error);
86
+ return false;
87
+ }
88
+ }
89
+ };
90
+ AccountSignatureGuard = AccountSignatureGuard_1 = __decorate([
91
+ Injectable(),
92
+ __metadata("design:paramtypes", [CryptoService,
93
+ Reflector])
94
+ ], AccountSignatureGuard);
95
+ export { AccountSignatureGuard };
96
+ //# sourceMappingURL=AccountSignatureGuard.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountSignatureGuard.service.js","sourceRoot":"","sources":["../../../ts/auth/AccountSignatureGuard.service.ts"],"names":[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AC;QACf,CAAC;IACH,CAAC;CACF,CAAA;AAxDY,qBAAqB;IADjC,UAAU,EAAE;qCAQuB,aAAa;QACjB,SAAS;GAR5B,qBAAqB,CAwDjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AccountSignatureGuard.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountSignatureGuard.test.d.ts","sourceRoot":"","sources":["../../../../ts/auth/__tests__/AccountSignatureGuard.test.ts"],"names":[],"mappings":""}