@fuel-ts/account 0.0.0-rc-1356-20240322130951 → 0.0.0-rc-1815-20240322131329

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 (39) 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 +75 -13
  6. package/dist/index.global.js.map +1 -1
  7. package/dist/index.js +178 -108
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +76 -7
  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/transaction-request.d.ts +20 -1
  14. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  15. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  16. package/dist/providers/utils/index.d.ts +1 -0
  17. package/dist/providers/utils/index.d.ts.map +1 -1
  18. package/dist/providers/utils/sleep.d.ts +3 -0
  19. package/dist/providers/utils/sleep.d.ts.map +1 -0
  20. package/dist/test-utils/index.d.ts +0 -4
  21. package/dist/test-utils/index.d.ts.map +1 -1
  22. package/dist/test-utils/launchNode.d.ts +1 -8
  23. package/dist/test-utils/launchNode.d.ts.map +1 -1
  24. package/dist/test-utils.global.js +75 -329
  25. package/dist/test-utils.global.js.map +1 -1
  26. package/dist/test-utils.js +169 -333
  27. package/dist/test-utils.js.map +1 -1
  28. package/dist/test-utils.mjs +76 -236
  29. package/dist/test-utils.mjs.map +1 -1
  30. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  31. package/package.json +16 -17
  32. package/dist/test-utils/asset-id.d.ts +0 -9
  33. package/dist/test-utils/asset-id.d.ts.map +0 -1
  34. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
  35. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
  36. package/dist/test-utils/test-message.d.ts +0 -28
  37. package/dist/test-utils/test-message.d.ts.map +0 -1
  38. package/dist/test-utils/wallet-config.d.ts +0 -49
  39. package/dist/test-utils/wallet-config.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1553,6 +1553,15 @@ function normalizeJSON(root) {
1553
1553
  return normalize(clone(root));
1554
1554
  }
1555
1555
 
1556
+ // src/providers/utils/sleep.ts
1557
+ function sleep(time) {
1558
+ return new Promise((resolve) => {
1559
+ setTimeout(() => {
1560
+ resolve(true);
1561
+ }, time);
1562
+ });
1563
+ }
1564
+
1556
1565
  // src/providers/transaction-request/errors.ts
1557
1566
  var ChangeOutputCollisionError = class extends Error {
1558
1567
  name = "ChangeOutputCollisionError";
@@ -1694,13 +1703,27 @@ var BaseTransactionRequest = class {
1694
1703
  this.outputs.push(output);
1695
1704
  return this.outputs.length - 1;
1696
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
+ }
1697
1718
  /**
1698
1719
  * @hidden
1699
1720
  *
1700
1721
  * Creates an empty witness without any side effects and returns the index
1722
+ *
1723
+ * @returns The index of the created witness.
1701
1724
  */
1702
- createWitness() {
1703
- this.witnesses.push(concat([ZeroBytes324, ZeroBytes324]));
1725
+ addEmptyWitness() {
1726
+ this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
1704
1727
  return this.witnesses.length - 1;
1705
1728
  }
1706
1729
  /**
@@ -1729,6 +1752,21 @@ var BaseTransactionRequest = class {
1729
1752
  }
1730
1753
  this.witnesses[index] = witness;
1731
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
+ }
1732
1770
  /**
1733
1771
  * Gets the coin inputs for a transaction.
1734
1772
  *
@@ -1794,7 +1832,7 @@ var BaseTransactionRequest = class {
1794
1832
  } else {
1795
1833
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1796
1834
  if (typeof witnessIndex !== "number") {
1797
- witnessIndex = this.createWitness();
1835
+ witnessIndex = this.addEmptyWitness();
1798
1836
  }
1799
1837
  }
1800
1838
  const input = {
@@ -1828,7 +1866,7 @@ var BaseTransactionRequest = class {
1828
1866
  } else {
1829
1867
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1830
1868
  if (typeof witnessIndex !== "number") {
1831
- witnessIndex = this.createWitness();
1869
+ witnessIndex = this.addEmptyWitness();
1832
1870
  }
1833
1871
  }
1834
1872
  const input = {
@@ -3410,7 +3448,6 @@ function getDecodedLogs(receipts, abiInterface) {
3410
3448
  }
3411
3449
 
3412
3450
  // src/providers/utils/auto-retry-fetch.ts
3413
- import { sleep } from "@fuel-ts/utils";
3414
3451
  function getWaitDelay(options, retryAttemptNum) {
3415
3452
  const duration = options.baseDelay ?? 150;
3416
3453
  switch (options.backoff) {
@@ -3916,7 +3953,8 @@ var _Provider = class {
3916
3953
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3917
3954
  estimateTxDependencies = true,
3918
3955
  estimatePredicates = true,
3919
- resourcesOwner
3956
+ resourcesOwner,
3957
+ signatureCallback
3920
3958
  } = {}) {
3921
3959
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3922
3960
  const chainInfo = this.getChain();
@@ -3935,6 +3973,9 @@ var _Provider = class {
3935
3973
  }
3936
3974
  await this.estimatePredicates(txRequestClone);
3937
3975
  }
3976
+ if (signatureCallback && isScriptTransaction) {
3977
+ await signatureCallback(txRequestClone);
3978
+ }
3938
3979
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3939
3980
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3940
3981
  let receipts = [];
@@ -4982,6 +5023,21 @@ var Account = class extends AbstractAccount {
4982
5023
  }
4983
5024
  return this._connector.signMessage(this.address.toString(), message);
4984
5025
  }
5026
+ /**
5027
+ * Signs a transaction with the wallet's private key.
5028
+ *
5029
+ * @param transactionRequestLike - The transaction request to sign.
5030
+ * @returns A promise that resolves to the signature of the transaction.
5031
+ */
5032
+ async signTransaction(transactionRequestLike) {
5033
+ if (!this._connector) {
5034
+ throw new FuelError14(
5035
+ ErrorCode14.MISSING_CONNECTOR,
5036
+ "A connector is required to sign transactions."
5037
+ );
5038
+ }
5039
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
5040
+ }
4985
5041
  /**
4986
5042
  * Sends a transaction to the network.
4987
5043
  *
@@ -5300,7 +5356,7 @@ var BaseWalletUnlocked = class extends Account {
5300
5356
  */
5301
5357
  async signTransaction(transactionRequestLike) {
5302
5358
  const transactionRequest = transactionRequestify(transactionRequestLike);
5303
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5359
+ const chainId = this.provider.getChainId();
5304
5360
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5305
5361
  const signature = await this.signer().sign(hashedTransaction);
5306
5362
  return hexlify15(signature);
@@ -8847,6 +8903,18 @@ var FuelConnector = class extends EventEmitter2 {
8847
8903
  async signMessage(_address, _message) {
8848
8904
  throw new Error("Method not implemented.");
8849
8905
  }
8906
+ /**
8907
+ * Should start the sign transaction process and return
8908
+ * the signed transaction.
8909
+ *
8910
+ * @param address - The address to sign the transaction
8911
+ * @param transaction - The transaction to sign
8912
+ *
8913
+ * @returns Transaction signature
8914
+ */
8915
+ async signTransaction(_address, _transaction) {
8916
+ throw new Error("Method not implemented.");
8917
+ }
8850
8918
  /**
8851
8919
  * Should start the send transaction process and return
8852
8920
  * the transaction id submitted to the network.
@@ -9482,6 +9550,7 @@ export {
9482
9550
  resolveGasDependentCosts,
9483
9551
  resolveIconPaths,
9484
9552
  returnZeroScript,
9553
+ sleep,
9485
9554
  transactionRequestify,
9486
9555
  urlJoin,
9487
9556
  withTimeout,