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