@fuel-ts/account 0.0.0-rc-2034-20240410172045 → 0.0.0-rc-2037-20240411020051

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.

@@ -1032,7 +1032,7 @@ var inputify = (value) => {
1032
1032
  return {
1033
1033
  type: InputType.Coin,
1034
1034
  txID: hexlify3(arrayify(value.id).slice(0, 32)),
1035
- outputIndex: toNumber(arrayify(value.id).slice(32, 33)),
1035
+ outputIndex: arrayify(value.id)[32],
1036
1036
  owner: hexlify3(value.owner),
1037
1037
  amount: bn2(value.amount),
1038
1038
  assetId: hexlify3(value.assetId),
@@ -1152,7 +1152,6 @@ var outputify = (value) => {
1152
1152
  // src/providers/transaction-request/transaction-request.ts
1153
1153
  import { Address, addressify } from "@fuel-ts/address";
1154
1154
  import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1155
- import { randomBytes } from "@fuel-ts/crypto";
1156
1155
  import { bn as bn7 } from "@fuel-ts/math";
1157
1156
  import {
1158
1157
  PolicyType,
@@ -1826,8 +1825,8 @@ var BaseTransactionRequest = class {
1826
1825
  * @param predicate - Predicate bytes.
1827
1826
  * @param predicateData - Predicate data bytes.
1828
1827
  */
1829
- addCoinInput(coin, predicate) {
1830
- const { assetId, owner, amount } = coin;
1828
+ addCoinInput(coin) {
1829
+ const { assetId, owner, amount, id, predicate } = coin;
1831
1830
  let witnessIndex;
1832
1831
  if (predicate) {
1833
1832
  witnessIndex = 0;
@@ -1838,14 +1837,14 @@ var BaseTransactionRequest = class {
1838
1837
  }
1839
1838
  }
1840
1839
  const input = {
1841
- ...coin,
1840
+ id,
1842
1841
  type: InputType2.Coin,
1843
1842
  owner: owner.toB256(),
1844
1843
  amount,
1845
1844
  assetId,
1846
1845
  txPointer: "0x00000000000000000000000000000000",
1847
1846
  witnessIndex,
1848
- predicate: predicate?.bytes
1847
+ predicate
1849
1848
  };
1850
1849
  this.pushInput(input);
1851
1850
  this.addChangeOutput(owner, assetId);
@@ -1858,8 +1857,8 @@ var BaseTransactionRequest = class {
1858
1857
  * @param predicate - Predicate bytes.
1859
1858
  * @param predicateData - Predicate data bytes.
1860
1859
  */
1861
- addMessageInput(message, predicate) {
1862
- const { recipient, sender, amount } = message;
1860
+ addMessageInput(message) {
1861
+ const { recipient, sender, amount, predicate, nonce } = message;
1863
1862
  const assetId = BaseAssetId2;
1864
1863
  let witnessIndex;
1865
1864
  if (predicate) {
@@ -1871,13 +1870,13 @@ var BaseTransactionRequest = class {
1871
1870
  }
1872
1871
  }
1873
1872
  const input = {
1874
- ...message,
1873
+ nonce,
1875
1874
  type: InputType2.Message,
1876
1875
  sender: sender.toB256(),
1877
1876
  recipient: recipient.toB256(),
1878
1877
  amount,
1879
1878
  witnessIndex,
1880
- predicate: predicate?.bytes
1879
+ predicate
1881
1880
  };
1882
1881
  this.pushInput(input);
1883
1882
  this.addChangeOutput(recipient, assetId);
@@ -1908,32 +1907,6 @@ var BaseTransactionRequest = class {
1908
1907
  resources.forEach((resource) => this.addResource(resource));
1909
1908
  return this;
1910
1909
  }
1911
- /**
1912
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1913
- * outputs from the related assetIds.
1914
- *
1915
- * @param resources - The resources to add.
1916
- * @returns This transaction.
1917
- */
1918
- addPredicateResource(resource, predicate) {
1919
- if (isCoin(resource)) {
1920
- this.addCoinInput(resource, predicate);
1921
- } else {
1922
- this.addMessageInput(resource, predicate);
1923
- }
1924
- return this;
1925
- }
1926
- /**
1927
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1928
- * from the related assetIds.
1929
- *
1930
- * @param resources - The resources to add.
1931
- * @returns This transaction.
1932
- */
1933
- addPredicateResources(resources, predicate) {
1934
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1935
- return this;
1936
- }
1937
1910
  /**
1938
1911
  * Adds a coin output to the transaction.
1939
1912
  *
@@ -2032,6 +2005,12 @@ var BaseTransactionRequest = class {
2032
2005
  * @param quantities - CoinQuantity Array.
2033
2006
  */
2034
2007
  fundWithFakeUtxos(quantities, resourcesOwner) {
2008
+ let idCounter = 0;
2009
+ const generateId = () => {
2010
+ const counterString = String(idCounter++);
2011
+ const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
2012
+ return id;
2013
+ };
2035
2014
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2036
2015
  if ("assetId" in input) {
2037
2016
  return input.assetId === assetId;
@@ -2041,12 +2020,12 @@ var BaseTransactionRequest = class {
2041
2020
  const updateAssetInput = (assetId, quantity) => {
2042
2021
  const assetInput = findAssetInput(assetId);
2043
2022
  if (assetInput && "assetId" in assetInput) {
2044
- assetInput.id = hexlify7(randomBytes(33));
2023
+ assetInput.id = generateId();
2045
2024
  assetInput.amount = quantity;
2046
2025
  } else {
2047
2026
  this.addResources([
2048
2027
  {
2049
- id: hexlify7(randomBytes(33)),
2028
+ id: generateId(),
2050
2029
  amount: quantity,
2051
2030
  assetId,
2052
2031
  owner: resourcesOwner || Address.fromRandom(),
@@ -3876,36 +3855,6 @@ var _Provider = class {
3876
3855
  missingContractIds
3877
3856
  };
3878
3857
  }
3879
- /**
3880
- * Estimates the transaction gas and fee based on the provided transaction request.
3881
- * @param transactionRequest - The transaction request object.
3882
- * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3883
- */
3884
- estimateTxGasAndFee(params) {
3885
- const { transactionRequest } = params;
3886
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3887
- const chainInfo = this.getChain();
3888
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3889
- transactionRequest.gasPrice = gasPrice;
3890
- const minGas = transactionRequest.calculateMinGas(chainInfo);
3891
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3892
- if (transactionRequest.type === TransactionType8.Script) {
3893
- if (transactionRequest.gasLimit.eq(0)) {
3894
- transactionRequest.gasLimit = minGas;
3895
- transactionRequest.gasLimit = maxGasPerTx.sub(
3896
- transactionRequest.calculateMaxGas(chainInfo, minGas)
3897
- );
3898
- }
3899
- }
3900
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3901
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3902
- return {
3903
- minGas,
3904
- minFee,
3905
- maxGas,
3906
- maxFee
3907
- };
3908
- }
3909
3858
  /**
3910
3859
  * Executes a signed transaction without applying the states changes
3911
3860
  * on the chain.
@@ -3953,16 +3902,17 @@ var _Provider = class {
3953
3902
  signatureCallback
3954
3903
  } = {}) {
3955
3904
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3956
- const { minGasPrice } = this.getGasConfig();
3957
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3905
+ const chainInfo = this.getChain();
3906
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3907
+ const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3958
3908
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3959
3909
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3960
3910
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3961
3911
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3962
- if (isScriptTransaction) {
3963
- txRequestClone.gasLimit = bn15(0);
3964
- }
3965
3912
  if (estimatePredicates) {
3913
+ if (isScriptTransaction) {
3914
+ txRequestClone.gasLimit = bn15(0);
3915
+ }
3966
3916
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3967
3917
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3968
3918
  }
@@ -3971,34 +3921,36 @@ var _Provider = class {
3971
3921
  if (signatureCallback && isScriptTransaction) {
3972
3922
  await signatureCallback(txRequestClone);
3973
3923
  }
3974
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3975
- transactionRequest: txRequestClone
3976
- });
3924
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
3925
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3977
3926
  let receipts = [];
3978
3927
  let missingContractIds = [];
3979
3928
  let outputVariables = 0;
3980
- let gasUsed = bn15(0);
3981
3929
  if (isScriptTransaction && estimateTxDependencies) {
3982
3930
  txRequestClone.gasPrice = bn15(0);
3931
+ txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3983
3932
  const result = await this.estimateTxDependencies(txRequestClone);
3984
3933
  receipts = result.receipts;
3985
3934
  outputVariables = result.outputVariables;
3986
3935
  missingContractIds = result.missingContractIds;
3987
- gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
3988
- txRequestClone.gasLimit = gasUsed;
3989
- txRequestClone.gasPrice = setGasPrice;
3990
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3991
- transactionRequest: txRequestClone
3992
- }));
3993
3936
  }
3937
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3938
+ const usedFee = calculatePriceWithFactor(
3939
+ gasUsed,
3940
+ gasPrice,
3941
+ gasPriceFactor
3942
+ ).normalizeZeroToOne();
3943
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3944
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3994
3945
  return {
3995
3946
  requiredQuantities: allQuantities,
3996
3947
  receipts,
3997
3948
  gasUsed,
3998
3949
  minGasPrice,
3999
- gasPrice: setGasPrice,
3950
+ gasPrice,
4000
3951
  minGas,
4001
3952
  maxGas,
3953
+ usedFee,
4002
3954
  minFee,
4003
3955
  maxFee,
4004
3956
  estimatedInputs: txRequestClone.inputs,
@@ -4922,7 +4874,7 @@ var Account = class extends AbstractAccount {
4922
4874
 
4923
4875
  // src/signer/signer.ts
4924
4876
  import { Address as Address4 } from "@fuel-ts/address";
4925
- import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4877
+ import { randomBytes } from "@fuel-ts/crypto";
4926
4878
  import { hash } from "@fuel-ts/hasher";
4927
4879
  import { toBytes } from "@fuel-ts/math";
4928
4880
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -5015,7 +4967,7 @@ var Signer = class {
5015
4967
  * @returns random 32-byte hashed
5016
4968
  */
5017
4969
  static generatePrivateKey(entropy) {
5018
- return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
4970
+ return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5019
4971
  }
5020
4972
  /**
5021
4973
  * Extended publicKey from a compact publicKey
@@ -5034,7 +4986,7 @@ import { Address as Address5 } from "@fuel-ts/address";
5034
4986
  import {
5035
4987
  bufferFromString,
5036
4988
  keccak256,
5037
- randomBytes as randomBytes3,
4989
+ randomBytes as randomBytes2,
5038
4990
  scrypt,
5039
4991
  stringFromBuffer,
5040
4992
  decryptJsonWalletData,
@@ -5057,7 +5009,7 @@ var removeHexPrefix = (hexString) => {
5057
5009
  async function encryptKeystoreWallet(privateKey, address, password) {
5058
5010
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
5059
5011
  const ownerAddress = Address5.fromAddressOrString(address);
5060
- const salt = randomBytes3(DEFAULT_KEY_SIZE);
5012
+ const salt = randomBytes2(DEFAULT_KEY_SIZE);
5061
5013
  const key = scrypt({
5062
5014
  password: bufferFromString(password),
5063
5015
  salt,
@@ -5066,7 +5018,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5066
5018
  r: DEFAULT_KDF_PARAMS_R,
5067
5019
  p: DEFAULT_KDF_PARAMS_P
5068
5020
  });
5069
- const iv = randomBytes3(DEFAULT_IV_SIZE);
5021
+ const iv = randomBytes2(DEFAULT_IV_SIZE);
5070
5022
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
5071
5023
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5072
5024
  const macHashUint8Array = keccak256(data);
@@ -5248,7 +5200,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
5248
5200
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5249
5201
 
5250
5202
  // src/mnemonic/mnemonic.ts
5251
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5203
+ import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5252
5204
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5253
5205
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5254
5206
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
@@ -7603,7 +7555,7 @@ var Mnemonic = class {
7603
7555
  * @returns A randomly generated mnemonic
7604
7556
  */
7605
7557
  static generate(size = 32, extraEntropy = "") {
7606
- const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7558
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7607
7559
  return Mnemonic.entropyToMnemonic(entropy);
7608
7560
  }
7609
7561
  };
@@ -7974,10 +7926,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7974
7926
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7975
7927
 
7976
7928
  // src/test-utils/seedTestWallet.ts
7977
- import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7929
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
7978
7930
  var seedTestWallet = async (wallet, quantities) => {
7979
7931
  const genesisWallet = new WalletUnlocked(
7980
- process.env.GENESIS_SECRET || randomBytes5(32),
7932
+ process.env.GENESIS_SECRET || randomBytes4(32),
7981
7933
  wallet.provider
7982
7934
  );
7983
7935
  const resources = await genesisWallet.getResourcesToSpend(quantities);