@dorafactory/maci-sdk 0.0.1

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 (74) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +11 -0
  3. package/dist/index.js +4157 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +4123 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/libs/const.d.ts +117 -0
  8. package/dist/libs/contract/config.d.ts +29 -0
  9. package/dist/libs/contract/contract.d.ts +37 -0
  10. package/dist/libs/contract/index.d.ts +1 -0
  11. package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
  12. package/dist/libs/contract/ts/AMaci.types.d.ts +203 -0
  13. package/dist/libs/contract/ts/Maci.client.d.ts +206 -0
  14. package/dist/libs/contract/ts/Maci.types.d.ts +217 -0
  15. package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
  16. package/dist/libs/contract/ts/OracleMaci.types.d.ts +253 -0
  17. package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
  18. package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
  19. package/dist/libs/contract/types.d.ts +50 -0
  20. package/dist/libs/contract/utils.d.ts +67 -0
  21. package/dist/libs/contract/vars.d.ts +65 -0
  22. package/dist/libs/errors/index.d.ts +28 -0
  23. package/dist/libs/errors/types.d.ts +14 -0
  24. package/dist/libs/http/http.d.ts +16 -0
  25. package/dist/libs/http/index.d.ts +1 -0
  26. package/dist/libs/index.d.ts +4 -0
  27. package/dist/libs/indexer/index.d.ts +1 -0
  28. package/dist/libs/indexer/indexer.d.ts +133 -0
  29. package/dist/libs/indexer/types.d.ts +7 -0
  30. package/dist/libs/query/account.d.ts +7 -0
  31. package/dist/libs/query/circuit.d.ts +8 -0
  32. package/dist/libs/query/index.d.ts +6 -0
  33. package/dist/libs/query/operator.d.ts +9 -0
  34. package/dist/libs/query/proof.d.ts +7 -0
  35. package/dist/libs/query/round.d.ts +11 -0
  36. package/dist/libs/query/transaction.d.ts +9 -0
  37. package/dist/maci.d.ts +151 -0
  38. package/dist/types/index.d.ts +254 -0
  39. package/dist/utils/index.d.ts +1 -0
  40. package/package.json +154 -0
  41. package/src/index.ts +11 -0
  42. package/src/libs/const.ts +196 -0
  43. package/src/libs/contract/config.ts +117 -0
  44. package/src/libs/contract/contract.ts +330 -0
  45. package/src/libs/contract/index.ts +1 -0
  46. package/src/libs/contract/ts/AMaci.client.ts +893 -0
  47. package/src/libs/contract/ts/AMaci.types.ts +252 -0
  48. package/src/libs/contract/ts/Maci.client.ts +906 -0
  49. package/src/libs/contract/ts/Maci.types.ts +263 -0
  50. package/src/libs/contract/ts/OracleMaci.client.ts +561 -0
  51. package/src/libs/contract/ts/OracleMaci.types.ts +254 -0
  52. package/src/libs/contract/ts/Registry.client.ts +466 -0
  53. package/src/libs/contract/ts/Registry.types.ts +127 -0
  54. package/src/libs/contract/types.ts +57 -0
  55. package/src/libs/contract/utils.ts +175 -0
  56. package/src/libs/contract/vars.ts +420 -0
  57. package/src/libs/errors/index.ts +122 -0
  58. package/src/libs/errors/types.ts +14 -0
  59. package/src/libs/http/http.ts +152 -0
  60. package/src/libs/http/index.ts +1 -0
  61. package/src/libs/index.ts +4 -0
  62. package/src/libs/indexer/index.ts +1 -0
  63. package/src/libs/indexer/indexer.ts +240 -0
  64. package/src/libs/indexer/types.ts +8 -0
  65. package/src/libs/query/account.ts +39 -0
  66. package/src/libs/query/circuit.ts +99 -0
  67. package/src/libs/query/index.ts +6 -0
  68. package/src/libs/query/operator.ts +263 -0
  69. package/src/libs/query/proof.ts +76 -0
  70. package/src/libs/query/round.ts +533 -0
  71. package/src/libs/query/transaction.ts +204 -0
  72. package/src/maci.ts +313 -0
  73. package/src/types/index.ts +301 -0
  74. package/src/utils/index.ts +44 -0
@@ -0,0 +1,330 @@
1
+ import { Secp256k1HdWallet } from '@cosmjs/launchpad';
2
+ import { DirectSecp256k1HdWallet, OfflineSigner } from '@cosmjs/proto-signing';
3
+ import {
4
+ GasPrice,
5
+ SigningStargateClient,
6
+ SigningStargateClientOptions,
7
+ } from '@cosmjs/stargate';
8
+ import {
9
+ SigningCosmWasmClient,
10
+ SigningCosmWasmClientOptions,
11
+ } from '@cosmjs/cosmwasm-stargate';
12
+ import { MaciClient } from './ts/Maci.client';
13
+ import { AMaciClient } from './ts/AMaci.client';
14
+ import { RegistryClient } from './ts/Registry.client';
15
+ import { ContractParams } from '../../types';
16
+ import {
17
+ createAMaciClientBy,
18
+ createContractClientByWallet,
19
+ createMaciClientBy,
20
+ createOracleMaciClientBy,
21
+ createRegistryClientBy,
22
+ } from './config';
23
+ import { Whitelist } from './ts/Registry.types';
24
+ import { getDefaultParams } from '../const';
25
+ import {
26
+ CreateAMaciRoundParams,
27
+ CreateMaciRoundParams,
28
+ CreateOracleMaciRoundParams,
29
+ MaciCertSystemType,
30
+ MaciRoundType,
31
+ } from './types';
32
+ import { getContractParams, parsePubkey } from './utils';
33
+ import { QTR_LIB } from './vars';
34
+
35
+ export const prefix = 'dora';
36
+
37
+ export class Contract {
38
+ public rpcEndpoint: string;
39
+ public registryAddress: string;
40
+ public maciCodeId: number;
41
+ public oracleCodeId: number;
42
+
43
+ constructor({
44
+ rpcEndpoint,
45
+ registryAddress,
46
+ maciCodeId,
47
+ oracleCodeId,
48
+ }: ContractParams) {
49
+ this.rpcEndpoint = rpcEndpoint;
50
+ this.registryAddress = registryAddress;
51
+ this.maciCodeId = maciCodeId;
52
+ this.oracleCodeId = oracleCodeId;
53
+ }
54
+
55
+ async createAMaciRound({
56
+ signer,
57
+ startVoting,
58
+ endVoting,
59
+ operator,
60
+ whitelist,
61
+ title,
62
+ description,
63
+ link,
64
+ maxVoter,
65
+ maxOption,
66
+ voiceCreditAmount,
67
+ circuitType,
68
+ preDeactivateRoot,
69
+ }: CreateAMaciRoundParams) {
70
+ const start_time = (startVoting.getTime() * 10 ** 6).toString();
71
+ const end_time = (endVoting.getTime() * 10 ** 6).toString();
72
+
73
+ const client = await createRegistryClientBy({
74
+ rpcEndpoint: this.rpcEndpoint,
75
+ wallet: signer,
76
+ contractAddress: this.registryAddress,
77
+ });
78
+
79
+ preDeactivateRoot = preDeactivateRoot || '0';
80
+ const res = await client.createRound({
81
+ operator,
82
+ preDeactivateRoot,
83
+ voiceCreditAmount,
84
+ whitelist,
85
+ roundInfo: {
86
+ title,
87
+ description: description || '',
88
+ link: link || '',
89
+ },
90
+ votingTime: {
91
+ start_time,
92
+ end_time,
93
+ },
94
+ maxVoter,
95
+ maxOption,
96
+ certificationSystem: '0',
97
+ circuitType,
98
+ });
99
+ let contractAddress = '';
100
+ res.events.map((event) => {
101
+ if (event.type === 'wasm') {
102
+ let actionEvent = event.attributes.find(
103
+ (attr) => attr.key === 'action'
104
+ )!;
105
+ if (actionEvent.value === 'created_round') {
106
+ contractAddress = event.attributes
107
+ .find((attr) => attr.key === 'round_addr')!
108
+ .value.toString();
109
+ }
110
+ }
111
+ });
112
+ console.log(`Deploy tx: ${res.transactionHash} - ${contractAddress}`);
113
+ return contractAddress;
114
+ }
115
+
116
+ async createMaciRound({
117
+ signer,
118
+ operatorPubkey,
119
+ startVoting,
120
+ endVoting,
121
+ whitelist,
122
+ title,
123
+ description,
124
+ link,
125
+ maxVoter,
126
+ maxOption,
127
+ circuitType,
128
+ certSystemType,
129
+ }: CreateMaciRoundParams) {
130
+ const start_time = (startVoting.getTime() * 10 ** 6).toString();
131
+ const end_time = (endVoting.getTime() * 10 ** 6).toString();
132
+ const [{ address }] = await signer.getAccounts();
133
+ const client = await createContractClientByWallet(this.rpcEndpoint, signer);
134
+ const { x: operatorPubkeyX, y: operatorPubkeyY } =
135
+ parsePubkey(operatorPubkey);
136
+ const {
137
+ parameters,
138
+ groth16ProcessVkey,
139
+ groth16TallyVkey,
140
+ plonkProcessVkey,
141
+ plonkTallyVkey,
142
+ maciVoteType,
143
+ maciCertSystem,
144
+ } = getContractParams(
145
+ MaciRoundType.MACI,
146
+ circuitType,
147
+ certSystemType,
148
+ maxVoter,
149
+ maxOption
150
+ );
151
+ const instantiateResponse = await client.instantiate(
152
+ address,
153
+ this.maciCodeId,
154
+ {
155
+ round_info: { title, description, link },
156
+ voting_time: {
157
+ start_time,
158
+ end_time,
159
+ },
160
+ parameters,
161
+ coordinator: {
162
+ x: operatorPubkeyX,
163
+ y: operatorPubkeyY,
164
+ },
165
+ groth16_process_vkey: groth16ProcessVkey,
166
+ groth16_tally_vkey: groth16TallyVkey,
167
+ plonk_process_vkey: plonkProcessVkey,
168
+ plonk_tally_vkey: plonkTallyVkey,
169
+ max_vote_options: maxOption,
170
+ whitelist,
171
+ circuit_type: maciVoteType,
172
+ certification_system: maciCertSystem,
173
+ qtr_lib: QTR_LIB,
174
+ },
175
+ 'MACI',
176
+ 'auto'
177
+ );
178
+
179
+ return instantiateResponse;
180
+ }
181
+
182
+ async createOracleMaciRound({
183
+ signer,
184
+ operatorPubkey,
185
+ startVoting,
186
+ endVoting,
187
+ title,
188
+ description,
189
+ link,
190
+ maxVoter,
191
+ maxOption,
192
+ circuitType,
193
+ whitelistBackendPubkey,
194
+ whitelistEcosystem,
195
+ whitelistSnapshotHeight,
196
+ whitelistVotingPowerArgs,
197
+ feegrantOperator,
198
+ }: CreateOracleMaciRoundParams) {
199
+ const start_time = (startVoting.getTime() * 1_000_000).toString();
200
+ const end_time = (endVoting.getTime() * 1_000_000).toString();
201
+ const [{ address }] = await signer.getAccounts();
202
+ const client = await createContractClientByWallet(this.rpcEndpoint, signer);
203
+ const { x: operatorPubkeyX, y: operatorPubkeyY } =
204
+ parsePubkey(operatorPubkey);
205
+ const {
206
+ parameters,
207
+ groth16ProcessVkey,
208
+ groth16TallyVkey,
209
+ plonkProcessVkey,
210
+ plonkTallyVkey,
211
+ maciVoteType,
212
+ maciCertSystem,
213
+ } = getContractParams(
214
+ MaciRoundType.ORACLE_MACI,
215
+ circuitType,
216
+ MaciCertSystemType.GROTH16,
217
+ maxVoter,
218
+ maxOption
219
+ );
220
+ const instantiateResponse = await client.instantiate(
221
+ address,
222
+ this.oracleCodeId,
223
+ {
224
+ round_info: { title, description: description || '', link: link || '' },
225
+ voting_time: {
226
+ start_time,
227
+ end_time,
228
+ },
229
+ parameters,
230
+ coordinator: {
231
+ x: operatorPubkeyX,
232
+ y: operatorPubkeyY,
233
+ },
234
+ groth16_process_vkey: groth16ProcessVkey,
235
+ groth16_tally_vkey: groth16TallyVkey,
236
+ plonk_process_vkey: plonkProcessVkey,
237
+ plonk_tally_vkey: plonkTallyVkey,
238
+ max_vote_options: maxOption,
239
+ whitelist_backend_pubkey: whitelistBackendPubkey,
240
+ whitelist_ecosystem: whitelistEcosystem,
241
+ whitelist_snapshot_height: whitelistSnapshotHeight,
242
+ whitelist_voting_power_args: whitelistVotingPowerArgs,
243
+ circuit_type: maciVoteType,
244
+ certification_system: maciCertSystem,
245
+ qtr_lib: QTR_LIB,
246
+ feegrant_operator: feegrantOperator,
247
+ },
248
+ '[Oracle MACI]' + title,
249
+ 'auto'
250
+ );
251
+
252
+ // console.log(
253
+ // `Deploy tx: ${instantiateResponse.transactionHash} - ${instantiateResponse.contractAddress} `
254
+ // );
255
+ return instantiateResponse;
256
+ }
257
+
258
+ async queryRoundInfo({
259
+ signer,
260
+ roundAddress,
261
+ }: {
262
+ signer: OfflineSigner;
263
+ roundAddress: string;
264
+ }) {
265
+ const client = await createMaciClientBy({
266
+ rpcEndpoint: this.rpcEndpoint,
267
+ wallet: signer,
268
+ contractAddress: roundAddress,
269
+ });
270
+ const roundInfo = await client.getRoundInfo();
271
+ return roundInfo;
272
+ }
273
+
274
+ async oracleMaciClient({
275
+ signer,
276
+ contractAddress,
277
+ }: {
278
+ signer: OfflineSigner;
279
+ contractAddress: string;
280
+ }) {
281
+ const client = await createOracleMaciClientBy({
282
+ rpcEndpoint: this.rpcEndpoint,
283
+ wallet: signer,
284
+ contractAddress,
285
+ });
286
+ return client;
287
+ }
288
+
289
+ async registryClient({
290
+ signer,
291
+ contractAddress,
292
+ }: {
293
+ signer: OfflineSigner;
294
+ contractAddress: string;
295
+ }) {
296
+ return createRegistryClientBy({
297
+ rpcEndpoint: this.rpcEndpoint,
298
+ wallet: signer,
299
+ contractAddress,
300
+ });
301
+ }
302
+
303
+ async maciClient({
304
+ signer,
305
+ contractAddress,
306
+ }: {
307
+ signer: OfflineSigner;
308
+ contractAddress: string;
309
+ }) {
310
+ return createMaciClientBy({
311
+ rpcEndpoint: this.rpcEndpoint,
312
+ wallet: signer,
313
+ contractAddress,
314
+ });
315
+ }
316
+
317
+ async amaciClient({
318
+ signer,
319
+ contractAddress,
320
+ }: {
321
+ signer: OfflineSigner;
322
+ contractAddress: string;
323
+ }) {
324
+ return createAMaciClientBy({
325
+ rpcEndpoint: this.rpcEndpoint,
326
+ wallet: signer,
327
+ contractAddress,
328
+ });
329
+ }
330
+ }
@@ -0,0 +1 @@
1
+ export { Contract } from './contract';