@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.js
CHANGED
@@ -1051,6 +1051,7 @@ var MemoryCache = class {
|
|
1051
1051
|
};
|
1052
1052
|
|
1053
1053
|
// src/providers/transaction-request/input.ts
|
1054
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1054
1055
|
var import_configs2 = require("@fuel-ts/address/configs");
|
1055
1056
|
var import_errors3 = require("@fuel-ts/errors");
|
1056
1057
|
var import_math2 = require("@fuel-ts/math");
|
@@ -1064,8 +1065,8 @@ var inputify = (value) => {
|
|
1064
1065
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1065
1066
|
return {
|
1066
1067
|
type: import_transactions.InputType.Coin,
|
1067
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1068
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1068
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
|
1069
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
|
1069
1070
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1070
1071
|
amount: (0, import_math2.bn)(value.amount),
|
1071
1072
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1183,8 +1184,10 @@ var outputify = (value) => {
|
|
1183
1184
|
};
|
1184
1185
|
|
1185
1186
|
// src/providers/transaction-request/transaction-request.ts
|
1187
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1186
1188
|
var import_address = require("@fuel-ts/address");
|
1187
1189
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1190
|
+
var import_crypto = require("@fuel-ts/crypto");
|
1188
1191
|
var import_math7 = require("@fuel-ts/math");
|
1189
1192
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1190
1193
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1839,8 +1842,8 @@ var BaseTransactionRequest = class {
|
|
1839
1842
|
* @param predicate - Predicate bytes.
|
1840
1843
|
* @param predicateData - Predicate data bytes.
|
1841
1844
|
*/
|
1842
|
-
addCoinInput(coin) {
|
1843
|
-
const { assetId, owner, amount
|
1845
|
+
addCoinInput(coin, predicate) {
|
1846
|
+
const { assetId, owner, amount } = coin;
|
1844
1847
|
let witnessIndex;
|
1845
1848
|
if (predicate) {
|
1846
1849
|
witnessIndex = 0;
|
@@ -1851,14 +1854,14 @@ var BaseTransactionRequest = class {
|
|
1851
1854
|
}
|
1852
1855
|
}
|
1853
1856
|
const input = {
|
1854
|
-
|
1857
|
+
...coin,
|
1855
1858
|
type: import_transactions6.InputType.Coin,
|
1856
1859
|
owner: owner.toB256(),
|
1857
1860
|
amount,
|
1858
1861
|
assetId,
|
1859
1862
|
txPointer: "0x00000000000000000000000000000000",
|
1860
1863
|
witnessIndex,
|
1861
|
-
predicate
|
1864
|
+
predicate: predicate?.bytes
|
1862
1865
|
};
|
1863
1866
|
this.pushInput(input);
|
1864
1867
|
this.addChangeOutput(owner, assetId);
|
@@ -1871,8 +1874,8 @@ var BaseTransactionRequest = class {
|
|
1871
1874
|
* @param predicate - Predicate bytes.
|
1872
1875
|
* @param predicateData - Predicate data bytes.
|
1873
1876
|
*/
|
1874
|
-
addMessageInput(message) {
|
1875
|
-
const { recipient, sender, amount
|
1877
|
+
addMessageInput(message, predicate) {
|
1878
|
+
const { recipient, sender, amount } = message;
|
1876
1879
|
const assetId = import_configs7.BaseAssetId;
|
1877
1880
|
let witnessIndex;
|
1878
1881
|
if (predicate) {
|
@@ -1884,13 +1887,13 @@ var BaseTransactionRequest = class {
|
|
1884
1887
|
}
|
1885
1888
|
}
|
1886
1889
|
const input = {
|
1887
|
-
|
1890
|
+
...message,
|
1888
1891
|
type: import_transactions6.InputType.Message,
|
1889
1892
|
sender: sender.toB256(),
|
1890
1893
|
recipient: recipient.toB256(),
|
1891
1894
|
amount,
|
1892
1895
|
witnessIndex,
|
1893
|
-
predicate
|
1896
|
+
predicate: predicate?.bytes
|
1894
1897
|
};
|
1895
1898
|
this.pushInput(input);
|
1896
1899
|
this.addChangeOutput(recipient, assetId);
|
@@ -1921,6 +1924,32 @@ var BaseTransactionRequest = class {
|
|
1921
1924
|
resources.forEach((resource) => this.addResource(resource));
|
1922
1925
|
return this;
|
1923
1926
|
}
|
1927
|
+
/**
|
1928
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1929
|
+
* outputs from the related assetIds.
|
1930
|
+
*
|
1931
|
+
* @param resources - The resources to add.
|
1932
|
+
* @returns This transaction.
|
1933
|
+
*/
|
1934
|
+
addPredicateResource(resource, predicate) {
|
1935
|
+
if (isCoin(resource)) {
|
1936
|
+
this.addCoinInput(resource, predicate);
|
1937
|
+
} else {
|
1938
|
+
this.addMessageInput(resource, predicate);
|
1939
|
+
}
|
1940
|
+
return this;
|
1941
|
+
}
|
1942
|
+
/**
|
1943
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1944
|
+
* from the related assetIds.
|
1945
|
+
*
|
1946
|
+
* @param resources - The resources to add.
|
1947
|
+
* @returns This transaction.
|
1948
|
+
*/
|
1949
|
+
addPredicateResources(resources, predicate) {
|
1950
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1951
|
+
return this;
|
1952
|
+
}
|
1924
1953
|
/**
|
1925
1954
|
* Adds a coin output to the transaction.
|
1926
1955
|
*
|
@@ -2019,12 +2048,6 @@ var BaseTransactionRequest = class {
|
|
2019
2048
|
* @param quantities - CoinQuantity Array.
|
2020
2049
|
*/
|
2021
2050
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2022
|
-
let idCounter = 0;
|
2023
|
-
const generateId = () => {
|
2024
|
-
const counterString = String(idCounter++);
|
2025
|
-
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2026
|
-
return id;
|
2027
|
-
};
|
2028
2051
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2029
2052
|
if ("assetId" in input) {
|
2030
2053
|
return input.assetId === assetId;
|
@@ -2034,12 +2057,12 @@ var BaseTransactionRequest = class {
|
|
2034
2057
|
const updateAssetInput = (assetId, quantity) => {
|
2035
2058
|
const assetInput = findAssetInput(assetId);
|
2036
2059
|
if (assetInput && "assetId" in assetInput) {
|
2037
|
-
assetInput.id =
|
2060
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2038
2061
|
assetInput.amount = quantity;
|
2039
2062
|
} else {
|
2040
2063
|
this.addResources([
|
2041
2064
|
{
|
2042
|
-
id:
|
2065
|
+
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2043
2066
|
amount: quantity,
|
2044
2067
|
assetId,
|
2045
2068
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2294,7 +2317,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2294
2317
|
};
|
2295
2318
|
|
2296
2319
|
// src/providers/transaction-request/script-transaction-request.ts
|
2297
|
-
var
|
2320
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2298
2321
|
var import_address2 = require("@fuel-ts/address");
|
2299
2322
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2300
2323
|
var import_math10 = require("@fuel-ts/math");
|
@@ -2486,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2486
2509
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2487
2510
|
*/
|
2488
2511
|
setData(abi, args) {
|
2489
|
-
const abiInterface = new
|
2512
|
+
const abiInterface = new import_abi_coder3.Interface(abi);
|
2490
2513
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2491
2514
|
return this;
|
2492
2515
|
}
|
@@ -2608,17 +2631,17 @@ var import_math13 = require("@fuel-ts/math");
|
|
2608
2631
|
var import_transactions14 = require("@fuel-ts/transactions");
|
2609
2632
|
|
2610
2633
|
// src/providers/transaction-summary/call.ts
|
2611
|
-
var
|
2634
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
2612
2635
|
var import_math12 = require("@fuel-ts/math");
|
2613
2636
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2614
|
-
const abiInterface = new
|
2637
|
+
const abiInterface = new import_abi_coder4.Interface(abi);
|
2615
2638
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2616
2639
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2617
2640
|
const inputs = functionFragment.jsonFn.inputs;
|
2618
2641
|
let encodedArgs;
|
2619
2642
|
if (functionFragment.isInputDataPointer) {
|
2620
2643
|
if (rawPayload) {
|
2621
|
-
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0,
|
2644
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2622
2645
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2623
2646
|
}
|
2624
2647
|
} else {
|
@@ -3221,13 +3244,13 @@ function assembleTransactionSummary(params) {
|
|
3221
3244
|
}
|
3222
3245
|
|
3223
3246
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3224
|
-
var
|
3247
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3225
3248
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3226
3249
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3227
3250
|
return receipts.reduce((logs, receipt) => {
|
3228
3251
|
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3229
|
-
const interfaceToUse = new
|
3230
|
-
const data = receipt.type === import_transactions16.ReceiptType.Log ? new
|
3252
|
+
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3253
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3231
3254
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3232
3255
|
logs.push(decodedLog);
|
3233
3256
|
}
|
@@ -3869,6 +3892,36 @@ var _Provider = class {
|
|
3869
3892
|
missingContractIds
|
3870
3893
|
};
|
3871
3894
|
}
|
3895
|
+
/**
|
3896
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3897
|
+
* @param transactionRequest - The transaction request object.
|
3898
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3899
|
+
*/
|
3900
|
+
estimateTxGasAndFee(params) {
|
3901
|
+
const { transactionRequest } = params;
|
3902
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3903
|
+
const chainInfo = this.getChain();
|
3904
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3905
|
+
transactionRequest.gasPrice = gasPrice;
|
3906
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3907
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3908
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3909
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3910
|
+
transactionRequest.gasLimit = minGas;
|
3911
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3912
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3913
|
+
);
|
3914
|
+
}
|
3915
|
+
}
|
3916
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3917
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3918
|
+
return {
|
3919
|
+
minGas,
|
3920
|
+
minFee,
|
3921
|
+
maxGas,
|
3922
|
+
maxFee
|
3923
|
+
};
|
3924
|
+
}
|
3872
3925
|
/**
|
3873
3926
|
* Executes a signed transaction without applying the states changes
|
3874
3927
|
* on the chain.
|
@@ -3916,17 +3969,16 @@ var _Provider = class {
|
|
3916
3969
|
signatureCallback
|
3917
3970
|
} = {}) {
|
3918
3971
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3919
|
-
const
|
3920
|
-
const
|
3921
|
-
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3972
|
+
const { minGasPrice } = this.getGasConfig();
|
3973
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3922
3974
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3923
3975
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3924
3976
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3925
3977
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3978
|
+
if (isScriptTransaction) {
|
3979
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3980
|
+
}
|
3926
3981
|
if (estimatePredicates) {
|
3927
|
-
if (isScriptTransaction) {
|
3928
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3929
|
-
}
|
3930
3982
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3931
3983
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3932
3984
|
}
|
@@ -3935,36 +3987,34 @@ var _Provider = class {
|
|
3935
3987
|
if (signatureCallback && isScriptTransaction) {
|
3936
3988
|
await signatureCallback(txRequestClone);
|
3937
3989
|
}
|
3938
|
-
|
3939
|
-
|
3990
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3991
|
+
transactionRequest: txRequestClone
|
3992
|
+
});
|
3940
3993
|
let receipts = [];
|
3941
3994
|
let missingContractIds = [];
|
3942
3995
|
let outputVariables = 0;
|
3996
|
+
let gasUsed = (0, import_math15.bn)(0);
|
3943
3997
|
if (isScriptTransaction && estimateTxDependencies) {
|
3944
3998
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3945
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3946
3999
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3947
4000
|
receipts = result.receipts;
|
3948
4001
|
outputVariables = result.outputVariables;
|
3949
4002
|
missingContractIds = result.missingContractIds;
|
4003
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4004
|
+
txRequestClone.gasLimit = gasUsed;
|
4005
|
+
txRequestClone.gasPrice = setGasPrice;
|
4006
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4007
|
+
transactionRequest: txRequestClone
|
4008
|
+
}));
|
3950
4009
|
}
|
3951
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3952
|
-
const usedFee = calculatePriceWithFactor(
|
3953
|
-
gasUsed,
|
3954
|
-
gasPrice,
|
3955
|
-
gasPriceFactor
|
3956
|
-
).normalizeZeroToOne();
|
3957
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3958
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3959
4010
|
return {
|
3960
4011
|
requiredQuantities: allQuantities,
|
3961
4012
|
receipts,
|
3962
4013
|
gasUsed,
|
3963
4014
|
minGasPrice,
|
3964
|
-
gasPrice,
|
4015
|
+
gasPrice: setGasPrice,
|
3965
4016
|
minGas,
|
3966
4017
|
maxGas,
|
3967
|
-
usedFee,
|
3968
4018
|
minFee,
|
3969
4019
|
maxFee,
|
3970
4020
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4431,13 +4481,13 @@ var assets = [
|
|
4431
4481
|
];
|
4432
4482
|
|
4433
4483
|
// src/utils/formatTransferToContractScriptData.ts
|
4434
|
-
var
|
4484
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4435
4485
|
var import_math17 = require("@fuel-ts/math");
|
4436
4486
|
var import_utils27 = require("@fuel-ts/utils");
|
4437
4487
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4438
4488
|
var formatTransferToContractScriptData = (params) => {
|
4439
4489
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4440
|
-
const numberCoder = new
|
4490
|
+
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4441
4491
|
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4442
4492
|
const scriptData = Uint8Array.from([
|
4443
4493
|
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
@@ -4888,7 +4938,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4888
4938
|
|
4889
4939
|
// src/signer/signer.ts
|
4890
4940
|
var import_address5 = require("@fuel-ts/address");
|
4891
|
-
var
|
4941
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
4892
4942
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4893
4943
|
var import_math19 = require("@fuel-ts/math");
|
4894
4944
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -4981,7 +5031,7 @@ var Signer = class {
|
|
4981
5031
|
* @returns random 32-byte hashed
|
4982
5032
|
*/
|
4983
5033
|
static generatePrivateKey(entropy) {
|
4984
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5034
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
4985
5035
|
}
|
4986
5036
|
/**
|
4987
5037
|
* Extended publicKey from a compact publicKey
|
@@ -4997,7 +5047,7 @@ var Signer = class {
|
|
4997
5047
|
|
4998
5048
|
// src/wallet/keystore-wallet.ts
|
4999
5049
|
var import_address6 = require("@fuel-ts/address");
|
5000
|
-
var
|
5050
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5001
5051
|
var import_errors17 = require("@fuel-ts/errors");
|
5002
5052
|
var import_utils30 = require("@fuel-ts/utils");
|
5003
5053
|
var import_uuid = require("uuid");
|
@@ -5013,22 +5063,22 @@ var removeHexPrefix = (hexString) => {
|
|
5013
5063
|
return hexString;
|
5014
5064
|
};
|
5015
5065
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5016
|
-
const privateKeyBuffer = (0,
|
5066
|
+
const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5017
5067
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5018
|
-
const salt = (0,
|
5019
|
-
const key = (0,
|
5020
|
-
password: (0,
|
5068
|
+
const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
|
5069
|
+
const key = (0, import_crypto3.scrypt)({
|
5070
|
+
password: (0, import_crypto3.bufferFromString)(password),
|
5021
5071
|
salt,
|
5022
5072
|
dklen: DEFAULT_KEY_SIZE,
|
5023
5073
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5024
5074
|
r: DEFAULT_KDF_PARAMS_R,
|
5025
5075
|
p: DEFAULT_KDF_PARAMS_P
|
5026
5076
|
});
|
5027
|
-
const iv = (0,
|
5028
|
-
const ciphertext = await (0,
|
5077
|
+
const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
|
5078
|
+
const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5029
5079
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5030
|
-
const macHashUint8Array = (0,
|
5031
|
-
const mac = (0,
|
5080
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5081
|
+
const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5032
5082
|
const keystore = {
|
5033
5083
|
id: (0, import_uuid.v4)(),
|
5034
5084
|
version: 3,
|
@@ -5036,15 +5086,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5036
5086
|
crypto: {
|
5037
5087
|
cipher: "aes-128-ctr",
|
5038
5088
|
mac,
|
5039
|
-
cipherparams: { iv: (0,
|
5040
|
-
ciphertext: (0,
|
5089
|
+
cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
|
5090
|
+
ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
|
5041
5091
|
kdf: "scrypt",
|
5042
5092
|
kdfparams: {
|
5043
5093
|
dklen: DEFAULT_KEY_SIZE,
|
5044
5094
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5045
5095
|
p: DEFAULT_KDF_PARAMS_P,
|
5046
5096
|
r: DEFAULT_KDF_PARAMS_R,
|
5047
|
-
salt: (0,
|
5097
|
+
salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
|
5048
5098
|
}
|
5049
5099
|
}
|
5050
5100
|
};
|
@@ -5060,11 +5110,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5060
5110
|
kdfparams: { dklen, n, r, p, salt }
|
5061
5111
|
}
|
5062
5112
|
} = keystoreWallet;
|
5063
|
-
const ciphertextBuffer = (0,
|
5064
|
-
const ivBuffer = (0,
|
5065
|
-
const saltBuffer = (0,
|
5066
|
-
const passwordBuffer = (0,
|
5067
|
-
const key = (0,
|
5113
|
+
const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
|
5114
|
+
const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
|
5115
|
+
const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
|
5116
|
+
const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
|
5117
|
+
const key = (0, import_crypto3.scrypt)({
|
5068
5118
|
password: passwordBuffer,
|
5069
5119
|
salt: saltBuffer,
|
5070
5120
|
n,
|
@@ -5073,15 +5123,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5073
5123
|
dklen
|
5074
5124
|
});
|
5075
5125
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5076
|
-
const macHashUint8Array = (0,
|
5077
|
-
const macHash = (0,
|
5126
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5127
|
+
const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5078
5128
|
if (mac !== macHash) {
|
5079
5129
|
throw new import_errors17.FuelError(
|
5080
5130
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5081
5131
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5082
5132
|
);
|
5083
5133
|
}
|
5084
|
-
const buffer = await (0,
|
5134
|
+
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5085
5135
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5086
5136
|
return privateKey;
|
5087
5137
|
}
|
@@ -5206,7 +5256,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5206
5256
|
var import_ethers3 = require("ethers");
|
5207
5257
|
|
5208
5258
|
// src/mnemonic/mnemonic.ts
|
5209
|
-
var
|
5259
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5210
5260
|
var import_errors19 = require("@fuel-ts/errors");
|
5211
5261
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5212
5262
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -7561,7 +7611,7 @@ var Mnemonic = class {
|
|
7561
7611
|
* @returns A randomly generated mnemonic
|
7562
7612
|
*/
|
7563
7613
|
static generate(size = 32, extraEntropy = "") {
|
7564
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
7614
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7565
7615
|
return Mnemonic.entropyToMnemonic(entropy);
|
7566
7616
|
}
|
7567
7617
|
};
|
@@ -7932,10 +7982,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7932
7982
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7933
7983
|
|
7934
7984
|
// src/test-utils/seedTestWallet.ts
|
7935
|
-
var
|
7985
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
7936
7986
|
var seedTestWallet = async (wallet, quantities) => {
|
7937
7987
|
const genesisWallet = new WalletUnlocked(
|
7938
|
-
process.env.GENESIS_SECRET || (0,
|
7988
|
+
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7939
7989
|
wallet.provider
|
7940
7990
|
);
|
7941
7991
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
@@ -7964,7 +8014,7 @@ var import_math21 = require("@fuel-ts/math");
|
|
7964
8014
|
var import_utils36 = require("@fuel-ts/utils");
|
7965
8015
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7966
8016
|
var import_child_process = require("child_process");
|
7967
|
-
var
|
8017
|
+
var import_crypto6 = require("crypto");
|
7968
8018
|
var import_fs = require("fs");
|
7969
8019
|
var import_os = __toESM(require("os"));
|
7970
8020
|
var import_path = __toESM(require("path"));
|
@@ -8036,7 +8086,7 @@ var launchNode = async ({
|
|
8036
8086
|
})).toString();
|
8037
8087
|
let chainConfigPathToUse;
|
8038
8088
|
const prefix = basePath || import_os.default.tmpdir();
|
8039
|
-
const suffix = basePath ? "" : (0,
|
8089
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8040
8090
|
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8041
8091
|
if (chainConfigPath) {
|
8042
8092
|
chainConfigPathToUse = chainConfigPath;
|