@dorafactory/maci-sdk 0.1.3-pre.17 → 0.1.3-pre.19

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 CHANGED
@@ -7768,31 +7768,12 @@ var MACI = class {
7768
7768
  signer,
7769
7769
  address,
7770
7770
  contractAddress,
7771
- pubKey,
7772
7771
  payload,
7773
7772
  gasStation = false,
7774
7773
  granter,
7775
7774
  fee = 1.8
7776
7775
  }) {
7777
- const stateIdx = await this.getStateIdxByPubKey({
7778
- contractAddress,
7779
- pubKey
7780
- });
7781
- if (stateIdx === -1) {
7782
- throw new Error(
7783
- "State index is not set, Please signup or addNewKey first"
7784
- );
7785
- }
7786
7776
  try {
7787
- const round = await this.indexer.getRoundWithFields(contractAddress, [
7788
- "maciType",
7789
- "voiceCreditAmount"
7790
- ]);
7791
- if (isErrorResponse(round)) {
7792
- throw new Error(
7793
- `Failed to get round info: ${round.error.type} ${round.error.message}`
7794
- );
7795
- }
7796
7777
  if (!address) {
7797
7778
  address = (await signer.getAccounts())[0].address;
7798
7779
  }
@@ -8299,6 +8280,103 @@ var MACI = class {
8299
8280
  fee
8300
8281
  );
8301
8282
  }
8283
+ async rawPreAddNewKey({
8284
+ signer,
8285
+ contractAddress,
8286
+ d,
8287
+ proof,
8288
+ nullifier,
8289
+ newPubkey,
8290
+ gasStation = false,
8291
+ granter,
8292
+ fee = "auto"
8293
+ }) {
8294
+ const client = await this.contract.amaciClient({
8295
+ signer,
8296
+ contractAddress
8297
+ });
8298
+ if (gasStation === true && typeof fee !== "object") {
8299
+ const [{ address }] = await signer.getAccounts();
8300
+ const contractClient = await this.contract.contractClient({ signer });
8301
+ const msg = {
8302
+ pre_add_new_key: {
8303
+ d,
8304
+ groth16_proof: proof,
8305
+ nullifier: nullifier.toString(),
8306
+ pubkey: {
8307
+ x: newPubkey[0].toString(),
8308
+ y: newPubkey[1].toString()
8309
+ }
8310
+ }
8311
+ };
8312
+ const gasEstimation = await contractClient.simulate(
8313
+ address,
8314
+ [
8315
+ {
8316
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
8317
+ value: {
8318
+ sender: address,
8319
+ contract: contractAddress,
8320
+ msg: new TextEncoder().encode(JSON.stringify(msg))
8321
+ }
8322
+ }
8323
+ ],
8324
+ ""
8325
+ );
8326
+ const multiplier = typeof fee === "number" ? fee : 1.8;
8327
+ const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
8328
+ const calculatedFee = (0, import_stargate3.calculateFee)(
8329
+ Math.round(gasEstimation * multiplier),
8330
+ gasPrice
8331
+ );
8332
+ const grantFee = {
8333
+ amount: calculatedFee.amount,
8334
+ gas: calculatedFee.gas,
8335
+ granter: granter || contractAddress
8336
+ };
8337
+ return await client.preAddNewKey(
8338
+ {
8339
+ d,
8340
+ groth16Proof: proof,
8341
+ nullifier: nullifier.toString(),
8342
+ pubkey: {
8343
+ x: newPubkey[0].toString(),
8344
+ y: newPubkey[1].toString()
8345
+ }
8346
+ },
8347
+ grantFee
8348
+ );
8349
+ } else if (gasStation === true && typeof fee === "object") {
8350
+ const grantFee = {
8351
+ ...fee,
8352
+ granter: granter || contractAddress
8353
+ };
8354
+ return await client.preAddNewKey(
8355
+ {
8356
+ d,
8357
+ groth16Proof: proof,
8358
+ nullifier: nullifier.toString(),
8359
+ pubkey: {
8360
+ x: newPubkey[0].toString(),
8361
+ y: newPubkey[1].toString()
8362
+ }
8363
+ },
8364
+ grantFee
8365
+ );
8366
+ }
8367
+ return await client.preAddNewKey(
8368
+ {
8369
+ d,
8370
+ groth16Proof: proof,
8371
+ nullifier: nullifier.toString(),
8372
+ pubkey: {
8373
+ x: newPubkey[0].toString(),
8374
+ y: newPubkey[1].toString()
8375
+ }
8376
+ },
8377
+ fee
8378
+ );
8379
+ }
8302
8380
  async claimAMaciRound({
8303
8381
  signer,
8304
8382
  contractAddress,
@@ -8934,7 +9012,6 @@ var MaciClient2 = class {
8934
9012
  signer,
8935
9013
  address,
8936
9014
  contractAddress,
8937
- pubKey,
8938
9015
  payload,
8939
9016
  gasStation = false,
8940
9017
  granter,
@@ -8944,7 +9021,6 @@ var MaciClient2 = class {
8944
9021
  signer: this.getSigner(signer),
8945
9022
  address,
8946
9023
  contractAddress,
8947
- pubKey,
8948
9024
  payload,
8949
9025
  gasStation,
8950
9026
  granter,
@@ -8999,6 +9075,29 @@ var MaciClient2 = class {
8999
9075
  fee
9000
9076
  });
9001
9077
  }
9078
+ async rawPreAddNewKey({
9079
+ signer,
9080
+ contractAddress,
9081
+ d,
9082
+ proof,
9083
+ nullifier,
9084
+ newPubkey,
9085
+ gasStation = false,
9086
+ granter,
9087
+ fee
9088
+ }) {
9089
+ return await this.maci.rawPreAddNewKey({
9090
+ signer: this.getSigner(signer),
9091
+ contractAddress,
9092
+ d,
9093
+ proof,
9094
+ nullifier,
9095
+ newPubkey,
9096
+ gasStation,
9097
+ granter,
9098
+ fee
9099
+ });
9100
+ }
9002
9101
  };
9003
9102
  // Annotate the CommonJS export names for ESM import in node:
9004
9103
  0 && (module.exports = {