@fuel-ts/account 0.0.0-rc-2045-20240415152456 → 0.0.0-rc-2040-20240415161332

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,
@@ -2034,6 +2031,12 @@ var BaseTransactionRequest = class {
2034
2031
  * @param quantities - CoinQuantity Array.
2035
2032
  */
2036
2033
  fundWithFakeUtxos(quantities, resourcesOwner) {
2034
+ let idCounter = 0;
2035
+ const generateId = () => {
2036
+ const counterString = String(idCounter++);
2037
+ const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
2038
+ return id;
2039
+ };
2037
2040
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2038
2041
  if ("assetId" in input) {
2039
2042
  return input.assetId === assetId;
@@ -2043,12 +2046,12 @@ var BaseTransactionRequest = class {
2043
2046
  const updateAssetInput = (assetId, quantity) => {
2044
2047
  const assetInput = findAssetInput(assetId);
2045
2048
  if (assetInput && "assetId" in assetInput) {
2046
- assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2049
+ assetInput.id = generateId();
2047
2050
  assetInput.amount = quantity;
2048
2051
  } else {
2049
2052
  this.addResources([
2050
2053
  {
2051
- id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2054
+ id: generateId(),
2052
2055
  amount: quantity,
2053
2056
  assetId,
2054
2057
  owner: resourcesOwner || Address.fromRandom(),
@@ -3878,36 +3881,6 @@ var _Provider = class {
3878
3881
  missingContractIds
3879
3882
  };
3880
3883
  }
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
3884
  /**
3912
3885
  * Executes a signed transaction without applying the states changes
3913
3886
  * on the chain.
@@ -3955,16 +3928,17 @@ var _Provider = class {
3955
3928
  signatureCallback
3956
3929
  } = {}) {
3957
3930
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3958
- const { minGasPrice } = this.getGasConfig();
3959
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3931
+ const chainInfo = this.getChain();
3932
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3933
+ const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3960
3934
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3961
3935
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3962
3936
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3963
3937
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3964
- if (isScriptTransaction) {
3965
- txRequestClone.gasLimit = bn15(0);
3966
- }
3967
3938
  if (estimatePredicates) {
3939
+ if (isScriptTransaction) {
3940
+ txRequestClone.gasLimit = bn15(0);
3941
+ }
3968
3942
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3969
3943
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3970
3944
  }
@@ -3973,34 +3947,36 @@ var _Provider = class {
3973
3947
  if (signatureCallback && isScriptTransaction) {
3974
3948
  await signatureCallback(txRequestClone);
3975
3949
  }
3976
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3977
- transactionRequest: txRequestClone
3978
- });
3950
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
3951
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3979
3952
  let receipts = [];
3980
3953
  let missingContractIds = [];
3981
3954
  let outputVariables = 0;
3982
- let gasUsed = bn15(0);
3983
3955
  if (isScriptTransaction && estimateTxDependencies) {
3984
3956
  txRequestClone.gasPrice = bn15(0);
3957
+ txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3985
3958
  const result = await this.estimateTxDependencies(txRequestClone);
3986
3959
  receipts = result.receipts;
3987
3960
  outputVariables = result.outputVariables;
3988
3961
  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
3962
  }
3963
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3964
+ const usedFee = calculatePriceWithFactor(
3965
+ gasUsed,
3966
+ gasPrice,
3967
+ gasPriceFactor
3968
+ ).normalizeZeroToOne();
3969
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3970
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3996
3971
  return {
3997
3972
  requiredQuantities: allQuantities,
3998
3973
  receipts,
3999
3974
  gasUsed,
4000
3975
  minGasPrice,
4001
- gasPrice: setGasPrice,
3976
+ gasPrice,
4002
3977
  minGas,
4003
3978
  maxGas,
3979
+ usedFee,
4004
3980
  minFee,
4005
3981
  maxFee,
4006
3982
  estimatedInputs: txRequestClone.inputs,
@@ -4924,7 +4900,7 @@ var Account = class extends AbstractAccount {
4924
4900
 
4925
4901
  // src/signer/signer.ts
4926
4902
  import { Address as Address4 } from "@fuel-ts/address";
4927
- import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4903
+ import { randomBytes } from "@fuel-ts/crypto";
4928
4904
  import { hash } from "@fuel-ts/hasher";
4929
4905
  import { toBytes } from "@fuel-ts/math";
4930
4906
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -5017,7 +4993,7 @@ var Signer = class {
5017
4993
  * @returns random 32-byte hashed
5018
4994
  */
5019
4995
  static generatePrivateKey(entropy) {
5020
- return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
4996
+ return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5021
4997
  }
5022
4998
  /**
5023
4999
  * Extended publicKey from a compact publicKey
@@ -5036,7 +5012,7 @@ import { Address as Address5 } from "@fuel-ts/address";
5036
5012
  import {
5037
5013
  bufferFromString,
5038
5014
  keccak256,
5039
- randomBytes as randomBytes3,
5015
+ randomBytes as randomBytes2,
5040
5016
  scrypt,
5041
5017
  stringFromBuffer,
5042
5018
  decryptJsonWalletData,
@@ -5059,7 +5035,7 @@ var removeHexPrefix = (hexString) => {
5059
5035
  async function encryptKeystoreWallet(privateKey, address, password) {
5060
5036
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
5061
5037
  const ownerAddress = Address5.fromAddressOrString(address);
5062
- const salt = randomBytes3(DEFAULT_KEY_SIZE);
5038
+ const salt = randomBytes2(DEFAULT_KEY_SIZE);
5063
5039
  const key = scrypt({
5064
5040
  password: bufferFromString(password),
5065
5041
  salt,
@@ -5068,7 +5044,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5068
5044
  r: DEFAULT_KDF_PARAMS_R,
5069
5045
  p: DEFAULT_KDF_PARAMS_P
5070
5046
  });
5071
- const iv = randomBytes3(DEFAULT_IV_SIZE);
5047
+ const iv = randomBytes2(DEFAULT_IV_SIZE);
5072
5048
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
5073
5049
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5074
5050
  const macHashUint8Array = keccak256(data);
@@ -5250,7 +5226,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
5250
5226
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5251
5227
 
5252
5228
  // src/mnemonic/mnemonic.ts
5253
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5229
+ import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5254
5230
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5255
5231
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5256
5232
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
@@ -7605,7 +7581,7 @@ var Mnemonic = class {
7605
7581
  * @returns A randomly generated mnemonic
7606
7582
  */
7607
7583
  static generate(size = 32, extraEntropy = "") {
7608
- const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7584
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7609
7585
  return Mnemonic.entropyToMnemonic(entropy);
7610
7586
  }
7611
7587
  };
@@ -7976,10 +7952,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7976
7952
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7977
7953
 
7978
7954
  // src/test-utils/seedTestWallet.ts
7979
- import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7955
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
7980
7956
  var seedTestWallet = async (wallet, quantities) => {
7981
7957
  const genesisWallet = new WalletUnlocked(
7982
- process.env.GENESIS_SECRET || randomBytes5(32),
7958
+ process.env.GENESIS_SECRET || randomBytes4(32),
7983
7959
  wallet.provider
7984
7960
  );
7985
7961
  const resources = await genesisWallet.getResourcesToSpend(quantities);