@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
@@ -1624,13 +1624,27 @@ var BaseTransactionRequest = class {
1624
1624
  this.outputs.push(output);
1625
1625
  return this.outputs.length - 1;
1626
1626
  }
1627
+ /**
1628
+ * @hidden
1629
+ *
1630
+ * Pushes a witness to the list and returns the index
1631
+ *
1632
+ * @param signature - The signature to add to the witness.
1633
+ * @returns The index of the created witness.
1634
+ */
1635
+ addWitness(signature) {
1636
+ this.witnesses.push(signature);
1637
+ return this.witnesses.length - 1;
1638
+ }
1627
1639
  /**
1628
1640
  * @hidden
1629
1641
  *
1630
1642
  * Creates an empty witness without any side effects and returns the index
1643
+ *
1644
+ * @returns The index of the created witness.
1631
1645
  */
1632
- createWitness() {
1633
- this.witnesses.push(concat([ZeroBytes324, ZeroBytes324]));
1646
+ addEmptyWitness() {
1647
+ this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
1634
1648
  return this.witnesses.length - 1;
1635
1649
  }
1636
1650
  /**
@@ -1659,6 +1673,21 @@ var BaseTransactionRequest = class {
1659
1673
  }
1660
1674
  this.witnesses[index] = witness;
1661
1675
  }
1676
+ /**
1677
+ * Helper function to add an external signature to the transaction.
1678
+ *
1679
+ * @param account - The account/s to sign to the transaction.
1680
+ * @returns The transaction with the signature witness added.
1681
+ */
1682
+ async addAccountWitnesses(account) {
1683
+ const accounts = Array.isArray(account) ? account : [account];
1684
+ await Promise.all(
1685
+ accounts.map(async (acc) => {
1686
+ this.addWitness(await acc.signTransaction(this));
1687
+ })
1688
+ );
1689
+ return this;
1690
+ }
1662
1691
  /**
1663
1692
  * Gets the coin inputs for a transaction.
1664
1693
  *
@@ -1724,7 +1753,7 @@ var BaseTransactionRequest = class {
1724
1753
  } else {
1725
1754
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1726
1755
  if (typeof witnessIndex !== "number") {
1727
- witnessIndex = this.createWitness();
1756
+ witnessIndex = this.addEmptyWitness();
1728
1757
  }
1729
1758
  }
1730
1759
  const input = {
@@ -1758,7 +1787,7 @@ var BaseTransactionRequest = class {
1758
1787
  } else {
1759
1788
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1760
1789
  if (typeof witnessIndex !== "number") {
1761
- witnessIndex = this.createWitness();
1790
+ witnessIndex = this.addEmptyWitness();
1762
1791
  }
1763
1792
  }
1764
1793
  const input = {
@@ -2248,6 +2277,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2248
2277
  script;
2249
2278
  /** Script input data (parameters) */
2250
2279
  scriptData;
2280
+ abis;
2251
2281
  /**
2252
2282
  * Constructor for `ScriptTransactionRequest`.
2253
2283
  *
@@ -2258,6 +2288,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2258
2288
  this.gasLimit = bn9(gasLimit);
2259
2289
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2260
2290
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2291
+ this.abis = rest.abis;
2261
2292
  }
2262
2293
  /**
2263
2294
  * Converts the transaction request to a `TransactionScript`.
@@ -3123,6 +3154,21 @@ function assembleTransactionSummary(params) {
3123
3154
  return transactionSummary;
3124
3155
  }
3125
3156
 
3157
+ // src/providers/transaction-response/getDecodedLogs.ts
3158
+ import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
3159
+ import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3160
+ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3161
+ return receipts.reduce((logs, receipt) => {
3162
+ if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
3163
+ const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
3164
+ const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3165
+ const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3166
+ logs.push(decodedLog);
3167
+ }
3168
+ return logs;
3169
+ }, []);
3170
+ }
3171
+
3126
3172
  // src/providers/transaction-response/transaction-response.ts
3127
3173
  var TransactionResponse = class {
3128
3174
  /** Transaction ID */
@@ -3133,15 +3179,17 @@ var TransactionResponse = class {
3133
3179
  gasUsed = bn13(0);
3134
3180
  /** The graphql Transaction with receipts object. */
3135
3181
  gqlTransaction;
3182
+ abis;
3136
3183
  /**
3137
3184
  * Constructor for `TransactionResponse`.
3138
3185
  *
3139
3186
  * @param id - The transaction ID.
3140
3187
  * @param provider - The provider.
3141
3188
  */
3142
- constructor(id, provider) {
3189
+ constructor(id, provider, abis) {
3143
3190
  this.id = id;
3144
3191
  this.provider = provider;
3192
+ this.abis = abis;
3145
3193
  }
3146
3194
  /**
3147
3195
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -3151,8 +3199,8 @@ var TransactionResponse = class {
3151
3199
  * @param id - The transaction ID.
3152
3200
  * @param provider - The provider.
3153
3201
  */
3154
- static async create(id, provider) {
3155
- const response = new TransactionResponse(id, provider);
3202
+ static async create(id, provider, abis) {
3203
+ const response = new TransactionResponse(id, provider, abis);
3156
3204
  await response.fetch();
3157
3205
  return response;
3158
3206
  }
@@ -3256,6 +3304,14 @@ var TransactionResponse = class {
3256
3304
  gqlTransaction: this.gqlTransaction,
3257
3305
  ...transactionSummary
3258
3306
  };
3307
+ if (this.abis) {
3308
+ const logs = getDecodedLogs(
3309
+ transactionSummary.receipts,
3310
+ this.abis.main,
3311
+ this.abis.otherContractsAbis
3312
+ );
3313
+ transactionResult.logs = logs;
3314
+ }
3259
3315
  return transactionResult;
3260
3316
  }
3261
3317
  /**
@@ -3275,10 +3331,6 @@ var TransactionResponse = class {
3275
3331
  }
3276
3332
  };
3277
3333
 
3278
- // src/providers/transaction-response/getDecodedLogs.ts
3279
- import { BigNumberCoder } from "@fuel-ts/abi-coder";
3280
- import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3281
-
3282
3334
  // src/providers/utils/auto-retry-fetch.ts
3283
3335
  function getWaitDelay(options, retryAttemptNum) {
3284
3336
  const duration = options.baseDelay ?? 150;
@@ -3613,6 +3665,10 @@ var _Provider = class {
3613
3665
  await this.estimateTxDependencies(transactionRequest);
3614
3666
  }
3615
3667
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3668
+ let abis;
3669
+ if (transactionRequest.type === TransactionType8.Script) {
3670
+ abis = transactionRequest.abis;
3671
+ }
3616
3672
  if (awaitExecution) {
3617
3673
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3618
3674
  for await (const { submitAndAwait } of subscription) {
@@ -3627,14 +3683,14 @@ var _Provider = class {
3627
3683
  }
3628
3684
  }
3629
3685
  const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
3630
- const response = new TransactionResponse(transactionId2, this);
3686
+ const response = new TransactionResponse(transactionId2, this, abis);
3631
3687
  await response.fetch();
3632
3688
  return response;
3633
3689
  }
3634
3690
  const {
3635
3691
  submit: { id: transactionId }
3636
3692
  } = await this.operations.submit({ encodedTransaction });
3637
- return new TransactionResponse(transactionId, this);
3693
+ return new TransactionResponse(transactionId, this, abis);
3638
3694
  }
3639
3695
  /**
3640
3696
  * Executes a transaction without actually submitting it to the chain.
@@ -3785,7 +3841,8 @@ var _Provider = class {
3785
3841
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3786
3842
  estimateTxDependencies = true,
3787
3843
  estimatePredicates = true,
3788
- resourcesOwner
3844
+ resourcesOwner,
3845
+ signatureCallback
3789
3846
  } = {}) {
3790
3847
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3791
3848
  const chainInfo = this.getChain();
@@ -3804,6 +3861,9 @@ var _Provider = class {
3804
3861
  }
3805
3862
  await this.estimatePredicates(txRequestClone);
3806
3863
  }
3864
+ if (signatureCallback && isScriptTransaction) {
3865
+ await signatureCallback(txRequestClone);
3866
+ }
3807
3867
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3808
3868
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3809
3869
  let receipts = [];
@@ -4685,6 +4745,21 @@ var Account = class extends AbstractAccount {
4685
4745
  }
4686
4746
  return this._connector.signMessage(this.address.toString(), message);
4687
4747
  }
4748
+ /**
4749
+ * Signs a transaction with the wallet's private key.
4750
+ *
4751
+ * @param transactionRequestLike - The transaction request to sign.
4752
+ * @returns A promise that resolves to the signature of the transaction.
4753
+ */
4754
+ async signTransaction(transactionRequestLike) {
4755
+ if (!this._connector) {
4756
+ throw new FuelError14(
4757
+ ErrorCode14.MISSING_CONNECTOR,
4758
+ "A connector is required to sign transactions."
4759
+ );
4760
+ }
4761
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4762
+ }
4688
4763
  /**
4689
4764
  * Sends a transaction to the network.
4690
4765
  *
@@ -4999,7 +5074,7 @@ var BaseWalletUnlocked = class extends Account {
4999
5074
  */
5000
5075
  async signTransaction(transactionRequestLike) {
5001
5076
  const transactionRequest = transactionRequestify(transactionRequestLike);
5002
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5077
+ const chainId = this.provider.getChainId();
5003
5078
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5004
5079
  const signature = await this.signer().sign(hashedTransaction);
5005
5080
  return hexlify15(signature);