@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.

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 = {
@@ -3924,7 +3953,8 @@ var _Provider = class {
3924
3953
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3925
3954
  estimateTxDependencies = true,
3926
3955
  estimatePredicates = true,
3927
- resourcesOwner
3956
+ resourcesOwner,
3957
+ signatureCallback
3928
3958
  } = {}) {
3929
3959
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3930
3960
  const chainInfo = this.getChain();
@@ -3943,6 +3973,9 @@ var _Provider = class {
3943
3973
  }
3944
3974
  await this.estimatePredicates(txRequestClone);
3945
3975
  }
3976
+ if (signatureCallback && isScriptTransaction) {
3977
+ await signatureCallback(txRequestClone);
3978
+ }
3946
3979
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3947
3980
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3948
3981
  let receipts = [];
@@ -4990,6 +5023,21 @@ var Account = class extends AbstractAccount {
4990
5023
  }
4991
5024
  return this._connector.signMessage(this.address.toString(), message);
4992
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
+ }
4993
5041
  /**
4994
5042
  * Sends a transaction to the network.
4995
5043
  *
@@ -5308,7 +5356,7 @@ var BaseWalletUnlocked = class extends Account {
5308
5356
  */
5309
5357
  async signTransaction(transactionRequestLike) {
5310
5358
  const transactionRequest = transactionRequestify(transactionRequestLike);
5311
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5359
+ const chainId = this.provider.getChainId();
5312
5360
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5313
5361
  const signature = await this.signer().sign(hashedTransaction);
5314
5362
  return hexlify15(signature);
@@ -8855,6 +8903,18 @@ var FuelConnector = class extends EventEmitter2 {
8855
8903
  async signMessage(_address, _message) {
8856
8904
  throw new Error("Method not implemented.");
8857
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
+ }
8858
8918
  /**
8859
8919
  * Should start the send transaction process and return
8860
8920
  * the transaction id submitted to the network.