@dorafactory/maci-sdk 0.1.3-pre.46.beta.12 → 0.1.3-pre.46.beta.15

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 (35) hide show
  1. package/dist/index.js +336 -169
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +332 -165
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/libs/api/client.d.ts +4 -1
  6. package/dist/libs/api/types.d.ts +6 -10
  7. package/dist/libs/contract/config.d.ts +5 -1
  8. package/dist/libs/contract/contract.d.ts +1 -0
  9. package/dist/libs/contract/ts/AMaci.client.d.ts +5 -1
  10. package/dist/libs/contract/ts/AMaci.types.d.ts +24 -1
  11. package/dist/libs/contract/ts/ApiSaas.client.d.ts +49 -5
  12. package/dist/libs/contract/ts/ApiSaas.types.d.ts +35 -1
  13. package/dist/libs/contract/ts/Registry.client.d.ts +19 -5
  14. package/dist/libs/contract/ts/Registry.types.d.ts +25 -1
  15. package/dist/libs/contract/types.d.ts +0 -3
  16. package/dist/libs/maci/config.d.ts +24 -0
  17. package/dist/libs/maci/maci.d.ts +21 -7
  18. package/dist/maci.d.ts +0 -7
  19. package/dist/voter.d.ts +5 -2
  20. package/package.json +1 -1
  21. package/src/libs/api/client.ts +6 -3
  22. package/src/libs/api/types.ts +6 -10
  23. package/src/libs/contract/config.ts +12 -1
  24. package/src/libs/contract/contract.ts +12 -11
  25. package/src/libs/contract/ts/AMaci.client.ts +17 -0
  26. package/src/libs/contract/ts/AMaci.types.ts +26 -1
  27. package/src/libs/contract/ts/ApiSaas.client.ts +193 -5
  28. package/src/libs/contract/ts/ApiSaas.types.ts +39 -1
  29. package/src/libs/contract/ts/Registry.client.ts +85 -5
  30. package/src/libs/contract/ts/Registry.types.ts +29 -1
  31. package/src/libs/contract/types.ts +0 -3
  32. package/src/libs/maci/config.ts +55 -4
  33. package/src/libs/maci/maci.ts +118 -96
  34. package/src/maci.ts +0 -7
  35. package/src/voter.ts +3 -2
package/dist/index.js CHANGED
@@ -3536,6 +3536,16 @@ var AMaciQueryClient = class {
3536
3536
  }
3537
3537
  });
3538
3538
  };
3539
+ this.getFeeConfig = async () => {
3540
+ return this.client.queryContractSmart(this.contractAddress, {
3541
+ get_fee_config: {}
3542
+ });
3543
+ };
3544
+ this.getDelayConfig = async () => {
3545
+ return this.client.queryContractSmart(this.contractAddress, {
3546
+ get_delay_config: {}
3547
+ });
3548
+ };
3539
3549
  this.client = client;
3540
3550
  this.contractAddress = contractAddress;
3541
3551
  this.admin = this.admin.bind(this);
@@ -3575,6 +3585,8 @@ var AMaciQueryClient = class {
3575
3585
  this.getDeactivateEnabled = this.getDeactivateEnabled.bind(this);
3576
3586
  this.getRegistrationConfig = this.getRegistrationConfig.bind(this);
3577
3587
  this.queryRegistrationStatus = this.queryRegistrationStatus.bind(this);
3588
+ this.getFeeConfig = this.getFeeConfig.bind(this);
3589
+ this.getDelayConfig = this.getDelayConfig.bind(this);
3578
3590
  }
3579
3591
  };
3580
3592
  var AMaciClient = class extends AMaciQueryClient {
@@ -3919,6 +3931,16 @@ var RegistryQueryClient = class {
3919
3931
  get_circuit_charge_config: {}
3920
3932
  });
3921
3933
  };
3934
+ this.getFeeConfig = async () => {
3935
+ return this.client.queryContractSmart(this.contractAddress, {
3936
+ get_fee_config: {}
3937
+ });
3938
+ };
3939
+ this.getDelayConfig = async () => {
3940
+ return this.client.queryContractSmart(this.contractAddress, {
3941
+ get_delay_config: {}
3942
+ });
3943
+ };
3922
3944
  this.getPollId = async ({ address }) => {
3923
3945
  return this.client.queryContractSmart(this.contractAddress, {
3924
3946
  get_poll_id: {
@@ -3954,6 +3976,8 @@ var RegistryQueryClient = class {
3954
3976
  this.getMaciOperatorPubkey = this.getMaciOperatorPubkey.bind(this);
3955
3977
  this.getMaciOperatorIdentity = this.getMaciOperatorIdentity.bind(this);
3956
3978
  this.getCircuitChargeConfig = this.getCircuitChargeConfig.bind(this);
3979
+ this.getFeeConfig = this.getFeeConfig.bind(this);
3980
+ this.getDelayConfig = this.getDelayConfig.bind(this);
3957
3981
  this.getPollId = this.getPollId.bind(this);
3958
3982
  this.getPollAddress = this.getPollAddress.bind(this);
3959
3983
  this.getNextPollId = this.getNextPollId.bind(this);
@@ -4015,7 +4039,6 @@ var RegistryClient = class extends RegistryQueryClient {
4015
4039
  certificationSystem,
4016
4040
  circuitType,
4017
4041
  deactivateEnabled,
4018
- maxVoter,
4019
4042
  operator,
4020
4043
  registrationMode,
4021
4044
  roundInfo,
@@ -4031,7 +4054,6 @@ var RegistryClient = class extends RegistryQueryClient {
4031
4054
  certification_system: certificationSystem,
4032
4055
  circuit_type: circuitType,
4033
4056
  deactivate_enabled: deactivateEnabled,
4034
- max_voter: maxVoter,
4035
4057
  operator,
4036
4058
  registration_mode: registrationMode,
4037
4059
  round_info: roundInfo,
@@ -4125,6 +4147,38 @@ var RegistryClient = class extends RegistryQueryClient {
4125
4147
  _funds
4126
4148
  );
4127
4149
  };
4150
+ this.updateFeeConfig = async ({
4151
+ config
4152
+ }, fee = "auto", memo, _funds) => {
4153
+ return await this.client.execute(
4154
+ this.sender,
4155
+ this.contractAddress,
4156
+ {
4157
+ update_fee_config: {
4158
+ config
4159
+ }
4160
+ },
4161
+ fee,
4162
+ memo,
4163
+ _funds
4164
+ );
4165
+ };
4166
+ this.updateDelayConfig = async ({
4167
+ config
4168
+ }, fee = "auto", memo, _funds) => {
4169
+ return await this.client.execute(
4170
+ this.sender,
4171
+ this.contractAddress,
4172
+ {
4173
+ update_delay_config: {
4174
+ config
4175
+ }
4176
+ },
4177
+ fee,
4178
+ memo,
4179
+ _funds
4180
+ );
4181
+ };
4128
4182
  this.client = client;
4129
4183
  this.sender = sender;
4130
4184
  this.contractAddress = contractAddress;
@@ -4137,6 +4191,8 @@ var RegistryClient = class extends RegistryQueryClient {
4137
4191
  this.updateAmaciCodeId = this.updateAmaciCodeId.bind(this);
4138
4192
  this.changeOperator = this.changeOperator.bind(this);
4139
4193
  this.changeChargeConfig = this.changeChargeConfig.bind(this);
4194
+ this.updateFeeConfig = this.updateFeeConfig.bind(this);
4195
+ this.updateDelayConfig = this.updateDelayConfig.bind(this);
4140
4196
  }
4141
4197
  };
4142
4198
 
@@ -4282,7 +4338,6 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4282
4338
  certificationSystem,
4283
4339
  circuitType,
4284
4340
  deactivateEnabled,
4285
- maxVoter,
4286
4341
  operator,
4287
4342
  registrationMode,
4288
4343
  roundInfo,
@@ -4298,7 +4353,6 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4298
4353
  certification_system: certificationSystem,
4299
4354
  circuit_type: circuitType,
4300
4355
  deactivate_enabled: deactivateEnabled,
4301
- max_voter: maxVoter,
4302
4356
  operator,
4303
4357
  registration_mode: registrationMode,
4304
4358
  round_info: roundInfo,
@@ -4312,6 +4366,22 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4312
4366
  _funds
4313
4367
  );
4314
4368
  };
4369
+ this.updateFeeConfig = async ({
4370
+ config
4371
+ }, fee = "auto", memo, _funds) => {
4372
+ return await this.client.execute(
4373
+ this.sender,
4374
+ this.contractAddress,
4375
+ {
4376
+ update_fee_config: {
4377
+ config
4378
+ }
4379
+ },
4380
+ fee,
4381
+ memo,
4382
+ _funds
4383
+ );
4384
+ };
4315
4385
  this.setRoundInfo = async ({
4316
4386
  contractAddr,
4317
4387
  roundInfo
@@ -4388,6 +4458,76 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4388
4458
  _funds
4389
4459
  );
4390
4460
  };
4461
+ this.signUp = async ({
4462
+ amount,
4463
+ certificate,
4464
+ contractAddr,
4465
+ pubkey
4466
+ }, fee = "auto", memo, _funds) => {
4467
+ return await this.client.execute(
4468
+ this.sender,
4469
+ this.contractAddress,
4470
+ {
4471
+ sign_up: {
4472
+ amount,
4473
+ certificate,
4474
+ contract_addr: contractAddr,
4475
+ pubkey
4476
+ }
4477
+ },
4478
+ fee,
4479
+ memo,
4480
+ _funds
4481
+ );
4482
+ };
4483
+ this.addNewKey = async ({
4484
+ contractAddr,
4485
+ d,
4486
+ groth16Proof,
4487
+ nullifier,
4488
+ pubkey
4489
+ }, fee = "auto", memo, _funds) => {
4490
+ return await this.client.execute(
4491
+ this.sender,
4492
+ this.contractAddress,
4493
+ {
4494
+ add_new_key: {
4495
+ contract_addr: contractAddr,
4496
+ d,
4497
+ groth16_proof: groth16Proof,
4498
+ nullifier,
4499
+ pubkey
4500
+ }
4501
+ },
4502
+ fee,
4503
+ memo,
4504
+ _funds
4505
+ );
4506
+ };
4507
+ this.preAddNewKey = async ({
4508
+ contractAddr,
4509
+ d,
4510
+ groth16Proof,
4511
+ nullifier,
4512
+ pubkey
4513
+ }, fee = "auto", memo, _funds) => {
4514
+ return await this.client.execute(
4515
+ this.sender,
4516
+ this.contractAddress,
4517
+ {
4518
+ pre_add_new_key: {
4519
+ contract_addr: contractAddr,
4520
+ d,
4521
+ groth16_proof: groth16Proof,
4522
+ nullifier,
4523
+ pubkey
4524
+ }
4525
+ },
4526
+ fee,
4527
+ memo,
4528
+ _funds
4529
+ );
4530
+ };
4391
4531
  this.client = client;
4392
4532
  this.sender = sender;
4393
4533
  this.contractAddress = contractAddress;
@@ -4398,10 +4538,14 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4398
4538
  this.deposit = this.deposit.bind(this);
4399
4539
  this.withdraw = this.withdraw.bind(this);
4400
4540
  this.createAmaciRound = this.createAmaciRound.bind(this);
4541
+ this.updateFeeConfig = this.updateFeeConfig.bind(this);
4401
4542
  this.setRoundInfo = this.setRoundInfo.bind(this);
4402
4543
  this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
4403
4544
  this.publishMessage = this.publishMessage.bind(this);
4404
4545
  this.publishDeactivateMessage = this.publishDeactivateMessage.bind(this);
4546
+ this.signUp = this.signUp.bind(this);
4547
+ this.addNewKey = this.addNewKey.bind(this);
4548
+ this.preAddNewKey = this.preAddNewKey.bind(this);
4405
4549
  }
4406
4550
  };
4407
4551
 
@@ -4437,6 +4581,13 @@ async function createRegistryClientBy({
4437
4581
  const [{ address }] = await wallet.getAccounts();
4438
4582
  return new RegistryClient(signingCosmWasmClient, address, contractAddress);
4439
4583
  }
4584
+ async function createRegistryQueryClientBy({
4585
+ rpcEndpoint,
4586
+ contractAddress
4587
+ }) {
4588
+ const cosmWasmClient = await import_cosmwasm_stargate.CosmWasmClient.connect(rpcEndpoint);
4589
+ return new RegistryQueryClient(cosmWasmClient, contractAddress);
4590
+ }
4440
4591
  async function createApiSaasClientBy({
4441
4592
  rpcEndpoint,
4442
4593
  wallet,
@@ -4453,53 +4604,33 @@ async function createContractClientByWallet(rpcEndpoint, wallet) {
4453
4604
  return client;
4454
4605
  }
4455
4606
 
4456
- // src/types/index.ts
4457
- var MaciCircuitType = /* @__PURE__ */ ((MaciCircuitType2) => {
4458
- MaciCircuitType2["IP1V"] = "0";
4459
- MaciCircuitType2["QV"] = "1";
4460
- return MaciCircuitType2;
4461
- })(MaciCircuitType || {});
4462
- var MaciCertSystemType = /* @__PURE__ */ ((MaciCertSystemType2) => {
4463
- MaciCertSystemType2["GROTH16"] = "groth16";
4464
- MaciCertSystemType2["PLONK"] = "plonk";
4465
- return MaciCertSystemType2;
4466
- })(MaciCertSystemType || {});
4467
- var MaciRoundType = /* @__PURE__ */ ((MaciRoundType2) => {
4468
- MaciRoundType2["MACI"] = "0";
4469
- MaciRoundType2["AMACI"] = "1";
4470
- MaciRoundType2["ORACLE_MACI"] = "2";
4471
- return MaciRoundType2;
4472
- })(MaciRoundType || {});
4607
+ // src/libs/contract/contract.ts
4608
+ var import_stargate2 = require("@cosmjs/stargate");
4473
4609
 
4474
- // src/libs/contract/utils.ts
4475
- function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
4476
- let requiredFee = {
4477
- denom: "peaka",
4478
- amount: "0"
4479
- };
4480
- if (maxVoter <= 25 && maxOption <= 5) {
4481
- requiredFee.amount = "5000000000000000000";
4482
- } else if (maxVoter <= 625 && maxOption <= 25) {
4483
- requiredFee.amount = "27000000000000000000";
4484
- } else if (maxVoter <= 15625 && maxOption <= 125) {
4485
- requiredFee.amount = "208000000000000000000";
4486
- } else {
4487
- throw new Error("Number of voters or options is too large.");
4488
- }
4489
- return requiredFee;
4490
- }
4491
- function getMaciRoundCircuitFee(network, maxVoter, maxOption) {
4492
- const amaciRoundFee = getAMaciRoundCircuitFee(network, maxVoter, maxOption);
4493
- const feeAmount = BigInt(amaciRoundFee.amount);
4494
- const maciRoundFeeAmount = feeAmount * BigInt(1) / BigInt(10);
4495
- return {
4496
- denom: "peaka",
4497
- amount: maciRoundFeeAmount.toString()
4498
- };
4499
- }
4610
+ // src/libs/maci/config.ts
4611
+ var FEE_DENOM = "peaka";
4612
+ var DEFAULT_BASE_FEE = "30000000000000000000";
4613
+ var DEFAULT_MESSAGE_FEE = "60000000000000000";
4614
+ var DEFAULT_DEACTIVATE_FEE = "10000000000000000000";
4615
+ var DEFAULT_SIGNUP_FEE = "30000000000000000";
4616
+ var DEFAULT_BASE_DELAY = 200;
4617
+ var DEFAULT_MESSAGE_DELAY = 2;
4618
+ var DEFAULT_SIGNUP_DELAY = 1;
4619
+ var DEFAULT_DEACTIVATE_DELAY = 600;
4620
+ var DEFAULT_FEE_CONFIG = {
4621
+ baseFee: DEFAULT_BASE_FEE,
4622
+ messageFee: DEFAULT_MESSAGE_FEE,
4623
+ deactivateFee: DEFAULT_DEACTIVATE_FEE,
4624
+ signupFee: DEFAULT_SIGNUP_FEE
4625
+ };
4626
+ var DEFAULT_DELAY_CONFIG = {
4627
+ baseDelay: DEFAULT_BASE_DELAY,
4628
+ messageDelay: DEFAULT_MESSAGE_DELAY,
4629
+ signupDelay: DEFAULT_SIGNUP_DELAY,
4630
+ deactivateDelay: DEFAULT_DEACTIVATE_DELAY
4631
+ };
4500
4632
 
4501
4633
  // src/libs/contract/contract.ts
4502
- var import_stargate2 = require("@cosmjs/stargate");
4503
4634
  var Contract = class {
4504
4635
  constructor({
4505
4636
  network,
@@ -4538,18 +4669,12 @@ var Contract = class {
4538
4669
  wallet: signer,
4539
4670
  contractAddress: this.registryAddress
4540
4671
  });
4541
- const requiredFee = getAMaciRoundCircuitFee(
4542
- this.network,
4543
- params.maxVoter,
4544
- params.voteOptionMap.length
4545
- );
4546
4672
  const fee = params.fee ?? "auto";
4547
4673
  const res = await client.createRound(
4548
4674
  {
4549
4675
  certificationSystem: params.certificationSystem ?? "0",
4550
4676
  circuitType: params.circuitType.toString(),
4551
4677
  deactivateEnabled: params.deactivateEnabled,
4552
- maxVoter: params.maxVoter.toString(),
4553
4678
  operator: params.operator,
4554
4679
  registrationMode: params.registrationMode,
4555
4680
  roundInfo,
@@ -4559,7 +4684,7 @@ var Contract = class {
4559
4684
  },
4560
4685
  fee,
4561
4686
  void 0,
4562
- [requiredFee]
4687
+ [{ denom: FEE_DENOM, amount: DEFAULT_BASE_FEE }]
4563
4688
  );
4564
4689
  let contractAddress = "";
4565
4690
  let pollId = "";
@@ -4647,6 +4772,12 @@ var Contract = class {
4647
4772
  contractAddress
4648
4773
  });
4649
4774
  }
4775
+ async registryQueryClient() {
4776
+ return createRegistryQueryClientBy({
4777
+ rpcEndpoint: this.rpcEndpoint,
4778
+ contractAddress: this.registryAddress
4779
+ });
4780
+ }
4650
4781
  async apiSaasClient({
4651
4782
  signer,
4652
4783
  contractAddress
@@ -4940,7 +5071,6 @@ var Contract = class {
4940
5071
  certificationSystem: params.certificationSystem ?? "0",
4941
5072
  circuitType,
4942
5073
  deactivateEnabled: params.deactivateEnabled,
4943
- maxVoter: params.maxVoter.toString(),
4944
5074
  operator: params.operator,
4945
5075
  registrationMode: params.registrationMode,
4946
5076
  roundInfo,
@@ -4959,7 +5089,6 @@ var Contract = class {
4959
5089
  certification_system: roundParams.certificationSystem,
4960
5090
  circuit_type: roundParams.circuitType,
4961
5091
  deactivate_enabled: roundParams.deactivateEnabled,
4962
- max_voter: roundParams.maxVoter,
4963
5092
  operator: roundParams.operator,
4964
5093
  registration_mode: roundParams.registrationMode,
4965
5094
  round_info: roundParams.roundInfo,
@@ -5150,6 +5279,51 @@ var Contract = class {
5150
5279
  }
5151
5280
  };
5152
5281
 
5282
+ // src/types/index.ts
5283
+ var MaciCircuitType = /* @__PURE__ */ ((MaciCircuitType2) => {
5284
+ MaciCircuitType2["IP1V"] = "0";
5285
+ MaciCircuitType2["QV"] = "1";
5286
+ return MaciCircuitType2;
5287
+ })(MaciCircuitType || {});
5288
+ var MaciCertSystemType = /* @__PURE__ */ ((MaciCertSystemType2) => {
5289
+ MaciCertSystemType2["GROTH16"] = "groth16";
5290
+ MaciCertSystemType2["PLONK"] = "plonk";
5291
+ return MaciCertSystemType2;
5292
+ })(MaciCertSystemType || {});
5293
+ var MaciRoundType = /* @__PURE__ */ ((MaciRoundType2) => {
5294
+ MaciRoundType2["MACI"] = "0";
5295
+ MaciRoundType2["AMACI"] = "1";
5296
+ MaciRoundType2["ORACLE_MACI"] = "2";
5297
+ return MaciRoundType2;
5298
+ })(MaciRoundType || {});
5299
+
5300
+ // src/libs/contract/utils.ts
5301
+ function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
5302
+ let requiredFee = {
5303
+ denom: "peaka",
5304
+ amount: "0"
5305
+ };
5306
+ if (maxVoter <= 25 && maxOption <= 5) {
5307
+ requiredFee.amount = "5000000000000000000";
5308
+ } else if (maxVoter <= 625 && maxOption <= 25) {
5309
+ requiredFee.amount = "27000000000000000000";
5310
+ } else if (maxVoter <= 15625 && maxOption <= 125) {
5311
+ requiredFee.amount = "208000000000000000000";
5312
+ } else {
5313
+ throw new Error("Number of voters or options is too large.");
5314
+ }
5315
+ return requiredFee;
5316
+ }
5317
+ function getMaciRoundCircuitFee(network, maxVoter, maxOption) {
5318
+ const amaciRoundFee = getAMaciRoundCircuitFee(network, maxVoter, maxOption);
5319
+ const feeAmount = BigInt(amaciRoundFee.amount);
5320
+ const maciRoundFeeAmount = feeAmount * BigInt(1) / BigInt(10);
5321
+ return {
5322
+ denom: "peaka",
5323
+ amount: maciRoundFeeAmount.toString()
5324
+ };
5325
+ }
5326
+
5153
5327
  // src/libs/oracle-certificate/oracle-certificate.ts
5154
5328
  var OracleCertificate = class {
5155
5329
  constructor({ certificateApiEndpoint, http }) {
@@ -5202,13 +5376,6 @@ var OracleCertificate = class {
5202
5376
  // src/libs/maci/maci.ts
5203
5377
  var import_stargate3 = require("@cosmjs/stargate");
5204
5378
  var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx.js");
5205
-
5206
- // src/libs/maci/config.ts
5207
- var FEE_DENOM = "peaka";
5208
- var DEACTIVATE_FEE = "10000000000000000000";
5209
- var MESSAGE_FEE = "60000000000000000";
5210
-
5211
- // src/libs/maci/maci.ts
5212
5379
  function isErrorResponse(response) {
5213
5380
  return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
5214
5381
  }
@@ -5224,6 +5391,46 @@ var MACI = class {
5224
5391
  this.indexer = indexer;
5225
5392
  this.oracleCertificate = oracleCertificate;
5226
5393
  this.maciKeypair = maciKeypair;
5394
+ this.feeConfig = { ...DEFAULT_FEE_CONFIG };
5395
+ this.delayConfig = { ...DEFAULT_DELAY_CONFIG };
5396
+ }
5397
+ /**
5398
+ * Fetch the fee configuration from the given round contract and cache it locally.
5399
+ * Call this once after instantiation (or whenever fees may have changed) to ensure
5400
+ * the SDK uses the correct on-chain fee values for the specific round.
5401
+ */
5402
+ async fetchFeeConfig({ contractAddress }) {
5403
+ try {
5404
+ const roundClient = await this.contract.amaciQueryClient({ contractAddress });
5405
+ const feeConfig = await roundClient.getFeeConfig();
5406
+ this.feeConfig = {
5407
+ ...this.feeConfig,
5408
+ messageFee: feeConfig.message_fee,
5409
+ deactivateFee: feeConfig.deactivate_fee,
5410
+ signupFee: feeConfig.signup_fee
5411
+ };
5412
+ } catch {
5413
+ }
5414
+ return this.feeConfig;
5415
+ }
5416
+ /**
5417
+ * Fetch the delay configuration from the given round contract and cache it locally.
5418
+ * Call this once after instantiation (or whenever delays may have changed) to ensure
5419
+ * the SDK uses the correct on-chain delay values for the specific round.
5420
+ */
5421
+ async fetchDelayConfig({ contractAddress }) {
5422
+ try {
5423
+ const roundClient = await this.contract.amaciQueryClient({ contractAddress });
5424
+ const delayConfig = await roundClient.getDelayConfig();
5425
+ this.delayConfig = {
5426
+ baseDelay: delayConfig.base_delay,
5427
+ messageDelay: delayConfig.message_delay,
5428
+ signupDelay: delayConfig.signup_delay,
5429
+ deactivateDelay: delayConfig.deactivate_delay
5430
+ };
5431
+ } catch {
5432
+ }
5433
+ return this.delayConfig;
5227
5434
  }
5228
5435
  async getPollId({ contractAddress }) {
5229
5436
  const client = await this.contract.amaciQueryClient({ contractAddress });
@@ -5359,10 +5566,6 @@ var MACI = class {
5359
5566
  };
5360
5567
  }
5361
5568
  }
5362
- async queryAMaciChargeFee({ maxVoter, maxOption }) {
5363
- const fee = getAMaciRoundCircuitFee(this.network, maxVoter, maxOption);
5364
- return fee;
5365
- }
5366
5569
  async queryRoundGasStation({ contractAddress }) {
5367
5570
  const roundInfo = await this.getRoundInfo({ contractAddress });
5368
5571
  return roundInfo.gasStationEnable;
@@ -5445,6 +5648,7 @@ var MACI = class {
5445
5648
  certificate: oracleCertificate?.signature || ""
5446
5649
  }
5447
5650
  };
5651
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
5448
5652
  if (gasStation === true && typeof fee !== "object") {
5449
5653
  const gasEstimation = await client.simulate(
5450
5654
  address,
@@ -5454,7 +5658,8 @@ var MACI = class {
5454
5658
  value: {
5455
5659
  sender: address,
5456
5660
  contract: contractAddress,
5457
- msg: new TextEncoder().encode(JSON.stringify(msg))
5661
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
5662
+ funds: signupFunds
5458
5663
  }
5459
5664
  }
5460
5665
  ],
@@ -5468,15 +5673,15 @@ var MACI = class {
5468
5673
  gas: calculatedFee.gas,
5469
5674
  granter: contractAddress
5470
5675
  };
5471
- return client.execute(address, contractAddress, msg, grantFee);
5676
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5472
5677
  } else if (gasStation === true && typeof fee === "object") {
5473
5678
  const grantFee = {
5474
5679
  ...fee,
5475
5680
  granter: contractAddress
5476
5681
  };
5477
- return client.execute(address, contractAddress, msg, grantFee);
5682
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5478
5683
  }
5479
- return client.execute(address, contractAddress, msg, fee || "auto");
5684
+ return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
5480
5685
  } catch (error) {
5481
5686
  throw Error(`Signup failed! ${error}`);
5482
5687
  }
@@ -5508,6 +5713,7 @@ var MACI = class {
5508
5713
  certificate: oracleCertificate?.signature || ""
5509
5714
  }
5510
5715
  };
5716
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
5511
5717
  if (gasStation === true && typeof fee !== "object") {
5512
5718
  const gasEstimation = await client.simulate(
5513
5719
  address,
@@ -5517,7 +5723,8 @@ var MACI = class {
5517
5723
  value: {
5518
5724
  sender: address,
5519
5725
  contract: contractAddress,
5520
- msg: new TextEncoder().encode(JSON.stringify(msg))
5726
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
5727
+ funds: signupFunds
5521
5728
  }
5522
5729
  }
5523
5730
  ],
@@ -5531,15 +5738,15 @@ var MACI = class {
5531
5738
  gas: calculatedFee.gas,
5532
5739
  granter: granter || contractAddress
5533
5740
  };
5534
- return client.execute(address, contractAddress, msg, grantFee);
5741
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5535
5742
  } else if (gasStation === true && typeof fee === "object") {
5536
5743
  const grantFee = {
5537
5744
  ...fee,
5538
5745
  granter: granter || contractAddress
5539
5746
  };
5540
- return client.execute(address, contractAddress, msg, grantFee);
5747
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5541
5748
  }
5542
- return client.execute(address, contractAddress, msg, fee || "auto");
5749
+ return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
5543
5750
  } catch (error) {
5544
5751
  throw Error(`Signup failed! ${error}`);
5545
5752
  }
@@ -5718,7 +5925,7 @@ var MACI = class {
5718
5925
  })
5719
5926
  )
5720
5927
  ),
5721
- funds: [{ denom: FEE_DENOM, amount: MESSAGE_FEE }]
5928
+ funds: [{ denom: FEE_DENOM, amount: this.feeConfig.messageFee }]
5722
5929
  })
5723
5930
  }));
5724
5931
  if (gasStation && typeof fee !== "object") {
@@ -5764,7 +5971,7 @@ var MACI = class {
5764
5971
  x: p.encPubkeys[0].toString(),
5765
5972
  y: p.encPubkeys[1].toString()
5766
5973
  }));
5767
- const totalFee = (BigInt(MESSAGE_FEE) * BigInt(payload.length)).toString();
5974
+ const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
5768
5975
  const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
5769
5976
  if (gasStation && granter === this.contract.apiSaasAddress) {
5770
5977
  return this.contract.publishMessageViaSaas({
@@ -5827,6 +6034,8 @@ var MACI = class {
5827
6034
  x: p.encPubkeys[0],
5828
6035
  y: p.encPubkeys[1]
5829
6036
  }));
6037
+ const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
6038
+ const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
5830
6039
  const msg = {
5831
6040
  typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5832
6041
  value: import_tx.MsgExecuteContract.fromPartial({
@@ -5841,7 +6050,8 @@ var MACI = class {
5841
6050
  }
5842
6051
  })
5843
6052
  )
5844
- )
6053
+ ),
6054
+ funds: batchFunds
5845
6055
  })
5846
6056
  };
5847
6057
  if (gasStation && typeof fee !== "object") {
@@ -5910,7 +6120,7 @@ var MACI = class {
5910
6120
  }
5911
6121
  }
5912
6122
  });
5913
- const deactivateFunds = [{ denom: FEE_DENOM, amount: DEACTIVATE_FEE }];
6123
+ const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
5914
6124
  if (gasStation === true && typeof fee !== "object") {
5915
6125
  const gasEstimation = await client.simulate(
5916
6126
  address,
@@ -5987,7 +6197,7 @@ var MACI = class {
5987
6197
  }
5988
6198
  }
5989
6199
  });
5990
- const deactivateFunds = [{ denom: FEE_DENOM, amount: DEACTIVATE_FEE }];
6200
+ const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
5991
6201
  if (gasStation === true && typeof fee !== "object") {
5992
6202
  const gasEstimation = await client.simulate(
5993
6203
  address,
@@ -6065,6 +6275,7 @@ var MACI = class {
6065
6275
  signer,
6066
6276
  contractAddress
6067
6277
  });
6278
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6068
6279
  return await client.addNewKey(
6069
6280
  {
6070
6281
  d,
@@ -6075,7 +6286,9 @@ var MACI = class {
6075
6286
  y: newMaciKeypair.pubKey[1].toString()
6076
6287
  }
6077
6288
  },
6078
- fee
6289
+ fee,
6290
+ void 0,
6291
+ signupFunds
6079
6292
  );
6080
6293
  }
6081
6294
  async rawAddNewKey({
@@ -6093,6 +6306,16 @@ var MACI = class {
6093
6306
  signer,
6094
6307
  contractAddress
6095
6308
  });
6309
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6310
+ const keyParams = {
6311
+ d,
6312
+ groth16Proof: proof,
6313
+ nullifier: nullifier.toString(),
6314
+ pubkey: {
6315
+ x: newPubkey[0].toString(),
6316
+ y: newPubkey[1].toString()
6317
+ }
6318
+ };
6096
6319
  if (gasStation === true && typeof fee !== "object") {
6097
6320
  const [{ address }] = await signer.getAccounts();
6098
6321
  const contractClient = await this.contract.contractClient({ signer });
@@ -6115,7 +6338,8 @@ var MACI = class {
6115
6338
  value: {
6116
6339
  sender: address,
6117
6340
  contract: contractAddress,
6118
- msg: new TextEncoder().encode(JSON.stringify(msg))
6341
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
6342
+ funds: signupFunds
6119
6343
  }
6120
6344
  }
6121
6345
  ],
@@ -6129,48 +6353,15 @@ var MACI = class {
6129
6353
  gas: calculatedFee.gas,
6130
6354
  granter: granter || contractAddress
6131
6355
  };
6132
- return await client.addNewKey(
6133
- {
6134
- d,
6135
- groth16Proof: proof,
6136
- nullifier: nullifier.toString(),
6137
- pubkey: {
6138
- x: newPubkey[0].toString(),
6139
- y: newPubkey[1].toString()
6140
- }
6141
- },
6142
- grantFee
6143
- );
6356
+ return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
6144
6357
  } else if (gasStation === true && typeof fee === "object") {
6145
6358
  const grantFee = {
6146
6359
  ...fee,
6147
6360
  granter: granter || contractAddress
6148
6361
  };
6149
- return await client.addNewKey(
6150
- {
6151
- d,
6152
- groth16Proof: proof,
6153
- nullifier: nullifier.toString(),
6154
- pubkey: {
6155
- x: newPubkey[0].toString(),
6156
- y: newPubkey[1].toString()
6157
- }
6158
- },
6159
- grantFee
6160
- );
6362
+ return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
6161
6363
  }
6162
- return await client.addNewKey(
6163
- {
6164
- d,
6165
- groth16Proof: proof,
6166
- nullifier: nullifier.toString(),
6167
- pubkey: {
6168
- x: newPubkey[0].toString(),
6169
- y: newPubkey[1].toString()
6170
- }
6171
- },
6172
- fee
6173
- );
6364
+ return await client.addNewKey(keyParams, fee, void 0, signupFunds);
6174
6365
  }
6175
6366
  async rawPreAddNewKey({
6176
6367
  signer,
@@ -6187,6 +6378,16 @@ var MACI = class {
6187
6378
  signer,
6188
6379
  contractAddress
6189
6380
  });
6381
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6382
+ const keyParams = {
6383
+ d,
6384
+ groth16Proof: proof,
6385
+ nullifier: nullifier.toString(),
6386
+ pubkey: {
6387
+ x: newPubkey[0].toString(),
6388
+ y: newPubkey[1].toString()
6389
+ }
6390
+ };
6190
6391
  if (gasStation === true && typeof fee !== "object") {
6191
6392
  const [{ address }] = await signer.getAccounts();
6192
6393
  const contractClient = await this.contract.contractClient({ signer });
@@ -6209,7 +6410,8 @@ var MACI = class {
6209
6410
  value: {
6210
6411
  sender: address,
6211
6412
  contract: contractAddress,
6212
- msg: new TextEncoder().encode(JSON.stringify(msg))
6413
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
6414
+ funds: signupFunds
6213
6415
  }
6214
6416
  }
6215
6417
  ],
@@ -6223,48 +6425,15 @@ var MACI = class {
6223
6425
  gas: calculatedFee.gas,
6224
6426
  granter: granter || contractAddress
6225
6427
  };
6226
- return await client.preAddNewKey(
6227
- {
6228
- d,
6229
- groth16Proof: proof,
6230
- nullifier: nullifier.toString(),
6231
- pubkey: {
6232
- x: newPubkey[0].toString(),
6233
- y: newPubkey[1].toString()
6234
- }
6235
- },
6236
- grantFee
6237
- );
6428
+ return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
6238
6429
  } else if (gasStation === true && typeof fee === "object") {
6239
6430
  const grantFee = {
6240
6431
  ...fee,
6241
6432
  granter: granter || contractAddress
6242
6433
  };
6243
- return await client.preAddNewKey(
6244
- {
6245
- d,
6246
- groth16Proof: proof,
6247
- nullifier: nullifier.toString(),
6248
- pubkey: {
6249
- x: newPubkey[0].toString(),
6250
- y: newPubkey[1].toString()
6251
- }
6252
- },
6253
- grantFee
6254
- );
6434
+ return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
6255
6435
  }
6256
- return await client.preAddNewKey(
6257
- {
6258
- d,
6259
- groth16Proof: proof,
6260
- nullifier: nullifier.toString(),
6261
- pubkey: {
6262
- x: newPubkey[0].toString(),
6263
- y: newPubkey[1].toString()
6264
- }
6265
- },
6266
- fee
6267
- );
6436
+ return await client.preAddNewKey(keyParams, fee, void 0, signupFunds);
6268
6437
  }
6269
6438
  async claimAMaciRound({
6270
6439
  signer,
@@ -6716,14 +6885,17 @@ var MaciApiClient = class {
6716
6885
  /**
6717
6886
  * Claim MACI Key
6718
6887
  * Assign the next available pre-generated MACI key pair for an AMACI round (first-come-first-served).
6888
+ * Requires the X-Amaci-Claim-Key header for authentication.
6719
6889
  * Returns pubkey, secretKey, and the full deactivate Merkle proof.
6720
6890
  * WARNING: secretKey is returned only once and cannot be retrieved again.
6721
6891
  */
6722
6892
  async claimMaciKey(params) {
6723
- const { contractAddress, ...body } = params;
6893
+ const { contractAddress, amaciClaimKey } = params;
6724
6894
  return this.fetch(`/v1/rounds/${contractAddress}/claim-key`, {
6725
6895
  method: "POST",
6726
- body: JSON.stringify(body)
6896
+ headers: {
6897
+ "X-Amaci-Claim-Key": amaciClaimKey
6898
+ }
6727
6899
  });
6728
6900
  }
6729
6901
  /**
@@ -7011,12 +7183,6 @@ var MaciClient = class {
7011
7183
  async queryRoundClaimable({ contractAddress }) {
7012
7184
  return await this.maci.queryRoundClaimable({ contractAddress });
7013
7185
  }
7014
- async queryAMaciChargeFee({ maxVoter, maxOption }) {
7015
- return await this.maci.queryAMaciChargeFee({
7016
- maxVoter,
7017
- maxOption
7018
- });
7019
- }
7020
7186
  async queryRoundGasStation({ contractAddress }) {
7021
7187
  return await this.maci.queryRoundGasStation({ contractAddress });
7022
7188
  }
@@ -7322,7 +7488,7 @@ var import_snarkjs = require("snarkjs");
7322
7488
 
7323
7489
  // src/libs/keypairs/eddsa-poseidon/keypair.ts
7324
7490
  var import_blake2b = require("@noble/hashes/blake2b");
7325
- var import_utils9 = require("@noble/hashes/utils");
7491
+ var import_utils7 = require("@noble/hashes/utils");
7326
7492
  var import_bip32 = require("@scure/bip32");
7327
7493
  var import_sha2563 = require("@noble/hashes/sha256");
7328
7494
  var import_eddsa_poseidon4 = require("@zk-kit/eddsa-poseidon");
@@ -7533,7 +7699,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7533
7699
  static fromSecretKey(secretKey, options) {
7534
7700
  if (typeof secretKey === "string") {
7535
7701
  const cleanSecretKey = secretKey.startsWith("0x") ? secretKey.slice(2) : secretKey;
7536
- const decoded = buffer2Bigint((0, import_utils9.hexToBytes)(cleanSecretKey));
7702
+ const decoded = buffer2Bigint((0, import_utils7.hexToBytes)(cleanSecretKey));
7537
7703
  return this.fromSecretKey(decoded, options);
7538
7704
  }
7539
7705
  const unPackedPublicKey = genPubKey(secretKey);
@@ -7541,7 +7707,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7541
7707
  if (!options || !options.skipValidation) {
7542
7708
  const encoder = new TextEncoder();
7543
7709
  const signData = encoder.encode("dora validation");
7544
- const msgHash = (0, import_utils9.bytesToHex)((0, import_blake2b.blake2b)(signData, { dkLen: 16 }));
7710
+ const msgHash = (0, import_utils7.bytesToHex)((0, import_blake2b.blake2b)(signData, { dkLen: 16 }));
7545
7711
  const signature = (0, import_eddsa_poseidon4.signMessage)(bigInt2Buffer(secretKey), msgHash);
7546
7712
  if (!(0, import_eddsa_poseidon4.verifySignature)(msgHash, signature, unPackedPublicKey)) {
7547
7713
  throw new Error("Provided secretKey is invalid");
@@ -7571,7 +7737,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7571
7737
  * @returns The secret key encoded as a hexadecimal string
7572
7738
  */
7573
7739
  getSecretKey() {
7574
- return (0, import_utils9.bytesToHex)(bigInt2Buffer(this.keypair.secretKey));
7740
+ return (0, import_utils7.bytesToHex)(bigInt2Buffer(this.keypair.secretKey));
7575
7741
  }
7576
7742
  /**
7577
7743
  * Get the secret key as a bigint.
@@ -8760,8 +8926,9 @@ var VoterClient = class _VoterClient {
8760
8926
  /**
8761
8927
  * Claim the next available pre-generated MACI key pair for an AMACI round via SaaS API.
8762
8928
  * The key is assigned on a first-come-first-served basis.
8929
+ * Requires an AMACI claim key passed via the X-Amaci-Claim-Key header.
8763
8930
  * WARNING: secretKey is returned only once — save it immediately, it cannot be retrieved again.
8764
- * @param params - Parameters including contractAddress and ticket
8931
+ * @param params - Parameters including contractAddress and amaciClaimKey
8765
8932
  * @returns Claimed key pair with full deactivate Merkle proof
8766
8933
  */
8767
8934
  async saasClaimKey(params) {