@dorafactory/maci-sdk 0.1.3-pre.43 → 0.1.3-pre.45
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.js +377 -209
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -210
- package/dist/index.mjs.map +1 -1
- package/dist/libs/api/types.d.ts +91 -2
- package/dist/libs/contract/config.d.ts +5 -1
- package/dist/libs/contract/contract.d.ts +35 -28
- package/dist/libs/contract/ts/AMaci.client.d.ts +6 -6
- package/dist/libs/contract/ts/AMaci.types.d.ts +1 -1
- package/dist/libs/contract/ts/ApiMaci.client.d.ts +42 -18
- package/dist/libs/contract/ts/ApiMaci.types.d.ts +24 -6
- package/dist/maci.d.ts +3 -0
- package/dist/voter.d.ts +130 -7
- package/package.json +1 -1
- package/src/libs/api/types.ts +91 -2
- package/src/libs/contract/config.ts +13 -2
- package/src/libs/contract/contract.ts +241 -323
- package/src/libs/contract/ts/AMaci.client.ts +3 -3
- package/src/libs/contract/ts/AMaci.types.ts +1 -1
- package/src/libs/contract/ts/ApiMaci.client.ts +474 -233
- package/src/libs/contract/ts/ApiMaci.types.ts +168 -113
- package/src/libs/maci/maci.ts +4 -1
- package/src/operator.ts +7 -0
- package/src/voter.ts +174 -30
package/dist/index.js
CHANGED
|
@@ -3598,10 +3598,10 @@ var AMaciQueryClient = class {
|
|
|
3598
3598
|
}
|
|
3599
3599
|
});
|
|
3600
3600
|
};
|
|
3601
|
-
this.signuped = async ({
|
|
3601
|
+
this.signuped = async ({ pubkey }) => {
|
|
3602
3602
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
3603
3603
|
signuped: {
|
|
3604
|
-
|
|
3604
|
+
pubkey
|
|
3605
3605
|
}
|
|
3606
3606
|
});
|
|
3607
3607
|
};
|
|
@@ -5058,9 +5058,7 @@ var ApiMaciQueryClient = class {
|
|
|
5058
5058
|
get_processed_user_count: {}
|
|
5059
5059
|
});
|
|
5060
5060
|
};
|
|
5061
|
-
this.getResult = async ({
|
|
5062
|
-
index
|
|
5063
|
-
}) => {
|
|
5061
|
+
this.getResult = async ({ index }) => {
|
|
5064
5062
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
5065
5063
|
get_result: {
|
|
5066
5064
|
index
|
|
@@ -5072,18 +5070,14 @@ var ApiMaciQueryClient = class {
|
|
|
5072
5070
|
get_all_result: {}
|
|
5073
5071
|
});
|
|
5074
5072
|
};
|
|
5075
|
-
this.getStateIdxInc = async ({
|
|
5076
|
-
address
|
|
5077
|
-
}) => {
|
|
5073
|
+
this.getStateIdxInc = async ({ address }) => {
|
|
5078
5074
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
5079
5075
|
get_state_idx_inc: {
|
|
5080
5076
|
address
|
|
5081
5077
|
}
|
|
5082
5078
|
});
|
|
5083
5079
|
};
|
|
5084
|
-
this.getVoiceCreditBalance = async ({
|
|
5085
|
-
index
|
|
5086
|
-
}) => {
|
|
5080
|
+
this.getVoiceCreditBalance = async ({ index }) => {
|
|
5087
5081
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
5088
5082
|
get_voice_credit_balance: {
|
|
5089
5083
|
index
|
|
@@ -5116,9 +5110,7 @@ var ApiMaciQueryClient = class {
|
|
|
5116
5110
|
}
|
|
5117
5111
|
});
|
|
5118
5112
|
};
|
|
5119
|
-
this.whiteInfo = async ({
|
|
5120
|
-
pubkey
|
|
5121
|
-
}) => {
|
|
5113
|
+
this.whiteInfo = async ({ pubkey }) => {
|
|
5122
5114
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
5123
5115
|
white_info: {
|
|
5124
5116
|
pubkey
|
|
@@ -5160,6 +5152,30 @@ var ApiMaciQueryClient = class {
|
|
|
5160
5152
|
query_oracle_whitelist_config: {}
|
|
5161
5153
|
});
|
|
5162
5154
|
};
|
|
5155
|
+
this.queryCurrentStateCommitment = async () => {
|
|
5156
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
5157
|
+
query_current_state_commitment: {}
|
|
5158
|
+
});
|
|
5159
|
+
};
|
|
5160
|
+
this.getStateTreeRoot = async () => {
|
|
5161
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
5162
|
+
get_state_tree_root: {}
|
|
5163
|
+
});
|
|
5164
|
+
};
|
|
5165
|
+
this.getNode = async ({ index }) => {
|
|
5166
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
5167
|
+
get_node: {
|
|
5168
|
+
index
|
|
5169
|
+
}
|
|
5170
|
+
});
|
|
5171
|
+
};
|
|
5172
|
+
this.signuped = async ({ pubkey }) => {
|
|
5173
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
5174
|
+
signuped: {
|
|
5175
|
+
pubkey
|
|
5176
|
+
}
|
|
5177
|
+
});
|
|
5178
|
+
};
|
|
5163
5179
|
this.client = client;
|
|
5164
5180
|
this.contractAddress = contractAddress;
|
|
5165
5181
|
this.getRoundInfo = this.getRoundInfo.bind(this);
|
|
@@ -5183,6 +5199,10 @@ var ApiMaciQueryClient = class {
|
|
|
5183
5199
|
this.queryCircuitType = this.queryCircuitType.bind(this);
|
|
5184
5200
|
this.queryCertSystem = this.queryCertSystem.bind(this);
|
|
5185
5201
|
this.queryOracleWhitelistConfig = this.queryOracleWhitelistConfig.bind(this);
|
|
5202
|
+
this.queryCurrentStateCommitment = this.queryCurrentStateCommitment.bind(this);
|
|
5203
|
+
this.getStateTreeRoot = this.getStateTreeRoot.bind(this);
|
|
5204
|
+
this.getNode = this.getNode.bind(this);
|
|
5205
|
+
this.signuped = this.signuped.bind(this);
|
|
5186
5206
|
}
|
|
5187
5207
|
};
|
|
5188
5208
|
var ApiMaciClient = class extends ApiMaciQueryClient {
|
|
@@ -5191,105 +5211,200 @@ var ApiMaciClient = class extends ApiMaciQueryClient {
|
|
|
5191
5211
|
this.setRoundInfo = async ({
|
|
5192
5212
|
roundInfo
|
|
5193
5213
|
}, fee = "auto", memo, _funds) => {
|
|
5194
|
-
return await this.client.execute(
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5214
|
+
return await this.client.execute(
|
|
5215
|
+
this.sender,
|
|
5216
|
+
this.contractAddress,
|
|
5217
|
+
{
|
|
5218
|
+
set_round_info: {
|
|
5219
|
+
round_info: roundInfo
|
|
5220
|
+
}
|
|
5221
|
+
},
|
|
5222
|
+
fee,
|
|
5223
|
+
memo,
|
|
5224
|
+
_funds
|
|
5225
|
+
);
|
|
5199
5226
|
};
|
|
5200
5227
|
this.setVoteOptionsMap = async ({
|
|
5201
5228
|
voteOptionMap
|
|
5202
5229
|
}, fee = "auto", memo, _funds) => {
|
|
5203
|
-
return await this.client.execute(
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5230
|
+
return await this.client.execute(
|
|
5231
|
+
this.sender,
|
|
5232
|
+
this.contractAddress,
|
|
5233
|
+
{
|
|
5234
|
+
set_vote_options_map: {
|
|
5235
|
+
vote_option_map: voteOptionMap
|
|
5236
|
+
}
|
|
5237
|
+
},
|
|
5238
|
+
fee,
|
|
5239
|
+
memo,
|
|
5240
|
+
_funds
|
|
5241
|
+
);
|
|
5208
5242
|
};
|
|
5209
5243
|
this.signUp = async ({
|
|
5210
5244
|
amount,
|
|
5211
5245
|
certificate,
|
|
5212
5246
|
pubkey
|
|
5213
5247
|
}, fee = "auto", memo, _funds) => {
|
|
5214
|
-
return await this.client.execute(
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5248
|
+
return await this.client.execute(
|
|
5249
|
+
this.sender,
|
|
5250
|
+
this.contractAddress,
|
|
5251
|
+
{
|
|
5252
|
+
sign_up: {
|
|
5253
|
+
amount,
|
|
5254
|
+
certificate,
|
|
5255
|
+
pubkey
|
|
5256
|
+
}
|
|
5257
|
+
},
|
|
5258
|
+
fee,
|
|
5259
|
+
memo,
|
|
5260
|
+
_funds
|
|
5261
|
+
);
|
|
5221
5262
|
};
|
|
5222
5263
|
this.startProcessPeriod = async (fee = "auto", memo, _funds) => {
|
|
5223
|
-
return await this.client.execute(
|
|
5224
|
-
|
|
5225
|
-
|
|
5264
|
+
return await this.client.execute(
|
|
5265
|
+
this.sender,
|
|
5266
|
+
this.contractAddress,
|
|
5267
|
+
{
|
|
5268
|
+
start_process_period: {}
|
|
5269
|
+
},
|
|
5270
|
+
fee,
|
|
5271
|
+
memo,
|
|
5272
|
+
_funds
|
|
5273
|
+
);
|
|
5226
5274
|
};
|
|
5227
5275
|
this.publishMessage = async ({
|
|
5228
5276
|
encPubKey,
|
|
5229
5277
|
message
|
|
5230
5278
|
}, fee = "auto", memo, _funds) => {
|
|
5231
|
-
return await this.client.execute(
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5279
|
+
return await this.client.execute(
|
|
5280
|
+
this.sender,
|
|
5281
|
+
this.contractAddress,
|
|
5282
|
+
{
|
|
5283
|
+
publish_message: {
|
|
5284
|
+
enc_pub_key: encPubKey,
|
|
5285
|
+
message
|
|
5286
|
+
}
|
|
5287
|
+
},
|
|
5288
|
+
fee,
|
|
5289
|
+
memo,
|
|
5290
|
+
_funds
|
|
5291
|
+
);
|
|
5292
|
+
};
|
|
5293
|
+
this.publishMessageBatch = async ({
|
|
5294
|
+
encPubKeys,
|
|
5295
|
+
messages
|
|
5296
|
+
}, fee = "auto", memo, _funds) => {
|
|
5297
|
+
return await this.client.execute(
|
|
5298
|
+
this.sender,
|
|
5299
|
+
this.contractAddress,
|
|
5300
|
+
{
|
|
5301
|
+
publish_message_batch: {
|
|
5302
|
+
enc_pub_keys: encPubKeys,
|
|
5303
|
+
messages
|
|
5304
|
+
}
|
|
5305
|
+
},
|
|
5306
|
+
fee,
|
|
5307
|
+
memo,
|
|
5308
|
+
_funds
|
|
5309
|
+
);
|
|
5237
5310
|
};
|
|
5238
5311
|
this.processMessage = async ({
|
|
5239
5312
|
groth16Proof,
|
|
5240
5313
|
newStateCommitment,
|
|
5241
5314
|
plonkProof
|
|
5242
5315
|
}, fee = "auto", memo, _funds) => {
|
|
5243
|
-
return await this.client.execute(
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5316
|
+
return await this.client.execute(
|
|
5317
|
+
this.sender,
|
|
5318
|
+
this.contractAddress,
|
|
5319
|
+
{
|
|
5320
|
+
process_message: {
|
|
5321
|
+
groth16_proof: groth16Proof,
|
|
5322
|
+
new_state_commitment: newStateCommitment,
|
|
5323
|
+
plonk_proof: plonkProof
|
|
5324
|
+
}
|
|
5325
|
+
},
|
|
5326
|
+
fee,
|
|
5327
|
+
memo,
|
|
5328
|
+
_funds
|
|
5329
|
+
);
|
|
5250
5330
|
};
|
|
5251
5331
|
this.stopProcessingPeriod = async (fee = "auto", memo, _funds) => {
|
|
5252
|
-
return await this.client.execute(
|
|
5253
|
-
|
|
5254
|
-
|
|
5332
|
+
return await this.client.execute(
|
|
5333
|
+
this.sender,
|
|
5334
|
+
this.contractAddress,
|
|
5335
|
+
{
|
|
5336
|
+
stop_processing_period: {}
|
|
5337
|
+
},
|
|
5338
|
+
fee,
|
|
5339
|
+
memo,
|
|
5340
|
+
_funds
|
|
5341
|
+
);
|
|
5255
5342
|
};
|
|
5256
5343
|
this.processTally = async ({
|
|
5257
5344
|
groth16Proof,
|
|
5258
5345
|
newTallyCommitment,
|
|
5259
5346
|
plonkProof
|
|
5260
5347
|
}, fee = "auto", memo, _funds) => {
|
|
5261
|
-
return await this.client.execute(
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5348
|
+
return await this.client.execute(
|
|
5349
|
+
this.sender,
|
|
5350
|
+
this.contractAddress,
|
|
5351
|
+
{
|
|
5352
|
+
process_tally: {
|
|
5353
|
+
groth16_proof: groth16Proof,
|
|
5354
|
+
new_tally_commitment: newTallyCommitment,
|
|
5355
|
+
plonk_proof: plonkProof
|
|
5356
|
+
}
|
|
5357
|
+
},
|
|
5358
|
+
fee,
|
|
5359
|
+
memo,
|
|
5360
|
+
_funds
|
|
5361
|
+
);
|
|
5268
5362
|
};
|
|
5269
5363
|
this.stopTallyingPeriod = async ({
|
|
5270
5364
|
results,
|
|
5271
5365
|
salt
|
|
5272
5366
|
}, fee = "auto", memo, _funds) => {
|
|
5273
|
-
return await this.client.execute(
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5367
|
+
return await this.client.execute(
|
|
5368
|
+
this.sender,
|
|
5369
|
+
this.contractAddress,
|
|
5370
|
+
{
|
|
5371
|
+
stop_tallying_period: {
|
|
5372
|
+
results,
|
|
5373
|
+
salt
|
|
5374
|
+
}
|
|
5375
|
+
},
|
|
5376
|
+
fee,
|
|
5377
|
+
memo,
|
|
5378
|
+
_funds
|
|
5379
|
+
);
|
|
5279
5380
|
};
|
|
5280
5381
|
this.bond = async (fee = "auto", memo, _funds) => {
|
|
5281
|
-
return await this.client.execute(
|
|
5282
|
-
|
|
5283
|
-
|
|
5382
|
+
return await this.client.execute(
|
|
5383
|
+
this.sender,
|
|
5384
|
+
this.contractAddress,
|
|
5385
|
+
{
|
|
5386
|
+
bond: {}
|
|
5387
|
+
},
|
|
5388
|
+
fee,
|
|
5389
|
+
memo,
|
|
5390
|
+
_funds
|
|
5391
|
+
);
|
|
5284
5392
|
};
|
|
5285
5393
|
this.withdraw = async ({
|
|
5286
5394
|
amount
|
|
5287
5395
|
}, fee = "auto", memo, _funds) => {
|
|
5288
|
-
return await this.client.execute(
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5396
|
+
return await this.client.execute(
|
|
5397
|
+
this.sender,
|
|
5398
|
+
this.contractAddress,
|
|
5399
|
+
{
|
|
5400
|
+
withdraw: {
|
|
5401
|
+
amount
|
|
5402
|
+
}
|
|
5403
|
+
},
|
|
5404
|
+
fee,
|
|
5405
|
+
memo,
|
|
5406
|
+
_funds
|
|
5407
|
+
);
|
|
5293
5408
|
};
|
|
5294
5409
|
this.client = client;
|
|
5295
5410
|
this.sender = sender;
|
|
@@ -5299,6 +5414,7 @@ var ApiMaciClient = class extends ApiMaciQueryClient {
|
|
|
5299
5414
|
this.signUp = this.signUp.bind(this);
|
|
5300
5415
|
this.startProcessPeriod = this.startProcessPeriod.bind(this);
|
|
5301
5416
|
this.publishMessage = this.publishMessage.bind(this);
|
|
5417
|
+
this.publishMessageBatch = this.publishMessageBatch.bind(this);
|
|
5302
5418
|
this.processMessage = this.processMessage.bind(this);
|
|
5303
5419
|
this.stopProcessingPeriod = this.stopProcessingPeriod.bind(this);
|
|
5304
5420
|
this.processTally = this.processTally.bind(this);
|
|
@@ -5616,6 +5732,13 @@ async function createAMaciClientBy({
|
|
|
5616
5732
|
const [{ address }] = await wallet.getAccounts();
|
|
5617
5733
|
return new AMaciClient(signingCosmWasmClient, address, contractAddress);
|
|
5618
5734
|
}
|
|
5735
|
+
async function createAMaciQueryClientBy({
|
|
5736
|
+
rpcEndpoint,
|
|
5737
|
+
contractAddress
|
|
5738
|
+
}) {
|
|
5739
|
+
const cosmWasmClient = await import_cosmwasm_stargate.CosmWasmClient.connect(rpcEndpoint);
|
|
5740
|
+
return new AMaciQueryClient(cosmWasmClient, contractAddress);
|
|
5741
|
+
}
|
|
5619
5742
|
async function createApiMaciClientBy({
|
|
5620
5743
|
rpcEndpoint,
|
|
5621
5744
|
wallet,
|
|
@@ -6196,11 +6319,7 @@ var Contract = class {
|
|
|
6196
6319
|
wallet: signer,
|
|
6197
6320
|
contractAddress: this.registryAddress
|
|
6198
6321
|
});
|
|
6199
|
-
const requiredFee = getAMaciRoundCircuitFee(
|
|
6200
|
-
this.network,
|
|
6201
|
-
maxVoter,
|
|
6202
|
-
voteOptionMap.length
|
|
6203
|
-
);
|
|
6322
|
+
const requiredFee = getAMaciRoundCircuitFee(this.network, maxVoter, voteOptionMap.length);
|
|
6204
6323
|
preDeactivateRoot = preDeactivateRoot || "0";
|
|
6205
6324
|
let preDeactivateCoordinatorPubKey = void 0;
|
|
6206
6325
|
if (preDeactivateCoordinator !== void 0) {
|
|
@@ -6245,9 +6364,7 @@ var Contract = class {
|
|
|
6245
6364
|
let contractAddress = "";
|
|
6246
6365
|
res.events.map((event) => {
|
|
6247
6366
|
if (event.type === "wasm") {
|
|
6248
|
-
let actionEvent = event.attributes.find(
|
|
6249
|
-
(attr) => attr.key === "action"
|
|
6250
|
-
);
|
|
6367
|
+
let actionEvent = event.attributes.find((attr) => attr.key === "action");
|
|
6251
6368
|
if (actionEvent.value === "created_round") {
|
|
6252
6369
|
contractAddress = event.attributes.find((attr) => attr.key === "round_addr").value.toString();
|
|
6253
6370
|
}
|
|
@@ -6277,9 +6394,7 @@ var Contract = class {
|
|
|
6277
6394
|
const end_time = (endVoting.getTime() * 10 ** 6).toString();
|
|
6278
6395
|
const [{ address }] = await signer.getAccounts();
|
|
6279
6396
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
6280
|
-
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
6281
|
-
BigInt(operatorPubkey)
|
|
6282
|
-
);
|
|
6397
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(BigInt(operatorPubkey));
|
|
6283
6398
|
const {
|
|
6284
6399
|
parameters,
|
|
6285
6400
|
groth16ProcessVkey,
|
|
@@ -6288,13 +6403,7 @@ var Contract = class {
|
|
|
6288
6403
|
plonkTallyVkey,
|
|
6289
6404
|
maciVoteType,
|
|
6290
6405
|
maciCertSystem
|
|
6291
|
-
} = getContractParams(
|
|
6292
|
-
"0" /* MACI */,
|
|
6293
|
-
circuitType,
|
|
6294
|
-
certSystemType,
|
|
6295
|
-
maxVoter,
|
|
6296
|
-
maxOption
|
|
6297
|
-
);
|
|
6406
|
+
} = getContractParams("0" /* MACI */, circuitType, certSystemType, maxVoter, maxOption);
|
|
6298
6407
|
const instantiateResponse = await client.instantiate(
|
|
6299
6408
|
address,
|
|
6300
6409
|
this.maciCodeId,
|
|
@@ -6343,9 +6452,7 @@ var Contract = class {
|
|
|
6343
6452
|
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
6344
6453
|
const [{ address }] = await signer.getAccounts();
|
|
6345
6454
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
6346
|
-
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
6347
|
-
BigInt(operatorPubkey)
|
|
6348
|
-
);
|
|
6455
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(BigInt(operatorPubkey));
|
|
6349
6456
|
const { maciVoteType, maciCertSystem } = getContractParams(
|
|
6350
6457
|
"2" /* ORACLE_MACI */,
|
|
6351
6458
|
circuitType,
|
|
@@ -6401,9 +6508,7 @@ var Contract = class {
|
|
|
6401
6508
|
wallet: signer,
|
|
6402
6509
|
contractAddress: this.saasAddress
|
|
6403
6510
|
});
|
|
6404
|
-
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
6405
|
-
BigInt(operatorPubkey)
|
|
6406
|
-
);
|
|
6511
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(BigInt(operatorPubkey));
|
|
6407
6512
|
const roundParams = {
|
|
6408
6513
|
certificationSystem: "0",
|
|
6409
6514
|
circuitType: "0",
|
|
@@ -6455,37 +6560,26 @@ var Contract = class {
|
|
|
6455
6560
|
);
|
|
6456
6561
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6457
6562
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6458
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6459
|
-
Math.round(gasEstimation * multiplier),
|
|
6460
|
-
gasPrice
|
|
6461
|
-
);
|
|
6563
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6462
6564
|
const grantFee = {
|
|
6463
6565
|
amount: calculatedFee.amount,
|
|
6464
6566
|
gas: calculatedFee.gas,
|
|
6465
6567
|
granter: this.saasAddress
|
|
6466
6568
|
};
|
|
6467
|
-
createResponse = await client.createOracleMaciRound(
|
|
6468
|
-
roundParams,
|
|
6469
|
-
grantFee
|
|
6470
|
-
);
|
|
6569
|
+
createResponse = await client.createOracleMaciRound(roundParams, grantFee);
|
|
6471
6570
|
} else if (gasStation && typeof fee === "object") {
|
|
6472
6571
|
const grantFee = {
|
|
6473
6572
|
...fee,
|
|
6474
6573
|
granter: this.saasAddress
|
|
6475
6574
|
};
|
|
6476
|
-
createResponse = await client.createOracleMaciRound(
|
|
6477
|
-
roundParams,
|
|
6478
|
-
grantFee
|
|
6479
|
-
);
|
|
6575
|
+
createResponse = await client.createOracleMaciRound(roundParams, grantFee);
|
|
6480
6576
|
} else {
|
|
6481
6577
|
createResponse = await client.createOracleMaciRound(roundParams, fee);
|
|
6482
6578
|
}
|
|
6483
6579
|
let contractAddress = "";
|
|
6484
6580
|
createResponse.events.map((event) => {
|
|
6485
6581
|
if (event.type === "wasm") {
|
|
6486
|
-
let actionEvent = event.attributes.find(
|
|
6487
|
-
(attr) => attr.key === "action"
|
|
6488
|
-
);
|
|
6582
|
+
let actionEvent = event.attributes.find((attr) => attr.key === "action");
|
|
6489
6583
|
if (actionEvent.value === "created_oracle_maci_round") {
|
|
6490
6584
|
contractAddress = event.attributes.find((attr) => attr.key === "round_addr").value.toString();
|
|
6491
6585
|
}
|
|
@@ -6540,10 +6634,7 @@ var Contract = class {
|
|
|
6540
6634
|
);
|
|
6541
6635
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6542
6636
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6543
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6544
|
-
Math.round(gasEstimation * multiplier),
|
|
6545
|
-
gasPrice
|
|
6546
|
-
);
|
|
6637
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6547
6638
|
const grantFee = {
|
|
6548
6639
|
amount: calculatedFee.amount,
|
|
6549
6640
|
gas: calculatedFee.gas,
|
|
@@ -6614,10 +6705,7 @@ var Contract = class {
|
|
|
6614
6705
|
);
|
|
6615
6706
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6616
6707
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6617
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6618
|
-
Math.round(gasEstimation * multiplier),
|
|
6619
|
-
gasPrice
|
|
6620
|
-
);
|
|
6708
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6621
6709
|
const grantFee = {
|
|
6622
6710
|
amount: calculatedFee.amount,
|
|
6623
6711
|
gas: calculatedFee.gas,
|
|
@@ -6690,10 +6778,7 @@ var Contract = class {
|
|
|
6690
6778
|
);
|
|
6691
6779
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6692
6780
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6693
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6694
|
-
Math.round(gasEstimation * multiplier),
|
|
6695
|
-
gasPrice
|
|
6696
|
-
);
|
|
6781
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6697
6782
|
const grantFee = {
|
|
6698
6783
|
amount: calculatedFee.amount,
|
|
6699
6784
|
gas: calculatedFee.gas,
|
|
@@ -6765,10 +6850,7 @@ var Contract = class {
|
|
|
6765
6850
|
);
|
|
6766
6851
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6767
6852
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6768
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6769
|
-
Math.round(gasEstimation * multiplier),
|
|
6770
|
-
gasPrice
|
|
6771
|
-
);
|
|
6853
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6772
6854
|
const grantFee = {
|
|
6773
6855
|
amount: calculatedFee.amount,
|
|
6774
6856
|
gas: calculatedFee.gas,
|
|
@@ -6819,10 +6901,7 @@ var Contract = class {
|
|
|
6819
6901
|
);
|
|
6820
6902
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6821
6903
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6822
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6823
|
-
Math.round(gasEstimation * multiplier),
|
|
6824
|
-
gasPrice
|
|
6825
|
-
);
|
|
6904
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6826
6905
|
const grantFee = {
|
|
6827
6906
|
amount: calculatedFee.amount,
|
|
6828
6907
|
gas: calculatedFee.gas,
|
|
@@ -6838,10 +6917,7 @@ var Contract = class {
|
|
|
6838
6917
|
}
|
|
6839
6918
|
return client.removeOperator({ operator }, fee);
|
|
6840
6919
|
}
|
|
6841
|
-
async isSaasOperator({
|
|
6842
|
-
signer,
|
|
6843
|
-
operator
|
|
6844
|
-
}) {
|
|
6920
|
+
async isSaasOperator({ signer, operator }) {
|
|
6845
6921
|
const client = await createSaasClientBy({
|
|
6846
6922
|
rpcEndpoint: this.rpcEndpoint,
|
|
6847
6923
|
wallet: signer,
|
|
@@ -6889,10 +6965,7 @@ var Contract = class {
|
|
|
6889
6965
|
);
|
|
6890
6966
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6891
6967
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6892
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6893
|
-
Math.round(gasEstimation * multiplier),
|
|
6894
|
-
gasPrice
|
|
6895
|
-
);
|
|
6968
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6896
6969
|
const grantFee = {
|
|
6897
6970
|
amount: calculatedFee.amount,
|
|
6898
6971
|
gas: calculatedFee.gas,
|
|
@@ -6943,10 +7016,7 @@ var Contract = class {
|
|
|
6943
7016
|
);
|
|
6944
7017
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6945
7018
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
6946
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
6947
|
-
Math.round(gasEstimation * multiplier),
|
|
6948
|
-
gasPrice
|
|
6949
|
-
);
|
|
7019
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6950
7020
|
const grantFee = {
|
|
6951
7021
|
amount: calculatedFee.amount,
|
|
6952
7022
|
gas: calculatedFee.gas,
|
|
@@ -6962,10 +7032,7 @@ var Contract = class {
|
|
|
6962
7032
|
}
|
|
6963
7033
|
return client.withdraw({ amount }, fee);
|
|
6964
7034
|
}
|
|
6965
|
-
async queryRoundInfo({
|
|
6966
|
-
signer,
|
|
6967
|
-
roundAddress
|
|
6968
|
-
}) {
|
|
7035
|
+
async queryRoundInfo({ signer, roundAddress }) {
|
|
6969
7036
|
const client = await createMaciClientBy({
|
|
6970
7037
|
rpcEndpoint: this.rpcEndpoint,
|
|
6971
7038
|
wallet: signer,
|
|
@@ -6974,6 +7041,17 @@ var Contract = class {
|
|
|
6974
7041
|
const roundInfo = await client.getRoundInfo();
|
|
6975
7042
|
return roundInfo;
|
|
6976
7043
|
}
|
|
7044
|
+
async getStateIdx({
|
|
7045
|
+
contractAddress,
|
|
7046
|
+
pubkey
|
|
7047
|
+
}) {
|
|
7048
|
+
const client = await createAMaciQueryClientBy({
|
|
7049
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
7050
|
+
contractAddress
|
|
7051
|
+
});
|
|
7052
|
+
const stateIdx = await client.signuped({ pubkey });
|
|
7053
|
+
return stateIdx;
|
|
7054
|
+
}
|
|
6977
7055
|
async oracleMaciClient({
|
|
6978
7056
|
signer,
|
|
6979
7057
|
contractAddress
|
|
@@ -7069,9 +7147,7 @@ var Contract = class {
|
|
|
7069
7147
|
wallet: signer,
|
|
7070
7148
|
contractAddress: this.apiSaasAddress
|
|
7071
7149
|
});
|
|
7072
|
-
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
7073
|
-
BigInt(operatorPubkey)
|
|
7074
|
-
);
|
|
7150
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(BigInt(operatorPubkey));
|
|
7075
7151
|
const roundParams = {
|
|
7076
7152
|
certificationSystem: "0",
|
|
7077
7153
|
circuitType: "0",
|
|
@@ -7123,10 +7199,7 @@ var Contract = class {
|
|
|
7123
7199
|
);
|
|
7124
7200
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7125
7201
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7126
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7127
|
-
Math.round(gasEstimation * multiplier),
|
|
7128
|
-
gasPrice
|
|
7129
|
-
);
|
|
7202
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7130
7203
|
const grantFee = {
|
|
7131
7204
|
amount: calculatedFee.amount,
|
|
7132
7205
|
gas: calculatedFee.gas,
|
|
@@ -7145,9 +7218,7 @@ var Contract = class {
|
|
|
7145
7218
|
let contractAddress = "";
|
|
7146
7219
|
createResponse.events.map((event) => {
|
|
7147
7220
|
if (event.type === "wasm") {
|
|
7148
|
-
let actionEvent = event.attributes.find(
|
|
7149
|
-
(attr) => attr.key === "action"
|
|
7150
|
-
);
|
|
7221
|
+
let actionEvent = event.attributes.find((attr) => attr.key === "action");
|
|
7151
7222
|
if (actionEvent.value === "created_maci_round") {
|
|
7152
7223
|
contractAddress = event.attributes.find((attr) => attr.key === "round_addr").value.toString();
|
|
7153
7224
|
}
|
|
@@ -7202,10 +7273,7 @@ var Contract = class {
|
|
|
7202
7273
|
);
|
|
7203
7274
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7204
7275
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7205
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7206
|
-
Math.round(gasEstimation * multiplier),
|
|
7207
|
-
gasPrice
|
|
7208
|
-
);
|
|
7276
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7209
7277
|
const grantFee = {
|
|
7210
7278
|
amount: calculatedFee.amount,
|
|
7211
7279
|
gas: calculatedFee.gas,
|
|
@@ -7276,10 +7344,7 @@ var Contract = class {
|
|
|
7276
7344
|
);
|
|
7277
7345
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7278
7346
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7279
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7280
|
-
Math.round(gasEstimation * multiplier),
|
|
7281
|
-
gasPrice
|
|
7282
|
-
);
|
|
7347
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7283
7348
|
const grantFee = {
|
|
7284
7349
|
amount: calculatedFee.amount,
|
|
7285
7350
|
gas: calculatedFee.gas,
|
|
@@ -7348,10 +7413,7 @@ var Contract = class {
|
|
|
7348
7413
|
);
|
|
7349
7414
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7350
7415
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7351
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7352
|
-
Math.round(gasEstimation * multiplier),
|
|
7353
|
-
gasPrice
|
|
7354
|
-
);
|
|
7416
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7355
7417
|
const grantFee = {
|
|
7356
7418
|
amount: calculatedFee.amount,
|
|
7357
7419
|
gas: calculatedFee.gas,
|
|
@@ -7402,10 +7464,7 @@ var Contract = class {
|
|
|
7402
7464
|
);
|
|
7403
7465
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7404
7466
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7405
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7406
|
-
Math.round(gasEstimation * multiplier),
|
|
7407
|
-
gasPrice
|
|
7408
|
-
);
|
|
7467
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7409
7468
|
const grantFee = {
|
|
7410
7469
|
amount: calculatedFee.amount,
|
|
7411
7470
|
gas: calculatedFee.gas,
|
|
@@ -7421,10 +7480,7 @@ var Contract = class {
|
|
|
7421
7480
|
}
|
|
7422
7481
|
return client.removeOperator({ operator }, fee);
|
|
7423
7482
|
}
|
|
7424
|
-
async isApiSaasOperator({
|
|
7425
|
-
signer,
|
|
7426
|
-
operator
|
|
7427
|
-
}) {
|
|
7483
|
+
async isApiSaasOperator({ signer, operator }) {
|
|
7428
7484
|
const client = await createApiSaasClientBy({
|
|
7429
7485
|
rpcEndpoint: this.rpcEndpoint,
|
|
7430
7486
|
wallet: signer,
|
|
@@ -7529,10 +7585,7 @@ var Contract = class {
|
|
|
7529
7585
|
);
|
|
7530
7586
|
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
7531
7587
|
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
7532
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
7533
|
-
Math.round(gasEstimation * multiplier),
|
|
7534
|
-
gasPrice
|
|
7535
|
-
);
|
|
7588
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
7536
7589
|
const grantFee = {
|
|
7537
7590
|
amount: calculatedFee.amount,
|
|
7538
7591
|
gas: calculatedFee.gas,
|
|
@@ -7551,13 +7604,9 @@ var Contract = class {
|
|
|
7551
7604
|
let contractAddress = "";
|
|
7552
7605
|
createResponse.events.map((event) => {
|
|
7553
7606
|
if (event.type === "wasm") {
|
|
7554
|
-
let actionEvent = event.attributes.find(
|
|
7555
|
-
(attr) => attr.key === "action"
|
|
7556
|
-
);
|
|
7607
|
+
let actionEvent = event.attributes.find((attr) => attr.key === "action");
|
|
7557
7608
|
if (actionEvent && actionEvent.value === "created_round") {
|
|
7558
|
-
const roundAddrEvent = event.attributes.find(
|
|
7559
|
-
(attr) => attr.key === "round_addr"
|
|
7560
|
-
);
|
|
7609
|
+
const roundAddrEvent = event.attributes.find((attr) => attr.key === "round_addr");
|
|
7561
7610
|
if (roundAddrEvent) {
|
|
7562
7611
|
contractAddress = roundAddrEvent.value.toString();
|
|
7563
7612
|
}
|
|
@@ -8215,7 +8264,10 @@ var MACI = class {
|
|
|
8215
8264
|
}));
|
|
8216
8265
|
if (gasStation && typeof fee !== "object") {
|
|
8217
8266
|
const client = await this.contract.contractClient({ signer });
|
|
8218
|
-
const encPubKeysBigInt = payload.map((p) =>
|
|
8267
|
+
const encPubKeysBigInt = payload.map((p) => ({
|
|
8268
|
+
x: p.encPubkeys[0],
|
|
8269
|
+
y: p.encPubkeys[1]
|
|
8270
|
+
}));
|
|
8219
8271
|
const messagesBigInt = payload.map((p) => ({
|
|
8220
8272
|
data: p.msg
|
|
8221
8273
|
}));
|
|
@@ -10330,6 +10382,17 @@ var VoterClient = class _VoterClient {
|
|
|
10330
10382
|
apiKey: saasApiKey,
|
|
10331
10383
|
customFetch
|
|
10332
10384
|
});
|
|
10385
|
+
this.contract = new Contract({
|
|
10386
|
+
network: this.network,
|
|
10387
|
+
rpcEndpoint: defaultParams.rpcEndpoint,
|
|
10388
|
+
registryAddress: this.registryAddress,
|
|
10389
|
+
saasAddress: defaultParams.saasAddress,
|
|
10390
|
+
apiSaasAddress: defaultParams.apiSaasAddress,
|
|
10391
|
+
maciCodeId: defaultParams.maciCodeId,
|
|
10392
|
+
oracleCodeId: defaultParams.oracleCodeId,
|
|
10393
|
+
feegrantOperator: defaultParams.oracleFeegrantOperator,
|
|
10394
|
+
whitelistBackendPubkey: defaultParams.oracleWhitelistBackendPubkey
|
|
10395
|
+
});
|
|
10333
10396
|
}
|
|
10334
10397
|
/**
|
|
10335
10398
|
* Set SaaS API key for MaciApiClient
|
|
@@ -10373,12 +10436,15 @@ var VoterClient = class _VoterClient {
|
|
|
10373
10436
|
getPubkey(derivePathParams) {
|
|
10374
10437
|
return this.accountManager.getKeyPair(derivePathParams).getPublicKey();
|
|
10375
10438
|
}
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10439
|
+
/**
|
|
10440
|
+
* Normalize and validate vote options.
|
|
10441
|
+
* This method performs duplicate checking, filtering, sorting, and format conversion.
|
|
10442
|
+
*
|
|
10443
|
+
* @param selectedOptions - Array of vote options with idx and vc
|
|
10444
|
+
* @returns Normalized plan format: [voteOptionIndex, voteWeight][]
|
|
10445
|
+
* @throws Error if duplicate option indices are found
|
|
10446
|
+
*/
|
|
10447
|
+
normalizeVoteOptions(selectedOptions) {
|
|
10382
10448
|
const idxSet = /* @__PURE__ */ new Set();
|
|
10383
10449
|
for (const option of selectedOptions) {
|
|
10384
10450
|
if (idxSet.has(option.idx)) {
|
|
@@ -10390,6 +10456,15 @@ var VoterClient = class _VoterClient {
|
|
|
10390
10456
|
const plan = options.map((o) => {
|
|
10391
10457
|
return [o.idx, o.vc];
|
|
10392
10458
|
});
|
|
10459
|
+
return plan;
|
|
10460
|
+
}
|
|
10461
|
+
buildVotePayload({
|
|
10462
|
+
stateIdx,
|
|
10463
|
+
operatorPubkey,
|
|
10464
|
+
selectedOptions,
|
|
10465
|
+
derivePathParams
|
|
10466
|
+
}) {
|
|
10467
|
+
const plan = this.normalizeVoteOptions(selectedOptions);
|
|
10393
10468
|
const payload = this.batchGenMessage(stateIdx, operatorPubkey, plan, derivePathParams);
|
|
10394
10469
|
return stringizing(payload);
|
|
10395
10470
|
}
|
|
@@ -10399,7 +10474,8 @@ var VoterClient = class _VoterClient {
|
|
|
10399
10474
|
for (let i = plan.length - 1; i >= 0; i--) {
|
|
10400
10475
|
const p = plan[i];
|
|
10401
10476
|
const encAccount = genKeypair();
|
|
10402
|
-
const
|
|
10477
|
+
const isLastCmd = i === plan.length - 1;
|
|
10478
|
+
const msg = genMessage(BigInt(encAccount.privKey), i + 1, p[0], p[1], isLastCmd);
|
|
10403
10479
|
payload.push({
|
|
10404
10480
|
msg,
|
|
10405
10481
|
encPubkeys: encAccount.pubKey
|
|
@@ -10411,9 +10487,11 @@ var VoterClient = class _VoterClient {
|
|
|
10411
10487
|
return (encPriKey, nonce, voIdx, newVotes, isLastCmd, salt) => {
|
|
10412
10488
|
const packaged = packElement({ nonce, stateIdx, voIdx, newVotes, salt });
|
|
10413
10489
|
const signer = this.getSigner(derivePathParams);
|
|
10414
|
-
let newPubKey
|
|
10490
|
+
let newPubKey;
|
|
10415
10491
|
if (isLastCmd) {
|
|
10416
10492
|
newPubKey = [0n, 0n];
|
|
10493
|
+
} else {
|
|
10494
|
+
newPubKey = [...signer.getPublicKey().toPoints()];
|
|
10417
10495
|
}
|
|
10418
10496
|
const hash = poseidon([packaged, ...newPubKey]);
|
|
10419
10497
|
const signature = signer.sign(hash);
|
|
@@ -10425,14 +10503,29 @@ var VoterClient = class _VoterClient {
|
|
|
10425
10503
|
}
|
|
10426
10504
|
async getStateIdx({
|
|
10427
10505
|
contractAddress,
|
|
10428
|
-
pubkey
|
|
10506
|
+
pubkey,
|
|
10507
|
+
derivePathParams
|
|
10429
10508
|
}) {
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10509
|
+
if (!pubkey) {
|
|
10510
|
+
pubkey = this.getPubkey(derivePathParams).toPoints();
|
|
10511
|
+
}
|
|
10512
|
+
pubkey = this.unpackMaciPubkey(pubkey);
|
|
10513
|
+
try {
|
|
10514
|
+
const stateIdx = await this.contract.getStateIdx({
|
|
10515
|
+
contractAddress,
|
|
10516
|
+
pubkey: { x: pubkey[0].toString(), y: pubkey[1].toString() }
|
|
10517
|
+
});
|
|
10518
|
+
if (stateIdx === null) {
|
|
10519
|
+
return -1;
|
|
10520
|
+
}
|
|
10521
|
+
return parseInt(stateIdx);
|
|
10522
|
+
} catch (error) {
|
|
10523
|
+
const response = await this.indexer.getSignUpEventByPubKey(contractAddress, pubkey);
|
|
10524
|
+
if (isErrorResponse(response)) {
|
|
10525
|
+
return -1;
|
|
10526
|
+
}
|
|
10527
|
+
return response.data.signUpEvents[0].stateIdx;
|
|
10434
10528
|
}
|
|
10435
|
-
return response.data.signUpEvents[0].stateIdx;
|
|
10436
10529
|
}
|
|
10437
10530
|
async buildAddNewKeyPayload({
|
|
10438
10531
|
stateTreeDepth,
|
|
@@ -10609,6 +10702,28 @@ var VoterClient = class _VoterClient {
|
|
|
10609
10702
|
return stringizing(payload[0]);
|
|
10610
10703
|
}
|
|
10611
10704
|
// ==================== SaaS API Client Methods ====================
|
|
10705
|
+
/**
|
|
10706
|
+
* Create a MACI round via SaaS API
|
|
10707
|
+
* @param params - Round creation parameters
|
|
10708
|
+
* @returns Response with transaction details and ticket
|
|
10709
|
+
*/
|
|
10710
|
+
async saasCreateRound(params) {
|
|
10711
|
+
if (!this.saasApiClient) {
|
|
10712
|
+
throw new Error("SaaS API client not initialized");
|
|
10713
|
+
}
|
|
10714
|
+
return await this.saasApiClient.createRound(params);
|
|
10715
|
+
}
|
|
10716
|
+
/**
|
|
10717
|
+
* Create an AMACI round via SaaS API
|
|
10718
|
+
* @param params - AMACI round creation parameters
|
|
10719
|
+
* @returns Response with transaction details and ticket
|
|
10720
|
+
*/
|
|
10721
|
+
async saasCreateAmaciRound(params) {
|
|
10722
|
+
if (!this.saasApiClient) {
|
|
10723
|
+
throw new Error("SaaS API client not initialized");
|
|
10724
|
+
}
|
|
10725
|
+
return await this.saasApiClient.createAmaciRound(params);
|
|
10726
|
+
}
|
|
10612
10727
|
/**
|
|
10613
10728
|
* Get pre-deactivate data via SaaS API
|
|
10614
10729
|
* @param contractAddress - Contract address
|
|
@@ -10620,18 +10735,20 @@ var VoterClient = class _VoterClient {
|
|
|
10620
10735
|
return await this.saasApiClient.getPreDeactivate({ contractAddress });
|
|
10621
10736
|
}
|
|
10622
10737
|
/**
|
|
10623
|
-
*
|
|
10624
|
-
* @param params -
|
|
10738
|
+
* Signup via SaaS API
|
|
10739
|
+
* @param params - Signup parameters (including ticket)
|
|
10740
|
+
* @returns Response with transaction details
|
|
10625
10741
|
*/
|
|
10626
|
-
async
|
|
10742
|
+
async saasSignup(params) {
|
|
10627
10743
|
if (!this.saasApiClient) {
|
|
10628
10744
|
throw new Error("SaaS API client not initialized");
|
|
10629
10745
|
}
|
|
10630
|
-
return await this.saasApiClient.
|
|
10746
|
+
return await this.saasApiClient.signup(params);
|
|
10631
10747
|
}
|
|
10632
10748
|
/**
|
|
10633
10749
|
* Vote via SaaS API
|
|
10634
|
-
* @param params - Vote parameters
|
|
10750
|
+
* @param params - Vote parameters (including ticket)
|
|
10751
|
+
* @returns Response with transaction details
|
|
10635
10752
|
*/
|
|
10636
10753
|
async saasSubmitVote(params) {
|
|
10637
10754
|
if (!this.saasApiClient) {
|
|
@@ -10639,7 +10756,45 @@ var VoterClient = class _VoterClient {
|
|
|
10639
10756
|
}
|
|
10640
10757
|
return await this.saasApiClient.vote(params);
|
|
10641
10758
|
}
|
|
10759
|
+
/**
|
|
10760
|
+
* Deactivate via SaaS API
|
|
10761
|
+
* @param params - Deactivate parameters (including ticket)
|
|
10762
|
+
* @returns Response with transaction details
|
|
10763
|
+
*/
|
|
10764
|
+
async saasDeactivate(params) {
|
|
10765
|
+
if (!this.saasApiClient) {
|
|
10766
|
+
throw new Error("SaaS API client not initialized");
|
|
10767
|
+
}
|
|
10768
|
+
return await this.saasApiClient.deactivate(params);
|
|
10769
|
+
}
|
|
10770
|
+
/**
|
|
10771
|
+
* Add new key via SaaS API
|
|
10772
|
+
* @param params - Add new key parameters (including ticket)
|
|
10773
|
+
* @returns Response with transaction details
|
|
10774
|
+
*/
|
|
10775
|
+
async saasAddNewKey(params) {
|
|
10776
|
+
if (!this.saasApiClient) {
|
|
10777
|
+
throw new Error("SaaS API client not initialized");
|
|
10778
|
+
}
|
|
10779
|
+
return await this.saasApiClient.addNewKey(params);
|
|
10780
|
+
}
|
|
10781
|
+
/**
|
|
10782
|
+
* Pre add new key via SaaS API
|
|
10783
|
+
* @param params - Pre add new key parameters (including ticket)
|
|
10784
|
+
* @returns Response with transaction details
|
|
10785
|
+
*/
|
|
10786
|
+
async saasSubmitPreAddNewKey(params) {
|
|
10787
|
+
if (!this.saasApiClient) {
|
|
10788
|
+
throw new Error("SaaS API client not initialized");
|
|
10789
|
+
}
|
|
10790
|
+
return await this.saasApiClient.preAddNewKey(params);
|
|
10791
|
+
}
|
|
10642
10792
|
// ==================== Maci Voter Methods ====================
|
|
10793
|
+
/**
|
|
10794
|
+
* Pre-create a new account for AMACI voting (pre-deactivate mode)
|
|
10795
|
+
* @param params - Parameters including contract address, deactivates, circuit files, and ticket
|
|
10796
|
+
* @returns Result with transaction details and new voter account
|
|
10797
|
+
*/
|
|
10643
10798
|
async saasPreCreateNewAccount({
|
|
10644
10799
|
contractAddress,
|
|
10645
10800
|
stateTreeDepth,
|
|
@@ -10647,6 +10802,7 @@ var VoterClient = class _VoterClient {
|
|
|
10647
10802
|
deactivates,
|
|
10648
10803
|
wasmFile,
|
|
10649
10804
|
zkeyFile,
|
|
10805
|
+
ticket,
|
|
10650
10806
|
derivePathParams
|
|
10651
10807
|
}) {
|
|
10652
10808
|
const addNewKeyPayload = await this.buildPreAddNewKeyPayload({
|
|
@@ -10669,21 +10825,29 @@ var VoterClient = class _VoterClient {
|
|
|
10669
10825
|
proof: addNewKeyPayload.proof,
|
|
10670
10826
|
d: addNewKeyPayload.d,
|
|
10671
10827
|
nullifier: addNewKeyPayload.nullifier,
|
|
10672
|
-
newPubkey: newVoterClient.getPubkey().toPoints().map((p) => p.toString())
|
|
10828
|
+
newPubkey: newVoterClient.getPubkey().toPoints().map((p) => p.toString()),
|
|
10829
|
+
ticket
|
|
10673
10830
|
});
|
|
10674
10831
|
return {
|
|
10675
10832
|
result: addNewKeyResult,
|
|
10676
10833
|
account: newVoterClient
|
|
10677
10834
|
};
|
|
10678
10835
|
}
|
|
10836
|
+
/**
|
|
10837
|
+
* Vote via SaaS API with automatic payload building
|
|
10838
|
+
* @param params - Parameters including contract address, operator pubkey, vote options, and ticket
|
|
10839
|
+
* @returns Response with transaction details
|
|
10840
|
+
*/
|
|
10679
10841
|
async saasVote({
|
|
10680
10842
|
contractAddress,
|
|
10681
10843
|
operatorPubkey,
|
|
10682
10844
|
selectedOptions,
|
|
10845
|
+
ticket,
|
|
10683
10846
|
derivePathParams
|
|
10684
10847
|
}) {
|
|
10685
10848
|
const stateIdx = await this.getStateIdx({
|
|
10686
|
-
contractAddress
|
|
10849
|
+
contractAddress,
|
|
10850
|
+
derivePathParams
|
|
10687
10851
|
});
|
|
10688
10852
|
if (stateIdx === -1) {
|
|
10689
10853
|
throw new Error("State index is not set, Please signup or addNewKey first");
|
|
@@ -10696,7 +10860,8 @@ var VoterClient = class _VoterClient {
|
|
|
10696
10860
|
});
|
|
10697
10861
|
const voteResult = await this.saasSubmitVote({
|
|
10698
10862
|
contractAddress,
|
|
10699
|
-
payload
|
|
10863
|
+
payload,
|
|
10864
|
+
ticket
|
|
10700
10865
|
});
|
|
10701
10866
|
return voteResult;
|
|
10702
10867
|
}
|
|
@@ -11069,6 +11234,8 @@ var OperatorClient = class {
|
|
|
11069
11234
|
this.messages = [];
|
|
11070
11235
|
this.states = MACI_STATES.FILLING;
|
|
11071
11236
|
this.logs = [];
|
|
11237
|
+
this.stateCommitment = poseidon([this.stateTree.root, this.stateSalt]);
|
|
11238
|
+
console.log("- Initial state commitment:", this.stateCommitment);
|
|
11072
11239
|
}
|
|
11073
11240
|
/**
|
|
11074
11241
|
* Get empty message
|
|
@@ -11153,6 +11320,7 @@ var OperatorClient = class {
|
|
|
11153
11320
|
hash = poseidon([...s.pubKey, s.balance, s.voted ? s.voTree.root : 0n, s.nonce]);
|
|
11154
11321
|
}
|
|
11155
11322
|
this.stateTree.updateLeaf(leafIdx, hash);
|
|
11323
|
+
this.stateCommitment = poseidon([this.stateTree.root, this.stateSalt]);
|
|
11156
11324
|
console.log(`Set State Leaf ${leafIdx}:`);
|
|
11157
11325
|
console.log("- Leaf hash:", hash.toString());
|
|
11158
11326
|
console.log("- New tree root:", this.stateTree.root.toString());
|