@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.mjs CHANGED
@@ -1703,13 +1703,27 @@ var BaseTransactionRequest = class {
1703
1703
  this.outputs.push(output);
1704
1704
  return this.outputs.length - 1;
1705
1705
  }
1706
+ /**
1707
+ * @hidden
1708
+ *
1709
+ * Pushes a witness to the list and returns the index
1710
+ *
1711
+ * @param signature - The signature to add to the witness.
1712
+ * @returns The index of the created witness.
1713
+ */
1714
+ addWitness(signature) {
1715
+ this.witnesses.push(signature);
1716
+ return this.witnesses.length - 1;
1717
+ }
1706
1718
  /**
1707
1719
  * @hidden
1708
1720
  *
1709
1721
  * Creates an empty witness without any side effects and returns the index
1722
+ *
1723
+ * @returns The index of the created witness.
1710
1724
  */
1711
- createWitness() {
1712
- this.witnesses.push(concat([ZeroBytes324, ZeroBytes324]));
1725
+ addEmptyWitness() {
1726
+ this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
1713
1727
  return this.witnesses.length - 1;
1714
1728
  }
1715
1729
  /**
@@ -1738,6 +1752,21 @@ var BaseTransactionRequest = class {
1738
1752
  }
1739
1753
  this.witnesses[index] = witness;
1740
1754
  }
1755
+ /**
1756
+ * Helper function to add an external signature to the transaction.
1757
+ *
1758
+ * @param account - The account/s to sign to the transaction.
1759
+ * @returns The transaction with the signature witness added.
1760
+ */
1761
+ async addAccountWitnesses(account) {
1762
+ const accounts = Array.isArray(account) ? account : [account];
1763
+ await Promise.all(
1764
+ accounts.map(async (acc) => {
1765
+ this.addWitness(await acc.signTransaction(this));
1766
+ })
1767
+ );
1768
+ return this;
1769
+ }
1741
1770
  /**
1742
1771
  * Gets the coin inputs for a transaction.
1743
1772
  *
@@ -1803,7 +1832,7 @@ var BaseTransactionRequest = class {
1803
1832
  } else {
1804
1833
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1805
1834
  if (typeof witnessIndex !== "number") {
1806
- witnessIndex = this.createWitness();
1835
+ witnessIndex = this.addEmptyWitness();
1807
1836
  }
1808
1837
  }
1809
1838
  const input = {
@@ -1837,7 +1866,7 @@ var BaseTransactionRequest = class {
1837
1866
  } else {
1838
1867
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1839
1868
  if (typeof witnessIndex !== "number") {
1840
- witnessIndex = this.createWitness();
1869
+ witnessIndex = this.addEmptyWitness();
1841
1870
  }
1842
1871
  }
1843
1872
  const input = {
@@ -2327,6 +2356,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2327
2356
  script;
2328
2357
  /** Script input data (parameters) */
2329
2358
  scriptData;
2359
+ abis;
2330
2360
  /**
2331
2361
  * Constructor for `ScriptTransactionRequest`.
2332
2362
  *
@@ -2337,6 +2367,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2337
2367
  this.gasLimit = bn9(gasLimit);
2338
2368
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2339
2369
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2370
+ this.abis = rest.abis;
2340
2371
  }
2341
2372
  /**
2342
2373
  * Converts the transaction request to a `TransactionScript`.
@@ -3249,6 +3280,21 @@ function assembleTransactionSummary(params) {
3249
3280
  return transactionSummary;
3250
3281
  }
3251
3282
 
3283
+ // src/providers/transaction-response/getDecodedLogs.ts
3284
+ import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
3285
+ import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3286
+ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3287
+ return receipts.reduce((logs, receipt) => {
3288
+ if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
3289
+ const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
3290
+ const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3291
+ const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3292
+ logs.push(decodedLog);
3293
+ }
3294
+ return logs;
3295
+ }, []);
3296
+ }
3297
+
3252
3298
  // src/providers/transaction-response/transaction-response.ts
3253
3299
  var TransactionResponse = class {
3254
3300
  /** Transaction ID */
@@ -3259,15 +3305,17 @@ var TransactionResponse = class {
3259
3305
  gasUsed = bn13(0);
3260
3306
  /** The graphql Transaction with receipts object. */
3261
3307
  gqlTransaction;
3308
+ abis;
3262
3309
  /**
3263
3310
  * Constructor for `TransactionResponse`.
3264
3311
  *
3265
3312
  * @param id - The transaction ID.
3266
3313
  * @param provider - The provider.
3267
3314
  */
3268
- constructor(id, provider) {
3315
+ constructor(id, provider, abis) {
3269
3316
  this.id = id;
3270
3317
  this.provider = provider;
3318
+ this.abis = abis;
3271
3319
  }
3272
3320
  /**
3273
3321
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -3277,8 +3325,8 @@ var TransactionResponse = class {
3277
3325
  * @param id - The transaction ID.
3278
3326
  * @param provider - The provider.
3279
3327
  */
3280
- static async create(id, provider) {
3281
- const response = new TransactionResponse(id, provider);
3328
+ static async create(id, provider, abis) {
3329
+ const response = new TransactionResponse(id, provider, abis);
3282
3330
  await response.fetch();
3283
3331
  return response;
3284
3332
  }
@@ -3382,6 +3430,14 @@ var TransactionResponse = class {
3382
3430
  gqlTransaction: this.gqlTransaction,
3383
3431
  ...transactionSummary
3384
3432
  };
3433
+ if (this.abis) {
3434
+ const logs = getDecodedLogs(
3435
+ transactionSummary.receipts,
3436
+ this.abis.main,
3437
+ this.abis.otherContractsAbis
3438
+ );
3439
+ transactionResult.logs = logs;
3440
+ }
3385
3441
  return transactionResult;
3386
3442
  }
3387
3443
  /**
@@ -3401,23 +3457,6 @@ var TransactionResponse = class {
3401
3457
  }
3402
3458
  };
3403
3459
 
3404
- // src/providers/transaction-response/getDecodedLogs.ts
3405
- import { BigNumberCoder } from "@fuel-ts/abi-coder";
3406
- import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3407
- function getDecodedLogs(receipts, abiInterface) {
3408
- return receipts.reduce((logs, r) => {
3409
- if (r.type === ReceiptType5.LogData) {
3410
- logs.push(abiInterface.decodeLog(r.data, r.val1.toNumber(), r.id)[0]);
3411
- }
3412
- if (r.type === ReceiptType5.Log) {
3413
- logs.push(
3414
- abiInterface.decodeLog(new BigNumberCoder("u64").encode(r.val0), r.val1.toNumber(), r.id)[0]
3415
- );
3416
- }
3417
- return logs;
3418
- }, []);
3419
- }
3420
-
3421
3460
  // src/providers/utils/auto-retry-fetch.ts
3422
3461
  function getWaitDelay(options, retryAttemptNum) {
3423
3462
  const duration = options.baseDelay ?? 150;
@@ -3752,6 +3791,10 @@ var _Provider = class {
3752
3791
  await this.estimateTxDependencies(transactionRequest);
3753
3792
  }
3754
3793
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3794
+ let abis;
3795
+ if (transactionRequest.type === TransactionType8.Script) {
3796
+ abis = transactionRequest.abis;
3797
+ }
3755
3798
  if (awaitExecution) {
3756
3799
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3757
3800
  for await (const { submitAndAwait } of subscription) {
@@ -3766,14 +3809,14 @@ var _Provider = class {
3766
3809
  }
3767
3810
  }
3768
3811
  const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
3769
- const response = new TransactionResponse(transactionId2, this);
3812
+ const response = new TransactionResponse(transactionId2, this, abis);
3770
3813
  await response.fetch();
3771
3814
  return response;
3772
3815
  }
3773
3816
  const {
3774
3817
  submit: { id: transactionId }
3775
3818
  } = await this.operations.submit({ encodedTransaction });
3776
- return new TransactionResponse(transactionId, this);
3819
+ return new TransactionResponse(transactionId, this, abis);
3777
3820
  }
3778
3821
  /**
3779
3822
  * Executes a transaction without actually submitting it to the chain.
@@ -3924,7 +3967,8 @@ var _Provider = class {
3924
3967
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3925
3968
  estimateTxDependencies = true,
3926
3969
  estimatePredicates = true,
3927
- resourcesOwner
3970
+ resourcesOwner,
3971
+ signatureCallback
3928
3972
  } = {}) {
3929
3973
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3930
3974
  const chainInfo = this.getChain();
@@ -3943,6 +3987,9 @@ var _Provider = class {
3943
3987
  }
3944
3988
  await this.estimatePredicates(txRequestClone);
3945
3989
  }
3990
+ if (signatureCallback && isScriptTransaction) {
3991
+ await signatureCallback(txRequestClone);
3992
+ }
3946
3993
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3947
3994
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3948
3995
  let receipts = [];
@@ -4990,6 +5037,21 @@ var Account = class extends AbstractAccount {
4990
5037
  }
4991
5038
  return this._connector.signMessage(this.address.toString(), message);
4992
5039
  }
5040
+ /**
5041
+ * Signs a transaction with the wallet's private key.
5042
+ *
5043
+ * @param transactionRequestLike - The transaction request to sign.
5044
+ * @returns A promise that resolves to the signature of the transaction.
5045
+ */
5046
+ async signTransaction(transactionRequestLike) {
5047
+ if (!this._connector) {
5048
+ throw new FuelError14(
5049
+ ErrorCode14.MISSING_CONNECTOR,
5050
+ "A connector is required to sign transactions."
5051
+ );
5052
+ }
5053
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
5054
+ }
4993
5055
  /**
4994
5056
  * Sends a transaction to the network.
4995
5057
  *
@@ -5308,7 +5370,7 @@ var BaseWalletUnlocked = class extends Account {
5308
5370
  */
5309
5371
  async signTransaction(transactionRequestLike) {
5310
5372
  const transactionRequest = transactionRequestify(transactionRequestLike);
5311
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5373
+ const chainId = this.provider.getChainId();
5312
5374
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5313
5375
  const signature = await this.signer().sign(hashedTransaction);
5314
5376
  return hexlify15(signature);
@@ -8524,7 +8586,7 @@ var StorageAbstract = class {
8524
8586
 
8525
8587
  // src/predicate/predicate.ts
8526
8588
  import {
8527
- Interface as Interface3,
8589
+ Interface as Interface4,
8528
8590
  INPUT_COIN_FIXED_SIZE,
8529
8591
  WORD_SIZE,
8530
8592
  calculateVmTxMemory as calculateVmTxMemory2,
@@ -8658,7 +8720,7 @@ var Predicate = class extends Account {
8658
8720
  let predicateBytes = arrayify20(bytes);
8659
8721
  let abiInterface;
8660
8722
  if (jsonAbi) {
8661
- abiInterface = new Interface3(jsonAbi);
8723
+ abiInterface = new Interface4(jsonAbi);
8662
8724
  if (abiInterface.functions.main === void 0) {
8663
8725
  throw new FuelError23(
8664
8726
  ErrorCode23.ABI_MAIN_METHOD_MISSING,
@@ -8855,6 +8917,18 @@ var FuelConnector = class extends EventEmitter2 {
8855
8917
  async signMessage(_address, _message) {
8856
8918
  throw new Error("Method not implemented.");
8857
8919
  }
8920
+ /**
8921
+ * Should start the sign transaction process and return
8922
+ * the signed transaction.
8923
+ *
8924
+ * @param address - The address to sign the transaction
8925
+ * @param transaction - The transaction to sign
8926
+ *
8927
+ * @returns Transaction signature
8928
+ */
8929
+ async signTransaction(_address, _transaction) {
8930
+ throw new Error("Method not implemented.");
8931
+ }
8858
8932
  /**
8859
8933
  * Should start the send transaction process and return
8860
8934
  * the transaction id submitted to the network.