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

package/dist/index.mjs CHANGED
@@ -1023,7 +1023,6 @@ var MemoryCache = class {
1023
1023
  };
1024
1024
 
1025
1025
  // src/providers/transaction-request/input.ts
1026
- import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
1027
1026
  import { ZeroBytes32 } from "@fuel-ts/address/configs";
1028
1027
  import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
1029
1028
  import { bn as bn2, toNumber } from "@fuel-ts/math";
@@ -1037,8 +1036,8 @@ var inputify = (value) => {
1037
1036
  const predicateData = arrayify(value.predicateData ?? "0x");
1038
1037
  return {
1039
1038
  type: InputType.Coin,
1040
- txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
1041
- outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
1039
+ txID: hexlify3(arrayify(value.id).slice(0, 32)),
1040
+ outputIndex: arrayify(value.id)[32],
1042
1041
  owner: hexlify3(value.owner),
1043
1042
  amount: bn2(value.amount),
1044
1043
  assetId: hexlify3(value.assetId),
@@ -1156,10 +1155,8 @@ var outputify = (value) => {
1156
1155
  };
1157
1156
 
1158
1157
  // src/providers/transaction-request/transaction-request.ts
1159
- import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1160
1158
  import { Address, addressify } from "@fuel-ts/address";
1161
1159
  import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1162
- import { randomBytes } from "@fuel-ts/crypto";
1163
1160
  import { bn as bn7 } from "@fuel-ts/math";
1164
1161
  import {
1165
1162
  PolicyType,
@@ -2113,6 +2110,12 @@ var BaseTransactionRequest = class {
2113
2110
  * @param quantities - CoinQuantity Array.
2114
2111
  */
2115
2112
  fundWithFakeUtxos(quantities, resourcesOwner) {
2113
+ let idCounter = 0;
2114
+ const generateId = () => {
2115
+ const counterString = String(idCounter++);
2116
+ const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
2117
+ return id;
2118
+ };
2116
2119
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2117
2120
  if ("assetId" in input) {
2118
2121
  return input.assetId === assetId;
@@ -2122,12 +2125,12 @@ var BaseTransactionRequest = class {
2122
2125
  const updateAssetInput = (assetId, quantity) => {
2123
2126
  const assetInput = findAssetInput(assetId);
2124
2127
  if (assetInput && "assetId" in assetInput) {
2125
- assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2128
+ assetInput.id = generateId();
2126
2129
  assetInput.amount = quantity;
2127
2130
  } else {
2128
2131
  this.addResources([
2129
2132
  {
2130
- id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2133
+ id: generateId(),
2131
2134
  amount: quantity,
2132
2135
  assetId,
2133
2136
  owner: resourcesOwner || Address.fromRandom(),
@@ -4004,36 +4007,6 @@ var _Provider = class {
4004
4007
  missingContractIds
4005
4008
  };
4006
4009
  }
4007
- /**
4008
- * Estimates the transaction gas and fee based on the provided transaction request.
4009
- * @param transactionRequest - The transaction request object.
4010
- * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4011
- */
4012
- estimateTxGasAndFee(params) {
4013
- const { transactionRequest } = params;
4014
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4015
- const chainInfo = this.getChain();
4016
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4017
- transactionRequest.gasPrice = gasPrice;
4018
- const minGas = transactionRequest.calculateMinGas(chainInfo);
4019
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4020
- if (transactionRequest.type === TransactionType8.Script) {
4021
- if (transactionRequest.gasLimit.eq(0)) {
4022
- transactionRequest.gasLimit = minGas;
4023
- transactionRequest.gasLimit = maxGasPerTx.sub(
4024
- transactionRequest.calculateMaxGas(chainInfo, minGas)
4025
- );
4026
- }
4027
- }
4028
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4029
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4030
- return {
4031
- minGas,
4032
- minFee,
4033
- maxGas,
4034
- maxFee
4035
- };
4036
- }
4037
4010
  /**
4038
4011
  * Executes a signed transaction without applying the states changes
4039
4012
  * on the chain.
@@ -4081,16 +4054,17 @@ var _Provider = class {
4081
4054
  signatureCallback
4082
4055
  } = {}) {
4083
4056
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
4084
- const { minGasPrice } = this.getGasConfig();
4085
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4057
+ const chainInfo = this.getChain();
4058
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4059
+ const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
4086
4060
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4087
4061
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4088
4062
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4089
4063
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4090
- if (isScriptTransaction) {
4091
- txRequestClone.gasLimit = bn15(0);
4092
- }
4093
4064
  if (estimatePredicates) {
4065
+ if (isScriptTransaction) {
4066
+ txRequestClone.gasLimit = bn15(0);
4067
+ }
4094
4068
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4095
4069
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
4096
4070
  }
@@ -4099,34 +4073,36 @@ var _Provider = class {
4099
4073
  if (signatureCallback && isScriptTransaction) {
4100
4074
  await signatureCallback(txRequestClone);
4101
4075
  }
4102
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4103
- transactionRequest: txRequestClone
4104
- });
4076
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
4077
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4105
4078
  let receipts = [];
4106
4079
  let missingContractIds = [];
4107
4080
  let outputVariables = 0;
4108
- let gasUsed = bn15(0);
4109
4081
  if (isScriptTransaction && estimateTxDependencies) {
4110
4082
  txRequestClone.gasPrice = bn15(0);
4083
+ txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4111
4084
  const result = await this.estimateTxDependencies(txRequestClone);
4112
4085
  receipts = result.receipts;
4113
4086
  outputVariables = result.outputVariables;
4114
4087
  missingContractIds = result.missingContractIds;
4115
- gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4116
- txRequestClone.gasLimit = gasUsed;
4117
- txRequestClone.gasPrice = setGasPrice;
4118
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4119
- transactionRequest: txRequestClone
4120
- }));
4121
4088
  }
4089
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4090
+ const usedFee = calculatePriceWithFactor(
4091
+ gasUsed,
4092
+ gasPrice,
4093
+ gasPriceFactor
4094
+ ).normalizeZeroToOne();
4095
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4096
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4122
4097
  return {
4123
4098
  requiredQuantities: allQuantities,
4124
4099
  receipts,
4125
4100
  gasUsed,
4126
4101
  minGasPrice,
4127
- gasPrice: setGasPrice,
4102
+ gasPrice,
4128
4103
  minGas,
4129
4104
  maxGas,
4105
+ usedFee,
4130
4106
  minFee,
4131
4107
  maxFee,
4132
4108
  estimatedInputs: txRequestClone.inputs,
@@ -5220,7 +5196,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
5220
5196
 
5221
5197
  // src/signer/signer.ts
5222
5198
  import { Address as Address4 } from "@fuel-ts/address";
5223
- import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
5199
+ import { randomBytes } from "@fuel-ts/crypto";
5224
5200
  import { hash } from "@fuel-ts/hasher";
5225
5201
  import { toBytes } from "@fuel-ts/math";
5226
5202
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -5313,7 +5289,7 @@ var Signer = class {
5313
5289
  * @returns random 32-byte hashed
5314
5290
  */
5315
5291
  static generatePrivateKey(entropy) {
5316
- return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
5292
+ return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5317
5293
  }
5318
5294
  /**
5319
5295
  * Extended publicKey from a compact publicKey
@@ -5332,7 +5308,7 @@ import { Address as Address5 } from "@fuel-ts/address";
5332
5308
  import {
5333
5309
  bufferFromString,
5334
5310
  keccak256,
5335
- randomBytes as randomBytes3,
5311
+ randomBytes as randomBytes2,
5336
5312
  scrypt,
5337
5313
  stringFromBuffer,
5338
5314
  decryptJsonWalletData,
@@ -5355,7 +5331,7 @@ var removeHexPrefix = (hexString) => {
5355
5331
  async function encryptKeystoreWallet(privateKey, address, password) {
5356
5332
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
5357
5333
  const ownerAddress = Address5.fromAddressOrString(address);
5358
- const salt = randomBytes3(DEFAULT_KEY_SIZE);
5334
+ const salt = randomBytes2(DEFAULT_KEY_SIZE);
5359
5335
  const key = scrypt({
5360
5336
  password: bufferFromString(password),
5361
5337
  salt,
@@ -5364,7 +5340,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5364
5340
  r: DEFAULT_KDF_PARAMS_R,
5365
5341
  p: DEFAULT_KDF_PARAMS_P
5366
5342
  });
5367
- const iv = randomBytes3(DEFAULT_IV_SIZE);
5343
+ const iv = randomBytes2(DEFAULT_IV_SIZE);
5368
5344
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
5369
5345
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5370
5346
  const macHashUint8Array = keccak256(data);
@@ -5546,7 +5522,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
5546
5522
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5547
5523
 
5548
5524
  // src/mnemonic/mnemonic.ts
5549
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5525
+ import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5550
5526
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5551
5527
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5552
5528
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
@@ -7907,7 +7883,7 @@ var Mnemonic = class {
7907
7883
  * @returns A randomly generated mnemonic
7908
7884
  */
7909
7885
  static generate(size = 32, extraEntropy = "") {
7910
- const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7886
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7911
7887
  return Mnemonic.entropyToMnemonic(entropy);
7912
7888
  }
7913
7889
  };