@fuel-ts/account 0.77.0 → 0.78.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.

@@ -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 = {
@@ -3807,7 +3836,8 @@ var _Provider = class {
3807
3836
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3808
3837
  estimateTxDependencies = true,
3809
3838
  estimatePredicates = true,
3810
- resourcesOwner
3839
+ resourcesOwner,
3840
+ signatureCallback
3811
3841
  } = {}) {
3812
3842
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3813
3843
  const chainInfo = this.getChain();
@@ -3826,6 +3856,9 @@ var _Provider = class {
3826
3856
  }
3827
3857
  await this.estimatePredicates(txRequestClone);
3828
3858
  }
3859
+ if (signatureCallback && isScriptTransaction) {
3860
+ await signatureCallback(txRequestClone);
3861
+ }
3829
3862
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3830
3863
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3831
3864
  let receipts = [];
@@ -4707,6 +4740,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4707
4740
  }
4708
4741
  return this._connector.signMessage(this.address.toString(), message);
4709
4742
  }
4743
+ /**
4744
+ * Signs a transaction with the wallet's private key.
4745
+ *
4746
+ * @param transactionRequestLike - The transaction request to sign.
4747
+ * @returns A promise that resolves to the signature of the transaction.
4748
+ */
4749
+ async signTransaction(transactionRequestLike) {
4750
+ if (!this._connector) {
4751
+ throw new import_errors15.FuelError(
4752
+ import_errors15.ErrorCode.MISSING_CONNECTOR,
4753
+ "A connector is required to sign transactions."
4754
+ );
4755
+ }
4756
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4757
+ }
4710
4758
  /**
4711
4759
  * Sends a transaction to the network.
4712
4760
  *
@@ -5013,7 +5061,7 @@ var BaseWalletUnlocked = class extends Account {
5013
5061
  */
5014
5062
  async signTransaction(transactionRequestLike) {
5015
5063
  const transactionRequest = transactionRequestify(transactionRequestLike);
5016
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5064
+ const chainId = this.provider.getChainId();
5017
5065
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5018
5066
  const signature = await this.signer().sign(hashedTransaction);
5019
5067
  return (0, import_utils30.hexlify)(signature);