@maci-protocol/sdk 0.0.0-ci.185b643

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 (310) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/LICENSE +22 -0
  3. package/README.md +12 -0
  4. package/build/package.json +57 -0
  5. package/build/ts/browser/index.d.ts +13 -0
  6. package/build/ts/browser/index.d.ts.map +1 -0
  7. package/build/ts/browser/index.js +34 -0
  8. package/build/ts/browser/index.js.map +1 -0
  9. package/build/ts/browser/joinPoll.d.ts +8 -0
  10. package/build/ts/browser/joinPoll.d.ts.map +1 -0
  11. package/build/ts/browser/joinPoll.js +84 -0
  12. package/build/ts/browser/joinPoll.js.map +1 -0
  13. package/build/ts/browser/utils.d.ts +18 -0
  14. package/build/ts/browser/utils.d.ts.map +1 -0
  15. package/build/ts/browser/utils.js +37 -0
  16. package/build/ts/browser/utils.js.map +1 -0
  17. package/build/ts/deploy/index.d.ts +6 -0
  18. package/build/ts/deploy/index.d.ts.map +1 -0
  19. package/build/ts/deploy/index.js +12 -0
  20. package/build/ts/deploy/index.js.map +1 -0
  21. package/build/ts/deploy/maci.d.ts +8 -0
  22. package/build/ts/deploy/maci.d.ts.map +1 -0
  23. package/build/ts/deploy/maci.js +87 -0
  24. package/build/ts/deploy/maci.js.map +1 -0
  25. package/build/ts/deploy/poll.d.ts +8 -0
  26. package/build/ts/deploy/poll.d.ts.map +1 -0
  27. package/build/ts/deploy/poll.js +114 -0
  28. package/build/ts/deploy/poll.js.map +1 -0
  29. package/build/ts/deploy/types.d.ts +216 -0
  30. package/build/ts/deploy/types.d.ts.map +1 -0
  31. package/build/ts/deploy/types.js +3 -0
  32. package/build/ts/deploy/types.js.map +1 -0
  33. package/build/ts/deploy/utils.d.ts +11 -0
  34. package/build/ts/deploy/utils.d.ts.map +1 -0
  35. package/build/ts/deploy/utils.js +22 -0
  36. package/build/ts/deploy/utils.js.map +1 -0
  37. package/build/ts/deploy/vkRegistry.d.ts +7 -0
  38. package/build/ts/deploy/vkRegistry.d.ts.map +1 -0
  39. package/build/ts/deploy/vkRegistry.js +14 -0
  40. package/build/ts/deploy/vkRegistry.js.map +1 -0
  41. package/build/ts/index.d.ts +16 -0
  42. package/build/ts/index.d.ts.map +1 -0
  43. package/build/ts/index.js +82 -0
  44. package/build/ts/index.js.map +1 -0
  45. package/build/ts/maci/index.d.ts +6 -0
  46. package/build/ts/maci/index.d.ts.map +1 -0
  47. package/build/ts/maci/index.js +17 -0
  48. package/build/ts/maci/index.js.map +1 -0
  49. package/build/ts/maci/merge.d.ts +9 -0
  50. package/build/ts/maci/merge.d.ts.map +1 -0
  51. package/build/ts/maci/merge.js +29 -0
  52. package/build/ts/maci/merge.js.map +1 -0
  53. package/build/ts/maci/policy.d.ts +53 -0
  54. package/build/ts/maci/policy.d.ts.map +1 -0
  55. package/build/ts/maci/policy.js +166 -0
  56. package/build/ts/maci/policy.js.map +1 -0
  57. package/build/ts/maci/state.d.ts +8 -0
  58. package/build/ts/maci/state.d.ts.map +1 -0
  59. package/build/ts/maci/state.js +82 -0
  60. package/build/ts/maci/state.js.map +1 -0
  61. package/build/ts/maci/types.d.ts +208 -0
  62. package/build/ts/maci/types.d.ts.map +1 -0
  63. package/build/ts/maci/types.js +20 -0
  64. package/build/ts/maci/types.js.map +1 -0
  65. package/build/ts/maciKeys/__tests__/keypair.test.d.ts +2 -0
  66. package/build/ts/maciKeys/__tests__/keypair.test.d.ts.map +1 -0
  67. package/build/ts/maciKeys/__tests__/keypair.test.js +24 -0
  68. package/build/ts/maciKeys/__tests__/keypair.test.js.map +1 -0
  69. package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts +2 -0
  70. package/build/ts/maciKeys/__tests__/publicKeys.test.d.ts.map +1 -0
  71. package/build/ts/maciKeys/__tests__/publicKeys.test.js +22 -0
  72. package/build/ts/maciKeys/__tests__/publicKeys.test.js.map +1 -0
  73. package/build/ts/maciKeys/index.d.ts +4 -0
  74. package/build/ts/maciKeys/index.d.ts.map +1 -0
  75. package/build/ts/maciKeys/index.js +8 -0
  76. package/build/ts/maciKeys/index.js.map +1 -0
  77. package/build/ts/maciKeys/keypair.d.ts +9 -0
  78. package/build/ts/maciKeys/keypair.d.ts.map +1 -0
  79. package/build/ts/maciKeys/keypair.js +20 -0
  80. package/build/ts/maciKeys/keypair.js.map +1 -0
  81. package/build/ts/maciKeys/publicKeys.d.ts +8 -0
  82. package/build/ts/maciKeys/publicKeys.d.ts.map +1 -0
  83. package/build/ts/maciKeys/publicKeys.js +23 -0
  84. package/build/ts/maciKeys/publicKeys.js.map +1 -0
  85. package/build/ts/maciKeys/types.d.ts +23 -0
  86. package/build/ts/maciKeys/types.d.ts.map +1 -0
  87. package/build/ts/maciKeys/types.js +3 -0
  88. package/build/ts/maciKeys/types.js.map +1 -0
  89. package/build/ts/poll/index.d.ts +4 -0
  90. package/build/ts/poll/index.d.ts.map +1 -0
  91. package/build/ts/poll/index.js +9 -0
  92. package/build/ts/poll/index.js.map +1 -0
  93. package/build/ts/poll/poll.d.ts +14 -0
  94. package/build/ts/poll/poll.d.ts.map +1 -0
  95. package/build/ts/poll/poll.js +62 -0
  96. package/build/ts/poll/poll.js.map +1 -0
  97. package/build/ts/poll/types.d.ts +151 -0
  98. package/build/ts/poll/types.d.ts.map +1 -0
  99. package/build/ts/poll/types.js +3 -0
  100. package/build/ts/poll/types.js.map +1 -0
  101. package/build/ts/poll/utils.d.ts +9 -0
  102. package/build/ts/poll/utils.d.ts.map +1 -0
  103. package/build/ts/poll/utils.js +43 -0
  104. package/build/ts/poll/utils.js.map +1 -0
  105. package/build/ts/proof/__tests__/download.test.d.ts +2 -0
  106. package/build/ts/proof/__tests__/download.test.d.ts.map +1 -0
  107. package/build/ts/proof/__tests__/download.test.js +50 -0
  108. package/build/ts/proof/__tests__/download.test.js.map +1 -0
  109. package/build/ts/proof/constants.d.ts +17 -0
  110. package/build/ts/proof/constants.d.ts.map +1 -0
  111. package/build/ts/proof/constants.js +20 -0
  112. package/build/ts/proof/constants.js.map +1 -0
  113. package/build/ts/proof/download.d.ts +9 -0
  114. package/build/ts/proof/download.d.ts.map +1 -0
  115. package/build/ts/proof/download.js +49 -0
  116. package/build/ts/proof/download.js.map +1 -0
  117. package/build/ts/proof/generate.d.ts +8 -0
  118. package/build/ts/proof/generate.d.ts.map +1 -0
  119. package/build/ts/proof/generate.js +127 -0
  120. package/build/ts/proof/generate.js.map +1 -0
  121. package/build/ts/proof/index.d.ts +4 -0
  122. package/build/ts/proof/index.d.ts.map +1 -0
  123. package/build/ts/proof/index.js +8 -0
  124. package/build/ts/proof/index.js.map +1 -0
  125. package/build/ts/proof/prove.d.ts +8 -0
  126. package/build/ts/proof/prove.d.ts.map +1 -0
  127. package/build/ts/proof/prove.js +81 -0
  128. package/build/ts/proof/prove.js.map +1 -0
  129. package/build/ts/proof/types.d.ts +175 -0
  130. package/build/ts/proof/types.d.ts.map +1 -0
  131. package/build/ts/proof/types.js +3 -0
  132. package/build/ts/proof/types.js.map +1 -0
  133. package/build/ts/relayer/__tests__/messages.test.d.ts +2 -0
  134. package/build/ts/relayer/__tests__/messages.test.d.ts.map +1 -0
  135. package/build/ts/relayer/__tests__/messages.test.js +76 -0
  136. package/build/ts/relayer/__tests__/messages.test.js.map +1 -0
  137. package/build/ts/relayer/__tests__/utils.test.d.ts +2 -0
  138. package/build/ts/relayer/__tests__/utils.test.d.ts.map +1 -0
  139. package/build/ts/relayer/__tests__/utils.test.js +73 -0
  140. package/build/ts/relayer/__tests__/utils.test.js.map +1 -0
  141. package/build/ts/relayer/index.d.ts +3 -0
  142. package/build/ts/relayer/index.d.ts.map +1 -0
  143. package/build/ts/relayer/index.js +8 -0
  144. package/build/ts/relayer/index.js.map +1 -0
  145. package/build/ts/relayer/messages.d.ts +23 -0
  146. package/build/ts/relayer/messages.d.ts.map +1 -0
  147. package/build/ts/relayer/messages.js +66 -0
  148. package/build/ts/relayer/messages.js.map +1 -0
  149. package/build/ts/relayer/types.d.ts +168 -0
  150. package/build/ts/relayer/types.d.ts.map +1 -0
  151. package/build/ts/relayer/types.js +3 -0
  152. package/build/ts/relayer/types.js.map +1 -0
  153. package/build/ts/relayer/utils.d.ts +12 -0
  154. package/build/ts/relayer/utils.d.ts.map +1 -0
  155. package/build/ts/relayer/utils.js +37 -0
  156. package/build/ts/relayer/utils.js.map +1 -0
  157. package/build/ts/tally/commitments.d.ts +9 -0
  158. package/build/ts/tally/commitments.d.ts.map +1 -0
  159. package/build/ts/tally/commitments.js +42 -0
  160. package/build/ts/tally/commitments.js.map +1 -0
  161. package/build/ts/tally/index.d.ts +4 -0
  162. package/build/ts/tally/index.d.ts.map +1 -0
  163. package/build/ts/tally/index.js +8 -0
  164. package/build/ts/tally/index.js.map +1 -0
  165. package/build/ts/tally/types.d.ts +179 -0
  166. package/build/ts/tally/types.d.ts.map +1 -0
  167. package/build/ts/tally/types.js +3 -0
  168. package/build/ts/tally/types.js.map +1 -0
  169. package/build/ts/tally/utils.d.ts +24 -0
  170. package/build/ts/tally/utils.d.ts.map +1 -0
  171. package/build/ts/tally/utils.js +50 -0
  172. package/build/ts/tally/utils.js.map +1 -0
  173. package/build/ts/tally/verification.d.ts +7 -0
  174. package/build/ts/tally/verification.d.ts.map +1 -0
  175. package/build/ts/tally/verification.js +62 -0
  176. package/build/ts/tally/verification.js.map +1 -0
  177. package/build/ts/trees/index.d.ts +3 -0
  178. package/build/ts/trees/index.d.ts.map +1 -0
  179. package/build/ts/trees/index.js +6 -0
  180. package/build/ts/trees/index.js.map +1 -0
  181. package/build/ts/trees/stateTree.d.ts +13 -0
  182. package/build/ts/trees/stateTree.d.ts.map +1 -0
  183. package/build/ts/trees/stateTree.js +56 -0
  184. package/build/ts/trees/stateTree.js.map +1 -0
  185. package/build/ts/trees/types.d.ts +46 -0
  186. package/build/ts/trees/types.d.ts.map +1 -0
  187. package/build/ts/trees/types.js +3 -0
  188. package/build/ts/trees/types.js.map +1 -0
  189. package/build/ts/user/index.d.ts +5 -0
  190. package/build/ts/user/index.d.ts.map +1 -0
  191. package/build/ts/user/index.js +13 -0
  192. package/build/ts/user/index.js.map +1 -0
  193. package/build/ts/user/joinPoll.d.ts +8 -0
  194. package/build/ts/user/joinPoll.d.ts.map +1 -0
  195. package/build/ts/user/joinPoll.js +84 -0
  196. package/build/ts/user/joinPoll.js.map +1 -0
  197. package/build/ts/user/signup.d.ts +20 -0
  198. package/build/ts/user/signup.d.ts.map +1 -0
  199. package/build/ts/user/signup.js +79 -0
  200. package/build/ts/user/signup.js.map +1 -0
  201. package/build/ts/user/types.d.ts +416 -0
  202. package/build/ts/user/types.d.ts.map +1 -0
  203. package/build/ts/user/types.js +3 -0
  204. package/build/ts/user/types.js.map +1 -0
  205. package/build/ts/user/utils.d.ts +68 -0
  206. package/build/ts/user/utils.d.ts.map +1 -0
  207. package/build/ts/user/utils.js +224 -0
  208. package/build/ts/user/utils.js.map +1 -0
  209. package/build/ts/utils/cid.d.ts +23 -0
  210. package/build/ts/utils/cid.d.ts.map +1 -0
  211. package/build/ts/utils/cid.js +72 -0
  212. package/build/ts/utils/cid.js.map +1 -0
  213. package/build/ts/utils/constants.d.ts +2 -0
  214. package/build/ts/utils/constants.d.ts.map +1 -0
  215. package/build/ts/utils/constants.js +5 -0
  216. package/build/ts/utils/constants.js.map +1 -0
  217. package/build/ts/utils/contracts.d.ts +15 -0
  218. package/build/ts/utils/contracts.d.ts.map +1 -0
  219. package/build/ts/utils/contracts.js +26 -0
  220. package/build/ts/utils/contracts.js.map +1 -0
  221. package/build/ts/utils/files.d.ts +9 -0
  222. package/build/ts/utils/files.d.ts.map +1 -0
  223. package/build/ts/utils/files.js +20 -0
  224. package/build/ts/utils/files.js.map +1 -0
  225. package/build/ts/utils/formatting.d.ts +8 -0
  226. package/build/ts/utils/formatting.d.ts.map +1 -0
  227. package/build/ts/utils/formatting.js +11 -0
  228. package/build/ts/utils/formatting.js.map +1 -0
  229. package/build/ts/utils/fundWallet.d.ts +7 -0
  230. package/build/ts/utils/fundWallet.d.ts.map +1 -0
  231. package/build/ts/utils/fundWallet.js +20 -0
  232. package/build/ts/utils/fundWallet.js.map +1 -0
  233. package/build/ts/utils/index.d.ts +12 -0
  234. package/build/ts/utils/index.d.ts.map +1 -0
  235. package/build/ts/utils/index.js +28 -0
  236. package/build/ts/utils/index.js.map +1 -0
  237. package/build/ts/utils/params.d.ts +7 -0
  238. package/build/ts/utils/params.d.ts.map +1 -0
  239. package/build/ts/utils/params.js +19 -0
  240. package/build/ts/utils/params.js.map +1 -0
  241. package/build/ts/utils/proofs.d.ts +13 -0
  242. package/build/ts/utils/proofs.d.ts.map +1 -0
  243. package/build/ts/utils/proofs.js +41 -0
  244. package/build/ts/utils/proofs.js.map +1 -0
  245. package/build/ts/utils/timeTravel.d.ts +7 -0
  246. package/build/ts/utils/timeTravel.d.ts.map +1 -0
  247. package/build/ts/utils/timeTravel.js +14 -0
  248. package/build/ts/utils/timeTravel.js.map +1 -0
  249. package/build/ts/utils/trees.d.ts +13 -0
  250. package/build/ts/utils/trees.d.ts.map +1 -0
  251. package/build/ts/utils/trees.js +30 -0
  252. package/build/ts/utils/trees.js.map +1 -0
  253. package/build/ts/utils/types.d.ts +71 -0
  254. package/build/ts/utils/types.d.ts.map +1 -0
  255. package/build/ts/utils/types.js +3 -0
  256. package/build/ts/utils/types.js.map +1 -0
  257. package/build/ts/utils/utils.d.ts +24 -0
  258. package/build/ts/utils/utils.d.ts.map +1 -0
  259. package/build/ts/utils/utils.js +49 -0
  260. package/build/ts/utils/utils.js.map +1 -0
  261. package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts +10 -0
  262. package/build/ts/verifyingKeys/checkVerifyingKeys.d.ts.map +1 -0
  263. package/build/ts/verifyingKeys/checkVerifyingKeys.js +67 -0
  264. package/build/ts/verifyingKeys/checkVerifyingKeys.js.map +1 -0
  265. package/build/ts/verifyingKeys/index.d.ts +5 -0
  266. package/build/ts/verifyingKeys/index.d.ts.map +1 -0
  267. package/build/ts/verifyingKeys/index.js +13 -0
  268. package/build/ts/verifyingKeys/index.js.map +1 -0
  269. package/build/ts/verifyingKeys/setVerifyingKeys.d.ts +7 -0
  270. package/build/ts/verifyingKeys/setVerifyingKeys.d.ts.map +1 -0
  271. package/build/ts/verifyingKeys/setVerifyingKeys.js +85 -0
  272. package/build/ts/verifyingKeys/setVerifyingKeys.js.map +1 -0
  273. package/build/ts/verifyingKeys/types.d.ts +235 -0
  274. package/build/ts/verifyingKeys/types.d.ts.map +1 -0
  275. package/build/ts/verifyingKeys/types.js +3 -0
  276. package/build/ts/verifyingKeys/types.js.map +1 -0
  277. package/build/ts/verifyingKeys/utils.d.ts +29 -0
  278. package/build/ts/verifyingKeys/utils.d.ts.map +1 -0
  279. package/build/ts/verifyingKeys/utils.js +103 -0
  280. package/build/ts/verifyingKeys/utils.js.map +1 -0
  281. package/build/ts/vote/generate.d.ts +8 -0
  282. package/build/ts/vote/generate.d.ts.map +1 -0
  283. package/build/ts/vote/generate.js +46 -0
  284. package/build/ts/vote/generate.js.map +1 -0
  285. package/build/ts/vote/index.d.ts +6 -0
  286. package/build/ts/vote/index.d.ts.map +1 -0
  287. package/build/ts/vote/index.js +15 -0
  288. package/build/ts/vote/index.js.map +1 -0
  289. package/build/ts/vote/invalidate.d.ts +13 -0
  290. package/build/ts/vote/invalidate.d.ts.map +1 -0
  291. package/build/ts/vote/invalidate.js +44 -0
  292. package/build/ts/vote/invalidate.js.map +1 -0
  293. package/build/ts/vote/publish.d.ts +14 -0
  294. package/build/ts/vote/publish.d.ts.map +1 -0
  295. package/build/ts/vote/publish.js +88 -0
  296. package/build/ts/vote/publish.js.map +1 -0
  297. package/build/ts/vote/submit.d.ts +13 -0
  298. package/build/ts/vote/submit.d.ts.map +1 -0
  299. package/build/ts/vote/submit.js +36 -0
  300. package/build/ts/vote/submit.js.map +1 -0
  301. package/build/ts/vote/types.d.ts +238 -0
  302. package/build/ts/vote/types.d.ts.map +1 -0
  303. package/build/ts/vote/types.js +3 -0
  304. package/build/ts/vote/types.js.map +1 -0
  305. package/build/ts/vote/utils.d.ts +16 -0
  306. package/build/ts/vote/utils.d.ts.map +1 -0
  307. package/build/ts/vote/utils.js +26 -0
  308. package/build/ts/vote/utils.js.map +1 -0
  309. package/build/tsconfig.build.tsbuildinfo +1 -0
  310. package/package.json +58 -0
@@ -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,M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;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,+BAA+B,EAAE,MAAM,CAAC;IACxC,mCAAmC,EAAE,MAAM,CAAC;IAC5C,6BAA6B,EAAE,MAAM,EAAE,CAAC;IACxC,qCAAqC,EAAE,MAAM,CAAC;IAC9C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iCAAiC,EAAE,MAAM,CAAC;IAC1C,+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"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyTallyResults = exports.verifyPerVOSpentVoiceCredits = void 0;
4
+ const crypto_1 = require("@maci-protocol/crypto");
5
+ /**
6
+ * Loop through each per vote option spent voice credits and verify it on-chain
7
+ *
8
+ * @param tallyContract The tally contract
9
+ * @param tallyData The tally.json file data
10
+ * @param voteOptionTreeDepth The vote option tree depth
11
+ * @param newSpentVoiceCreditsCommitment The total spent voice credits commitment
12
+ * @param newResultsCommitment The tally result commitment
13
+ * @returns list of the indexes of the tally result that failed on-chain verification
14
+ */
15
+ const verifyPerVOSpentVoiceCredits = async (tallyContract, tallyData, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newResultsCommitment) => {
16
+ const failedIndices = [];
17
+ for (let i = 0; i < tallyData.perVOSpentVoiceCredits.tally.length; i += 1) {
18
+ const proof = (0, crypto_1.genTreeProof)(i, tallyData.perVOSpentVoiceCredits.tally.map((x) => BigInt(x)), voteOptionTreeDepth);
19
+ // eslint-disable-next-line no-await-in-loop
20
+ const isValid = await tallyContract.verifyPerVOSpentVoiceCredits(i, tallyData.perVOSpentVoiceCredits.tally[i], proof, tallyData.perVOSpentVoiceCredits.salt, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newResultsCommitment);
21
+ if (!isValid) {
22
+ failedIndices.push(i);
23
+ }
24
+ }
25
+ return failedIndices;
26
+ };
27
+ exports.verifyPerVOSpentVoiceCredits = verifyPerVOSpentVoiceCredits;
28
+ /**
29
+ * Loop through each tally result and verify it on-chain
30
+ * @param tallyContract The tally contract
31
+ * @param tallyData The tally.json file data
32
+ * @param voteOptionTreeDepth The vote option tree depth
33
+ * @param newSpentVoiceCreditsCommitment The total spent voice credits commitment
34
+ * @param newPerVOSpentVoiceCreditsCommitment The per vote option voice credits commitment
35
+ * @returns list of the indexes of the tally result that failed on-chain verification
36
+ */
37
+ const verifyTallyResults = async (tallyContract, tallyData, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newPerVOSpentVoiceCreditsCommitment) => {
38
+ const failedIndices = [];
39
+ for (let i = 0; i < tallyData.results.tally.length; i += 1) {
40
+ const proof = (0, crypto_1.genTreeProof)(i, tallyData.results.tally.map((x) => BigInt(x)), voteOptionTreeDepth);
41
+ // eslint-disable-next-line no-await-in-loop
42
+ const isValid = await tallyContract.verifyTallyResult(i, tallyData.results.tally[i], proof, tallyData.results.salt, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newPerVOSpentVoiceCreditsCommitment ?? 0n);
43
+ if (!isValid) {
44
+ failedIndices.push(i);
45
+ }
46
+ }
47
+ return failedIndices;
48
+ };
49
+ exports.verifyTallyResults = verifyTallyResults;
50
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../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M,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3D,MAAM,KAAK,GAAG,IAAA,qBAAY,EACxB,CAAC,EACD,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAC7C,mBAAmB,CACpB,CAAC;QAEF,4CAA4C;QAC5C,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,iBAAiB,CACnD,CAAC,EACD,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAC1B,KAAK,EACL,SAAS,CAAC,OAAO,CAAC,IAAI,EACtB,mBAAmB,EACnB,8BAA8B,EAC9B,mCAAmC,IAAI,EAAE,CAC1C,CAAC;QAEF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAjCW,QAAA,kBAAkB,sBAiC7B"}
@@ -0,0 +1,7 @@
1
+ import type { IVerifyArgs } from "./types";
2
+ /**
3
+ * Verify the results of a poll on-chain
4
+ * @param VerifyArgs - The arguments for the verify command
5
+ */
6
+ export declare const verify: ({ pollId, tallyData, signer, tallyCommitments, numVoteOptions, voteOptionTreeDepth, }: IVerifyArgs) => Promise<boolean>;
7
+ //# sourceMappingURL=verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../../ts/tally/verification.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM3C;;;GAGG;AACH,eAAO,MAAM,MAAM,GAAU,uFAO1B,WAAW,KAAG,OAAO,CAAC,OAAO,CAiG/B,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verify = void 0;
4
+ const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
5
+ const contracts_1 = require("../utils/contracts");
6
+ const utils_1 = require("./utils");
7
+ /**
8
+ * Verify the results of a poll on-chain
9
+ * @param VerifyArgs - The arguments for the verify command
10
+ */
11
+ const verify = async ({ pollId, tallyData, signer, tallyCommitments, numVoteOptions, voteOptionTreeDepth, }) => {
12
+ const useQv = tallyData.isQuadratic;
13
+ const maciContractAddress = tallyData.maci;
14
+ const validContract = await (0, contracts_1.contractExists)(signer.provider, maciContractAddress);
15
+ if (!validContract) {
16
+ throw new Error(`There is no MACI contract deployed at ${maciContractAddress}.`);
17
+ }
18
+ // get the contract objects
19
+ const maciContract = typechain_types_1.MACI__factory.connect(maciContractAddress, signer);
20
+ const pollContracts = await maciContract.polls(pollId);
21
+ const tallyContract = typechain_types_1.Tally__factory.connect(pollContracts.tally, signer);
22
+ // get the on-chain tally commitment\
23
+ const onChainTallyCommitment = BigInt(await tallyContract.tallyCommitment());
24
+ // check the results commitment
25
+ const validResultsCommitment = tallyData.newTallyCommitment.match(/0x[a-fA-F0-9]+/);
26
+ if (!validResultsCommitment) {
27
+ throw new Error("Invalid results commitment format");
28
+ }
29
+ if (tallyData.results.tally.length !== numVoteOptions) {
30
+ throw new Error("Wrong number of vote options.");
31
+ }
32
+ // destructure the tally commitments
33
+ const { newTallyCommitment, newSpentVoiceCreditsCommitment, newPerVOSpentVoiceCreditsCommitment, newResultsCommitment, } = tallyCommitments;
34
+ // verify that the results commitment matches the output of genTreeCommitment()
35
+ if (onChainTallyCommitment !== newTallyCommitment) {
36
+ throw new Error("The on-chain tally commitment does not match.");
37
+ }
38
+ // verify total spent voice credits on-chain
39
+ const verified = await tallyContract.verifySpentVoiceCredits(tallyData.totalSpentVoiceCredits.spent, tallyData.totalSpentVoiceCredits.salt, newResultsCommitment, newPerVOSpentVoiceCreditsCommitment ?? 0n);
40
+ if (!verified) {
41
+ throw new Error("The on-chain verification of total spent voice credits failed.");
42
+ }
43
+ // verify tally result on-chain for each vote option
44
+ const failedPerVOSpentCredits = await (0, utils_1.verifyTallyResults)(tallyContract, tallyData, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newPerVOSpentVoiceCreditsCommitment);
45
+ if (failedPerVOSpentCredits.length > 0) {
46
+ throw new Error(`At least one spent voice credits entry in the tally results failed the on-chain verification. Please check your tally results at these indexes: ${failedPerVOSpentCredits.join(", ")}`);
47
+ }
48
+ if (!useQv) {
49
+ return true;
50
+ }
51
+ if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) {
52
+ throw new Error("Wrong number of vote options.");
53
+ }
54
+ // verify per vote option voice credits on-chain
55
+ const failedSpentCredits = await (0, utils_1.verifyPerVOSpentVoiceCredits)(tallyContract, tallyData, voteOptionTreeDepth, newSpentVoiceCreditsCommitment, newResultsCommitment);
56
+ if (failedSpentCredits.length > 0) {
57
+ throw new Error(`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join(", ")}`);
58
+ }
59
+ return true;
60
+ };
61
+ exports.verify = verify;
62
+ //# sourceMappingURL=verification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.js","sourceRoot":"","sources":["../../../ts/tally/verification.ts"],"names":[],"mappings":";;;AAAA,8EAAwH;AAIxH,kDAAoD;AAEpD,mCAA2E;AAE3E;;;GAGG;AACI,MAAM,MAAM,GAAG,KAAK,EAAE,EAC3B,MAAM,EACN,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,mBAAmB,GACP,EAAoB,EAAE;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC;IACpC,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC;IAE3C,MAAM,aAAa,GAAG,MAAM,IAAA,0BAAc,EAAC,MAAM,CAAC,QAAS,EAAE,mBAAmB,CAAC,CAAC;IAElF,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,mBAAmB,GAAG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E,CAAC,CAAC;IACpF,CAAC;IAED,oDAAoD;IACpD,MAAM,uBAAuB,GAAG,MAAM,IAAA,0BAAkB,EACtD,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,8BAA8B,EAC9B,mCAAmC,CACpC,CAAC;IAEF,IAAI,uBAAuB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,mJAAmJ,uBAAuB,CAAC,IAAI,CAC7K,IAAI,CACL,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,SAAS,CAAC,sBAAsB,EAAE,KAAK,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,gDAAgD;IAChD,MAAM,kBAAkB,GAAG,MAAM,IAAA,oCAA4B,EAC3D,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,8BAA8B,EAC9B,oBAAoB,CACrB,CAAC;IAEF,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,8GAA8G,kBAAkB,CAAC,IAAI,CACnI,IAAI,CACL,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAxGW,QAAA,MAAM,UAwGjB"}
@@ -0,0 +1,3 @@
1
+ export { generateSignUpTree } from "./stateTree";
2
+ export type { IGenerateSignUpTreeArgs, IGenerateSignUpTree } from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/trees/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSignUpTree = void 0;
4
+ var stateTree_1 = require("./stateTree");
5
+ Object.defineProperty(exports, "generateSignUpTree", { enumerable: true, get: function () { return stateTree_1.generateSignUpTree; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/trees/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiD;AAAxC,+GAAA,kBAAkB,OAAA"}
@@ -0,0 +1,13 @@
1
+ import type { IGenerateSignUpTreeArgs, IGenerateSignUpTree } from "./types";
2
+ /**
3
+ * Generate a State tree object from the events of a MACI smart contracts
4
+ * @param provider - the ethereum provider
5
+ * @param address - the address of the MACI contract
6
+ * @param fromBlock - the block number from which to start fetching events
7
+ * @param blocksPerRequest - the number of blocks to fetch in each request
8
+ * @param endBlock - the block number at which to stop fetching events
9
+ * @param sleepAmount - the amount of time to sleep between each request
10
+ * @returns State tree
11
+ */
12
+ export declare const generateSignUpTree: ({ provider, address, fromBlock, blocksPerRequest, endBlock, sleepAmount, }: IGenerateSignUpTreeArgs) => Promise<IGenerateSignUpTree>;
13
+ //# sourceMappingURL=stateTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stateTree.d.ts","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAI5E;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAU,4EAOtC,uBAAuB,KAAG,OAAO,CAAC,mBAAmB,CAqCvD,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateSignUpTree = void 0;
7
+ /* eslint-disable no-underscore-dangle */
8
+ const typechain_types_1 = require("@maci-protocol/contracts/typechain-types");
9
+ const crypto_1 = require("@maci-protocol/crypto");
10
+ const domainobjs_1 = require("@maci-protocol/domainobjs");
11
+ const lean_imt_1 = require("@zk-kit/lean-imt");
12
+ const assert_1 = __importDefault(require("assert"));
13
+ const utils_1 = require("../utils/utils");
14
+ /**
15
+ * Generate a State tree object from the events of a MACI smart contracts
16
+ * @param provider - the ethereum provider
17
+ * @param address - the address of the MACI contract
18
+ * @param fromBlock - the block number from which to start fetching events
19
+ * @param blocksPerRequest - the number of blocks to fetch in each request
20
+ * @param endBlock - the block number at which to stop fetching events
21
+ * @param sleepAmount - the amount of time to sleep between each request
22
+ * @returns State tree
23
+ */
24
+ const generateSignUpTree = async ({ provider, address, fromBlock = 0, blocksPerRequest = 50, endBlock, sleepAmount, }) => {
25
+ const lastBlock = endBlock || (await provider.getBlockNumber());
26
+ const maciContract = typechain_types_1.MACI__factory.connect(address, provider);
27
+ const signUpTree = new lean_imt_1.LeanIMT(crypto_1.hashLeanIMT);
28
+ signUpTree.insert(crypto_1.PAD_KEY_HASH);
29
+ const pubKeys = [];
30
+ // Fetch event logs in batches (lastBlock inclusive)
31
+ for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) {
32
+ // the last block batch will be either current iteration block + blockPerRequest
33
+ // or the end block if it is set
34
+ const toBlock = i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest;
35
+ // eslint-disable-next-line no-await-in-loop
36
+ const signUpLogs = await maciContract.queryFilter(maciContract.filters.SignUp(), i, toBlock);
37
+ signUpLogs.forEach((event) => {
38
+ (0, assert_1.default)(!!event);
39
+ const pubKeyX = event.args._userPubKeyX;
40
+ const pubKeyY = event.args._userPubKeyY;
41
+ const pubKey = new domainobjs_1.PubKey([pubKeyX, pubKeyY]);
42
+ pubKeys.push(pubKey);
43
+ signUpTree.insert((0, crypto_1.hashLeftRight)(pubKeyX, pubKeyY));
44
+ });
45
+ if (sleepAmount) {
46
+ // eslint-disable-next-line no-await-in-loop
47
+ await (0, utils_1.sleep)(sleepAmount);
48
+ }
49
+ }
50
+ return {
51
+ signUpTree,
52
+ pubKeys,
53
+ };
54
+ };
55
+ exports.generateSignUpTree = generateSignUpTree;
56
+ //# sourceMappingURL=stateTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stateTree.js","sourceRoot":"","sources":["../../../ts/trees/stateTree.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAyC;AACzC,8EAAwF;AACxF,kDAAiF;AACjF,0DAAmD;AACnD,+CAAgE;AAEhE,oDAA4B;AAI5B,0CAAuC;AAEvC;;;;;;;;;GASG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,QAAQ,EACR,OAAO,EACP,SAAS,GAAG,CAAC,EACb,gBAAgB,GAAG,EAAE,EACrB,QAAQ,EACR,WAAW,GACa,EAAgC,EAAE;IAC1D,MAAM,SAAS,GAAG,QAAQ,IAAI,CAAC,MAAM,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;IAEhE,MAAM,YAAY,GAAG,+BAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,kBAAO,CAAC,oBAAkC,CAAC,CAAC;IACnE,UAAU,CAAC,MAAM,CAAC,qBAAY,CAAC,CAAC;IAChC,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,oDAAoD;IACpD,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC,IAAI,gBAAgB,GAAG,CAAC,EAAE,CAAC;QAClE,gFAAgF;QAChF,gCAAgC;QAChC,MAAM,OAAO,GAAG,CAAC,GAAG,gBAAgB,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;QAErF,4CAA4C;QAC5C,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7F,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,IAAA,gBAAM,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC;YACxC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC;YAExC,MAAM,MAAM,GAAG,IAAI,mBAAM,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAE9C,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,UAAU,CAAC,MAAM,CAAC,IAAA,sBAAa,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,IAAI,WAAW,EAAE,CAAC;YAChB,4CAA4C;YAC5C,MAAM,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,kBAAkB,sBA4C7B"}
@@ -0,0 +1,46 @@
1
+ import type { PubKey } from "@maci-protocol/domainobjs";
2
+ import type { LeanIMT } from "@zk-kit/lean-imt";
3
+ import type { Provider } from "ethers";
4
+ /**
5
+ * An interface that represents arguments of generation sign up tree and state leaves
6
+ */
7
+ export interface IGenerateSignUpTreeArgs {
8
+ /**
9
+ * The etherum provider
10
+ */
11
+ provider: Provider;
12
+ /**
13
+ * The address of MACI contract
14
+ */
15
+ address: string;
16
+ /**
17
+ * The block number from which to start fetching events
18
+ */
19
+ fromBlock?: number;
20
+ /**
21
+ * The number of blocks to fetch in each request
22
+ */
23
+ blocksPerRequest?: number;
24
+ /**
25
+ * The block number at which to stop fetching events
26
+ */
27
+ endBlock?: number;
28
+ /**
29
+ * The amount of time to sleep between each request
30
+ */
31
+ sleepAmount?: number;
32
+ }
33
+ /**
34
+ * An interface that represents sign up tree and state leaves
35
+ */
36
+ export interface IGenerateSignUpTree {
37
+ /**
38
+ * Sign up tree
39
+ */
40
+ signUpTree: LeanIMT;
41
+ /**
42
+ * State leaves
43
+ */
44
+ pubKeys: PubKey[];
45
+ }
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/trees/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
@@ -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/trees/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export { joinPoll } from "./joinPoll";
2
+ export { getSignedupUserData, signup, hasUserSignedUp } from "./signup";
3
+ export { getJoinedUserData, hasUserJoinedPoll } from "./utils";
4
+ export type { IJoinedUserArgs, IIsRegisteredUser, IIsJoinedUser, ISignupArgs, IRegisteredUserArgs, IPollJoinedCircuitInputs, IPollJoiningCircuitInputs, IJoinPollArgs, IIsNullifierOnChainArgs, IGetPollJoiningCircuitEventsArgs, IGetPollJoiningCircuitInputsFromStateFileArgs, IJoinPollData, IParsePollJoinEventsArgs, IParseSignupEventsArgs, ISignupData, IHasUserSignedUpArgs, } from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC/D,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACb,uBAAuB,EACvB,gCAAgC,EAChC,6CAA6C,EAC7C,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.hasUserSignedUp = exports.signup = exports.getSignedupUserData = exports.joinPoll = void 0;
4
+ var joinPoll_1 = require("./joinPoll");
5
+ Object.defineProperty(exports, "joinPoll", { enumerable: true, get: function () { return joinPoll_1.joinPoll; } });
6
+ var signup_1 = require("./signup");
7
+ Object.defineProperty(exports, "getSignedupUserData", { enumerable: true, get: function () { return signup_1.getSignedupUserData; } });
8
+ Object.defineProperty(exports, "signup", { enumerable: true, get: function () { return signup_1.signup; } });
9
+ Object.defineProperty(exports, "hasUserSignedUp", { enumerable: true, get: function () { return signup_1.hasUserSignedUp; } });
10
+ var utils_1 = require("./utils");
11
+ Object.defineProperty(exports, "getJoinedUserData", { enumerable: true, get: function () { return utils_1.getJoinedUserData; } });
12
+ Object.defineProperty(exports, "hasUserJoinedPoll", { enumerable: true, get: function () { return utils_1.hasUserJoinedPoll; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/user/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,mCAAwE;AAA/D,6GAAA,mBAAmB,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,yGAAA,eAAe,OAAA;AACrD,iCAA+D;AAAtD,0GAAA,iBAAiB,OAAA;AAAE,0GAAA,iBAAiB,OAAA"}
@@ -0,0 +1,8 @@
1
+ import type { IJoinPollData, IJoinPollArgs } from "./types";
2
+ /**
3
+ * Join Poll user to the Poll contract
4
+ * @param {IJoinPollArgs} args - The arguments for the join poll command
5
+ * @returns {IJoinPollData} The poll state index of the joined user and transaction hash
6
+ */
7
+ export declare const joinPoll: ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark, pollWitgen, pollWasm, sgDataArg, ivcpDataArg, }: IJoinPollArgs) => Promise<IJoinPollData>;
8
+ //# sourceMappingURL=joinPoll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joinPoll.d.ts","sourceRoot":"","sources":["../../../ts/user/joinPoll.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQ5D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,mLAgB5B,aAAa,KAAG,OAAO,CAAC,aAAa,CA4FvC,CAAC"}