@maci-protocol/sdk 0.0.0-ci.2653bc0

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 (298) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/LICENSE +22 -0
  3. package/README.md +12 -0
  4. package/build/package.json +56 -0
  5. package/build/ts/browser/index.d.ts +15 -0
  6. package/build/ts/browser/index.d.ts.map +1 -0
  7. package/build/ts/browser/index.js +43 -0
  8. package/build/ts/browser/index.js.map +1 -0
  9. package/build/ts/deploy/index.d.ts +5 -0
  10. package/build/ts/deploy/index.d.ts.map +1 -0
  11. package/build/ts/deploy/index.js +10 -0
  12. package/build/ts/deploy/index.js.map +1 -0
  13. package/build/ts/deploy/maci.d.ts +8 -0
  14. package/build/ts/deploy/maci.d.ts.map +1 -0
  15. package/build/ts/deploy/maci.js +87 -0
  16. package/build/ts/deploy/maci.js.map +1 -0
  17. package/build/ts/deploy/poll.d.ts +8 -0
  18. package/build/ts/deploy/poll.d.ts.map +1 -0
  19. package/build/ts/deploy/poll.js +107 -0
  20. package/build/ts/deploy/poll.js.map +1 -0
  21. package/build/ts/deploy/types.d.ts +204 -0
  22. package/build/ts/deploy/types.d.ts.map +1 -0
  23. package/build/ts/deploy/types.js +3 -0
  24. package/build/ts/deploy/types.js.map +1 -0
  25. package/build/ts/deploy/utils.d.ts +11 -0
  26. package/build/ts/deploy/utils.d.ts.map +1 -0
  27. package/build/ts/deploy/utils.js +22 -0
  28. package/build/ts/deploy/utils.js.map +1 -0
  29. package/build/ts/deploy/vkRegistry.d.ts +7 -0
  30. package/build/ts/deploy/vkRegistry.d.ts.map +1 -0
  31. package/build/ts/deploy/vkRegistry.js +14 -0
  32. package/build/ts/deploy/vkRegistry.js.map +1 -0
  33. package/build/ts/index.d.ts +16 -0
  34. package/build/ts/index.d.ts.map +1 -0
  35. package/build/ts/index.js +69 -0
  36. package/build/ts/index.js.map +1 -0
  37. package/build/ts/maci/index.d.ts +6 -0
  38. package/build/ts/maci/index.d.ts.map +1 -0
  39. package/build/ts/maci/index.js +17 -0
  40. package/build/ts/maci/index.js.map +1 -0
  41. package/build/ts/maci/merge.d.ts +9 -0
  42. package/build/ts/maci/merge.d.ts.map +1 -0
  43. package/build/ts/maci/merge.js +29 -0
  44. package/build/ts/maci/merge.js.map +1 -0
  45. package/build/ts/maci/policy.d.ts +41 -0
  46. package/build/ts/maci/policy.d.ts.map +1 -0
  47. package/build/ts/maci/policy.js +127 -0
  48. package/build/ts/maci/policy.js.map +1 -0
  49. package/build/ts/maci/state.d.ts +8 -0
  50. package/build/ts/maci/state.d.ts.map +1 -0
  51. package/build/ts/maci/state.js +82 -0
  52. package/build/ts/maci/state.js.map +1 -0
  53. package/build/ts/maci/types.d.ts +176 -0
  54. package/build/ts/maci/types.d.ts.map +1 -0
  55. package/build/ts/maci/types.js +18 -0
  56. package/build/ts/maci/types.js.map +1 -0
  57. package/build/ts/maciKeys/__tests__/keypair.test.d.ts +2 -0
  58. package/build/ts/maciKeys/__tests__/keypair.test.d.ts.map +1 -0
  59. package/build/ts/maciKeys/__tests__/keypair.test.js +24 -0
  60. package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -0
  61. package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts +2 -0
  62. package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts.map +1 -0
  63. package/build/ts/maciKeys/__tests__/publicKeys.test.js +22 -0
  64. package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -0
  65. package/build/ts/maciKeys/index.d.ts +4 -0
  66. package/build/ts/maciKeys/index.d.ts.map +1 -0
  67. package/build/ts/maciKeys/index.js +8 -0
  68. package/build/ts/maciKeys/index.js.map +1 -0
  69. package/build/ts/maciKeys/keypair.d.ts +9 -0
  70. package/build/ts/maciKeys/keypair.d.ts.map +1 -0
  71. package/build/ts/maciKeys/keypair.js +20 -0
  72. package/build/ts/maciKeys/keypair.js.map +1 -0
  73. package/build/ts/maciKeys/publicKeys.d.ts +8 -0
  74. package/build/ts/maciKeys/publicKeys.d.ts.map +1 -0
  75. package/build/ts/maciKeys/publicKeys.js +23 -0
  76. package/build/ts/maciKeys/publicKeys.js.map +1 -0
  77. package/build/ts/maciKeys/types.d.ts +23 -0
  78. package/build/ts/maciKeys/types.d.ts.map +1 -0
  79. package/build/ts/maciKeys/types.js +3 -0
  80. package/build/ts/maciKeys/types.js.map +1 -0
  81. package/build/ts/poll/index.d.ts +4 -0
  82. package/build/ts/poll/index.d.ts.map +1 -0
  83. package/build/ts/poll/index.js +9 -0
  84. package/build/ts/poll/index.js.map +1 -0
  85. package/build/ts/poll/poll.d.ts +14 -0
  86. package/build/ts/poll/poll.d.ts.map +1 -0
  87. package/build/ts/poll/poll.js +62 -0
  88. package/build/ts/poll/poll.js.map +1 -0
  89. package/build/ts/poll/types.d.ts +152 -0
  90. package/build/ts/poll/types.d.ts.map +1 -0
  91. package/build/ts/poll/types.js +3 -0
  92. package/build/ts/poll/types.js.map +1 -0
  93. package/build/ts/poll/utils.d.ts +9 -0
  94. package/build/ts/poll/utils.d.ts.map +1 -0
  95. package/build/ts/poll/utils.js +43 -0
  96. package/build/ts/poll/utils.js.map +1 -0
  97. package/build/ts/proof/__tests__/download.test.d.ts +2 -0
  98. package/build/ts/proof/__tests__/download.test.d.ts.map +1 -0
  99. package/build/ts/proof/__tests__/download.test.js +50 -0
  100. package/build/ts/proof/__tests__/download.test.js.map +1 -0
  101. package/build/ts/proof/constants.d.ts +17 -0
  102. package/build/ts/proof/constants.d.ts.map +1 -0
  103. package/build/ts/proof/constants.js +20 -0
  104. package/build/ts/proof/constants.js.map +1 -0
  105. package/build/ts/proof/download.d.ts +9 -0
  106. package/build/ts/proof/download.d.ts.map +1 -0
  107. package/build/ts/proof/download.js +49 -0
  108. package/build/ts/proof/download.js.map +1 -0
  109. package/build/ts/proof/generate.d.ts +8 -0
  110. package/build/ts/proof/generate.d.ts.map +1 -0
  111. package/build/ts/proof/generate.js +127 -0
  112. package/build/ts/proof/generate.js.map +1 -0
  113. package/build/ts/proof/index.d.ts +4 -0
  114. package/build/ts/proof/index.d.ts.map +1 -0
  115. package/build/ts/proof/index.js +8 -0
  116. package/build/ts/proof/index.js.map +1 -0
  117. package/build/ts/proof/prove.d.ts +8 -0
  118. package/build/ts/proof/prove.d.ts.map +1 -0
  119. package/build/ts/proof/prove.js +81 -0
  120. package/build/ts/proof/prove.js.map +1 -0
  121. package/build/ts/proof/types.d.ts +175 -0
  122. package/build/ts/proof/types.d.ts.map +1 -0
  123. package/build/ts/proof/types.js +3 -0
  124. package/build/ts/proof/types.js.map +1 -0
  125. package/build/ts/relayer/__tests__/messages.test.d.ts +2 -0
  126. package/build/ts/relayer/__tests__/messages.test.d.ts.map +1 -0
  127. package/build/ts/relayer/__tests__/messages.test.js +76 -0
  128. package/build/ts/relayer/__tests__/messages.test.js.map +1 -0
  129. package/build/ts/relayer/__tests__/utils.test.d.ts +2 -0
  130. package/build/ts/relayer/__tests__/utils.test.d.ts.map +1 -0
  131. package/build/ts/relayer/__tests__/utils.test.js +73 -0
  132. package/build/ts/relayer/__tests__/utils.test.js.map +1 -0
  133. package/build/ts/relayer/index.d.ts +3 -0
  134. package/build/ts/relayer/index.d.ts.map +1 -0
  135. package/build/ts/relayer/index.js +8 -0
  136. package/build/ts/relayer/index.js.map +1 -0
  137. package/build/ts/relayer/messages.d.ts +23 -0
  138. package/build/ts/relayer/messages.d.ts.map +1 -0
  139. package/build/ts/relayer/messages.js +66 -0
  140. package/build/ts/relayer/messages.js.map +1 -0
  141. package/build/ts/relayer/types.d.ts +168 -0
  142. package/build/ts/relayer/types.d.ts.map +1 -0
  143. package/build/ts/relayer/types.js +3 -0
  144. package/build/ts/relayer/types.js.map +1 -0
  145. package/build/ts/relayer/utils.d.ts +12 -0
  146. package/build/ts/relayer/utils.d.ts.map +1 -0
  147. package/build/ts/relayer/utils.js +37 -0
  148. package/build/ts/relayer/utils.js.map +1 -0
  149. package/build/ts/tally/commitments.d.ts +9 -0
  150. package/build/ts/tally/commitments.d.ts.map +1 -0
  151. package/build/ts/tally/commitments.js +42 -0
  152. package/build/ts/tally/commitments.js.map +1 -0
  153. package/build/ts/tally/index.d.ts +4 -0
  154. package/build/ts/tally/index.d.ts.map +1 -0
  155. package/build/ts/tally/index.js +8 -0
  156. package/build/ts/tally/index.js.map +1 -0
  157. package/build/ts/tally/types.d.ts +179 -0
  158. package/build/ts/tally/types.d.ts.map +1 -0
  159. package/build/ts/tally/types.js +3 -0
  160. package/build/ts/tally/types.js.map +1 -0
  161. package/build/ts/tally/utils.d.ts +24 -0
  162. package/build/ts/tally/utils.d.ts.map +1 -0
  163. package/build/ts/tally/utils.js +50 -0
  164. package/build/ts/tally/utils.js.map +1 -0
  165. package/build/ts/tally/verification.d.ts +7 -0
  166. package/build/ts/tally/verification.d.ts.map +1 -0
  167. package/build/ts/tally/verification.js +62 -0
  168. package/build/ts/tally/verification.js.map +1 -0
  169. package/build/ts/trees/index.d.ts +3 -0
  170. package/build/ts/trees/index.d.ts.map +1 -0
  171. package/build/ts/trees/index.js +6 -0
  172. package/build/ts/trees/index.js.map +1 -0
  173. package/build/ts/trees/stateTree.d.ts +13 -0
  174. package/build/ts/trees/stateTree.d.ts.map +1 -0
  175. package/build/ts/trees/stateTree.js +53 -0
  176. package/build/ts/trees/stateTree.js.map +1 -0
  177. package/build/ts/trees/types.d.ts +46 -0
  178. package/build/ts/trees/types.d.ts.map +1 -0
  179. package/build/ts/trees/types.js +3 -0
  180. package/build/ts/trees/types.js.map +1 -0
  181. package/build/ts/user/index.d.ts +3 -0
  182. package/build/ts/user/index.d.ts.map +1 -0
  183. package/build/ts/user/index.js +11 -0
  184. package/build/ts/user/index.js.map +1 -0
  185. package/build/ts/user/types.d.ts +424 -0
  186. package/build/ts/user/types.d.ts.map +1 -0
  187. package/build/ts/user/types.js +3 -0
  188. package/build/ts/user/types.js.map +1 -0
  189. package/build/ts/user/user.d.ts +42 -0
  190. package/build/ts/user/user.d.ts.map +1 -0
  191. package/build/ts/user/user.js +192 -0
  192. package/build/ts/user/user.js.map +1 -0
  193. package/build/ts/user/utils.d.ts +52 -0
  194. package/build/ts/user/utils.d.ts.map +1 -0
  195. package/build/ts/user/utils.js +186 -0
  196. package/build/ts/user/utils.js.map +1 -0
  197. package/build/ts/utils/cid.d.ts +23 -0
  198. package/build/ts/utils/cid.d.ts.map +1 -0
  199. package/build/ts/utils/cid.js +72 -0
  200. package/build/ts/utils/cid.js.map +1 -0
  201. package/build/ts/utils/constants.d.ts +2 -0
  202. package/build/ts/utils/constants.d.ts.map +1 -0
  203. package/build/ts/utils/constants.js +5 -0
  204. package/build/ts/utils/constants.js.map +1 -0
  205. package/build/ts/utils/contracts.d.ts +15 -0
  206. package/build/ts/utils/contracts.d.ts.map +1 -0
  207. package/build/ts/utils/contracts.js +26 -0
  208. package/build/ts/utils/contracts.js.map +1 -0
  209. package/build/ts/utils/files.d.ts +9 -0
  210. package/build/ts/utils/files.d.ts.map +1 -0
  211. package/build/ts/utils/files.js +20 -0
  212. package/build/ts/utils/files.js.map +1 -0
  213. package/build/ts/utils/formatting.d.ts +8 -0
  214. package/build/ts/utils/formatting.d.ts.map +1 -0
  215. package/build/ts/utils/formatting.js +11 -0
  216. package/build/ts/utils/formatting.js.map +1 -0
  217. package/build/ts/utils/fundWallet.d.ts +7 -0
  218. package/build/ts/utils/fundWallet.d.ts.map +1 -0
  219. package/build/ts/utils/fundWallet.js +20 -0
  220. package/build/ts/utils/fundWallet.js.map +1 -0
  221. package/build/ts/utils/index.d.ts +12 -0
  222. package/build/ts/utils/index.d.ts.map +1 -0
  223. package/build/ts/utils/index.js +28 -0
  224. package/build/ts/utils/index.js.map +1 -0
  225. package/build/ts/utils/params.d.ts +7 -0
  226. package/build/ts/utils/params.d.ts.map +1 -0
  227. package/build/ts/utils/params.js +19 -0
  228. package/build/ts/utils/params.js.map +1 -0
  229. package/build/ts/utils/proofs.d.ts +13 -0
  230. package/build/ts/utils/proofs.d.ts.map +1 -0
  231. package/build/ts/utils/proofs.js +41 -0
  232. package/build/ts/utils/proofs.js.map +1 -0
  233. package/build/ts/utils/timeTravel.d.ts +7 -0
  234. package/build/ts/utils/timeTravel.d.ts.map +1 -0
  235. package/build/ts/utils/timeTravel.js +14 -0
  236. package/build/ts/utils/timeTravel.js.map +1 -0
  237. package/build/ts/utils/trees.d.ts +13 -0
  238. package/build/ts/utils/trees.d.ts.map +1 -0
  239. package/build/ts/utils/trees.js +30 -0
  240. package/build/ts/utils/trees.js.map +1 -0
  241. package/build/ts/utils/types.d.ts +71 -0
  242. package/build/ts/utils/types.d.ts.map +1 -0
  243. package/build/ts/utils/types.js +3 -0
  244. package/build/ts/utils/types.js.map +1 -0
  245. package/build/ts/utils/utils.d.ts +16 -0
  246. package/build/ts/utils/utils.d.ts.map +1 -0
  247. package/build/ts/utils/utils.js +36 -0
  248. package/build/ts/utils/utils.js.map +1 -0
  249. package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts +10 -0
  250. package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts.map +1 -0
  251. package/build/ts/verifyingKeys/checkVerifyingKeys.js +67 -0
  252. package/build/ts/verifyingKeys/checkVerifyingKeys.js.map +1 -0
  253. package/build/ts/verifyingKeys/index.d.ts +5 -0
  254. package/build/ts/verifyingKeys/index.d.ts.map +1 -0
  255. package/build/ts/verifyingKeys/index.js +13 -0
  256. package/build/ts/verifyingKeys/index.js.map +1 -0
  257. package/build/ts/verifyingKeys/setVerifyingKeys.d.ts +7 -0
  258. package/build/ts/verifyingKeys/setVerifyingKeys.d.ts.map +1 -0
  259. package/build/ts/verifyingKeys/setVerifyingKeys.js +73 -0
  260. package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -0
  261. package/build/ts/verifyingKeys/types.d.ts +231 -0
  262. package/build/ts/verifyingKeys/types.d.ts.map +1 -0
  263. package/build/ts/verifyingKeys/types.js +3 -0
  264. package/build/ts/verifyingKeys/types.js.map +1 -0
  265. package/build/ts/verifyingKeys/utils.d.ts +29 -0
  266. package/build/ts/verifyingKeys/utils.d.ts.map +1 -0
  267. package/build/ts/verifyingKeys/utils.js +102 -0
  268. package/build/ts/verifyingKeys/utils.js.map +1 -0
  269. package/build/ts/vote/generate.d.ts +8 -0
  270. package/build/ts/vote/generate.d.ts.map +1 -0
  271. package/build/ts/vote/generate.js +46 -0
  272. package/build/ts/vote/generate.js.map +1 -0
  273. package/build/ts/vote/index.d.ts +6 -0
  274. package/build/ts/vote/index.d.ts.map +1 -0
  275. package/build/ts/vote/index.js +15 -0
  276. package/build/ts/vote/index.js.map +1 -0
  277. package/build/ts/vote/invalidate.d.ts +13 -0
  278. package/build/ts/vote/invalidate.d.ts.map +1 -0
  279. package/build/ts/vote/invalidate.js +44 -0
  280. package/build/ts/vote/invalidate.js.map +1 -0
  281. package/build/ts/vote/publish.d.ts +14 -0
  282. package/build/ts/vote/publish.d.ts.map +1 -0
  283. package/build/ts/vote/publish.js +88 -0
  284. package/build/ts/vote/publish.js.map +1 -0
  285. package/build/ts/vote/submit.d.ts +13 -0
  286. package/build/ts/vote/submit.d.ts.map +1 -0
  287. package/build/ts/vote/submit.js +36 -0
  288. package/build/ts/vote/submit.js.map +1 -0
  289. package/build/ts/vote/types.d.ts +238 -0
  290. package/build/ts/vote/types.d.ts.map +1 -0
  291. package/build/ts/vote/types.js +3 -0
  292. package/build/ts/vote/types.js.map +1 -0
  293. package/build/ts/vote/utils.d.ts +16 -0
  294. package/build/ts/vote/utils.d.ts.map +1 -0
  295. package/build/ts/vote/utils.js +26 -0
  296. package/build/ts/vote/utils.js.map +1 -0
  297. package/build/tsconfig.build.tsbuildinfo +1 -0
  298. package/package.json +57 -0
@@ -0,0 +1,23 @@
1
+ import type { IGetMessageBatchesArgs, IGetMessageBatchesData, IGetRelayedMessagesArgs, IGetRelayedMessagesData, IRelayMessagesArgs, IRelayMessagesData } from "./types";
2
+ /**
3
+ * Get relayed messages from Poll contract.
4
+ *
5
+ * @param args get relayed messages arguments
6
+ * @returns relayed messages
7
+ */
8
+ export declare const getRelayedMessages: ({ maciAddress, pollId, signer, provider, startBlock, publicKeys, messageHashes, }: IGetRelayedMessagesArgs) => Promise<IGetRelayedMessagesData>;
9
+ /**
10
+ * Get message batches from relayer service.
11
+ *
12
+ * @param args get message batches arguments
13
+ * @returns message batches
14
+ */
15
+ export declare const getMessageBatches: ({ url, limit, skip, ipfsHashes, maciContractAddress, poll, publicKeys, messageHashes, }: IGetMessageBatchesArgs) => Promise<IGetMessageBatchesData>;
16
+ /**
17
+ * Relay IPFS messages to Poll contract.
18
+ *
19
+ * @param args relay messages arguments
20
+ * @returns transaction hash
21
+ */
22
+ export declare const relayMessages: ({ maciAddress, pollId, ipfsHash, messages, signer, provider, }: IRelayMessagesArgs) => Promise<IRelayMessagesData>;
23
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../ts/relayer/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EAEvB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAMjB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAU,mFAQtC,uBAAuB,KAAG,OAAO,CAAC,uBAAuB,CAY3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAU,yFASrC,sBAAsB,KAAG,OAAO,CAAC,sBAAsB,CAoBzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAU,gEAOjC,kBAAkB,KAAG,OAAO,CAAC,kBAAkB,CAcjD,CAAC"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relayMessages = exports.getMessageBatches = exports.getRelayedMessages = void 0;
4
+ const utils_1 = require("../poll/utils");
5
+ const utils_2 = require("./utils");
6
+ /**
7
+ * Get relayed messages from Poll contract.
8
+ *
9
+ * @param args get relayed messages arguments
10
+ * @returns relayed messages
11
+ */
12
+ const getRelayedMessages = async ({ maciAddress, pollId, signer, provider, startBlock = 0, publicKeys, messageHashes, }) => {
13
+ const { poll: pollContract } = await (0, utils_1.getPollContracts)({ maciAddress, pollId, signer, provider });
14
+ const { messages } = await (0, utils_2.parseIpfsHashAddedEvents)({
15
+ pollContract,
16
+ startBlock,
17
+ publicKeys,
18
+ messageHashes,
19
+ provider,
20
+ });
21
+ return { messages };
22
+ };
23
+ exports.getRelayedMessages = getRelayedMessages;
24
+ /**
25
+ * Get message batches from relayer service.
26
+ *
27
+ * @param args get message batches arguments
28
+ * @returns message batches
29
+ */
30
+ const getMessageBatches = async ({ url, limit, skip, ipfsHashes, maciContractAddress, poll, publicKeys, messageHashes, }) => {
31
+ const messageBatches = await fetch(`${url}/v1/messageBatches/get`, {
32
+ method: "GET",
33
+ headers: {
34
+ "Content-Type": "application/json",
35
+ },
36
+ body: JSON.stringify({
37
+ limit,
38
+ skip,
39
+ ipfsHashes,
40
+ poll,
41
+ maciContractAddress,
42
+ messageHashes,
43
+ publicKeys,
44
+ }),
45
+ })
46
+ .then((res) => res.json())
47
+ .then((res) => res);
48
+ return { messageBatches };
49
+ };
50
+ exports.getMessageBatches = getMessageBatches;
51
+ /**
52
+ * Relay IPFS messages to Poll contract.
53
+ *
54
+ * @param args relay messages arguments
55
+ * @returns transaction hash
56
+ */
57
+ const relayMessages = async ({ maciAddress, pollId, ipfsHash, messages, signer, provider, }) => {
58
+ const { poll: pollContract } = await (0, utils_1.getPollContracts)({ maciAddress, pollId, signer, provider });
59
+ const messageHashes = await Promise.all(messages.map(({ data, publicKey }) => pollContract.hashMessageAndEncPubKey({ data }, { x: publicKey[0], y: publicKey[1] })));
60
+ const receipt = await pollContract.relayMessagesBatch(messageHashes, ipfsHash).then((tx) => tx.wait());
61
+ return {
62
+ hash: receipt?.hash,
63
+ };
64
+ };
65
+ exports.relayMessages = relayMessages;
66
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../ts/relayer/messages.ts"],"names":[],"mappings":";;;AAUA,yCAAiD;AAEjD,mCAAmD;AAEnD;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,WAAW,EACX,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,GAAG,CAAC,EACd,UAAU,EACV,aAAa,GACW,EAAoC,EAAE;IAC9D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,wBAAgB,EAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEjG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,gCAAwB,EAAC;QAClD,YAAY;QACZ,UAAU;QACV,UAAU;QACV,aAAa;QACb,QAAQ;KACT,CAAC,CAAC;IAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC,CAAC;AApBW,QAAA,kBAAkB,sBAoB7B;AAEF;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,GAAG,EACH,KAAK,EACL,IAAI,EACJ,UAAU,EACV,mBAAmB,EACnB,IAAI,EACJ,UAAU,EACV,aAAa,GACU,EAAmC,EAAE;IAC5D,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,wBAAwB,EAAE;QACjE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,KAAK;YACL,IAAI;YACJ,UAAU;YACV,IAAI;YACJ,mBAAmB;YACnB,aAAa;YACb,UAAU;SACX,CAAC;KACH,CAAC;SACC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACzB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAsB,CAAC,CAAC;IAEzC,OAAO,EAAE,cAAc,EAAE,CAAC;AAC5B,CAAC,CAAC;AA7BW,QAAA,iBAAiB,qBA6B5B;AAEF;;;;;GAKG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,WAAW,EACX,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,GACW,EAA+B,EAAE;IACpD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,wBAAgB,EAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEjG,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACrC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CACnC,YAAY,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CACrF,CACF,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,kBAAkB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IAEvG,OAAO;QACL,IAAI,EAAE,OAAO,EAAE,IAAI;KACpB,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,aAAa,iBAqBxB"}
@@ -0,0 +1,168 @@
1
+ import type { IIpfsMessage } from "@maci-protocol/contracts";
2
+ import type { Poll } from "@maci-protocol/contracts/typechain-types";
3
+ import type { Provider, Signer } from "ethers";
4
+ /**
5
+ * Interface that represents get relayed messages arguments
6
+ */
7
+ export interface IGetRelayedMessagesArgs {
8
+ /**
9
+ * MACI contract address
10
+ */
11
+ maciAddress: string;
12
+ /**
13
+ * Poll id
14
+ */
15
+ pollId: number;
16
+ /**
17
+ * Signer
18
+ */
19
+ signer: Signer;
20
+ /**
21
+ * Provider
22
+ */
23
+ provider: Provider;
24
+ /**
25
+ * Start block
26
+ */
27
+ startBlock?: number;
28
+ /**
29
+ * User public keys (optional)
30
+ */
31
+ publicKeys?: string[];
32
+ /**
33
+ * Message hashes (optional)
34
+ */
35
+ messageHashes?: string[];
36
+ }
37
+ /**
38
+ * Interface that represents get message batches arguments
39
+ */
40
+ export interface IGetMessageBatchesArgs {
41
+ /**
42
+ * Relayer service url
43
+ */
44
+ url: string;
45
+ /**
46
+ * Limit
47
+ */
48
+ limit: number;
49
+ /**
50
+ * Skip
51
+ */
52
+ skip: number;
53
+ /**
54
+ * Poll id
55
+ */
56
+ poll: number;
57
+ /**
58
+ * MACI contract address
59
+ */
60
+ maciContractAddress: string;
61
+ /**
62
+ * IPFS hashes of message batches (optional)
63
+ */
64
+ ipfsHashes?: string[];
65
+ /**
66
+ * User public keys (optional)
67
+ */
68
+ publicKeys?: string[];
69
+ /**
70
+ * Message hashes (optional)
71
+ */
72
+ messageHashes?: string[];
73
+ }
74
+ /**
75
+ * Interface for the arguments for IpfsHashAdded events parsing
76
+ */
77
+ export interface IParseIpfsHashAddedEventsArgs {
78
+ /**
79
+ * Poll contract
80
+ */
81
+ pollContract: Poll;
82
+ /**
83
+ * Start block
84
+ */
85
+ startBlock: number;
86
+ /**
87
+ * Provider
88
+ */
89
+ provider: Provider;
90
+ /**
91
+ * User public keys (optional)
92
+ */
93
+ publicKeys?: string[];
94
+ /**
95
+ * Message hashes (optional)
96
+ */
97
+ messageHashes?: string[];
98
+ }
99
+ /**
100
+ * Interface for the return type for getting relayed messages
101
+ */
102
+ export interface IGetRelayedMessagesData {
103
+ /**
104
+ * Uploaded IPFS messages
105
+ */
106
+ messages: IIpfsMessage[];
107
+ }
108
+ /**
109
+ * Interface for the return type for getting message batches from relayer service
110
+ */
111
+ export interface IGetMessageBatchesData {
112
+ /**
113
+ * Relayer message batches
114
+ */
115
+ messageBatches: IMessageBatch[];
116
+ }
117
+ /**
118
+ * Interface that represents message batch
119
+ */
120
+ export interface IMessageBatch {
121
+ /**
122
+ * Messages
123
+ */
124
+ messages: IIpfsMessage[];
125
+ /**
126
+ * IPFS hash
127
+ */
128
+ ipfsHash?: string;
129
+ }
130
+ /**
131
+ * Interface that represents relay messages arguments
132
+ */
133
+ export interface IRelayMessagesArgs {
134
+ /**
135
+ * Poll id
136
+ */
137
+ pollId: number;
138
+ /**
139
+ * MACI contract address
140
+ */
141
+ maciAddress: string;
142
+ /**
143
+ * IPFS hash
144
+ */
145
+ ipfsHash: string;
146
+ /**
147
+ * IPFS Messages
148
+ */
149
+ messages: IIpfsMessage[];
150
+ /**
151
+ * Signer
152
+ */
153
+ signer?: Signer;
154
+ /**
155
+ * Provider
156
+ */
157
+ provider?: Provider;
158
+ }
159
+ /**
160
+ * Interface that represents return data for relay messages
161
+ */
162
+ export interface IRelayMessagesData {
163
+ /**
164
+ * Transaction hash
165
+ */
166
+ hash?: string;
167
+ }
168
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/relayer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;I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AC;IAEf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../ts/relayer/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { type IIpfsMessage } from "@maci-protocol/contracts";
2
+ import type { IParseIpfsHashAddedEventsArgs } from "./types";
3
+ /**
4
+ * Parse the ipfs hash events from the Poll contract
5
+ *
6
+ * @param args parsing params
7
+ * @returns ipfs messages
8
+ */
9
+ export declare const parseIpfsHashAddedEvents: ({ pollContract, startBlock, provider, publicKeys, messageHashes, }: IParseIpfsHashAddedEventsArgs) => Promise<{
10
+ messages: IIpfsMessage[];
11
+ }>;
12
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/relayer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,0BAA0B,CAAC;AAG1E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAI7D;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAU,oEAM5C,6BAA6B,KAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,CAwCtE,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseIpfsHashAddedEvents = void 0;
4
+ const contracts_1 = require("@maci-protocol/contracts");
5
+ const domainobjs_1 = require("@maci-protocol/domainobjs");
6
+ const utils_1 = require("../utils");
7
+ /**
8
+ * Parse the ipfs hash events from the Poll contract
9
+ *
10
+ * @param args parsing params
11
+ * @returns ipfs messages
12
+ */
13
+ const parseIpfsHashAddedEvents = async ({ pollContract, startBlock, provider, publicKeys, messageHashes, }) => {
14
+ const ipfsService = contracts_1.IpfsService.getInstance();
15
+ const currentBlock = await provider.getBlockNumber();
16
+ const ipfsHashes = [];
17
+ for (let block = startBlock; block <= currentBlock; block += utils_1.BLOCKS_STEP) {
18
+ const toBlock = Math.min(block + utils_1.BLOCKS_STEP - 1, currentBlock);
19
+ // eslint-disable-next-line no-await-in-loop
20
+ const events = await pollContract.queryFilter(pollContract.filters.IpfsHashAdded(), block, toBlock);
21
+ // eslint-disable-next-line no-underscore-dangle
22
+ ipfsHashes.push(...events.map((event) => event.args._ipfsHash));
23
+ }
24
+ const messages = await Promise.all(ipfsHashes.map((ipfsHash) => ipfsService.read(ipfsHash))).then((data) => data.reduce((acc, items) => {
25
+ acc?.push(...(items || [])
26
+ .filter((message) => publicKeys && publicKeys.length > 0
27
+ ? publicKeys.some((publicKey) => domainobjs_1.PubKey.deserialize(publicKey).equals(new domainobjs_1.PubKey([BigInt(message.publicKey[0]), BigInt(message.publicKey[1])])))
28
+ : true)
29
+ .filter((message) => messageHashes && messageHashes.length > 0 ? messageHashes.some((hash) => message.hash === hash) : true));
30
+ return acc ?? [];
31
+ }, []));
32
+ return {
33
+ messages: messages ?? [],
34
+ };
35
+ };
36
+ exports.parseIpfsHashAddedEvents = parseIpfsHashAddedEvents;
37
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../ts/relayer/utils.ts"],"names":[],"mappings":";;;AAAA,wDAA0E;A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AAM,GAAG,CAAC;YACjC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC5B,mBAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,MAAM,CAClC,IAAI,mBAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACzE,CACF;YACH,CAAC,CAAC,IAAI,CACT;aACA,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAClB,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CACvG,CACJ,CAAC;QAEF,OAAO,GAAG,IAAI,EAAE,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CACT,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,QAAQ,IAAI,EAAE;KACzB,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,wBAAwB,4BA8CnC"}
@@ -0,0 +1,9 @@
1
+ import type { IGenerateTallyCommitmentsArgs, ITallyCommitments } from "./types";
2
+ /**
3
+ * Generate the tally commitments for this current batch of proving
4
+ * @param tallyData - The tally data
5
+ * @param voteOptionTreeDepth - The vote option tree depth
6
+ * @returns The commitments to the Tally data
7
+ */
8
+ export declare const generateTallyCommitments: ({ tallyData, voteOptionTreeDepth, }: IGenerateTallyCommitmentsArgs) => ITallyCommitments;
9
+ //# sourceMappingURL=commitments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commitments.d.ts","sourceRoot":"","sources":["../../../ts/tally/commitments.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,qCAGtC,6BAA6B,KAAG,iBAyClC,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTallyCommitments = void 0;
4
+ const crypto_1 = require("@maci-protocol/crypto");
5
+ /**
6
+ * Generate the tally commitments for this current batch of proving
7
+ * @param tallyData - The tally data
8
+ * @param voteOptionTreeDepth - The vote option tree depth
9
+ * @returns The commitments to the Tally data
10
+ */
11
+ const generateTallyCommitments = ({ tallyData, voteOptionTreeDepth, }) => {
12
+ // compute newResultsCommitment
13
+ const newResultsCommitment = (0, crypto_1.genTreeCommitment)(tallyData.results.tally.map((x) => BigInt(x)), BigInt(tallyData.results.salt), voteOptionTreeDepth);
14
+ // compute newSpentVoiceCreditsCommitment
15
+ const newSpentVoiceCreditsCommitment = (0, crypto_1.hash2)([
16
+ BigInt(tallyData.totalSpentVoiceCredits.spent),
17
+ BigInt(tallyData.totalSpentVoiceCredits.salt),
18
+ ]);
19
+ let newTallyCommitment;
20
+ let newPerVOSpentVoiceCreditsCommitment;
21
+ if (tallyData.isQuadratic) {
22
+ // compute newPerVOSpentVoiceCreditsCommitment
23
+ newPerVOSpentVoiceCreditsCommitment = (0, crypto_1.genTreeCommitment)(tallyData.perVOSpentVoiceCredits.tally.map((x) => BigInt(x)), BigInt(tallyData.perVOSpentVoiceCredits.salt), voteOptionTreeDepth);
24
+ // compute newTallyCommitment
25
+ newTallyCommitment = (0, crypto_1.hash3)([
26
+ newResultsCommitment,
27
+ newSpentVoiceCreditsCommitment,
28
+ newPerVOSpentVoiceCreditsCommitment,
29
+ ]);
30
+ }
31
+ else {
32
+ newTallyCommitment = (0, crypto_1.hashLeftRight)(newResultsCommitment, newSpentVoiceCreditsCommitment);
33
+ }
34
+ return {
35
+ newTallyCommitment,
36
+ newSpentVoiceCreditsCommitment,
37
+ newPerVOSpentVoiceCreditsCommitment,
38
+ newResultsCommitment,
39
+ };
40
+ };
41
+ exports.generateTallyCommitments = generateTallyCommitments;
42
+ //# sourceMappingURL=commitments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commitments.js","sourceRoot":"","sources":["../../../ts/tally/commitments.ts"],"names":[],"mappings":";;;AAAA,kDAAuF;AAIvF;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,CAAC,EACvC,SAAS,EACT,mBAAmB,GACW,EAAqB,EAAE;IACrD,+BAA+B;IAC/B,MAAM,oBAAoB,GAAG,IAAA,0BAAiB,EAC5C,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAC9B,mBAAmB,CACpB,CAAC;IAEF,yCAAyC;IACzC,MAAM,8BAA8B,GAAG,IAAA,cAAK,EAAC;QAC3C,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,KAAK,CAAC;QAC9C,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC;KAC9C,CAAC,CAAC;IAEH,IAAI,kBAA0B,CAAC;IAC/B,IAAI,mCAAuD,CAAC;IAE5D,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC1B,8CAA8C;QAC9C,mCAAmC,GAAG,IAAA,0BAAiB,EACrD,SAAS,CAAC,sBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAC7D,MAAM,CAAC,SAAS,CAAC,sBAAuB,CAAC,IAAI,CAAC,EAC9C,mBAAmB,CACpB,CAAC;QAEF,6BAA6B;QAC7B,kBAAkB,GAAG,IAAA,cAAK,EAAC;YACzB,oBAAoB;YACpB,8BAA8B;YAC9B,mCAAmC;SACpC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,kBAAkB,GAAG,IAAA,sBAAa,EAAC,oBAAoB,EAAE,8BAA8B,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO;QACL,kBAAkB;QAClB,8BAA8B;QAC9B,mCAAmC;QACnC,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,wBAAwB,4BA4CnC"}
@@ -0,0 +1,4 @@
1
+ export { generateTallyCommitments } from "./commitments";
2
+ export { verify } from "./verification";
3
+ export type { ITallyData, IVerifyArgs, IGenerateTallyCommitmentsArgs, ITallyCommitments, ITallyVotesInputs, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/tally/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,YAAY,EACV,UAAU,EACV,WAAW,EACX,6BAA6B,EAC7B,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verify = exports.generateTallyCommitments = void 0;
4
+ var commitments_1 = require("./commitments");
5
+ Object.defineProperty(exports, "generateTallyCommitments", { enumerable: true, get: function () { return commitments_1.generateTallyCommitments; } });
6
+ var verification_1 = require("./verification");
7
+ Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verification_1.verify; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/tally/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyD;AAAhD,uHAAA,wBAAwB,OAAA;AACjC,+CAAwC;AAA/B,sGAAA,MAAM,OAAA"}
@@ -0,0 +1,179 @@
1
+ import type { Signer } from "ethers";
2
+ /**
3
+ * Interface for the tally file data.
4
+ */
5
+ export interface ITallyData {
6
+ /**
7
+ * The MACI address.
8
+ */
9
+ maci: string;
10
+ /**
11
+ * The ID of the poll.
12
+ */
13
+ pollId: string;
14
+ /**
15
+ * The name of the network for which these proofs
16
+ * are valid for
17
+ */
18
+ network?: string;
19
+ /**
20
+ * The chain ID for which these proofs are valid for
21
+ */
22
+ chainId?: string;
23
+ /**
24
+ * Whether the poll is using quadratic voting or not.
25
+ */
26
+ isQuadratic: boolean;
27
+ /**
28
+ * The address of the Tally contract.
29
+ */
30
+ tallyAddress: string;
31
+ /**
32
+ * The new tally commitment.
33
+ */
34
+ newTallyCommitment: string;
35
+ /**
36
+ * The results of the poll.
37
+ */
38
+ results: {
39
+ /**
40
+ * The tally of the results.
41
+ */
42
+ tally: string[];
43
+ /**
44
+ * The salt of the results.
45
+ */
46
+ salt: string;
47
+ /**
48
+ * The commitment of the results.
49
+ */
50
+ commitment: string;
51
+ };
52
+ /**
53
+ * The total spent voice credits.
54
+ */
55
+ totalSpentVoiceCredits: {
56
+ /**
57
+ * The spent voice credits.
58
+ */
59
+ spent: string;
60
+ /**
61
+ * The salt of the spent voice credits.
62
+ */
63
+ salt: string;
64
+ /**
65
+ * The commitment of the spent voice credits.
66
+ */
67
+ commitment: string;
68
+ };
69
+ /**
70
+ * The per VO spent voice credits.
71
+ */
72
+ perVOSpentVoiceCredits?: {
73
+ /**
74
+ * The tally of the per VO spent voice credits.
75
+ */
76
+ tally: string[];
77
+ /**
78
+ * The salt of the per VO spent voice credits.
79
+ */
80
+ salt: string;
81
+ /**
82
+ * The commitment of the per VO spent voice credits.
83
+ */
84
+ commitment: string;
85
+ };
86
+ }
87
+ /**
88
+ * Interface for the arguments to the verifyProof command
89
+ */
90
+ export interface IVerifyArgs {
91
+ /**
92
+ * The id of the poll
93
+ */
94
+ pollId: bigint;
95
+ /**
96
+ * A signer object
97
+ */
98
+ signer: Signer;
99
+ /**
100
+ * The tally data
101
+ */
102
+ tallyData: ITallyData;
103
+ /**
104
+ * The address of the MACI contract
105
+ */
106
+ maciAddress: string;
107
+ /**
108
+ * The tally commitments
109
+ */
110
+ tallyCommitments: ITallyCommitments;
111
+ /**
112
+ * The number of vote options
113
+ */
114
+ numVoteOptions: number;
115
+ /**
116
+ * The vote option tree depth
117
+ */
118
+ voteOptionTreeDepth: number;
119
+ }
120
+ /**
121
+ * Arguments for the generateTallyCommitments function
122
+ */
123
+ export interface IGenerateTallyCommitmentsArgs {
124
+ /**
125
+ * The tally data
126
+ */
127
+ tallyData: ITallyData;
128
+ /**
129
+ * The vote option tree depth
130
+ */
131
+ voteOptionTreeDepth: number;
132
+ }
133
+ /**
134
+ * Interface for the tally commitments
135
+ */
136
+ export interface ITallyCommitments {
137
+ /**
138
+ * The new tally commitment
139
+ */
140
+ newTallyCommitment: bigint;
141
+ /**
142
+ * The new spent voice credits commitment
143
+ */
144
+ newSpentVoiceCreditsCommitment: bigint;
145
+ /**
146
+ * The new per vote option spent voice credits commitment
147
+ */
148
+ newPerVOSpentVoiceCreditsCommitment?: bigint;
149
+ /**
150
+ * The commitment to the results tree root
151
+ */
152
+ newResultsCommitment: bigint;
153
+ }
154
+ /**
155
+ * Inputs for circuit TallyVotes
156
+ */
157
+ export interface ITallyVotesInputs {
158
+ stateRoot: bigint;
159
+ ballotRoot: bigint;
160
+ sbSalt: bigint;
161
+ index: bigint;
162
+ numSignUps: bigint;
163
+ sbCommitment: bigint;
164
+ currentTallyCommitment: bigint;
165
+ newTallyCommitment: bigint;
166
+ ballots: bigint[];
167
+ ballotPathElements: bigint[];
168
+ votes: bigint[][];
169
+ currentResults: bigint[];
170
+ currentResultsRootSalt: bigint;
171
+ currentSpentVoiceCreditSubtotal: bigint;
172
+ currentSpentVoiceCreditSubtotalSalt: bigint;
173
+ currentPerVOSpentVoiceCredits: bigint[];
174
+ currentPerVOSpentVoiceCreditsRootSalt: bigint;
175
+ newResultsRootSalt: bigint;
176
+ newPerVOSpentVoiceCreditsRootSalt: bigint;
177
+ newSpentVoiceCreditSubtotalSalt: bigint;
178
+ }
179
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/tally/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,OAAO,EAAE;QACP;;WAEG;QACH,KAAK,EAAE,MAAM,EAAE,CAAC;QAEhB;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QAEb;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,sBAAsB,EAAE;QACtB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QAEd;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QAEb;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,sBAAsB,CAAC,EAAE;QACvB;;WAEG;QACH,KAAK,EAAE,MAAM,EAAE,CAAC;QAEhB;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QAEb;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC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C,+BAA+B,EAAE,MAAM,CAAC;CACzC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../ts/tally/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import type { ITallyData } from "./types";
2
+ import type { Tally } from "@maci-protocol/contracts";
3
+ /**
4
+ * Loop through each per vote option spent voice credits and verify it on-chain
5
+ *
6
+ * @param tallyContract The tally contract
7
+ * @param tallyData The tally.json file data
8
+ * @param voteOptionTreeDepth The vote option tree depth
9
+ * @param newSpentVoiceCreditsCommitment The total spent voice credits commitment
10
+ * @param newResultsCommitment The tally result commitment
11
+ * @returns list of the indexes of the tally result that failed on-chain verification
12
+ */
13
+ export declare const verifyPerVOSpentVoiceCredits: (tallyContract: Tally, tallyData: ITallyData, voteOptionTreeDepth: number, newSpentVoiceCreditsCommitment: bigint, newResultsCommitment: bigint) => Promise<number[]>;
14
+ /**
15
+ * Loop through each tally result and verify it on-chain
16
+ * @param tallyContract The tally contract
17
+ * @param tallyData The tally.json file data
18
+ * @param voteOptionTreeDepth The vote option tree depth
19
+ * @param newSpentVoiceCreditsCommitment The total spent voice credits commitment
20
+ * @param newPerVOSpentVoiceCreditsCommitment The per vote option voice credits commitment
21
+ * @returns list of the indexes of the tally result that failed on-chain verification
22
+ */
23
+ export declare const verifyTallyResults: (tallyContract: Tally, tallyData: ITallyData, voteOptionTreeDepth: number, newSpentVoiceCreditsCommitment: bigint, newPerVOSpentVoiceCreditsCommitment?: bigint) => Promise<number[]>;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../ts/tally/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GACvC,eAAe,KAAK,EACpB,WAAW,UAAU,EACrB,qBAAqB,MAAM,EAC3B,gCAAgC,MAAM,EACtC,sBAAsB,MAAM,KAC3B,OAAO,CAAC,MAAM,EAAE,CA2BlB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC7B,eAAe,KAAK,EACpB,WAAW,UAAU,EACrB,qBAAqB,MAAM,EAC3B,gCAAgC,MAAM,EACtC,sCAAsC,MAAM,KAC3C,OAAO,CAAC,MAAM,EAAE,CA2BlB,CAAC"}