@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/index.js
CHANGED
@@ -1173,6 +1173,7 @@ var MemoryCache = class {
|
|
1173
1173
|
};
|
1174
1174
|
|
1175
1175
|
// src/providers/transaction-request/input.ts
|
1176
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1176
1177
|
var import_configs2 = require("@fuel-ts/address/configs");
|
1177
1178
|
var import_errors3 = require("@fuel-ts/errors");
|
1178
1179
|
var import_math2 = require("@fuel-ts/math");
|
@@ -1186,8 +1187,8 @@ var inputify = (value) => {
|
|
1186
1187
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1187
1188
|
return {
|
1188
1189
|
type: import_transactions.InputType.Coin,
|
1189
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1190
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1190
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
|
1191
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
|
1191
1192
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1192
1193
|
amount: (0, import_math2.bn)(value.amount),
|
1193
1194
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1305,8 +1306,10 @@ var outputify = (value) => {
|
|
1305
1306
|
};
|
1306
1307
|
|
1307
1308
|
// src/providers/transaction-request/transaction-request.ts
|
1309
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1308
1310
|
var import_address = require("@fuel-ts/address");
|
1309
1311
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1312
|
+
var import_crypto = require("@fuel-ts/crypto");
|
1310
1313
|
var import_math7 = require("@fuel-ts/math");
|
1311
1314
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1312
1315
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -2035,8 +2038,8 @@ var BaseTransactionRequest = class {
|
|
2035
2038
|
* @param predicate - Predicate bytes.
|
2036
2039
|
* @param predicateData - Predicate data bytes.
|
2037
2040
|
*/
|
2038
|
-
addCoinInput(coin) {
|
2039
|
-
const { assetId, owner, amount
|
2041
|
+
addCoinInput(coin, predicate) {
|
2042
|
+
const { assetId, owner, amount } = coin;
|
2040
2043
|
let witnessIndex;
|
2041
2044
|
if (predicate) {
|
2042
2045
|
witnessIndex = 0;
|
@@ -2047,14 +2050,14 @@ var BaseTransactionRequest = class {
|
|
2047
2050
|
}
|
2048
2051
|
}
|
2049
2052
|
const input = {
|
2050
|
-
|
2053
|
+
...coin,
|
2051
2054
|
type: import_transactions6.InputType.Coin,
|
2052
2055
|
owner: owner.toB256(),
|
2053
2056
|
amount,
|
2054
2057
|
assetId,
|
2055
2058
|
txPointer: "0x00000000000000000000000000000000",
|
2056
2059
|
witnessIndex,
|
2057
|
-
predicate
|
2060
|
+
predicate: predicate?.bytes
|
2058
2061
|
};
|
2059
2062
|
this.pushInput(input);
|
2060
2063
|
this.addChangeOutput(owner, assetId);
|
@@ -2067,8 +2070,8 @@ var BaseTransactionRequest = class {
|
|
2067
2070
|
* @param predicate - Predicate bytes.
|
2068
2071
|
* @param predicateData - Predicate data bytes.
|
2069
2072
|
*/
|
2070
|
-
addMessageInput(message) {
|
2071
|
-
const { recipient, sender, amount
|
2073
|
+
addMessageInput(message, predicate) {
|
2074
|
+
const { recipient, sender, amount } = message;
|
2072
2075
|
const assetId = import_configs7.BaseAssetId;
|
2073
2076
|
let witnessIndex;
|
2074
2077
|
if (predicate) {
|
@@ -2080,13 +2083,13 @@ var BaseTransactionRequest = class {
|
|
2080
2083
|
}
|
2081
2084
|
}
|
2082
2085
|
const input = {
|
2083
|
-
|
2086
|
+
...message,
|
2084
2087
|
type: import_transactions6.InputType.Message,
|
2085
2088
|
sender: sender.toB256(),
|
2086
2089
|
recipient: recipient.toB256(),
|
2087
2090
|
amount,
|
2088
2091
|
witnessIndex,
|
2089
|
-
predicate
|
2092
|
+
predicate: predicate?.bytes
|
2090
2093
|
};
|
2091
2094
|
this.pushInput(input);
|
2092
2095
|
this.addChangeOutput(recipient, assetId);
|
@@ -2117,6 +2120,32 @@ var BaseTransactionRequest = class {
|
|
2117
2120
|
resources.forEach((resource) => this.addResource(resource));
|
2118
2121
|
return this;
|
2119
2122
|
}
|
2123
|
+
/**
|
2124
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2125
|
+
* outputs from the related assetIds.
|
2126
|
+
*
|
2127
|
+
* @param resources - The resources to add.
|
2128
|
+
* @returns This transaction.
|
2129
|
+
*/
|
2130
|
+
addPredicateResource(resource, predicate) {
|
2131
|
+
if (isCoin(resource)) {
|
2132
|
+
this.addCoinInput(resource, predicate);
|
2133
|
+
} else {
|
2134
|
+
this.addMessageInput(resource, predicate);
|
2135
|
+
}
|
2136
|
+
return this;
|
2137
|
+
}
|
2138
|
+
/**
|
2139
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2140
|
+
* from the related assetIds.
|
2141
|
+
*
|
2142
|
+
* @param resources - The resources to add.
|
2143
|
+
* @returns This transaction.
|
2144
|
+
*/
|
2145
|
+
addPredicateResources(resources, predicate) {
|
2146
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2147
|
+
return this;
|
2148
|
+
}
|
2120
2149
|
/**
|
2121
2150
|
* Adds a coin output to the transaction.
|
2122
2151
|
*
|
@@ -2215,12 +2244,6 @@ var BaseTransactionRequest = class {
|
|
2215
2244
|
* @param quantities - CoinQuantity Array.
|
2216
2245
|
*/
|
2217
2246
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2218
|
-
let idCounter = 0;
|
2219
|
-
const generateId = () => {
|
2220
|
-
const counterString = String(idCounter++);
|
2221
|
-
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2222
|
-
return id;
|
2223
|
-
};
|
2224
2247
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2225
2248
|
if ("assetId" in input) {
|
2226
2249
|
return input.assetId === assetId;
|
@@ -2230,12 +2253,12 @@ var BaseTransactionRequest = class {
|
|
2230
2253
|
const updateAssetInput = (assetId, quantity) => {
|
2231
2254
|
const assetInput = findAssetInput(assetId);
|
2232
2255
|
if (assetInput && "assetId" in assetInput) {
|
2233
|
-
assetInput.id =
|
2256
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2234
2257
|
assetInput.amount = quantity;
|
2235
2258
|
} else {
|
2236
2259
|
this.addResources([
|
2237
2260
|
{
|
2238
|
-
id:
|
2261
|
+
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2239
2262
|
amount: quantity,
|
2240
2263
|
assetId,
|
2241
2264
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2490,7 +2513,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2490
2513
|
};
|
2491
2514
|
|
2492
2515
|
// src/providers/transaction-request/script-transaction-request.ts
|
2493
|
-
var
|
2516
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2494
2517
|
var import_address2 = require("@fuel-ts/address");
|
2495
2518
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2496
2519
|
var import_math10 = require("@fuel-ts/math");
|
@@ -2682,7 +2705,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2682
2705
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2683
2706
|
*/
|
2684
2707
|
setData(abi, args) {
|
2685
|
-
const abiInterface = new
|
2708
|
+
const abiInterface = new import_abi_coder3.Interface(abi);
|
2686
2709
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2687
2710
|
return this;
|
2688
2711
|
}
|
@@ -2804,17 +2827,17 @@ var import_math13 = require("@fuel-ts/math");
|
|
2804
2827
|
var import_transactions14 = require("@fuel-ts/transactions");
|
2805
2828
|
|
2806
2829
|
// src/providers/transaction-summary/call.ts
|
2807
|
-
var
|
2830
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
2808
2831
|
var import_math12 = require("@fuel-ts/math");
|
2809
2832
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2810
|
-
const abiInterface = new
|
2833
|
+
const abiInterface = new import_abi_coder4.Interface(abi);
|
2811
2834
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2812
2835
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2813
2836
|
const inputs = functionFragment.jsonFn.inputs;
|
2814
2837
|
let encodedArgs;
|
2815
2838
|
if (functionFragment.isInputDataPointer) {
|
2816
2839
|
if (rawPayload) {
|
2817
|
-
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0,
|
2840
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2818
2841
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2819
2842
|
}
|
2820
2843
|
} else {
|
@@ -3464,13 +3487,13 @@ function assembleTransactionSummary(params) {
|
|
3464
3487
|
}
|
3465
3488
|
|
3466
3489
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3467
|
-
var
|
3490
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3468
3491
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3469
3492
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3470
3493
|
return receipts.reduce((logs, receipt) => {
|
3471
3494
|
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3472
|
-
const interfaceToUse = new
|
3473
|
-
const data = receipt.type === import_transactions16.ReceiptType.Log ? new
|
3495
|
+
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3496
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3474
3497
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3475
3498
|
logs.push(decodedLog);
|
3476
3499
|
}
|
@@ -4112,6 +4135,36 @@ var _Provider = class {
|
|
4112
4135
|
missingContractIds
|
4113
4136
|
};
|
4114
4137
|
}
|
4138
|
+
/**
|
4139
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4140
|
+
* @param transactionRequest - The transaction request object.
|
4141
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4142
|
+
*/
|
4143
|
+
estimateTxGasAndFee(params) {
|
4144
|
+
const { transactionRequest } = params;
|
4145
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4146
|
+
const chainInfo = this.getChain();
|
4147
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4148
|
+
transactionRequest.gasPrice = gasPrice;
|
4149
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4150
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4151
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4152
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4153
|
+
transactionRequest.gasLimit = minGas;
|
4154
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4155
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4156
|
+
);
|
4157
|
+
}
|
4158
|
+
}
|
4159
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4160
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4161
|
+
return {
|
4162
|
+
minGas,
|
4163
|
+
minFee,
|
4164
|
+
maxGas,
|
4165
|
+
maxFee
|
4166
|
+
};
|
4167
|
+
}
|
4115
4168
|
/**
|
4116
4169
|
* Executes a signed transaction without applying the states changes
|
4117
4170
|
* on the chain.
|
@@ -4159,17 +4212,16 @@ var _Provider = class {
|
|
4159
4212
|
signatureCallback
|
4160
4213
|
} = {}) {
|
4161
4214
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4162
|
-
const
|
4163
|
-
const
|
4164
|
-
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4215
|
+
const { minGasPrice } = this.getGasConfig();
|
4216
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4165
4217
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4166
4218
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4167
4219
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4168
4220
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4221
|
+
if (isScriptTransaction) {
|
4222
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4223
|
+
}
|
4169
4224
|
if (estimatePredicates) {
|
4170
|
-
if (isScriptTransaction) {
|
4171
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4172
|
-
}
|
4173
4225
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4174
4226
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4175
4227
|
}
|
@@ -4178,36 +4230,34 @@ var _Provider = class {
|
|
4178
4230
|
if (signatureCallback && isScriptTransaction) {
|
4179
4231
|
await signatureCallback(txRequestClone);
|
4180
4232
|
}
|
4181
|
-
|
4182
|
-
|
4233
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4234
|
+
transactionRequest: txRequestClone
|
4235
|
+
});
|
4183
4236
|
let receipts = [];
|
4184
4237
|
let missingContractIds = [];
|
4185
4238
|
let outputVariables = 0;
|
4239
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4186
4240
|
if (isScriptTransaction && estimateTxDependencies) {
|
4187
4241
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4188
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4189
4242
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4190
4243
|
receipts = result.receipts;
|
4191
4244
|
outputVariables = result.outputVariables;
|
4192
4245
|
missingContractIds = result.missingContractIds;
|
4246
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4247
|
+
txRequestClone.gasLimit = gasUsed;
|
4248
|
+
txRequestClone.gasPrice = setGasPrice;
|
4249
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4250
|
+
transactionRequest: txRequestClone
|
4251
|
+
}));
|
4193
4252
|
}
|
4194
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4195
|
-
const usedFee = calculatePriceWithFactor(
|
4196
|
-
gasUsed,
|
4197
|
-
gasPrice,
|
4198
|
-
gasPriceFactor
|
4199
|
-
).normalizeZeroToOne();
|
4200
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4201
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4202
4253
|
return {
|
4203
4254
|
requiredQuantities: allQuantities,
|
4204
4255
|
receipts,
|
4205
4256
|
gasUsed,
|
4206
4257
|
minGasPrice,
|
4207
|
-
gasPrice,
|
4258
|
+
gasPrice: setGasPrice,
|
4208
4259
|
minGas,
|
4209
4260
|
maxGas,
|
4210
|
-
usedFee,
|
4211
4261
|
minFee,
|
4212
4262
|
maxFee,
|
4213
4263
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4840,13 +4890,13 @@ var assets = [
|
|
4840
4890
|
];
|
4841
4891
|
|
4842
4892
|
// src/utils/formatTransferToContractScriptData.ts
|
4843
|
-
var
|
4893
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4844
4894
|
var import_math17 = require("@fuel-ts/math");
|
4845
4895
|
var import_utils27 = require("@fuel-ts/utils");
|
4846
4896
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4847
4897
|
var formatTransferToContractScriptData = (params) => {
|
4848
4898
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4849
|
-
const numberCoder = new
|
4899
|
+
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4850
4900
|
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4851
4901
|
const scriptData = Uint8Array.from([
|
4852
4902
|
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
@@ -5301,7 +5351,7 @@ var import_utils31 = require("@fuel-ts/utils");
|
|
5301
5351
|
|
5302
5352
|
// src/signer/signer.ts
|
5303
5353
|
var import_address5 = require("@fuel-ts/address");
|
5304
|
-
var
|
5354
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
5305
5355
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5306
5356
|
var import_math19 = require("@fuel-ts/math");
|
5307
5357
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5394,7 +5444,7 @@ var Signer = class {
|
|
5394
5444
|
* @returns random 32-byte hashed
|
5395
5445
|
*/
|
5396
5446
|
static generatePrivateKey(entropy) {
|
5397
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5447
|
+
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);
|
5398
5448
|
}
|
5399
5449
|
/**
|
5400
5450
|
* Extended publicKey from a compact publicKey
|
@@ -5410,7 +5460,7 @@ var Signer = class {
|
|
5410
5460
|
|
5411
5461
|
// src/wallet/keystore-wallet.ts
|
5412
5462
|
var import_address6 = require("@fuel-ts/address");
|
5413
|
-
var
|
5463
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5414
5464
|
var import_errors17 = require("@fuel-ts/errors");
|
5415
5465
|
var import_utils30 = require("@fuel-ts/utils");
|
5416
5466
|
var import_uuid = require("uuid");
|
@@ -5426,22 +5476,22 @@ var removeHexPrefix = (hexString) => {
|
|
5426
5476
|
return hexString;
|
5427
5477
|
};
|
5428
5478
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5429
|
-
const privateKeyBuffer = (0,
|
5479
|
+
const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5430
5480
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5431
|
-
const salt = (0,
|
5432
|
-
const key = (0,
|
5433
|
-
password: (0,
|
5481
|
+
const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
|
5482
|
+
const key = (0, import_crypto3.scrypt)({
|
5483
|
+
password: (0, import_crypto3.bufferFromString)(password),
|
5434
5484
|
salt,
|
5435
5485
|
dklen: DEFAULT_KEY_SIZE,
|
5436
5486
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5437
5487
|
r: DEFAULT_KDF_PARAMS_R,
|
5438
5488
|
p: DEFAULT_KDF_PARAMS_P
|
5439
5489
|
});
|
5440
|
-
const iv = (0,
|
5441
|
-
const ciphertext = await (0,
|
5490
|
+
const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
|
5491
|
+
const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5442
5492
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5443
|
-
const macHashUint8Array = (0,
|
5444
|
-
const mac = (0,
|
5493
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5494
|
+
const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5445
5495
|
const keystore = {
|
5446
5496
|
id: (0, import_uuid.v4)(),
|
5447
5497
|
version: 3,
|
@@ -5449,15 +5499,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5449
5499
|
crypto: {
|
5450
5500
|
cipher: "aes-128-ctr",
|
5451
5501
|
mac,
|
5452
|
-
cipherparams: { iv: (0,
|
5453
|
-
ciphertext: (0,
|
5502
|
+
cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
|
5503
|
+
ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
|
5454
5504
|
kdf: "scrypt",
|
5455
5505
|
kdfparams: {
|
5456
5506
|
dklen: DEFAULT_KEY_SIZE,
|
5457
5507
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5458
5508
|
p: DEFAULT_KDF_PARAMS_P,
|
5459
5509
|
r: DEFAULT_KDF_PARAMS_R,
|
5460
|
-
salt: (0,
|
5510
|
+
salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
|
5461
5511
|
}
|
5462
5512
|
}
|
5463
5513
|
};
|
@@ -5473,11 +5523,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5473
5523
|
kdfparams: { dklen, n, r, p, salt }
|
5474
5524
|
}
|
5475
5525
|
} = keystoreWallet;
|
5476
|
-
const ciphertextBuffer = (0,
|
5477
|
-
const ivBuffer = (0,
|
5478
|
-
const saltBuffer = (0,
|
5479
|
-
const passwordBuffer = (0,
|
5480
|
-
const key = (0,
|
5526
|
+
const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
|
5527
|
+
const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
|
5528
|
+
const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
|
5529
|
+
const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
|
5530
|
+
const key = (0, import_crypto3.scrypt)({
|
5481
5531
|
password: passwordBuffer,
|
5482
5532
|
salt: saltBuffer,
|
5483
5533
|
n,
|
@@ -5486,15 +5536,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5486
5536
|
dklen
|
5487
5537
|
});
|
5488
5538
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5489
|
-
const macHashUint8Array = (0,
|
5490
|
-
const macHash = (0,
|
5539
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5540
|
+
const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5491
5541
|
if (mac !== macHash) {
|
5492
5542
|
throw new import_errors17.FuelError(
|
5493
5543
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5494
5544
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5495
5545
|
);
|
5496
5546
|
}
|
5497
|
-
const buffer = await (0,
|
5547
|
+
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5498
5548
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5499
5549
|
return privateKey;
|
5500
5550
|
}
|
@@ -5619,7 +5669,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5619
5669
|
var import_ethers3 = require("ethers");
|
5620
5670
|
|
5621
5671
|
// src/mnemonic/mnemonic.ts
|
5622
|
-
var
|
5672
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5623
5673
|
var import_errors19 = require("@fuel-ts/errors");
|
5624
5674
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5625
5675
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -7980,7 +8030,7 @@ var Mnemonic = class {
|
|
7980
8030
|
* @returns A randomly generated mnemonic
|
7981
8031
|
*/
|
7982
8032
|
static generate(size = 32, extraEntropy = "") {
|
7983
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
8033
|
+
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);
|
7984
8034
|
return Mnemonic.entropyToMnemonic(entropy);
|
7985
8035
|
}
|
7986
8036
|
};
|
@@ -8352,7 +8402,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8352
8402
|
|
8353
8403
|
// src/wallet-manager/wallet-manager.ts
|
8354
8404
|
var import_address9 = require("@fuel-ts/address");
|
8355
|
-
var
|
8405
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
8356
8406
|
var import_errors23 = require("@fuel-ts/errors");
|
8357
8407
|
var import_events = require("events");
|
8358
8408
|
|
@@ -8680,7 +8730,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
8680
8730
|
await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
|
8681
8731
|
const data = await this.storage.getItem(this.STORAGE_KEY);
|
8682
8732
|
if (data) {
|
8683
|
-
const state = await (0,
|
8733
|
+
const state = await (0, import_crypto5.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
|
8684
8734
|
__privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
|
8685
8735
|
}
|
8686
8736
|
}
|
@@ -8689,7 +8739,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
8689
8739
|
*/
|
8690
8740
|
async saveState() {
|
8691
8741
|
await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
|
8692
|
-
const encryptedData = await (0,
|
8742
|
+
const encryptedData = await (0, import_crypto5.encrypt)(__privateGet(this, _passphrase), {
|
8693
8743
|
vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
|
8694
8744
|
});
|
8695
8745
|
await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
|
@@ -8765,7 +8815,7 @@ var StorageAbstract = class {
|
|
8765
8815
|
};
|
8766
8816
|
|
8767
8817
|
// src/predicate/predicate.ts
|
8768
|
-
var
|
8818
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8769
8819
|
var import_address10 = require("@fuel-ts/address");
|
8770
8820
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8771
8821
|
var import_errors25 = require("@fuel-ts/errors");
|
@@ -8832,7 +8882,6 @@ var Predicate = class extends Account {
|
|
8832
8882
|
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8833
8883
|
input.predicate = this.bytes;
|
8834
8884
|
input.predicateData = this.getPredicateData(policies.length);
|
8835
|
-
input.witnessIndex = 0;
|
8836
8885
|
}
|
8837
8886
|
});
|
8838
8887
|
return request;
|
@@ -8870,30 +8919,16 @@ var Predicate = class extends Account {
|
|
8870
8919
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8871
8920
|
return super.simulateTransaction(transactionRequest);
|
8872
8921
|
}
|
8873
|
-
/**
|
8874
|
-
* Retrieves resources satisfying the spend query for the account.
|
8875
|
-
*
|
8876
|
-
* @param quantities - IDs of coins to exclude.
|
8877
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
8878
|
-
* @returns A promise that resolves to an array of Resources.
|
8879
|
-
*/
|
8880
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
8881
|
-
const resources = await super.getResourcesToSpend(quantities, excludedIds);
|
8882
|
-
return resources.map((resource) => ({
|
8883
|
-
...resource,
|
8884
|
-
predicate: (0, import_utils37.hexlify)(this.bytes)
|
8885
|
-
}));
|
8886
|
-
}
|
8887
8922
|
getPredicateData(policiesLength) {
|
8888
8923
|
if (!this.predicateData.length) {
|
8889
8924
|
return new Uint8Array();
|
8890
8925
|
}
|
8891
8926
|
const mainFn = this.interface?.functions.main;
|
8892
8927
|
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8893
|
-
const VM_TX_MEMORY = (0,
|
8928
|
+
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
8894
8929
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8895
8930
|
});
|
8896
|
-
const OFFSET = VM_TX_MEMORY +
|
8931
|
+
const OFFSET = VM_TX_MEMORY + import_abi_coder7.SCRIPT_FIXED_SIZE + import_abi_coder7.INPUT_COIN_FIXED_SIZE + import_abi_coder7.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder7.WORD_SIZE;
|
8897
8932
|
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
8898
8933
|
}
|
8899
8934
|
/**
|
@@ -8908,7 +8943,7 @@ var Predicate = class extends Account {
|
|
8908
8943
|
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
8909
8944
|
let abiInterface;
|
8910
8945
|
if (jsonAbi) {
|
8911
|
-
abiInterface = new
|
8946
|
+
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
8912
8947
|
if (abiInterface.functions.main === void 0) {
|
8913
8948
|
throw new import_errors25.FuelError(
|
8914
8949
|
import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,
|