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