@fuel-ts/account 0.0.0-rc-1866-20240322105123 → 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.

@@ -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 = {
@@ -4685,6 +4714,21 @@ var Account = class extends AbstractAccount {
4685
4714
  }
4686
4715
  return this._connector.signMessage(this.address.toString(), message);
4687
4716
  }
4717
+ /**
4718
+ * Signs a transaction with the wallet's private key.
4719
+ *
4720
+ * @param transactionRequestLike - The transaction request to sign.
4721
+ * @returns A promise that resolves to the signature of the transaction.
4722
+ */
4723
+ async signTransaction(transactionRequestLike) {
4724
+ if (!this._connector) {
4725
+ throw new FuelError14(
4726
+ ErrorCode14.MISSING_CONNECTOR,
4727
+ "A connector is required to sign transactions."
4728
+ );
4729
+ }
4730
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
4731
+ }
4688
4732
  /**
4689
4733
  * Sends a transaction to the network.
4690
4734
  *
@@ -4999,7 +5043,7 @@ var BaseWalletUnlocked = class extends Account {
4999
5043
  */
5000
5044
  async signTransaction(transactionRequestLike) {
5001
5045
  const transactionRequest = transactionRequestify(transactionRequestLike);
5002
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
5046
+ const chainId = this.provider.getChainId();
5003
5047
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5004
5048
  const signature = await this.signer().sign(hashedTransaction);
5005
5049
  return hexlify15(signature);