@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.

@@ -1065,7 +1065,7 @@ var inputify = (value) => {
1065
1065
  return {
1066
1066
  type: import_transactions.InputType.Coin,
1067
1067
  txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1068
- outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 33)),
1068
+ outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1069
1069
  owner: (0, import_utils3.hexlify)(value.owner),
1070
1070
  amount: (0, import_math2.bn)(value.amount),
1071
1071
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1185,7 +1185,6 @@ var outputify = (value) => {
1185
1185
  // src/providers/transaction-request/transaction-request.ts
1186
1186
  var import_address = require("@fuel-ts/address");
1187
1187
  var import_configs7 = require("@fuel-ts/address/configs");
1188
- var import_crypto = require("@fuel-ts/crypto");
1189
1188
  var import_math7 = require("@fuel-ts/math");
1190
1189
  var import_transactions6 = require("@fuel-ts/transactions");
1191
1190
  var import_utils9 = require("@fuel-ts/utils");
@@ -1840,8 +1839,8 @@ var BaseTransactionRequest = class {
1840
1839
  * @param predicate - Predicate bytes.
1841
1840
  * @param predicateData - Predicate data bytes.
1842
1841
  */
1843
- addCoinInput(coin, predicate) {
1844
- const { assetId, owner, amount } = coin;
1842
+ addCoinInput(coin) {
1843
+ const { assetId, owner, amount, id, predicate } = coin;
1845
1844
  let witnessIndex;
1846
1845
  if (predicate) {
1847
1846
  witnessIndex = 0;
@@ -1852,14 +1851,14 @@ var BaseTransactionRequest = class {
1852
1851
  }
1853
1852
  }
1854
1853
  const input = {
1855
- ...coin,
1854
+ id,
1856
1855
  type: import_transactions6.InputType.Coin,
1857
1856
  owner: owner.toB256(),
1858
1857
  amount,
1859
1858
  assetId,
1860
1859
  txPointer: "0x00000000000000000000000000000000",
1861
1860
  witnessIndex,
1862
- predicate: predicate?.bytes
1861
+ predicate
1863
1862
  };
1864
1863
  this.pushInput(input);
1865
1864
  this.addChangeOutput(owner, assetId);
@@ -1872,8 +1871,8 @@ var BaseTransactionRequest = class {
1872
1871
  * @param predicate - Predicate bytes.
1873
1872
  * @param predicateData - Predicate data bytes.
1874
1873
  */
1875
- addMessageInput(message, predicate) {
1876
- const { recipient, sender, amount } = message;
1874
+ addMessageInput(message) {
1875
+ const { recipient, sender, amount, predicate, nonce } = message;
1877
1876
  const assetId = import_configs7.BaseAssetId;
1878
1877
  let witnessIndex;
1879
1878
  if (predicate) {
@@ -1885,13 +1884,13 @@ var BaseTransactionRequest = class {
1885
1884
  }
1886
1885
  }
1887
1886
  const input = {
1888
- ...message,
1887
+ nonce,
1889
1888
  type: import_transactions6.InputType.Message,
1890
1889
  sender: sender.toB256(),
1891
1890
  recipient: recipient.toB256(),
1892
1891
  amount,
1893
1892
  witnessIndex,
1894
- predicate: predicate?.bytes
1893
+ predicate
1895
1894
  };
1896
1895
  this.pushInput(input);
1897
1896
  this.addChangeOutput(recipient, assetId);
@@ -1922,32 +1921,6 @@ var BaseTransactionRequest = class {
1922
1921
  resources.forEach((resource) => this.addResource(resource));
1923
1922
  return this;
1924
1923
  }
1925
- /**
1926
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1927
- * outputs from the related assetIds.
1928
- *
1929
- * @param resources - The resources to add.
1930
- * @returns This transaction.
1931
- */
1932
- addPredicateResource(resource, predicate) {
1933
- if (isCoin(resource)) {
1934
- this.addCoinInput(resource, predicate);
1935
- } else {
1936
- this.addMessageInput(resource, predicate);
1937
- }
1938
- return this;
1939
- }
1940
- /**
1941
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1942
- * from the related assetIds.
1943
- *
1944
- * @param resources - The resources to add.
1945
- * @returns This transaction.
1946
- */
1947
- addPredicateResources(resources, predicate) {
1948
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1949
- return this;
1950
- }
1951
1924
  /**
1952
1925
  * Adds a coin output to the transaction.
1953
1926
  *
@@ -2046,6 +2019,12 @@ var BaseTransactionRequest = class {
2046
2019
  * @param quantities - CoinQuantity Array.
2047
2020
  */
2048
2021
  fundWithFakeUtxos(quantities, resourcesOwner) {
2022
+ let idCounter = 0;
2023
+ const generateId = () => {
2024
+ const counterString = String(idCounter++);
2025
+ const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2026
+ return id;
2027
+ };
2049
2028
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2050
2029
  if ("assetId" in input) {
2051
2030
  return input.assetId === assetId;
@@ -2055,12 +2034,12 @@ var BaseTransactionRequest = class {
2055
2034
  const updateAssetInput = (assetId, quantity) => {
2056
2035
  const assetInput = findAssetInput(assetId);
2057
2036
  if (assetInput && "assetId" in assetInput) {
2058
- assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(33));
2037
+ assetInput.id = generateId();
2059
2038
  assetInput.amount = quantity;
2060
2039
  } else {
2061
2040
  this.addResources([
2062
2041
  {
2063
- id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(33)),
2042
+ id: generateId(),
2064
2043
  amount: quantity,
2065
2044
  assetId,
2066
2045
  owner: resourcesOwner || import_address.Address.fromRandom(),
@@ -3890,36 +3869,6 @@ var _Provider = class {
3890
3869
  missingContractIds
3891
3870
  };
3892
3871
  }
3893
- /**
3894
- * Estimates the transaction gas and fee based on the provided transaction request.
3895
- * @param transactionRequest - The transaction request object.
3896
- * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3897
- */
3898
- estimateTxGasAndFee(params) {
3899
- const { transactionRequest } = params;
3900
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3901
- const chainInfo = this.getChain();
3902
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3903
- transactionRequest.gasPrice = gasPrice;
3904
- const minGas = transactionRequest.calculateMinGas(chainInfo);
3905
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3906
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3907
- if (transactionRequest.gasLimit.eq(0)) {
3908
- transactionRequest.gasLimit = minGas;
3909
- transactionRequest.gasLimit = maxGasPerTx.sub(
3910
- transactionRequest.calculateMaxGas(chainInfo, minGas)
3911
- );
3912
- }
3913
- }
3914
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3915
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3916
- return {
3917
- minGas,
3918
- minFee,
3919
- maxGas,
3920
- maxFee
3921
- };
3922
- }
3923
3872
  /**
3924
3873
  * Executes a signed transaction without applying the states changes
3925
3874
  * on the chain.
@@ -3967,16 +3916,17 @@ var _Provider = class {
3967
3916
  signatureCallback
3968
3917
  } = {}) {
3969
3918
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3970
- const { minGasPrice } = this.getGasConfig();
3971
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3919
+ const chainInfo = this.getChain();
3920
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3921
+ const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3972
3922
  const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
3973
3923
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3974
3924
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3975
3925
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3976
- if (isScriptTransaction) {
3977
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
3978
- }
3979
3926
  if (estimatePredicates) {
3927
+ if (isScriptTransaction) {
3928
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
3929
+ }
3980
3930
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3981
3931
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3982
3932
  }
@@ -3985,34 +3935,36 @@ var _Provider = class {
3985
3935
  if (signatureCallback && isScriptTransaction) {
3986
3936
  await signatureCallback(txRequestClone);
3987
3937
  }
3988
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3989
- transactionRequest: txRequestClone
3990
- });
3938
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
3939
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3991
3940
  let receipts = [];
3992
3941
  let missingContractIds = [];
3993
3942
  let outputVariables = 0;
3994
- let gasUsed = (0, import_math15.bn)(0);
3995
3943
  if (isScriptTransaction && estimateTxDependencies) {
3996
3944
  txRequestClone.gasPrice = (0, import_math15.bn)(0);
3945
+ txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3997
3946
  const result = await this.estimateTxDependencies(txRequestClone);
3998
3947
  receipts = result.receipts;
3999
3948
  outputVariables = result.outputVariables;
4000
3949
  missingContractIds = result.missingContractIds;
4001
- gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4002
- txRequestClone.gasLimit = gasUsed;
4003
- txRequestClone.gasPrice = setGasPrice;
4004
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4005
- transactionRequest: txRequestClone
4006
- }));
4007
3950
  }
3951
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3952
+ const usedFee = calculatePriceWithFactor(
3953
+ gasUsed,
3954
+ gasPrice,
3955
+ gasPriceFactor
3956
+ ).normalizeZeroToOne();
3957
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3958
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4008
3959
  return {
4009
3960
  requiredQuantities: allQuantities,
4010
3961
  receipts,
4011
3962
  gasUsed,
4012
3963
  minGasPrice,
4013
- gasPrice: setGasPrice,
3964
+ gasPrice,
4014
3965
  minGas,
4015
3966
  maxGas,
3967
+ usedFee,
4016
3968
  minFee,
4017
3969
  maxFee,
4018
3970
  estimatedInputs: txRequestClone.inputs,
@@ -4936,7 +4888,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4936
4888
 
4937
4889
  // src/signer/signer.ts
4938
4890
  var import_address5 = require("@fuel-ts/address");
4939
- var import_crypto2 = require("@fuel-ts/crypto");
4891
+ var import_crypto = require("@fuel-ts/crypto");
4940
4892
  var import_hasher2 = require("@fuel-ts/hasher");
4941
4893
  var import_math19 = require("@fuel-ts/math");
4942
4894
  var import_utils29 = require("@fuel-ts/utils");
@@ -5029,7 +4981,7 @@ var Signer = class {
5029
4981
  * @returns random 32-byte hashed
5030
4982
  */
5031
4983
  static generatePrivateKey(entropy) {
5032
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
4984
+ return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5033
4985
  }
5034
4986
  /**
5035
4987
  * Extended publicKey from a compact publicKey
@@ -5045,7 +4997,7 @@ var Signer = class {
5045
4997
 
5046
4998
  // src/wallet/keystore-wallet.ts
5047
4999
  var import_address6 = require("@fuel-ts/address");
5048
- var import_crypto3 = require("@fuel-ts/crypto");
5000
+ var import_crypto2 = require("@fuel-ts/crypto");
5049
5001
  var import_errors17 = require("@fuel-ts/errors");
5050
5002
  var import_utils30 = require("@fuel-ts/utils");
5051
5003
  var import_uuid = require("uuid");
@@ -5061,22 +5013,22 @@ var removeHexPrefix = (hexString) => {
5061
5013
  return hexString;
5062
5014
  };
5063
5015
  async function encryptKeystoreWallet(privateKey, address, password) {
5064
- const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
5016
+ const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
5065
5017
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5066
- const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
5067
- const key = (0, import_crypto3.scrypt)({
5068
- password: (0, import_crypto3.bufferFromString)(password),
5018
+ const salt = (0, import_crypto2.randomBytes)(DEFAULT_KEY_SIZE);
5019
+ const key = (0, import_crypto2.scrypt)({
5020
+ password: (0, import_crypto2.bufferFromString)(password),
5069
5021
  salt,
5070
5022
  dklen: DEFAULT_KEY_SIZE,
5071
5023
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5072
5024
  r: DEFAULT_KDF_PARAMS_R,
5073
5025
  p: DEFAULT_KDF_PARAMS_P
5074
5026
  });
5075
- const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
5076
- const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5027
+ const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
5028
+ const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5077
5029
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5078
- const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5079
- const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5030
+ const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5031
+ const mac = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5080
5032
  const keystore = {
5081
5033
  id: (0, import_uuid.v4)(),
5082
5034
  version: 3,
@@ -5084,15 +5036,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5084
5036
  crypto: {
5085
5037
  cipher: "aes-128-ctr",
5086
5038
  mac,
5087
- cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
5088
- ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
5039
+ cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
5040
+ ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
5089
5041
  kdf: "scrypt",
5090
5042
  kdfparams: {
5091
5043
  dklen: DEFAULT_KEY_SIZE,
5092
5044
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5093
5045
  p: DEFAULT_KDF_PARAMS_P,
5094
5046
  r: DEFAULT_KDF_PARAMS_R,
5095
- salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
5047
+ salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
5096
5048
  }
5097
5049
  }
5098
5050
  };
@@ -5108,11 +5060,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5108
5060
  kdfparams: { dklen, n, r, p, salt }
5109
5061
  }
5110
5062
  } = keystoreWallet;
5111
- const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
5112
- const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
5113
- const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
5114
- const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
5115
- const key = (0, import_crypto3.scrypt)({
5063
+ const ciphertextBuffer = (0, import_crypto2.bufferFromString)(ciphertext, "hex");
5064
+ const ivBuffer = (0, import_crypto2.bufferFromString)(iv, "hex");
5065
+ const saltBuffer = (0, import_crypto2.bufferFromString)(salt, "hex");
5066
+ const passwordBuffer = (0, import_crypto2.bufferFromString)(password);
5067
+ const key = (0, import_crypto2.scrypt)({
5116
5068
  password: passwordBuffer,
5117
5069
  salt: saltBuffer,
5118
5070
  n,
@@ -5121,15 +5073,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5121
5073
  dklen
5122
5074
  });
5123
5075
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5124
- const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5125
- const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5076
+ const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5077
+ const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5126
5078
  if (mac !== macHash) {
5127
5079
  throw new import_errors17.FuelError(
5128
5080
  import_errors17.ErrorCode.INVALID_PASSWORD,
5129
5081
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5130
5082
  );
5131
5083
  }
5132
- const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5084
+ const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5133
5085
  const privateKey = (0, import_utils30.hexlify)(buffer);
5134
5086
  return privateKey;
5135
5087
  }
@@ -5254,7 +5206,7 @@ var import_utils35 = require("@fuel-ts/utils");
5254
5206
  var import_ethers3 = require("ethers");
5255
5207
 
5256
5208
  // src/mnemonic/mnemonic.ts
5257
- var import_crypto4 = require("@fuel-ts/crypto");
5209
+ var import_crypto3 = require("@fuel-ts/crypto");
5258
5210
  var import_errors19 = require("@fuel-ts/errors");
5259
5211
  var import_hasher5 = require("@fuel-ts/hasher");
5260
5212
  var import_utils33 = require("@fuel-ts/utils");
@@ -7609,7 +7561,7 @@ var Mnemonic = class {
7609
7561
  * @returns A randomly generated mnemonic
7610
7562
  */
7611
7563
  static generate(size = 32, extraEntropy = "") {
7612
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
7564
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7613
7565
  return Mnemonic.entropyToMnemonic(entropy);
7614
7566
  }
7615
7567
  };
@@ -7980,10 +7932,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7980
7932
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7981
7933
 
7982
7934
  // src/test-utils/seedTestWallet.ts
7983
- var import_crypto5 = require("@fuel-ts/crypto");
7935
+ var import_crypto4 = require("@fuel-ts/crypto");
7984
7936
  var seedTestWallet = async (wallet, quantities) => {
7985
7937
  const genesisWallet = new WalletUnlocked(
7986
- process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
7938
+ process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
7987
7939
  wallet.provider
7988
7940
  );
7989
7941
  const resources = await genesisWallet.getResourcesToSpend(quantities);
@@ -8012,7 +7964,7 @@ var import_math21 = require("@fuel-ts/math");
8012
7964
  var import_utils36 = require("@fuel-ts/utils");
8013
7965
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8014
7966
  var import_child_process = require("child_process");
8015
- var import_crypto6 = require("crypto");
7967
+ var import_crypto5 = require("crypto");
8016
7968
  var import_fs = require("fs");
8017
7969
  var import_os = __toESM(require("os"));
8018
7970
  var import_path = __toESM(require("path"));
@@ -8084,7 +8036,7 @@ var launchNode = async ({
8084
8036
  })).toString();
8085
8037
  let chainConfigPathToUse;
8086
8038
  const prefix = basePath || import_os.default.tmpdir();
8087
- const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
8039
+ const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
8088
8040
  const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
8089
8041
  if (chainConfigPath) {
8090
8042
  chainConfigPathToUse = chainConfigPath;