@fuel-ts/account 0.0.0-rc-2037-20240411020051 → 0.0.0-rc-2034-20240411020813
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 +89 -56
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +128 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -59
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +1 -9
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +0 -1
- package/dist/providers/message.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 +20 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils.global.js +91 -43
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +125 -75
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +96 -46
- 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,
|
@@ -1825,8 +1828,8 @@ var BaseTransactionRequest = class {
|
|
1825
1828
|
* @param predicate - Predicate bytes.
|
1826
1829
|
* @param predicateData - Predicate data bytes.
|
1827
1830
|
*/
|
1828
|
-
addCoinInput(coin) {
|
1829
|
-
const { assetId, owner, amount
|
1831
|
+
addCoinInput(coin, predicate) {
|
1832
|
+
const { assetId, owner, amount } = coin;
|
1830
1833
|
let witnessIndex;
|
1831
1834
|
if (predicate) {
|
1832
1835
|
witnessIndex = 0;
|
@@ -1837,14 +1840,14 @@ var BaseTransactionRequest = class {
|
|
1837
1840
|
}
|
1838
1841
|
}
|
1839
1842
|
const input = {
|
1840
|
-
|
1843
|
+
...coin,
|
1841
1844
|
type: InputType2.Coin,
|
1842
1845
|
owner: owner.toB256(),
|
1843
1846
|
amount,
|
1844
1847
|
assetId,
|
1845
1848
|
txPointer: "0x00000000000000000000000000000000",
|
1846
1849
|
witnessIndex,
|
1847
|
-
predicate
|
1850
|
+
predicate: predicate?.bytes
|
1848
1851
|
};
|
1849
1852
|
this.pushInput(input);
|
1850
1853
|
this.addChangeOutput(owner, assetId);
|
@@ -1857,8 +1860,8 @@ var BaseTransactionRequest = class {
|
|
1857
1860
|
* @param predicate - Predicate bytes.
|
1858
1861
|
* @param predicateData - Predicate data bytes.
|
1859
1862
|
*/
|
1860
|
-
addMessageInput(message) {
|
1861
|
-
const { recipient, sender, amount
|
1863
|
+
addMessageInput(message, predicate) {
|
1864
|
+
const { recipient, sender, amount } = message;
|
1862
1865
|
const assetId = BaseAssetId2;
|
1863
1866
|
let witnessIndex;
|
1864
1867
|
if (predicate) {
|
@@ -1870,13 +1873,13 @@ var BaseTransactionRequest = class {
|
|
1870
1873
|
}
|
1871
1874
|
}
|
1872
1875
|
const input = {
|
1873
|
-
|
1876
|
+
...message,
|
1874
1877
|
type: InputType2.Message,
|
1875
1878
|
sender: sender.toB256(),
|
1876
1879
|
recipient: recipient.toB256(),
|
1877
1880
|
amount,
|
1878
1881
|
witnessIndex,
|
1879
|
-
predicate
|
1882
|
+
predicate: predicate?.bytes
|
1880
1883
|
};
|
1881
1884
|
this.pushInput(input);
|
1882
1885
|
this.addChangeOutput(recipient, assetId);
|
@@ -1907,6 +1910,32 @@ var BaseTransactionRequest = class {
|
|
1907
1910
|
resources.forEach((resource) => this.addResource(resource));
|
1908
1911
|
return this;
|
1909
1912
|
}
|
1913
|
+
/**
|
1914
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1915
|
+
* outputs from the related assetIds.
|
1916
|
+
*
|
1917
|
+
* @param resources - The resources to add.
|
1918
|
+
* @returns This transaction.
|
1919
|
+
*/
|
1920
|
+
addPredicateResource(resource, predicate) {
|
1921
|
+
if (isCoin(resource)) {
|
1922
|
+
this.addCoinInput(resource, predicate);
|
1923
|
+
} else {
|
1924
|
+
this.addMessageInput(resource, predicate);
|
1925
|
+
}
|
1926
|
+
return this;
|
1927
|
+
}
|
1928
|
+
/**
|
1929
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1930
|
+
* from the related assetIds.
|
1931
|
+
*
|
1932
|
+
* @param resources - The resources to add.
|
1933
|
+
* @returns This transaction.
|
1934
|
+
*/
|
1935
|
+
addPredicateResources(resources, predicate) {
|
1936
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1937
|
+
return this;
|
1938
|
+
}
|
1910
1939
|
/**
|
1911
1940
|
* Adds a coin output to the transaction.
|
1912
1941
|
*
|
@@ -2005,12 +2034,6 @@ var BaseTransactionRequest = class {
|
|
2005
2034
|
* @param quantities - CoinQuantity Array.
|
2006
2035
|
*/
|
2007
2036
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2008
|
-
let idCounter = 0;
|
2009
|
-
const generateId = () => {
|
2010
|
-
const counterString = String(idCounter++);
|
2011
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2012
|
-
return id;
|
2013
|
-
};
|
2014
2037
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2015
2038
|
if ("assetId" in input) {
|
2016
2039
|
return input.assetId === assetId;
|
@@ -2020,12 +2043,12 @@ var BaseTransactionRequest = class {
|
|
2020
2043
|
const updateAssetInput = (assetId, quantity) => {
|
2021
2044
|
const assetInput = findAssetInput(assetId);
|
2022
2045
|
if (assetInput && "assetId" in assetInput) {
|
2023
|
-
assetInput.id =
|
2046
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2024
2047
|
assetInput.amount = quantity;
|
2025
2048
|
} else {
|
2026
2049
|
this.addResources([
|
2027
2050
|
{
|
2028
|
-
id:
|
2051
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2029
2052
|
amount: quantity,
|
2030
2053
|
assetId,
|
2031
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -3855,6 +3878,36 @@ var _Provider = class {
|
|
3855
3878
|
missingContractIds
|
3856
3879
|
};
|
3857
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
|
+
}
|
3858
3911
|
/**
|
3859
3912
|
* Executes a signed transaction without applying the states changes
|
3860
3913
|
* on the chain.
|
@@ -3902,17 +3955,16 @@ var _Provider = class {
|
|
3902
3955
|
signatureCallback
|
3903
3956
|
} = {}) {
|
3904
3957
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3905
|
-
const
|
3906
|
-
const
|
3907
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3958
|
+
const { minGasPrice } = this.getGasConfig();
|
3959
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3908
3960
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3909
3961
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3910
3962
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3911
3963
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3964
|
+
if (isScriptTransaction) {
|
3965
|
+
txRequestClone.gasLimit = bn15(0);
|
3966
|
+
}
|
3912
3967
|
if (estimatePredicates) {
|
3913
|
-
if (isScriptTransaction) {
|
3914
|
-
txRequestClone.gasLimit = bn15(0);
|
3915
|
-
}
|
3916
3968
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3917
3969
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3918
3970
|
}
|
@@ -3921,36 +3973,34 @@ var _Provider = class {
|
|
3921
3973
|
if (signatureCallback && isScriptTransaction) {
|
3922
3974
|
await signatureCallback(txRequestClone);
|
3923
3975
|
}
|
3924
|
-
|
3925
|
-
|
3976
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3977
|
+
transactionRequest: txRequestClone
|
3978
|
+
});
|
3926
3979
|
let receipts = [];
|
3927
3980
|
let missingContractIds = [];
|
3928
3981
|
let outputVariables = 0;
|
3982
|
+
let gasUsed = bn15(0);
|
3929
3983
|
if (isScriptTransaction && estimateTxDependencies) {
|
3930
3984
|
txRequestClone.gasPrice = bn15(0);
|
3931
|
-
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3932
3985
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3933
3986
|
receipts = result.receipts;
|
3934
3987
|
outputVariables = result.outputVariables;
|
3935
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
|
+
}));
|
3936
3995
|
}
|
3937
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3938
|
-
const usedFee = calculatePriceWithFactor(
|
3939
|
-
gasUsed,
|
3940
|
-
gasPrice,
|
3941
|
-
gasPriceFactor
|
3942
|
-
).normalizeZeroToOne();
|
3943
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3944
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3945
3996
|
return {
|
3946
3997
|
requiredQuantities: allQuantities,
|
3947
3998
|
receipts,
|
3948
3999
|
gasUsed,
|
3949
4000
|
minGasPrice,
|
3950
|
-
gasPrice,
|
4001
|
+
gasPrice: setGasPrice,
|
3951
4002
|
minGas,
|
3952
4003
|
maxGas,
|
3953
|
-
usedFee,
|
3954
4004
|
minFee,
|
3955
4005
|
maxFee,
|
3956
4006
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4874,7 +4924,7 @@ var Account = class extends AbstractAccount {
|
|
4874
4924
|
|
4875
4925
|
// src/signer/signer.ts
|
4876
4926
|
import { Address as Address4 } from "@fuel-ts/address";
|
4877
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
4927
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4878
4928
|
import { hash } from "@fuel-ts/hasher";
|
4879
4929
|
import { toBytes } from "@fuel-ts/math";
|
4880
4930
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -4967,7 +5017,7 @@ var Signer = class {
|
|
4967
5017
|
* @returns random 32-byte hashed
|
4968
5018
|
*/
|
4969
5019
|
static generatePrivateKey(entropy) {
|
4970
|
-
return entropy ? hash(concat3([
|
5020
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
4971
5021
|
}
|
4972
5022
|
/**
|
4973
5023
|
* Extended publicKey from a compact publicKey
|
@@ -4986,7 +5036,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
4986
5036
|
import {
|
4987
5037
|
bufferFromString,
|
4988
5038
|
keccak256,
|
4989
|
-
randomBytes as
|
5039
|
+
randomBytes as randomBytes3,
|
4990
5040
|
scrypt,
|
4991
5041
|
stringFromBuffer,
|
4992
5042
|
decryptJsonWalletData,
|
@@ -5009,7 +5059,7 @@ var removeHexPrefix = (hexString) => {
|
|
5009
5059
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5010
5060
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5011
5061
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5012
|
-
const salt =
|
5062
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5013
5063
|
const key = scrypt({
|
5014
5064
|
password: bufferFromString(password),
|
5015
5065
|
salt,
|
@@ -5018,7 +5068,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5018
5068
|
r: DEFAULT_KDF_PARAMS_R,
|
5019
5069
|
p: DEFAULT_KDF_PARAMS_P
|
5020
5070
|
});
|
5021
|
-
const iv =
|
5071
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5022
5072
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5023
5073
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5024
5074
|
const macHashUint8Array = keccak256(data);
|
@@ -5200,7 +5250,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5200
5250
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5201
5251
|
|
5202
5252
|
// src/mnemonic/mnemonic.ts
|
5203
|
-
import { randomBytes as
|
5253
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5204
5254
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5205
5255
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5206
5256
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7555,7 +7605,7 @@ var Mnemonic = class {
|
|
7555
7605
|
* @returns A randomly generated mnemonic
|
7556
7606
|
*/
|
7557
7607
|
static generate(size = 32, extraEntropy = "") {
|
7558
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7608
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7559
7609
|
return Mnemonic.entropyToMnemonic(entropy);
|
7560
7610
|
}
|
7561
7611
|
};
|
@@ -7926,10 +7976,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7926
7976
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7927
7977
|
|
7928
7978
|
// src/test-utils/seedTestWallet.ts
|
7929
|
-
import { randomBytes as
|
7979
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7930
7980
|
var seedTestWallet = async (wallet, quantities) => {
|
7931
7981
|
const genesisWallet = new WalletUnlocked(
|
7932
|
-
process.env.GENESIS_SECRET ||
|
7982
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7933
7983
|
wallet.provider
|
7934
7984
|
);
|
7935
7985
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|