@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.js CHANGED
@@ -1839,13 +1839,27 @@ var BaseTransactionRequest = class {
1839
1839
  this.outputs.push(output);
1840
1840
  return this.outputs.length - 1;
1841
1841
  }
1842
+ /**
1843
+ * @hidden
1844
+ *
1845
+ * Pushes a witness to the list and returns the index
1846
+ *
1847
+ * @param signature - The signature to add to the witness.
1848
+ * @returns The index of the created witness.
1849
+ */
1850
+ addWitness(signature) {
1851
+ this.witnesses.push(signature);
1852
+ return this.witnesses.length - 1;
1853
+ }
1842
1854
  /**
1843
1855
  * @hidden
1844
1856
  *
1845
1857
  * Creates an empty witness without any side effects and returns the index
1858
+ *
1859
+ * @returns The index of the created witness.
1846
1860
  */
1847
- createWitness() {
1848
- this.witnesses.push((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1861
+ addEmptyWitness() {
1862
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1849
1863
  return this.witnesses.length - 1;
1850
1864
  }
1851
1865
  /**
@@ -1874,6 +1888,21 @@ var BaseTransactionRequest = class {
1874
1888
  }
1875
1889
  this.witnesses[index] = witness;
1876
1890
  }
1891
+ /**
1892
+ * Helper function to add an external signature to the transaction.
1893
+ *
1894
+ * @param account - The account/s to sign to the transaction.
1895
+ * @returns The transaction with the signature witness added.
1896
+ */
1897
+ async addAccountWitnesses(account) {
1898
+ const accounts = Array.isArray(account) ? account : [account];
1899
+ await Promise.all(
1900
+ accounts.map(async (acc) => {
1901
+ this.addWitness(await acc.signTransaction(this));
1902
+ })
1903
+ );
1904
+ return this;
1905
+ }
1877
1906
  /**
1878
1907
  * Gets the coin inputs for a transaction.
1879
1908
  *
@@ -1939,7 +1968,7 @@ var BaseTransactionRequest = class {
1939
1968
  } else {
1940
1969
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1941
1970
  if (typeof witnessIndex !== "number") {
1942
- witnessIndex = this.createWitness();
1971
+ witnessIndex = this.addEmptyWitness();
1943
1972
  }
1944
1973
  }
1945
1974
  const input = {
@@ -1973,7 +2002,7 @@ var BaseTransactionRequest = class {
1973
2002
  } else {
1974
2003
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1975
2004
  if (typeof witnessIndex !== "number") {
1976
- witnessIndex = this.createWitness();
2005
+ witnessIndex = this.addEmptyWitness();
1977
2006
  }
1978
2007
  }
1979
2008
  const input = {
@@ -4060,7 +4089,8 @@ var _Provider = class {
4060
4089
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4061
4090
  estimateTxDependencies = true,
4062
4091
  estimatePredicates = true,
4063
- resourcesOwner
4092
+ resourcesOwner,
4093
+ signatureCallback
4064
4094
  } = {}) {
4065
4095
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4066
4096
  const chainInfo = this.getChain();
@@ -4079,6 +4109,9 @@ var _Provider = class {
4079
4109
  }
4080
4110
  await this.estimatePredicates(txRequestClone);
4081
4111
  }
4112
+ if (signatureCallback && isScriptTransaction) {
4113
+ await signatureCallback(txRequestClone);
4114
+ }
4082
4115
  const minGas = txRequestClone.calculateMinGas(chainInfo);
4083
4116
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4084
4117
  let receipts = [];
@@ -5126,6 +5159,21 @@ var Account = class extends import_interfaces.AbstractAccount {
5126
5159
  }
5127
5160
  return this._connector.signMessage(this.address.toString(), message);
5128
5161
  }
5162
+ /**
5163
+ * Signs a transaction with the wallet's private key.
5164
+ *
5165
+ * @param transactionRequestLike - The transaction request to sign.
5166
+ * @returns A promise that resolves to the signature of the transaction.
5167
+ */
5168
+ async signTransaction(transactionRequestLike) {
5169
+ if (!this._connector) {
5170
+ throw new import_errors15.FuelError(
5171
+ import_errors15.ErrorCode.MISSING_CONNECTOR,
5172
+ "A connector is required to sign transactions."
5173
+ );
5174
+ }
5175
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
5176
+ }
5129
5177
  /**
5130
5178
  * Sends a transaction to the network.
5131
5179
  *
@@ -5436,7 +5484,7 @@ var BaseWalletUnlocked = class extends Account {
5436
5484
  */
5437
5485
  async signTransaction(transactionRequestLike) {
5438
5486
  const transactionRequest = transactionRequestify(transactionRequestLike);
5439
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5487
+ const chainId = this.provider.getChainId();
5440
5488
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5441
5489
  const signature = await this.signer().sign(hashedTransaction);
5442
5490
  return (0, import_utils30.hexlify)(signature);
@@ -8977,6 +9025,18 @@ var FuelConnector = class extends import_events2.EventEmitter {
8977
9025
  async signMessage(_address, _message) {
8978
9026
  throw new Error("Method not implemented.");
8979
9027
  }
9028
+ /**
9029
+ * Should start the sign transaction process and return
9030
+ * the signed transaction.
9031
+ *
9032
+ * @param address - The address to sign the transaction
9033
+ * @param transaction - The transaction to sign
9034
+ *
9035
+ * @returns Transaction signature
9036
+ */
9037
+ async signTransaction(_address, _transaction) {
9038
+ throw new Error("Method not implemented.");
9039
+ }
8980
9040
  /**
8981
9041
  * Should start the send transaction process and return
8982
9042
  * the transaction id submitted to the network.