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

@@ -1624,13 +1624,27 @@ var BaseTransactionRequest = class {
1624
1624
  this.outputs.push(output);
1625
1625
  return this.outputs.length - 1;
1626
1626
  }
1627
+ /**
1628
+ * @hidden
1629
+ *
1630
+ * Pushes a witness to the list and returns the index
1631
+ *
1632
+ * @param signature - The signature to add to the witness.
1633
+ * @returns The index of the created witness.
1634
+ */
1635
+ addWitness(signature) {
1636
+ this.witnesses.push(signature);
1637
+ return this.witnesses.length - 1;
1638
+ }
1627
1639
  /**
1628
1640
  * @hidden
1629
1641
  *
1630
1642
  * Creates an empty witness without any side effects and returns the index
1643
+ *
1644
+ * @returns The index of the created witness.
1631
1645
  */
1632
- createWitness() {
1633
- this.witnesses.push(concat([ZeroBytes324, ZeroBytes324]));
1646
+ addEmptyWitness() {
1647
+ this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
1634
1648
  return this.witnesses.length - 1;
1635
1649
  }
1636
1650
  /**
@@ -1659,6 +1673,21 @@ var BaseTransactionRequest = class {
1659
1673
  }
1660
1674
  this.witnesses[index] = witness;
1661
1675
  }
1676
+ /**
1677
+ * Helper function to add an external signature to the transaction.
1678
+ *
1679
+ * @param account - The account/s to sign to the transaction.
1680
+ * @returns The transaction with the signature witness added.
1681
+ */
1682
+ async addAccountWitnesses(account) {
1683
+ const accounts = Array.isArray(account) ? account : [account];
1684
+ await Promise.all(
1685
+ accounts.map(async (acc) => {
1686
+ this.addWitness(await acc.signTransaction(this));
1687
+ })
1688
+ );
1689
+ return this;
1690
+ }
1662
1691
  /**
1663
1692
  * Gets the coin inputs for a transaction.
1664
1693
  *
@@ -1724,7 +1753,7 @@ var BaseTransactionRequest = class {
1724
1753
  } else {
1725
1754
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
1726
1755
  if (typeof witnessIndex !== "number") {
1727
- witnessIndex = this.createWitness();
1756
+ witnessIndex = this.addEmptyWitness();
1728
1757
  }
1729
1758
  }
1730
1759
  const input = {
@@ -1758,7 +1787,7 @@ var BaseTransactionRequest = class {
1758
1787
  } else {
1759
1788
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
1760
1789
  if (typeof witnessIndex !== "number") {
1761
- witnessIndex = this.createWitness();
1790
+ witnessIndex = this.addEmptyWitness();
1762
1791
  }
1763
1792
  }
1764
1793
  const input = {
@@ -3785,7 +3814,8 @@ var _Provider = class {
3785
3814
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3786
3815
  estimateTxDependencies = true,
3787
3816
  estimatePredicates = true,
3788
- resourcesOwner
3817
+ resourcesOwner,
3818
+ signatureCallback
3789
3819
  } = {}) {
3790
3820
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3791
3821
  const chainInfo = this.getChain();
@@ -3804,6 +3834,9 @@ var _Provider = class {
3804
3834
  }
3805
3835
  await this.estimatePredicates(txRequestClone);
3806
3836
  }
3837
+ if (signatureCallback && isScriptTransaction) {
3838
+ await signatureCallback(txRequestClone);
3839
+ }
3807
3840
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3808
3841
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3809
3842
  let receipts = [];
@@ -4685,6 +4718,21 @@ var Account = class extends AbstractAccount {
4685
4718
  }
4686
4719
  return this._connector.signMessage(this.address.toString(), message);
4687
4720
  }
4721
+ /**
4722
+ * Signs a transaction with the wallet's private key.
4723
+ *
4724
+ * @param transactionRequestLike - The transaction request to sign.
4725
+ * @returns A promise that resolves to the signature of the transaction.
4726
+ */
4727
+ async signTransaction(transactionRequestLike) {
4728
+ if (!this._connector) {
4729
+ throw new FuelError14(
4730
+ ErrorCode14.MISSING_CONNECTOR,
4731
+ "A connector is required to sign transactions."
4732
+ );
4733
+ }
4734
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4735
+ }
4688
4736
  /**
4689
4737
  * Sends a transaction to the network.
4690
4738
  *
@@ -4999,7 +5047,7 @@ var BaseWalletUnlocked = class extends Account {
4999
5047
  */
5000
5048
  async signTransaction(transactionRequestLike) {
5001
5049
  const transactionRequest = transactionRequestify(transactionRequestLike);
5002
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5050
+ const chainId = this.provider.getChainId();
5003
5051
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5004
5052
  const signature = await this.signer().sign(hashedTransaction);
5005
5053
  return hexlify15(signature);