@fuel-ts/account 0.0.0-rc-2045-20240415152456 → 0.0.0-rc-1832-20240415161726

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