@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
package/dist/index.js CHANGED
@@ -1839,13 +1839,27 @@ var BaseTransactionRequest = class {
1839
1839
  this.outputs.push(output);
1840
1840
  return this.outputs.length - 1;
1841
1841
  }
1842
+ /**
1843
+ * @hidden
1844
+ *
1845
+ * Pushes a witness to the list and returns the index
1846
+ *
1847
+ * @param signature - The signature to add to the witness.
1848
+ * @returns The index of the created witness.
1849
+ */
1850
+ addWitness(signature) {
1851
+ this.witnesses.push(signature);
1852
+ return this.witnesses.length - 1;
1853
+ }
1842
1854
  /**
1843
1855
  * @hidden
1844
1856
  *
1845
1857
  * Creates an empty witness without any side effects and returns the index
1858
+ *
1859
+ * @returns The index of the created witness.
1846
1860
  */
1847
- createWitness() {
1848
- this.witnesses.push((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1861
+ addEmptyWitness() {
1862
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1849
1863
  return this.witnesses.length - 1;
1850
1864
  }
1851
1865
  /**
@@ -1874,6 +1888,21 @@ var BaseTransactionRequest = class {
1874
1888
  }
1875
1889
  this.witnesses[index] = witness;
1876
1890
  }
1891
+ /**
1892
+ * Helper function to add an external signature to the transaction.
1893
+ *
1894
+ * @param account - The account/s to sign to the transaction.
1895
+ * @returns The transaction with the signature witness added.
1896
+ */
1897
+ async addAccountWitnesses(account) {
1898
+ const accounts = Array.isArray(account) ? account : [account];
1899
+ await Promise.all(
1900
+ accounts.map(async (acc) => {
1901
+ this.addWitness(await acc.signTransaction(this));
1902
+ })
1903
+ );
1904
+ return this;
1905
+ }
1877
1906
  /**
1878
1907
  * Gets the coin inputs for a transaction.
1879
1908
  *
@@ -1939,7 +1968,7 @@ var BaseTransactionRequest = class {
1939
1968
  } else {
1940
1969
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1941
1970
  if (typeof witnessIndex !== "number") {
1942
- witnessIndex = this.createWitness();
1971
+ witnessIndex = this.addEmptyWitness();
1943
1972
  }
1944
1973
  }
1945
1974
  const input = {
@@ -1973,7 +2002,7 @@ var BaseTransactionRequest = class {
1973
2002
  } else {
1974
2003
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1975
2004
  if (typeof witnessIndex !== "number") {
1976
- witnessIndex = this.createWitness();
2005
+ witnessIndex = this.addEmptyWitness();
1977
2006
  }
1978
2007
  }
1979
2008
  const input = {
@@ -2463,6 +2492,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2463
2492
  script;
2464
2493
  /** Script input data (parameters) */
2465
2494
  scriptData;
2495
+ abis;
2466
2496
  /**
2467
2497
  * Constructor for `ScriptTransactionRequest`.
2468
2498
  *
@@ -2473,6 +2503,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2473
2503
  this.gasLimit = (0, import_math9.bn)(gasLimit);
2474
2504
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2475
2505
  this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2506
+ this.abis = rest.abis;
2476
2507
  }
2477
2508
  /**
2478
2509
  * Converts the transaction request to a `TransactionScript`.
@@ -2640,7 +2671,7 @@ var transactionRequestify = (obj) => {
2640
2671
  // src/providers/transaction-response/transaction-response.ts
2641
2672
  var import_errors12 = require("@fuel-ts/errors");
2642
2673
  var import_math13 = require("@fuel-ts/math");
2643
- var import_transactions15 = require("@fuel-ts/transactions");
2674
+ var import_transactions16 = require("@fuel-ts/transactions");
2644
2675
  var import_utils21 = require("@fuel-ts/utils");
2645
2676
 
2646
2677
  // src/providers/transaction-summary/assemble-transaction-summary.ts
@@ -3385,6 +3416,21 @@ function assembleTransactionSummary(params) {
3385
3416
  return transactionSummary;
3386
3417
  }
3387
3418
 
3419
+ // src/providers/transaction-response/getDecodedLogs.ts
3420
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
3421
+ var import_transactions15 = require("@fuel-ts/transactions");
3422
+ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3423
+ return receipts.reduce((logs, receipt) => {
3424
+ if (receipt.type === import_transactions15.ReceiptType.LogData || receipt.type === import_transactions15.ReceiptType.Log) {
3425
+ const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3426
+ const data = receipt.type === import_transactions15.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3427
+ const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3428
+ logs.push(decodedLog);
3429
+ }
3430
+ return logs;
3431
+ }, []);
3432
+ }
3433
+
3388
3434
  // src/providers/transaction-response/transaction-response.ts
3389
3435
  var TransactionResponse = class {
3390
3436
  /** Transaction ID */
@@ -3395,15 +3441,17 @@ var TransactionResponse = class {
3395
3441
  gasUsed = (0, import_math13.bn)(0);
3396
3442
  /** The graphql Transaction with receipts object. */
3397
3443
  gqlTransaction;
3444
+ abis;
3398
3445
  /**
3399
3446
  * Constructor for `TransactionResponse`.
3400
3447
  *
3401
3448
  * @param id - The transaction ID.
3402
3449
  * @param provider - The provider.
3403
3450
  */
3404
- constructor(id, provider) {
3451
+ constructor(id, provider, abis) {
3405
3452
  this.id = id;
3406
3453
  this.provider = provider;
3454
+ this.abis = abis;
3407
3455
  }
3408
3456
  /**
3409
3457
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -3413,8 +3461,8 @@ var TransactionResponse = class {
3413
3461
  * @param id - The transaction ID.
3414
3462
  * @param provider - The provider.
3415
3463
  */
3416
- static async create(id, provider) {
3417
- const response = new TransactionResponse(id, provider);
3464
+ static async create(id, provider, abis) {
3465
+ const response = new TransactionResponse(id, provider, abis);
3418
3466
  await response.fetch();
3419
3467
  return response;
3420
3468
  }
@@ -3448,7 +3496,7 @@ var TransactionResponse = class {
3448
3496
  * @returns The decoded transaction.
3449
3497
  */
3450
3498
  decodeTransaction(transactionWithReceipts) {
3451
- return new import_transactions15.TransactionCoder().decode(
3499
+ return new import_transactions16.TransactionCoder().decode(
3452
3500
  (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3453
3501
  0
3454
3502
  )?.[0];
@@ -3518,6 +3566,14 @@ var TransactionResponse = class {
3518
3566
  gqlTransaction: this.gqlTransaction,
3519
3567
  ...transactionSummary
3520
3568
  };
3569
+ if (this.abis) {
3570
+ const logs = getDecodedLogs(
3571
+ transactionSummary.receipts,
3572
+ this.abis.main,
3573
+ this.abis.otherContractsAbis
3574
+ );
3575
+ transactionResult.logs = logs;
3576
+ }
3521
3577
  return transactionResult;
3522
3578
  }
3523
3579
  /**
@@ -3537,23 +3593,6 @@ var TransactionResponse = class {
3537
3593
  }
3538
3594
  };
3539
3595
 
3540
- // src/providers/transaction-response/getDecodedLogs.ts
3541
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
3542
- var import_transactions16 = require("@fuel-ts/transactions");
3543
- function getDecodedLogs(receipts, abiInterface) {
3544
- return receipts.reduce((logs, r) => {
3545
- if (r.type === import_transactions16.ReceiptType.LogData) {
3546
- logs.push(abiInterface.decodeLog(r.data, r.val1.toNumber(), r.id)[0]);
3547
- }
3548
- if (r.type === import_transactions16.ReceiptType.Log) {
3549
- logs.push(
3550
- abiInterface.decodeLog(new import_abi_coder3.BigNumberCoder("u64").encode(r.val0), r.val1.toNumber(), r.id)[0]
3551
- );
3552
- }
3553
- return logs;
3554
- }, []);
3555
- }
3556
-
3557
3596
  // src/providers/utils/auto-retry-fetch.ts
3558
3597
  function getWaitDelay(options, retryAttemptNum) {
3559
3598
  const duration = options.baseDelay ?? 150;
@@ -3888,6 +3927,10 @@ var _Provider = class {
3888
3927
  await this.estimateTxDependencies(transactionRequest);
3889
3928
  }
3890
3929
  const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3930
+ let abis;
3931
+ if (transactionRequest.type === import_transactions17.TransactionType.Script) {
3932
+ abis = transactionRequest.abis;
3933
+ }
3891
3934
  if (awaitExecution) {
3892
3935
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3893
3936
  for await (const { submitAndAwait } of subscription) {
@@ -3902,14 +3945,14 @@ var _Provider = class {
3902
3945
  }
3903
3946
  }
3904
3947
  const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
3905
- const response = new TransactionResponse(transactionId2, this);
3948
+ const response = new TransactionResponse(transactionId2, this, abis);
3906
3949
  await response.fetch();
3907
3950
  return response;
3908
3951
  }
3909
3952
  const {
3910
3953
  submit: { id: transactionId }
3911
3954
  } = await this.operations.submit({ encodedTransaction });
3912
- return new TransactionResponse(transactionId, this);
3955
+ return new TransactionResponse(transactionId, this, abis);
3913
3956
  }
3914
3957
  /**
3915
3958
  * Executes a transaction without actually submitting it to the chain.
@@ -4060,7 +4103,8 @@ var _Provider = class {
4060
4103
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4061
4104
  estimateTxDependencies = true,
4062
4105
  estimatePredicates = true,
4063
- resourcesOwner
4106
+ resourcesOwner,
4107
+ signatureCallback
4064
4108
  } = {}) {
4065
4109
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4066
4110
  const chainInfo = this.getChain();
@@ -4079,6 +4123,9 @@ var _Provider = class {
4079
4123
  }
4080
4124
  await this.estimatePredicates(txRequestClone);
4081
4125
  }
4126
+ if (signatureCallback && isScriptTransaction) {
4127
+ await signatureCallback(txRequestClone);
4128
+ }
4082
4129
  const minGas = txRequestClone.calculateMinGas(chainInfo);
4083
4130
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4084
4131
  let receipts = [];
@@ -5126,6 +5173,21 @@ var Account = class extends import_interfaces.AbstractAccount {
5126
5173
  }
5127
5174
  return this._connector.signMessage(this.address.toString(), message);
5128
5175
  }
5176
+ /**
5177
+ * Signs a transaction with the wallet's private key.
5178
+ *
5179
+ * @param transactionRequestLike - The transaction request to sign.
5180
+ * @returns A promise that resolves to the signature of the transaction.
5181
+ */
5182
+ async signTransaction(transactionRequestLike) {
5183
+ if (!this._connector) {
5184
+ throw new import_errors15.FuelError(
5185
+ import_errors15.ErrorCode.MISSING_CONNECTOR,
5186
+ "A connector is required to sign transactions."
5187
+ );
5188
+ }
5189
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
5190
+ }
5129
5191
  /**
5130
5192
  * Sends a transaction to the network.
5131
5193
  *
@@ -5436,7 +5498,7 @@ var BaseWalletUnlocked = class extends Account {
5436
5498
  */
5437
5499
  async signTransaction(transactionRequestLike) {
5438
5500
  const transactionRequest = transactionRequestify(transactionRequestLike);
5439
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5501
+ const chainId = this.provider.getChainId();
5440
5502
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5441
5503
  const signature = await this.signer().sign(hashedTransaction);
5442
5504
  return (0, import_utils30.hexlify)(signature);
@@ -8977,6 +9039,18 @@ var FuelConnector = class extends import_events2.EventEmitter {
8977
9039
  async signMessage(_address, _message) {
8978
9040
  throw new Error("Method not implemented.");
8979
9041
  }
9042
+ /**
9043
+ * Should start the sign transaction process and return
9044
+ * the signed transaction.
9045
+ *
9046
+ * @param address - The address to sign the transaction
9047
+ * @param transaction - The transaction to sign
9048
+ *
9049
+ * @returns Transaction signature
9050
+ */
9051
+ async signTransaction(_address, _transaction) {
9052
+ throw new Error("Method not implemented.");
9053
+ }
8980
9054
  /**
8981
9055
  * Should start the send transaction process and return
8982
9056
  * the transaction id submitted to the network.