@fuel-ts/account 0.0.0-rc-2040-20240411104812 → 0.0.0-rc-2034-20240411105200

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