@fuel-ts/account 0.0.0-rc-1866-20240322113439 → 0.0.0-rc-1815-20240322115843

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.

@@ -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 = {
@@ -4707,6 +4736,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4707
4736
  }
4708
4737
  return this._connector.signMessage(this.address.toString(), message);
4709
4738
  }
4739
+ /**
4740
+ * Signs a transaction with the wallet's private key.
4741
+ *
4742
+ * @param transactionRequestLike - The transaction request to sign.
4743
+ * @returns A promise that resolves to the signature of the transaction.
4744
+ */
4745
+ async signTransaction(transactionRequestLike) {
4746
+ if (!this._connector) {
4747
+ throw new import_errors15.FuelError(
4748
+ import_errors15.ErrorCode.MISSING_CONNECTOR,
4749
+ "A connector is required to sign transactions."
4750
+ );
4751
+ }
4752
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4753
+ }
4710
4754
  /**
4711
4755
  * Sends a transaction to the network.
4712
4756
  *
@@ -5013,7 +5057,7 @@ var BaseWalletUnlocked = class extends Account {
5013
5057
  */
5014
5058
  async signTransaction(transactionRequestLike) {
5015
5059
  const transactionRequest = transactionRequestify(transactionRequestLike);
5016
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5060
+ const chainId = this.provider.getChainId();
5017
5061
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5018
5062
  const signature = await this.signer().sign(hashedTransaction);
5019
5063
  return (0, import_utils30.hexlify)(signature);