@fuel-ts/account 0.0.0-rc-2034-20240411123358 → 0.0.0-rc-2037-20240411135757

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.

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