@dorafactory/maci-sdk 0.0.34 → 0.0.36
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.
- package/dist/index.d.ts +14 -2244
- package/dist/index.js +748 -363
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +722 -365
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +118 -0
- package/dist/libs/contract/config.d.ts +29 -0
- package/dist/libs/contract/contract.d.ts +57 -0
- package/dist/libs/contract/index.d.ts +1 -0
- package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
- package/dist/libs/contract/ts/AMaci.types.d.ts +221 -0
- package/dist/libs/contract/ts/Maci.client.d.ts +180 -0
- package/dist/libs/contract/ts/Maci.types.d.ts +226 -0
- package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
- package/dist/libs/contract/ts/OracleMaci.types.d.ts +263 -0
- package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
- package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
- package/dist/libs/contract/types.d.ts +39 -0
- package/dist/libs/contract/utils.d.ts +63 -0
- package/dist/libs/contract/vars.d.ts +63 -0
- package/dist/libs/crypto/babyjub.d.ts +73 -0
- package/dist/libs/crypto/bigintUtils.d.ts +6 -0
- package/dist/libs/crypto/constants.d.ts +3 -0
- package/dist/libs/crypto/hashing.d.ts +69 -0
- package/dist/libs/crypto/index.d.ts +9 -0
- package/dist/libs/crypto/keys.d.ts +74 -0
- package/dist/libs/crypto/sign.d.ts +9 -0
- package/dist/libs/crypto/tree.d.ts +23 -0
- package/dist/libs/crypto/types.d.ts +55 -0
- package/dist/libs/errors/index.d.ts +28 -0
- package/dist/libs/errors/types.d.ts +19 -0
- package/dist/libs/http/http.d.ts +16 -0
- package/dist/libs/http/index.d.ts +1 -0
- package/dist/libs/index.d.ts +7 -0
- package/dist/libs/indexer/index.d.ts +1 -0
- package/dist/libs/indexer/indexer.d.ts +152 -0
- package/dist/libs/indexer/types.d.ts +7 -0
- package/dist/libs/maci/index.d.ts +1 -0
- package/dist/libs/maci/maci.d.ts +182 -0
- package/dist/libs/maci/types.d.ts +6 -0
- package/dist/libs/oracle-certificate/index.d.ts +1 -0
- package/dist/libs/oracle-certificate/oracle-certificate.d.ts +9 -0
- package/dist/libs/oracle-certificate/types.d.ts +40 -0
- package/dist/libs/query/account.d.ts +7 -0
- package/dist/libs/query/circuit.d.ts +8 -0
- package/dist/libs/query/event.d.ts +7 -0
- package/dist/libs/query/index.d.ts +7 -0
- package/dist/libs/query/operator.d.ts +11 -0
- package/dist/libs/query/proof.d.ts +7 -0
- package/dist/libs/query/round.d.ts +18 -0
- package/dist/libs/query/transaction.d.ts +9 -0
- package/dist/maci.d.ts +190 -0
- package/dist/types/index.d.ts +383 -0
- package/dist/utils/index.d.ts +7 -0
- package/package.json +18 -24
- package/src/index.ts +1 -3
- package/src/libs/contract/contract.ts +14 -13
- package/src/libs/contract/types.ts +3 -3
- package/src/libs/crypto/babyjub.ts +132 -0
- package/src/libs/crypto/bigintUtils.ts +31 -0
- package/src/libs/crypto/constants.ts +22 -0
- package/src/libs/crypto/hashing.ts +167 -0
- package/src/libs/crypto/index.ts +9 -0
- package/src/libs/{circom/circomlib.ts → crypto/keys.ts} +104 -114
- package/src/libs/crypto/sign.ts +91 -0
- package/src/libs/crypto/tree.ts +176 -0
- package/src/libs/crypto/types.ts +101 -0
- package/src/libs/index.ts +1 -1
- package/src/libs/maci/maci.ts +28 -29
- package/src/maci.ts +140 -100
- package/src/types/index.ts +7 -0
- package/src/utils/index.ts +22 -22
- package/dist/browser.d.mts +0 -2243
- package/dist/browser.d.ts +0 -2243
- package/dist/browser.js +0 -31635
- package/dist/browser.js.map +0 -1
- package/dist/browser.mjs +0 -31646
- package/dist/browser.mjs.map +0 -1
- package/dist/index.d.mts +0 -2244
- package/src/browser.ts +0 -17
- package/src/libs/circom/index.ts +0 -98
- package/src/libs/circom/types.ts +0 -8
- package/src/polyfills/browser-polyfills.ts +0 -9
package/src/maci.ts
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
ClientParams,
|
|
4
|
-
RoundResponse,
|
|
5
|
-
RoundsResponse,
|
|
6
|
-
OperatorResponse,
|
|
7
|
-
OperatorsResponse,
|
|
8
|
-
CircuitResponse,
|
|
9
|
-
TransactionResponse,
|
|
10
|
-
TransactionsResponse,
|
|
11
|
-
CircuitsResponse,
|
|
12
|
-
ProofResponse,
|
|
13
|
-
SelectiveRoundResponse,
|
|
14
|
-
CertificateEcosystem,
|
|
15
|
-
ErrorResponse,
|
|
16
|
-
RoundType,
|
|
17
|
-
} from './types';
|
|
18
|
-
import {
|
|
19
|
-
Http,
|
|
20
|
-
Indexer,
|
|
21
|
-
Contract,
|
|
22
|
-
OracleCertificate,
|
|
23
|
-
Circom,
|
|
24
|
-
MACI,
|
|
25
|
-
} from './libs';
|
|
1
|
+
import { ClientParams, CertificateEcosystem } from './types';
|
|
2
|
+
import { Http, Indexer, Contract, OracleCertificate, MACI } from './libs';
|
|
26
3
|
import { getDefaultParams } from './libs/const';
|
|
27
4
|
import {
|
|
28
5
|
CreateAMaciRoundParams,
|
|
@@ -30,17 +7,23 @@ import {
|
|
|
30
7
|
CreateOracleMaciRoundParams,
|
|
31
8
|
} from './libs/contract/types';
|
|
32
9
|
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
33
|
-
import {
|
|
34
|
-
|
|
10
|
+
import {
|
|
11
|
+
genKeypair,
|
|
12
|
+
genKeypairFromSign,
|
|
13
|
+
Keypair,
|
|
14
|
+
packPubKey,
|
|
15
|
+
PubKey,
|
|
16
|
+
unpackPubKey,
|
|
17
|
+
} from './libs/crypto';
|
|
35
18
|
import { OracleWhitelistConfig } from './libs/contract/ts/OracleMaci.types';
|
|
36
19
|
import { SignatureResponse } from './libs/oracle-certificate/types';
|
|
37
|
-
import { StdFee } from '@cosmjs/stargate';
|
|
38
20
|
|
|
39
21
|
/**
|
|
40
22
|
* @class MaciClient
|
|
41
23
|
* @description This class is used to interact with Maci Client.
|
|
42
24
|
*/
|
|
43
25
|
export class MaciClient {
|
|
26
|
+
public network: 'mainnet' | 'testnet';
|
|
44
27
|
public rpcEndpoint: string;
|
|
45
28
|
public restEndpoint: string;
|
|
46
29
|
public apiEndpoint: string;
|
|
@@ -55,15 +38,18 @@ export class MaciClient {
|
|
|
55
38
|
public http: Http;
|
|
56
39
|
public indexer: Indexer;
|
|
57
40
|
public contract: Contract;
|
|
58
|
-
public circom: Circom;
|
|
59
41
|
public oracleCertificate: OracleCertificate;
|
|
60
42
|
public maci: MACI;
|
|
43
|
+
public maciKeypair: Keypair;
|
|
44
|
+
|
|
45
|
+
public signer: OfflineSigner;
|
|
61
46
|
|
|
62
47
|
/**
|
|
63
48
|
* @constructor
|
|
64
49
|
* @param {ClientParams} params - The parameters for the Maci Client instance.
|
|
65
50
|
*/
|
|
66
51
|
constructor({
|
|
52
|
+
signer,
|
|
67
53
|
network,
|
|
68
54
|
rpcEndpoint,
|
|
69
55
|
restEndpoint,
|
|
@@ -76,7 +62,10 @@ export class MaciClient {
|
|
|
76
62
|
feegrantOperator,
|
|
77
63
|
whitelistBackendPubkey,
|
|
78
64
|
certificateApiEndpoint,
|
|
65
|
+
maciKeypair,
|
|
79
66
|
}: ClientParams) {
|
|
67
|
+
this.signer = signer;
|
|
68
|
+
this.network = network;
|
|
80
69
|
const defaultParams = getDefaultParams(network);
|
|
81
70
|
|
|
82
71
|
this.rpcEndpoint = rpcEndpoint || defaultParams.rpcEndpoint;
|
|
@@ -91,6 +80,7 @@ export class MaciClient {
|
|
|
91
80
|
feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
92
81
|
this.whitelistBackendPubkey =
|
|
93
82
|
whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
|
|
83
|
+
this.maciKeypair = maciKeypair ?? genKeypair();
|
|
94
84
|
|
|
95
85
|
this.http = new Http(
|
|
96
86
|
this.apiEndpoint,
|
|
@@ -112,26 +102,51 @@ export class MaciClient {
|
|
|
112
102
|
feegrantOperator: this.feegrantOperator,
|
|
113
103
|
whitelistBackendPubkey: this.whitelistBackendPubkey,
|
|
114
104
|
});
|
|
115
|
-
this.circom = new Circom({ network });
|
|
116
105
|
this.oracleCertificate = new OracleCertificate({
|
|
117
106
|
certificateApiEndpoint: this.certificateApiEndpoint,
|
|
118
107
|
http: this.http,
|
|
119
108
|
});
|
|
120
109
|
this.maci = new MACI({
|
|
121
|
-
circom: this.circom,
|
|
122
110
|
contract: this.contract,
|
|
123
111
|
indexer: this.indexer,
|
|
124
112
|
oracleCertificate: this.oracleCertificate,
|
|
113
|
+
maciKeypair: this.maciKeypair,
|
|
125
114
|
});
|
|
126
115
|
}
|
|
127
116
|
|
|
117
|
+
getSigner(signer?: OfflineSigner) {
|
|
118
|
+
return signer || this.signer;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getMaciKeypair() {
|
|
122
|
+
return this.maciKeypair;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getMaciPubkey() {
|
|
126
|
+
return this.packMaciPubkey(this.maciKeypair.pubKey);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
packMaciPubkey(pubkey?: PubKey) {
|
|
130
|
+
return packPubKey(pubkey || this.maciKeypair.pubKey);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
unpackMaciPubkey(pubkey: bigint | string) {
|
|
134
|
+
return unpackPubKey(BigInt(pubkey));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getAddress(signer?: OfflineSigner) {
|
|
138
|
+
const [{ address }] = await this.getSigner(signer).getAccounts();
|
|
139
|
+
return address;
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
async oracleMaciClient({
|
|
129
143
|
signer,
|
|
130
144
|
contractAddress,
|
|
131
145
|
}: {
|
|
132
|
-
signer
|
|
146
|
+
signer?: OfflineSigner;
|
|
133
147
|
contractAddress: string;
|
|
134
148
|
}) {
|
|
149
|
+
signer = this.getSigner(signer);
|
|
135
150
|
return await this.contract.oracleMaciClient({
|
|
136
151
|
signer,
|
|
137
152
|
contractAddress,
|
|
@@ -142,9 +157,10 @@ export class MaciClient {
|
|
|
142
157
|
signer,
|
|
143
158
|
contractAddress,
|
|
144
159
|
}: {
|
|
145
|
-
signer
|
|
160
|
+
signer?: OfflineSigner;
|
|
146
161
|
contractAddress: string;
|
|
147
162
|
}) {
|
|
163
|
+
signer = this.getSigner(signer);
|
|
148
164
|
return await this.contract.registryClient({ signer, contractAddress });
|
|
149
165
|
}
|
|
150
166
|
|
|
@@ -152,9 +168,10 @@ export class MaciClient {
|
|
|
152
168
|
signer,
|
|
153
169
|
contractAddress,
|
|
154
170
|
}: {
|
|
155
|
-
signer
|
|
171
|
+
signer?: OfflineSigner;
|
|
156
172
|
contractAddress: string;
|
|
157
173
|
}) {
|
|
174
|
+
signer = this.getSigner(signer);
|
|
158
175
|
return await this.contract.maciClient({ signer, contractAddress });
|
|
159
176
|
}
|
|
160
177
|
|
|
@@ -162,22 +179,46 @@ export class MaciClient {
|
|
|
162
179
|
signer,
|
|
163
180
|
contractAddress,
|
|
164
181
|
}: {
|
|
165
|
-
signer
|
|
182
|
+
signer?: OfflineSigner;
|
|
166
183
|
contractAddress: string;
|
|
167
184
|
}) {
|
|
185
|
+
signer = this.getSigner(signer);
|
|
168
186
|
return await this.contract.amaciClient({ signer, contractAddress });
|
|
169
187
|
}
|
|
170
188
|
|
|
171
189
|
async createAMaciRound(params: CreateAMaciRoundParams) {
|
|
172
|
-
return await this.contract.createAMaciRound(
|
|
190
|
+
return await this.contract.createAMaciRound({
|
|
191
|
+
signer: this.getSigner(),
|
|
192
|
+
...params,
|
|
193
|
+
});
|
|
173
194
|
}
|
|
174
195
|
|
|
175
196
|
async createMaciRound(params: CreateMaciRoundParams) {
|
|
176
|
-
return await this.contract.createMaciRound(
|
|
197
|
+
return await this.contract.createMaciRound({
|
|
198
|
+
signer: this.getSigner(),
|
|
199
|
+
...params,
|
|
200
|
+
});
|
|
177
201
|
}
|
|
178
202
|
|
|
179
203
|
async createOracleMaciRound(params: CreateOracleMaciRoundParams) {
|
|
180
|
-
return await this.contract.createOracleMaciRound(
|
|
204
|
+
return await this.contract.createOracleMaciRound({
|
|
205
|
+
signer: this.getSigner(),
|
|
206
|
+
...params,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async genKeypairFromSign({
|
|
211
|
+
signer,
|
|
212
|
+
address,
|
|
213
|
+
}: {
|
|
214
|
+
signer?: OfflineSigner;
|
|
215
|
+
address?: string;
|
|
216
|
+
} = {}) {
|
|
217
|
+
return await genKeypairFromSign({
|
|
218
|
+
signer: this.getSigner(signer),
|
|
219
|
+
address,
|
|
220
|
+
network: this.network,
|
|
221
|
+
});
|
|
181
222
|
}
|
|
182
223
|
|
|
183
224
|
async getStateIdxInc({
|
|
@@ -185,12 +226,12 @@ export class MaciClient {
|
|
|
185
226
|
address,
|
|
186
227
|
contractAddress,
|
|
187
228
|
}: {
|
|
188
|
-
signer
|
|
189
|
-
address
|
|
229
|
+
signer?: OfflineSigner;
|
|
230
|
+
address?: string;
|
|
190
231
|
contractAddress: string;
|
|
191
232
|
}) {
|
|
192
233
|
return await this.maci.getStateIdxInc({
|
|
193
|
-
signer,
|
|
234
|
+
signer: this.getSigner(signer),
|
|
194
235
|
address,
|
|
195
236
|
contractAddress,
|
|
196
237
|
});
|
|
@@ -201,12 +242,12 @@ export class MaciClient {
|
|
|
201
242
|
stateIdx,
|
|
202
243
|
contractAddress,
|
|
203
244
|
}: {
|
|
204
|
-
signer
|
|
245
|
+
signer?: OfflineSigner;
|
|
205
246
|
stateIdx: number;
|
|
206
247
|
contractAddress: string;
|
|
207
248
|
}) {
|
|
208
249
|
return await this.maci.getVoiceCreditBalance({
|
|
209
|
-
signer,
|
|
250
|
+
signer: this.getSigner(signer),
|
|
210
251
|
stateIdx,
|
|
211
252
|
contractAddress,
|
|
212
253
|
});
|
|
@@ -226,12 +267,15 @@ export class MaciClient {
|
|
|
226
267
|
}
|
|
227
268
|
|
|
228
269
|
async feegrantAllowance({
|
|
270
|
+
signer,
|
|
229
271
|
address,
|
|
230
272
|
contractAddress,
|
|
231
273
|
}: {
|
|
232
|
-
|
|
274
|
+
signer?: OfflineSigner;
|
|
275
|
+
address?: string;
|
|
233
276
|
contractAddress: string;
|
|
234
277
|
}) {
|
|
278
|
+
address = await this.getAddress(signer);
|
|
235
279
|
return await this.maci.feegrantAllowance({
|
|
236
280
|
address,
|
|
237
281
|
contractAddress,
|
|
@@ -239,12 +283,15 @@ export class MaciClient {
|
|
|
239
283
|
}
|
|
240
284
|
|
|
241
285
|
async hasFeegrant({
|
|
286
|
+
signer,
|
|
242
287
|
address,
|
|
243
288
|
contractAddress,
|
|
244
289
|
}: {
|
|
245
|
-
|
|
290
|
+
signer?: OfflineSigner;
|
|
291
|
+
address?: string;
|
|
246
292
|
contractAddress: string;
|
|
247
293
|
}): Promise<boolean> {
|
|
294
|
+
address = await this.getAddress(signer);
|
|
248
295
|
return await this.maci.hasFeegrant({
|
|
249
296
|
address,
|
|
250
297
|
contractAddress,
|
|
@@ -258,12 +305,19 @@ export class MaciClient {
|
|
|
258
305
|
certificate,
|
|
259
306
|
mode = 'maci',
|
|
260
307
|
}: {
|
|
261
|
-
signer
|
|
262
|
-
address
|
|
308
|
+
signer?: OfflineSigner;
|
|
309
|
+
address?: string;
|
|
263
310
|
contractAddress: string;
|
|
264
|
-
certificate?:
|
|
311
|
+
certificate?: {
|
|
312
|
+
signature: string;
|
|
313
|
+
amount: string;
|
|
314
|
+
};
|
|
265
315
|
mode?: 'maci' | 'amaci';
|
|
266
316
|
}): Promise<string> {
|
|
317
|
+
signer = this.getSigner(signer);
|
|
318
|
+
if (!address) {
|
|
319
|
+
address = await this.getAddress(signer);
|
|
320
|
+
}
|
|
267
321
|
return await this.maci.queryWhitelistBalanceOf({
|
|
268
322
|
signer,
|
|
269
323
|
address,
|
|
@@ -278,10 +332,14 @@ export class MaciClient {
|
|
|
278
332
|
address,
|
|
279
333
|
contractAddress,
|
|
280
334
|
}: {
|
|
281
|
-
signer
|
|
282
|
-
address
|
|
335
|
+
signer?: OfflineSigner;
|
|
336
|
+
address?: string;
|
|
283
337
|
contractAddress: string;
|
|
284
338
|
}) {
|
|
339
|
+
signer = this.getSigner(signer);
|
|
340
|
+
if (!address) {
|
|
341
|
+
address = await this.getAddress(signer);
|
|
342
|
+
}
|
|
285
343
|
return await this.maci.isWhitelisted({
|
|
286
344
|
signer,
|
|
287
345
|
address,
|
|
@@ -293,11 +351,11 @@ export class MaciClient {
|
|
|
293
351
|
signer,
|
|
294
352
|
contractAddress,
|
|
295
353
|
}: {
|
|
296
|
-
signer
|
|
354
|
+
signer?: OfflineSigner;
|
|
297
355
|
contractAddress: string;
|
|
298
356
|
}): Promise<OracleWhitelistConfig> {
|
|
299
357
|
return await this.maci.getOracleWhitelistConfig({
|
|
300
|
-
signer,
|
|
358
|
+
signer: this.getSigner(signer),
|
|
301
359
|
contractAddress,
|
|
302
360
|
});
|
|
303
361
|
}
|
|
@@ -366,13 +424,13 @@ export class MaciClient {
|
|
|
366
424
|
address,
|
|
367
425
|
contractAddress,
|
|
368
426
|
}: {
|
|
369
|
-
signer
|
|
427
|
+
signer?: OfflineSigner;
|
|
370
428
|
ecosystem: CertificateEcosystem;
|
|
371
|
-
address
|
|
429
|
+
address?: string;
|
|
372
430
|
contractAddress: string;
|
|
373
431
|
}): Promise<SignatureResponse> {
|
|
374
432
|
return await this.maci.requestOracleCertificate({
|
|
375
|
-
signer,
|
|
433
|
+
signer: this.getSigner(signer),
|
|
376
434
|
ecosystem,
|
|
377
435
|
address,
|
|
378
436
|
contractAddress,
|
|
@@ -383,14 +441,14 @@ export class MaciClient {
|
|
|
383
441
|
signer,
|
|
384
442
|
address,
|
|
385
443
|
contractAddress,
|
|
386
|
-
|
|
444
|
+
maciKeypair,
|
|
387
445
|
oracleCertificate,
|
|
388
446
|
gasStation = false,
|
|
389
447
|
}: {
|
|
390
|
-
signer
|
|
391
|
-
address
|
|
448
|
+
signer?: OfflineSigner;
|
|
449
|
+
address?: string;
|
|
392
450
|
contractAddress: string;
|
|
393
|
-
|
|
451
|
+
maciKeypair?: Keypair;
|
|
394
452
|
oracleCertificate?: {
|
|
395
453
|
amount: string;
|
|
396
454
|
signature: string;
|
|
@@ -398,10 +456,10 @@ export class MaciClient {
|
|
|
398
456
|
gasStation?: boolean;
|
|
399
457
|
}) {
|
|
400
458
|
return await this.maci.signup({
|
|
401
|
-
signer,
|
|
459
|
+
signer: this.getSigner(signer),
|
|
402
460
|
address,
|
|
403
461
|
contractAddress,
|
|
404
|
-
|
|
462
|
+
maciKeypair,
|
|
405
463
|
oracleCertificate,
|
|
406
464
|
gasStation,
|
|
407
465
|
});
|
|
@@ -414,54 +472,29 @@ export class MaciClient {
|
|
|
414
472
|
contractAddress,
|
|
415
473
|
selectedOptions,
|
|
416
474
|
operatorCoordPubKey,
|
|
417
|
-
|
|
475
|
+
maciKeypair,
|
|
418
476
|
gasStation = false,
|
|
419
477
|
}: {
|
|
420
|
-
signer
|
|
421
|
-
address
|
|
478
|
+
signer?: OfflineSigner;
|
|
479
|
+
address?: string;
|
|
422
480
|
stateIdx: number;
|
|
423
481
|
contractAddress: string;
|
|
424
482
|
selectedOptions: {
|
|
425
483
|
idx: number;
|
|
426
484
|
vc: number;
|
|
427
485
|
}[];
|
|
428
|
-
operatorCoordPubKey:
|
|
429
|
-
|
|
486
|
+
operatorCoordPubKey: PubKey;
|
|
487
|
+
maciKeypair?: Keypair;
|
|
430
488
|
gasStation?: boolean;
|
|
431
489
|
}) {
|
|
432
490
|
return await this.maci.vote({
|
|
433
|
-
signer,
|
|
491
|
+
signer: this.getSigner(signer),
|
|
434
492
|
address,
|
|
435
493
|
stateIdx,
|
|
436
494
|
contractAddress,
|
|
437
495
|
selectedOptions,
|
|
438
496
|
operatorCoordPubKey,
|
|
439
|
-
|
|
440
|
-
gasStation,
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
async publishMessage({
|
|
445
|
-
client,
|
|
446
|
-
address,
|
|
447
|
-
payload,
|
|
448
|
-
contractAddress,
|
|
449
|
-
gasStation,
|
|
450
|
-
}: {
|
|
451
|
-
client: SigningCosmWasmClient;
|
|
452
|
-
address: string;
|
|
453
|
-
payload: {
|
|
454
|
-
msg: bigint[];
|
|
455
|
-
encPubkeys: PublicKey;
|
|
456
|
-
}[];
|
|
457
|
-
contractAddress: string;
|
|
458
|
-
gasStation: boolean;
|
|
459
|
-
}) {
|
|
460
|
-
return await this.maci.publishMessage({
|
|
461
|
-
client,
|
|
462
|
-
address,
|
|
463
|
-
payload,
|
|
464
|
-
contractAddress,
|
|
497
|
+
maciKeypair,
|
|
465
498
|
gasStation,
|
|
466
499
|
});
|
|
467
500
|
}
|
|
@@ -470,9 +503,10 @@ export class MaciClient {
|
|
|
470
503
|
signer,
|
|
471
504
|
contractAddress,
|
|
472
505
|
}: {
|
|
473
|
-
signer
|
|
506
|
+
signer?: OfflineSigner;
|
|
474
507
|
contractAddress: string;
|
|
475
508
|
}) {
|
|
509
|
+
signer = this.getSigner(signer);
|
|
476
510
|
return await this.maci.claimAMaciRound({
|
|
477
511
|
signer,
|
|
478
512
|
contractAddress,
|
|
@@ -489,13 +523,16 @@ export class MaciClient {
|
|
|
489
523
|
address,
|
|
490
524
|
amount,
|
|
491
525
|
}: {
|
|
492
|
-
signer
|
|
526
|
+
signer?: OfflineSigner;
|
|
493
527
|
contractAddress: string;
|
|
494
|
-
address
|
|
528
|
+
address?: string;
|
|
495
529
|
amount: string;
|
|
496
530
|
}) {
|
|
531
|
+
if (!address) {
|
|
532
|
+
address = await this.getAddress(signer);
|
|
533
|
+
}
|
|
497
534
|
return await this.maci.batchGrantWithBond({
|
|
498
|
-
signer,
|
|
535
|
+
signer: this.getSigner(signer),
|
|
499
536
|
contractAddress,
|
|
500
537
|
address,
|
|
501
538
|
amount,
|
|
@@ -507,12 +544,15 @@ export class MaciClient {
|
|
|
507
544
|
contractAddress,
|
|
508
545
|
address,
|
|
509
546
|
}: {
|
|
510
|
-
signer
|
|
547
|
+
signer?: OfflineSigner;
|
|
511
548
|
contractAddress: string;
|
|
512
|
-
address
|
|
549
|
+
address?: string;
|
|
513
550
|
}) {
|
|
551
|
+
if (!address) {
|
|
552
|
+
address = await this.getAddress(signer);
|
|
553
|
+
}
|
|
514
554
|
return await this.maci.batchRevokeWithdraw({
|
|
515
|
-
signer,
|
|
555
|
+
signer: this.getSigner(signer),
|
|
516
556
|
contractAddress,
|
|
517
557
|
address,
|
|
518
558
|
});
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
2
|
+
import { Keypair } from '../libs/crypto';
|
|
1
3
|
import { FetchOptions } from '../libs/http/http';
|
|
2
4
|
export type * from '../libs/contract/types';
|
|
5
|
+
export type * from '../libs/crypto/types';
|
|
3
6
|
|
|
4
7
|
export enum MaciCircuitType {
|
|
5
8
|
IP1V = '0',
|
|
@@ -20,6 +23,7 @@ export enum MaciRoundType {
|
|
|
20
23
|
export type CertificateEcosystem = 'cosmoshub' | 'doravota';
|
|
21
24
|
|
|
22
25
|
export type ClientParams = {
|
|
26
|
+
signer: OfflineSigner;
|
|
23
27
|
network: 'mainnet' | 'testnet';
|
|
24
28
|
rpcEndpoint?: string;
|
|
25
29
|
restEndpoint?: string;
|
|
@@ -32,6 +36,9 @@ export type ClientParams = {
|
|
|
32
36
|
defaultOptions?: FetchOptions;
|
|
33
37
|
feegrantOperator?: string;
|
|
34
38
|
whitelistBackendPubkey?: string;
|
|
39
|
+
maciKeypair?: Keypair;
|
|
40
|
+
secretKey?: string;
|
|
41
|
+
mnemonic?: string;
|
|
35
42
|
};
|
|
36
43
|
|
|
37
44
|
export type ContractParams = {
|
package/src/utils/index.ts
CHANGED
|
@@ -36,25 +36,25 @@ function padWithZerosIfNeeded(inputString: string) {
|
|
|
36
36
|
throw new Error('Invalid input string length');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export function decompressPublicKey(compressedPubkey: string) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function compressPublicKey(decompressedPubkey: any[]) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
39
|
+
// /**
|
|
40
|
+
// * Parses a public key string into its x and y coordinates.
|
|
41
|
+
// * @param publickKey - The public key string to parse (128 characters long).
|
|
42
|
+
// * @returns An object containing the x and y coordinates as decimal strings.
|
|
43
|
+
// */
|
|
44
|
+
// export function decompressPublicKey(compressedPubkey: string) {
|
|
45
|
+
// const x = compressedPubkey.slice(0, 64);
|
|
46
|
+
// const y = compressedPubkey.slice(64);
|
|
47
|
+
|
|
48
|
+
// return {
|
|
49
|
+
// x: hexToDecimalString(x),
|
|
50
|
+
// y: hexToDecimalString(y),
|
|
51
|
+
// };
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// export function compressPublicKey(decompressedPubkey: any[]) {
|
|
55
|
+
// const x = decompressedPubkey[0];
|
|
56
|
+
// const y = decompressedPubkey[1];
|
|
57
|
+
// const compressedPubkey =
|
|
58
|
+
// padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
|
|
59
|
+
// return compressedPubkey;
|
|
60
|
+
// }
|