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