@fuel-ts/account 0.77.0 → 0.79.0

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (30) hide show
  1. package/dist/account.d.ts +7 -0
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel-connector.d.ts +10 -0
  4. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  5. package/dist/index.global.js +103 -46
  6. package/dist/index.global.js.map +1 -1
  7. package/dist/index.js +104 -30
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +104 -30
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/providers/provider.d.ts +3 -2
  12. package/dist/providers/provider.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/script-transaction-request.d.ts +3 -0
  14. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  15. package/dist/providers/transaction-request/transaction-request.d.ts +20 -1
  16. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  17. package/dist/providers/transaction-request/types.d.ts +5 -0
  18. package/dist/providers/transaction-request/types.d.ts.map +1 -1
  19. package/dist/providers/transaction-response/getDecodedLogs.d.ts +2 -2
  20. package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
  21. package/dist/providers/transaction-response/transaction-response.d.ts +5 -2
  22. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  23. package/dist/test-utils.global.js +91 -31
  24. package/dist/test-utils.global.js.map +1 -1
  25. package/dist/test-utils.js +92 -17
  26. package/dist/test-utils.js.map +1 -1
  27. package/dist/test-utils.mjs +90 -15
  28. package/dist/test-utils.mjs.map +1 -1
  29. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  30. package/package.json +16 -16
@@ -1646,13 +1646,27 @@ var BaseTransactionRequest = class {
1646
1646
  this.outputs.push(output);
1647
1647
  return this.outputs.length - 1;
1648
1648
  }
1649
+ /**
1650
+ * @hidden
1651
+ *
1652
+ * Pushes a witness to the list and returns the index
1653
+ *
1654
+ * @param signature - The signature to add to the witness.
1655
+ * @returns The index of the created witness.
1656
+ */
1657
+ addWitness(signature) {
1658
+ this.witnesses.push(signature);
1659
+ return this.witnesses.length - 1;
1660
+ }
1649
1661
  /**
1650
1662
  * @hidden
1651
1663
  *
1652
1664
  * Creates an empty witness without any side effects and returns the index
1665
+ *
1666
+ * @returns The index of the created witness.
1653
1667
  */
1654
- createWitness() {
1655
- this.witnesses.push((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1668
+ addEmptyWitness() {
1669
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1656
1670
  return this.witnesses.length - 1;
1657
1671
  }
1658
1672
  /**
@@ -1681,6 +1695,21 @@ var BaseTransactionRequest = class {
1681
1695
  }
1682
1696
  this.witnesses[index] = witness;
1683
1697
  }
1698
+ /**
1699
+ * Helper function to add an external signature to the transaction.
1700
+ *
1701
+ * @param account - The account/s to sign to the transaction.
1702
+ * @returns The transaction with the signature witness added.
1703
+ */
1704
+ async addAccountWitnesses(account) {
1705
+ const accounts = Array.isArray(account) ? account : [account];
1706
+ await Promise.all(
1707
+ accounts.map(async (acc) => {
1708
+ this.addWitness(await acc.signTransaction(this));
1709
+ })
1710
+ );
1711
+ return this;
1712
+ }
1684
1713
  /**
1685
1714
  * Gets the coin inputs for a transaction.
1686
1715
  *
@@ -1746,7 +1775,7 @@ var BaseTransactionRequest = class {
1746
1775
  } else {
1747
1776
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1748
1777
  if (typeof witnessIndex !== "number") {
1749
- witnessIndex = this.createWitness();
1778
+ witnessIndex = this.addEmptyWitness();
1750
1779
  }
1751
1780
  }
1752
1781
  const input = {
@@ -1780,7 +1809,7 @@ var BaseTransactionRequest = class {
1780
1809
  } else {
1781
1810
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1782
1811
  if (typeof witnessIndex !== "number") {
1783
- witnessIndex = this.createWitness();
1812
+ witnessIndex = this.addEmptyWitness();
1784
1813
  }
1785
1814
  }
1786
1815
  const input = {
@@ -2270,6 +2299,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2270
2299
  script;
2271
2300
  /** Script input data (parameters) */
2272
2301
  scriptData;
2302
+ abis;
2273
2303
  /**
2274
2304
  * Constructor for `ScriptTransactionRequest`.
2275
2305
  *
@@ -2280,6 +2310,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2280
2310
  this.gasLimit = (0, import_math9.bn)(gasLimit);
2281
2311
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2282
2312
  this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2313
+ this.abis = rest.abis;
2283
2314
  }
2284
2315
  /**
2285
2316
  * Converts the transaction request to a `TransactionScript`.
@@ -2447,7 +2478,7 @@ var transactionRequestify = (obj) => {
2447
2478
  // src/providers/transaction-response/transaction-response.ts
2448
2479
  var import_errors12 = require("@fuel-ts/errors");
2449
2480
  var import_math13 = require("@fuel-ts/math");
2450
- var import_transactions15 = require("@fuel-ts/transactions");
2481
+ var import_transactions16 = require("@fuel-ts/transactions");
2451
2482
  var import_utils21 = require("@fuel-ts/utils");
2452
2483
 
2453
2484
  // src/providers/transaction-summary/assemble-transaction-summary.ts
@@ -3145,6 +3176,21 @@ function assembleTransactionSummary(params) {
3145
3176
  return transactionSummary;
3146
3177
  }
3147
3178
 
3179
+ // src/providers/transaction-response/getDecodedLogs.ts
3180
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
3181
+ var import_transactions15 = require("@fuel-ts/transactions");
3182
+ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3183
+ return receipts.reduce((logs, receipt) => {
3184
+ if (receipt.type === import_transactions15.ReceiptType.LogData || receipt.type === import_transactions15.ReceiptType.Log) {
3185
+ const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3186
+ const data = receipt.type === import_transactions15.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3187
+ const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3188
+ logs.push(decodedLog);
3189
+ }
3190
+ return logs;
3191
+ }, []);
3192
+ }
3193
+
3148
3194
  // src/providers/transaction-response/transaction-response.ts
3149
3195
  var TransactionResponse = class {
3150
3196
  /** Transaction ID */
@@ -3155,15 +3201,17 @@ var TransactionResponse = class {
3155
3201
  gasUsed = (0, import_math13.bn)(0);
3156
3202
  /** The graphql Transaction with receipts object. */
3157
3203
  gqlTransaction;
3204
+ abis;
3158
3205
  /**
3159
3206
  * Constructor for `TransactionResponse`.
3160
3207
  *
3161
3208
  * @param id - The transaction ID.
3162
3209
  * @param provider - The provider.
3163
3210
  */
3164
- constructor(id, provider) {
3211
+ constructor(id, provider, abis) {
3165
3212
  this.id = id;
3166
3213
  this.provider = provider;
3214
+ this.abis = abis;
3167
3215
  }
3168
3216
  /**
3169
3217
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -3173,8 +3221,8 @@ var TransactionResponse = class {
3173
3221
  * @param id - The transaction ID.
3174
3222
  * @param provider - The provider.
3175
3223
  */
3176
- static async create(id, provider) {
3177
- const response = new TransactionResponse(id, provider);
3224
+ static async create(id, provider, abis) {
3225
+ const response = new TransactionResponse(id, provider, abis);
3178
3226
  await response.fetch();
3179
3227
  return response;
3180
3228
  }
@@ -3208,7 +3256,7 @@ var TransactionResponse = class {
3208
3256
  * @returns The decoded transaction.
3209
3257
  */
3210
3258
  decodeTransaction(transactionWithReceipts) {
3211
- return new import_transactions15.TransactionCoder().decode(
3259
+ return new import_transactions16.TransactionCoder().decode(
3212
3260
  (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3213
3261
  0
3214
3262
  )?.[0];
@@ -3278,6 +3326,14 @@ var TransactionResponse = class {
3278
3326
  gqlTransaction: this.gqlTransaction,
3279
3327
  ...transactionSummary
3280
3328
  };
3329
+ if (this.abis) {
3330
+ const logs = getDecodedLogs(
3331
+ transactionSummary.receipts,
3332
+ this.abis.main,
3333
+ this.abis.otherContractsAbis
3334
+ );
3335
+ transactionResult.logs = logs;
3336
+ }
3281
3337
  return transactionResult;
3282
3338
  }
3283
3339
  /**
@@ -3297,10 +3353,6 @@ var TransactionResponse = class {
3297
3353
  }
3298
3354
  };
3299
3355
 
3300
- // src/providers/transaction-response/getDecodedLogs.ts
3301
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
3302
- var import_transactions16 = require("@fuel-ts/transactions");
3303
-
3304
3356
  // src/providers/utils/auto-retry-fetch.ts
3305
3357
  function getWaitDelay(options, retryAttemptNum) {
3306
3358
  const duration = options.baseDelay ?? 150;
@@ -3635,6 +3687,10 @@ var _Provider = class {
3635
3687
  await this.estimateTxDependencies(transactionRequest);
3636
3688
  }
3637
3689
  const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3690
+ let abis;
3691
+ if (transactionRequest.type === import_transactions17.TransactionType.Script) {
3692
+ abis = transactionRequest.abis;
3693
+ }
3638
3694
  if (awaitExecution) {
3639
3695
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3640
3696
  for await (const { submitAndAwait } of subscription) {
@@ -3649,14 +3705,14 @@ var _Provider = class {
3649
3705
  }
3650
3706
  }
3651
3707
  const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
3652
- const response = new TransactionResponse(transactionId2, this);
3708
+ const response = new TransactionResponse(transactionId2, this, abis);
3653
3709
  await response.fetch();
3654
3710
  return response;
3655
3711
  }
3656
3712
  const {
3657
3713
  submit: { id: transactionId }
3658
3714
  } = await this.operations.submit({ encodedTransaction });
3659
- return new TransactionResponse(transactionId, this);
3715
+ return new TransactionResponse(transactionId, this, abis);
3660
3716
  }
3661
3717
  /**
3662
3718
  * Executes a transaction without actually submitting it to the chain.
@@ -3807,7 +3863,8 @@ var _Provider = class {
3807
3863
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3808
3864
  estimateTxDependencies = true,
3809
3865
  estimatePredicates = true,
3810
- resourcesOwner
3866
+ resourcesOwner,
3867
+ signatureCallback
3811
3868
  } = {}) {
3812
3869
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3813
3870
  const chainInfo = this.getChain();
@@ -3826,6 +3883,9 @@ var _Provider = class {
3826
3883
  }
3827
3884
  await this.estimatePredicates(txRequestClone);
3828
3885
  }
3886
+ if (signatureCallback && isScriptTransaction) {
3887
+ await signatureCallback(txRequestClone);
3888
+ }
3829
3889
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3830
3890
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3831
3891
  let receipts = [];
@@ -4707,6 +4767,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4707
4767
  }
4708
4768
  return this._connector.signMessage(this.address.toString(), message);
4709
4769
  }
4770
+ /**
4771
+ * Signs a transaction with the wallet's private key.
4772
+ *
4773
+ * @param transactionRequestLike - The transaction request to sign.
4774
+ * @returns A promise that resolves to the signature of the transaction.
4775
+ */
4776
+ async signTransaction(transactionRequestLike) {
4777
+ if (!this._connector) {
4778
+ throw new import_errors15.FuelError(
4779
+ import_errors15.ErrorCode.MISSING_CONNECTOR,
4780
+ "A connector is required to sign transactions."
4781
+ );
4782
+ }
4783
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4784
+ }
4710
4785
  /**
4711
4786
  * Sends a transaction to the network.
4712
4787
  *
@@ -5013,7 +5088,7 @@ var BaseWalletUnlocked = class extends Account {
5013
5088
  */
5014
5089
  async signTransaction(transactionRequestLike) {
5015
5090
  const transactionRequest = transactionRequestify(transactionRequestLike);
5016
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5091
+ const chainId = this.provider.getChainId();
5017
5092
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5018
5093
  const signature = await this.signer().sign(hashedTransaction);
5019
5094
  return (0, import_utils30.hexlify)(signature);