@maci-protocol/sdk 0.0.0-ci.26f28d6

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,424 @@
1
+ import type { MACI, Poll } from "@maci-protocol/contracts/typechain-types";
2
+ import type { PrivKey, PubKey } from "@maci-protocol/domainobjs";
3
+ import type { Signer } from "ethers";
4
+ /**
5
+ * Interface for the arguments to the isJoinedUser command
6
+ */
7
+ export interface IJoinedUserArgs {
8
+ /**
9
+ * The address of the MACI contract
10
+ */
11
+ maciAddress: string;
12
+ /**
13
+ * The id of the poll
14
+ */
15
+ pollId: bigint;
16
+ /**
17
+ * Poll public key for the poll
18
+ */
19
+ pollPubKey: string;
20
+ /**
21
+ * A signer object
22
+ */
23
+ signer: Signer;
24
+ /**
25
+ * The start block number
26
+ */
27
+ startBlock: number;
28
+ }
29
+ /**
30
+ * Interface for the return data to the isRegisteredUser function
31
+ */
32
+ export interface IIsRegisteredUser {
33
+ /**
34
+ * Whether the user is registered
35
+ */
36
+ isRegistered: boolean;
37
+ /**
38
+ * The state index of the user
39
+ */
40
+ stateIndex?: string;
41
+ }
42
+ /**
43
+ * Interface for the return data to the isJoinedUser function
44
+ */
45
+ export interface IIsJoinedUser {
46
+ /**
47
+ * Whether the user joined the poll
48
+ */
49
+ isJoined: boolean;
50
+ /**
51
+ * The state index of the user
52
+ */
53
+ pollStateIndex?: string;
54
+ /**
55
+ * The voice credits of the user
56
+ */
57
+ voiceCredits?: string;
58
+ }
59
+ /**
60
+ * Interface for the arguments to the signup command
61
+ */
62
+ export interface ISignupArgs {
63
+ /**
64
+ * The public key of the user
65
+ */
66
+ maciPubKey: string;
67
+ /**
68
+ * A signer object
69
+ */
70
+ signer: Signer;
71
+ /**
72
+ * The address of the MACI contract
73
+ */
74
+ maciAddress: string;
75
+ /**
76
+ * The signup policy data
77
+ */
78
+ sgData: string;
79
+ }
80
+ /**
81
+ * Interface for the return data to the signup command
82
+ */
83
+ export interface ISignupData {
84
+ /**
85
+ * The state index of the user
86
+ */
87
+ stateIndex: string;
88
+ /**
89
+ * The signup transaction hash
90
+ */
91
+ transactionHash: string;
92
+ }
93
+ /**
94
+ * Interface for the arguments to the register check command
95
+ */
96
+ export interface IRegisteredUserArgs {
97
+ /**
98
+ * A signer object
99
+ */
100
+ signer: Signer;
101
+ /**
102
+ * The public key of the user
103
+ */
104
+ maciPubKey: string;
105
+ /**
106
+ * The address of the MACI contract
107
+ */
108
+ maciAddress: string;
109
+ /**
110
+ * Start block for event parsing
111
+ */
112
+ startBlock?: number;
113
+ }
114
+ /**
115
+ * Interface for the arguments to the parsePollJoinEvents function
116
+ */
117
+ export interface IParsePollJoinEventsArgs {
118
+ /**
119
+ * The MACI contract
120
+ */
121
+ pollContract: Poll;
122
+ /**
123
+ * The start block
124
+ */
125
+ startBlock: number;
126
+ /**
127
+ * The current block
128
+ */
129
+ currentBlock: number;
130
+ /**
131
+ * The public key
132
+ */
133
+ pollPublicKey: PubKey;
134
+ }
135
+ /**
136
+ * Interface for the arguments to the parseSignupEvents function
137
+ */
138
+ export interface IParseSignupEventsArgs {
139
+ /**
140
+ * The MACI contract
141
+ */
142
+ maciContract: MACI;
143
+ /**
144
+ * The start block
145
+ */
146
+ startBlock: number;
147
+ /**
148
+ * The current block
149
+ */
150
+ currentBlock: number;
151
+ /**
152
+ * The public key
153
+ */
154
+ publicKey: PubKey;
155
+ }
156
+ /**
157
+ * An interface describing the circuit inputs to the PollJoining circuit
158
+ */
159
+ export interface IPollJoiningCircuitInputs {
160
+ /**
161
+ * The private key
162
+ */
163
+ privKey: string;
164
+ /**
165
+ * The poll public key
166
+ */
167
+ pollPubKey: string[];
168
+ /**
169
+ * The state leaf
170
+ */
171
+ stateLeaf: string[];
172
+ /**
173
+ * The siblings for the merkle proof
174
+ */
175
+ siblings: string[][];
176
+ /**
177
+ * The path indices
178
+ */
179
+ indices: string[];
180
+ /**
181
+ * The nullifier
182
+ */
183
+ nullifier: string;
184
+ /**
185
+ * The state root
186
+ */
187
+ stateRoot: string;
188
+ /**
189
+ * The actual state tree depth
190
+ */
191
+ actualStateTreeDepth: string;
192
+ /**
193
+ * The poll id
194
+ */
195
+ pollId: string;
196
+ }
197
+ /**
198
+ * An interface describing the circuit inputs to the PollJoined circuit
199
+ */
200
+ export interface IPollJoinedCircuitInputs {
201
+ /**
202
+ * The private key
203
+ */
204
+ privKey: string;
205
+ /**
206
+ * The voice credits balance
207
+ */
208
+ voiceCreditsBalance: string;
209
+ /**
210
+ * The join timestamp
211
+ */
212
+ joinTimestamp: string;
213
+ /**
214
+ * The state leaf
215
+ */
216
+ stateLeaf: string[];
217
+ /**
218
+ * The path elements
219
+ */
220
+ pathElements: string[][];
221
+ /**
222
+ * The path indices
223
+ */
224
+ pathIndices: string[];
225
+ /**
226
+ * The state root
227
+ */
228
+ stateRoot: string;
229
+ /**
230
+ * The actual state tree depth
231
+ */
232
+ actualStateTreeDepth: string;
233
+ }
234
+ /**
235
+ * Interface for the arguments to the joinPoll command
236
+ */
237
+ export interface IJoinPollArgs {
238
+ /**
239
+ * A signer object
240
+ */
241
+ signer: Signer;
242
+ /**
243
+ * The private key of the user
244
+ */
245
+ privateKey: string;
246
+ /**
247
+ * The id of the poll
248
+ */
249
+ pollId: bigint;
250
+ /**
251
+ * The index of the public key in the state tree
252
+ */
253
+ stateIndex?: bigint;
254
+ /**
255
+ * Path to the state file with MACI state
256
+ */
257
+ stateFile?: string;
258
+ /**
259
+ * The address of the MACI contract
260
+ */
261
+ maciAddress: string;
262
+ /**
263
+ * The end block number
264
+ */
265
+ endBlock?: number;
266
+ /**
267
+ * The start block number
268
+ */
269
+ startBlock?: number;
270
+ /**
271
+ * The number of blocks to fetch per batch
272
+ */
273
+ blocksPerBatch?: number;
274
+ /**
275
+ * The path to the poll zkey file
276
+ */
277
+ pollJoiningZkey: string;
278
+ /**
279
+ * Whether to use wasm or rapidsnark
280
+ */
281
+ useWasm?: boolean;
282
+ /**
283
+ * The path to the rapidsnark binary
284
+ */
285
+ rapidsnark?: string;
286
+ /**
287
+ * The path to the poll witnessgen binary
288
+ */
289
+ pollWitgen?: string;
290
+ /**
291
+ * The path to the poll wasm file
292
+ */
293
+ pollWasm?: string;
294
+ /**
295
+ * The signup policy data
296
+ */
297
+ sgDataArg: string;
298
+ /**
299
+ * The initial voice credit proxy data
300
+ */
301
+ ivcpDataArg: string;
302
+ }
303
+ /**
304
+ * Interface for the return data to the joinPoll command
305
+ */
306
+ export interface IJoinPollData {
307
+ /**
308
+ * The poll state index of the joined user
309
+ */
310
+ pollStateIndex: string;
311
+ /**
312
+ * Voice credits balance
313
+ */
314
+ voiceCredits: string;
315
+ /**
316
+ * Joining poll timestamp
317
+ */
318
+ timestamp: string;
319
+ /**
320
+ * Private key nullifier
321
+ */
322
+ nullifier: string;
323
+ /**
324
+ * The join poll transaction hash
325
+ */
326
+ hash: string;
327
+ }
328
+ /**
329
+ * The arguments to check if a nullifier is on chain
330
+ */
331
+ export interface IIsNullifierOnChainArgs {
332
+ /**
333
+ * The address of the MACI contract
334
+ */
335
+ maciAddress: string;
336
+ /**
337
+ * The id of the poll
338
+ */
339
+ pollId: bigint;
340
+ /**
341
+ * The nullifier to check
342
+ */
343
+ nullifier: bigint;
344
+ /**
345
+ * The signer to use
346
+ */
347
+ signer: Signer;
348
+ }
349
+ /**
350
+ * Arguments for getPollJoiningCircuitEvents
351
+ */
352
+ export interface IGetPollJoiningCircuitEventsArgs {
353
+ /**
354
+ * The MACI contract
355
+ */
356
+ maciContract: MACI;
357
+ /**
358
+ * The state index
359
+ */
360
+ stateIndex: bigint;
361
+ /**
362
+ * The poll id
363
+ */
364
+ pollId: bigint;
365
+ /**
366
+ * The user's maci private key
367
+ */
368
+ userMaciPrivKey: PrivKey;
369
+ /**
370
+ * The signer
371
+ */
372
+ signer: Signer;
373
+ /**
374
+ * The start block
375
+ */
376
+ startBlock?: number;
377
+ /**
378
+ * The end block
379
+ */
380
+ endBlock?: number;
381
+ /**
382
+ * The blocks per batch
383
+ */
384
+ blocksPerBatch?: number;
385
+ }
386
+ /**
387
+ * Arguments for getPollJoiningCircuitInputsFromStateFile
388
+ */
389
+ export interface IGetPollJoiningCircuitInputsFromStateFileArgs {
390
+ /**
391
+ * The path to the file containing the serialized MACI state
392
+ */
393
+ stateFile: string;
394
+ /**
395
+ * The poll id
396
+ */
397
+ pollId: bigint;
398
+ /**
399
+ * The state index
400
+ */
401
+ stateIndex: bigint;
402
+ /**
403
+ * The user's maci private key
404
+ */
405
+ userMaciPrivKey: PrivKey;
406
+ }
407
+ /**
408
+ * Interface for the arguments for the is signed up command
409
+ */
410
+ export interface IHasUserSignedUpArgs {
411
+ /**
412
+ * The address of the MACI contract
413
+ */
414
+ maciAddress: string;
415
+ /**
416
+ * The public key of the user
417
+ */
418
+ maciPubKey: string;
419
+ /**
420
+ * The signer to use for the transaction
421
+ */
422
+ signer: Signer;
423
+ }
424
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/user/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;I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W,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -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/user/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import type { IIsRegisteredUser, IJoinedUserArgs, ISignupArgs, ISignupData, IRegisteredUserArgs, IJoinPollData, IJoinPollArgs, IIsNullifierOnChainArgs, IHasUserSignedUpArgs } from "./types";
2
+ /**
3
+ * Checks if user is registered with a given public key and get its data
4
+ * @param IRegisteredArgs - The arguments for the check register command
5
+ * @returns whether the user is registered or not and their state index
6
+ */
7
+ export declare const getSignedupUserData: ({ maciAddress, maciPubKey, signer, startBlock, }: IRegisteredUserArgs) => Promise<IIsRegisteredUser>;
8
+ /**
9
+ * Signup a user to the MACI contract
10
+ * @param {SignupArgs} args - The arguments for the signup command
11
+ * @returns {ISignupData} The state index of the user and transaction hash
12
+ */
13
+ export declare const signup: ({ maciPubKey, maciAddress, sgData, signer }: ISignupArgs) => Promise<ISignupData>;
14
+ /**
15
+ * Checks if user is joined to a poll with their public key and get its data
16
+ * @param {IJoinedUserArgs} - The arguments for the join check command
17
+ * @returns user joined or not and poll state index, voice credit balance
18
+ */
19
+ export declare const getJoinedUserData: ({ maciAddress, pollId, pollPubKey, signer, startBlock, }: IJoinedUserArgs) => Promise<{
20
+ isJoined: boolean;
21
+ pollStateIndex?: string;
22
+ voiceCredits?: string;
23
+ }>;
24
+ /**
25
+ * Checks if a user joined a poll with a given nullifier
26
+ * @param {IIsNullifierOnChainArgs} args - The arguments for the is nullifier on chain command
27
+ * @returns whether the nullifier is on chain or not
28
+ */
29
+ export declare const hasUserJoinedPoll: ({ maciAddress, pollId, nullifier, signer, }: IIsNullifierOnChainArgs) => Promise<boolean>;
30
+ /**
31
+ * Join Poll user to the Poll contract
32
+ * @param {IJoinPollArgs} args - The arguments for the join poll command
33
+ * @returns {IJoinPollData} The poll state index of the joined user and transaction hash
34
+ */
35
+ export declare const joinPoll: ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark, pollWitgen, pollWasm, sgDataArg, ivcpDataArg, }: IJoinPollArgs) => Promise<IJoinPollData>;
36
+ /**
37
+ * Checks if a user is signed up with a given public key
38
+ * @param {IIsSignedUpArgs} args - The arguments for the is signed up command
39
+ * @returns {boolean} Whether the user is signed up or not
40
+ */
41
+ export declare const hasUserSignedUp: ({ maciAddress, maciPubKey, signer }: IHasUserSignedUpArgs) => Promise<boolean>;
42
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../ts/user/user.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAYjB;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,kDAKvC,mBAAmB,KAAG,OAAO,CAAC,iBAAiB,CAiBjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAU,6CAA6C,WAAW,KAAG,OAAO,CAAC,WAAW,CA6C1G,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,0DAMrC,eAAe,KAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAqBjG,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,6CAKrC,uBAAuB,KAAG,OAAO,CAAC,OAAO,CAM3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,mLAgB5B,aAAa,KAAG,OAAO,CAAC,aAAa,CA6FvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,qCAAqC,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAMhH,CAAC"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasUserSignedUp = exports.joinPoll = exports.hasUserJoinedPoll = exports.getJoinedUserData = exports.signup = exports.getSignedupUserData = void 0;
4
+ /* eslint-disable no-underscore-dangle */
5
+ const contracts_1 = require("@maci-protocol/contracts");
6
+ const crypto_1 = require("@maci-protocol/crypto");
7
+ const domainobjs_1 = require("@maci-protocol/domainobjs");
8
+ const ethers_1 = require("ethers");
9
+ const utils_1 = require("../utils");
10
+ const utils_2 = require("./utils");
11
+ /**
12
+ * Checks if user is registered with a given public key and get its data
13
+ * @param IRegisteredArgs - The arguments for the check register command
14
+ * @returns whether the user is registered or not and their state index
15
+ */
16
+ const getSignedupUserData = async ({ maciAddress, maciPubKey, signer, startBlock, }) => {
17
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
18
+ const publicKey = domainobjs_1.PubKey.deserialize(maciPubKey);
19
+ const startBlockNumber = startBlock || 0;
20
+ const currentBlock = await signer.provider.getBlockNumber();
21
+ const { stateIndex } = await (0, utils_2.parseSignupEvents)({
22
+ maciContract,
23
+ startBlock: startBlockNumber,
24
+ currentBlock,
25
+ publicKey,
26
+ });
27
+ return {
28
+ isRegistered: stateIndex !== undefined,
29
+ stateIndex,
30
+ };
31
+ };
32
+ exports.getSignedupUserData = getSignedupUserData;
33
+ /**
34
+ * Signup a user to the MACI contract
35
+ * @param {SignupArgs} args - The arguments for the signup command
36
+ * @returns {ISignupData} The state index of the user and transaction hash
37
+ */
38
+ const signup = async ({ maciPubKey, maciAddress, sgData, signer }) => {
39
+ // validate user key
40
+ if (!domainobjs_1.PubKey.isValidSerializedPubKey(maciPubKey)) {
41
+ throw new Error("Invalid MACI public key");
42
+ }
43
+ const userMaciPubKey = domainobjs_1.PubKey.deserialize(maciPubKey);
44
+ const validContract = await (0, utils_1.contractExists)(signer.provider, maciAddress);
45
+ if (!validContract) {
46
+ throw new Error("There is no contract deployed at the specified address");
47
+ }
48
+ // we validate that the signup data and voice credit data is valid
49
+ if (!(0, ethers_1.isBytesLike)(sgData)) {
50
+ throw new Error("invalid signup gateway data");
51
+ }
52
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
53
+ let stateIndex = "";
54
+ let receipt = null;
55
+ // sign up to the MACI contract
56
+ const tx = await maciContract.signUp(userMaciPubKey.asContractParam(), sgData);
57
+ receipt = await tx.wait();
58
+ if (receipt?.status !== 1) {
59
+ throw new Error("The transaction failed");
60
+ }
61
+ // get state index from the event
62
+ const [{ args = [] } = { args: [] }] = await maciContract.queryFilter(maciContract.filters.SignUp, receipt.blockNumber, receipt.blockNumber);
63
+ stateIndex = args[0].toString();
64
+ return {
65
+ stateIndex: stateIndex ? stateIndex.toString() : "",
66
+ transactionHash: receipt.hash,
67
+ };
68
+ };
69
+ exports.signup = signup;
70
+ /**
71
+ * Checks if user is joined to a poll with their public key and get its data
72
+ * @param {IJoinedUserArgs} - The arguments for the join check command
73
+ * @returns user joined or not and poll state index, voice credit balance
74
+ */
75
+ const getJoinedUserData = async ({ maciAddress, pollId, pollPubKey, signer, startBlock, }) => {
76
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
77
+ const pollContracts = await maciContract.getPoll(pollId);
78
+ const pollContract = contracts_1.Poll__factory.connect(pollContracts.poll, signer);
79
+ const pollPublicKey = domainobjs_1.PubKey.deserialize(pollPubKey);
80
+ const startBlockNumber = startBlock || 0;
81
+ const currentBlock = await signer.provider.getBlockNumber();
82
+ const { pollStateIndex, voiceCredits } = await (0, utils_2.parsePollJoinEvents)({
83
+ pollContract,
84
+ startBlock: startBlockNumber,
85
+ currentBlock,
86
+ pollPublicKey,
87
+ });
88
+ return {
89
+ isJoined: pollStateIndex !== undefined,
90
+ pollStateIndex,
91
+ voiceCredits,
92
+ };
93
+ };
94
+ exports.getJoinedUserData = getJoinedUserData;
95
+ /**
96
+ * Checks if a user joined a poll with a given nullifier
97
+ * @param {IIsNullifierOnChainArgs} args - The arguments for the is nullifier on chain command
98
+ * @returns whether the nullifier is on chain or not
99
+ */
100
+ const hasUserJoinedPoll = async ({ maciAddress, pollId, nullifier, signer, }) => {
101
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
102
+ const pollContracts = await maciContract.getPoll(pollId);
103
+ const pollContract = contracts_1.Poll__factory.connect(pollContracts.poll, signer);
104
+ return pollContract.pollNullifiers(nullifier);
105
+ };
106
+ exports.hasUserJoinedPoll = hasUserJoinedPoll;
107
+ /**
108
+ * Join Poll user to the Poll contract
109
+ * @param {IJoinPollArgs} args - The arguments for the join poll command
110
+ * @returns {IJoinPollData} The poll state index of the joined user and transaction hash
111
+ */
112
+ const joinPoll = async ({ maciAddress, privateKey, stateFile, pollId, signer, startBlock, endBlock, blocksPerBatch, pollJoiningZkey, useWasm, rapidsnark, pollWitgen, pollWasm, sgDataArg, ivcpDataArg, }) => {
113
+ const validContract = await (0, utils_1.contractExists)(signer.provider, maciAddress);
114
+ if (!validContract) {
115
+ throw new Error("MACI contract does not exist");
116
+ }
117
+ if (!domainobjs_1.PrivKey.isValidSerializedPrivKey(privateKey)) {
118
+ throw new Error("Invalid MACI private key");
119
+ }
120
+ if (pollId < 0) {
121
+ throw new Error("Invalid poll id");
122
+ }
123
+ const userMaciPrivKey = domainobjs_1.PrivKey.deserialize(privateKey);
124
+ const userMaciPubKey = new domainobjs_1.Keypair(userMaciPrivKey).pubKey;
125
+ const nullifier = (0, crypto_1.poseidon)([BigInt(userMaciPrivKey.asCircuitInputs()), pollId]);
126
+ // check if the user has already joined the poll based on the nullifier
127
+ const hasUserJoinedAlready = await (0, exports.hasUserJoinedPoll)({
128
+ maciAddress,
129
+ pollId,
130
+ nullifier,
131
+ signer,
132
+ });
133
+ if (hasUserJoinedAlready) {
134
+ throw new Error("User has already joined");
135
+ }
136
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
137
+ const pollContracts = await maciContract.getPoll(pollId);
138
+ const pollContract = contracts_1.Poll__factory.connect(pollContracts.poll, signer);
139
+ // get the state index from the MACI contract
140
+ const stateIndex = await maciContract.getStateIndex(userMaciPubKey.hash()).catch(() => -1n);
141
+ let circuitInputs;
142
+ if (stateFile) {
143
+ circuitInputs = await (0, utils_2.getPollJoiningCircuitInputsFromStateFile)({
144
+ stateFile,
145
+ pollId,
146
+ stateIndex,
147
+ userMaciPrivKey,
148
+ });
149
+ }
150
+ else {
151
+ circuitInputs = await (0, utils_2.getPollJoiningCircuitEvents)({
152
+ maciContract,
153
+ stateIndex,
154
+ pollId,
155
+ userMaciPrivKey,
156
+ signer,
157
+ startBlock,
158
+ endBlock,
159
+ blocksPerBatch,
160
+ });
161
+ }
162
+ const currentStateRootIndex = Number.parseInt((await maciContract.numSignUps()).toString(), 10) - 1;
163
+ // generate the proof for this batch
164
+ const proof = await (0, utils_1.generateAndVerifyProof)(circuitInputs, pollJoiningZkey, useWasm, rapidsnark, pollWitgen, pollWasm);
165
+ // submit the message onchain as well as the encryption public key
166
+ const tx = await pollContract.joinPoll(nullifier, userMaciPubKey.asContractParam(), currentStateRootIndex, proof, sgDataArg, ivcpDataArg);
167
+ const receipt = await tx.wait();
168
+ if (receipt?.status !== 1) {
169
+ throw new Error("Transaction failed");
170
+ }
171
+ const [{ args }] = await pollContract.queryFilter(pollContract.filters.PollJoined, receipt.blockNumber, receipt.blockNumber);
172
+ return {
173
+ pollStateIndex: args._pollStateIndex.toString(),
174
+ voiceCredits: args._voiceCreditBalance.toString(),
175
+ timestamp: args._timestamp.toString(),
176
+ nullifier: nullifier.toString(),
177
+ hash: receipt.hash,
178
+ };
179
+ };
180
+ exports.joinPoll = joinPoll;
181
+ /**
182
+ * Checks if a user is signed up with a given public key
183
+ * @param {IIsSignedUpArgs} args - The arguments for the is signed up command
184
+ * @returns {boolean} Whether the user is signed up or not
185
+ */
186
+ const hasUserSignedUp = async ({ maciAddress, maciPubKey, signer }) => {
187
+ const maciContract = contracts_1.MACI__factory.connect(maciAddress, signer);
188
+ const stateIndex = await maciContract.getStateIndex(domainobjs_1.PubKey.deserialize(maciPubKey).hash());
189
+ return stateIndex !== 0n;
190
+ };
191
+ exports.hasUserSignedUp = hasUserSignedUp;
192
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../ts/user/user.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,wDAAsG;AACtG,kDAAiD;AACjD,0DAAqE;AACrE,mCAAiE;AAejE,oCAAkE;AAElE,mCAKiB;AAEjB;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,WAAW,EACX,UAAU,EACV,MAAM,EACN,UAAU,GACU,EAA8B,EAAE;IACpD,MAAM,YAAY,GAAG,yBAAW,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,mBAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACjD,MAAM,gBAAgB,GAAG,UAAU,IAAI,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,QAAS,CAAC,cAAc,EAAE,CAAC;IAE7D,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,yBAAiB,EAAC;QAC7C,YAAY;QACZ,UAAU,EAAE,gBAAgB;QAC5B,YAAY;QACZ,SAAS;KACV,CAAC,CAAC;IAEH,OAAO;QACL,YAAY,EAAE,UAAU,KAAK,SAAS;QACtC,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,mBAAmB,uBAsB9B;AAEF;;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