@fuel-ts/account 0.94.2 → 0.94.4
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.
- package/dist/account.d.ts +1 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +376 -277
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +328 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +325 -173
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +81 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +2 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +4 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts +6 -0
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -0
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +220 -127
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +283 -140
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +281 -138
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -349,20 +349,14 @@ var launchNode = async ({
|
|
349
349
|
const rows = text.split("\n");
|
350
350
|
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
351
351
|
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
snapshotDir: snapshotDirToUse,
|
361
|
-
pid: child.pid
|
362
|
-
})
|
363
|
-
),
|
364
|
-
500
|
365
|
-
);
|
352
|
+
resolve({
|
353
|
+
cleanup,
|
354
|
+
ip: realIp,
|
355
|
+
port: realPort,
|
356
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
357
|
+
snapshotDir: snapshotDirToUse,
|
358
|
+
pid: child.pid
|
359
|
+
});
|
366
360
|
}
|
367
361
|
if (/error/i.test(text)) {
|
368
362
|
console.log(text);
|
@@ -381,7 +375,7 @@ var launchNode = async ({
|
|
381
375
|
|
382
376
|
// src/test-utils/setup-test-provider-and-wallets.ts
|
383
377
|
var import_utils41 = require("@fuel-ts/utils");
|
384
|
-
var
|
378
|
+
var import_ramda8 = require("ramda");
|
385
379
|
|
386
380
|
// src/providers/coin-quantity.ts
|
387
381
|
var import_math2 = require("@fuel-ts/math");
|
@@ -420,14 +414,15 @@ var addAmountToCoinQuantities = (params) => {
|
|
420
414
|
|
421
415
|
// src/providers/provider.ts
|
422
416
|
var import_address4 = require("@fuel-ts/address");
|
423
|
-
var
|
417
|
+
var import_errors17 = require("@fuel-ts/errors");
|
424
418
|
var import_math19 = require("@fuel-ts/math");
|
425
419
|
var import_transactions20 = require("@fuel-ts/transactions");
|
426
420
|
var import_utils26 = require("@fuel-ts/utils");
|
427
421
|
var import_versions = require("@fuel-ts/versions");
|
428
422
|
var import_utils27 = require("@noble/curves/abstract/utils");
|
429
423
|
var import_graphql_request = require("graphql-request");
|
430
|
-
var
|
424
|
+
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
425
|
+
var import_ramda6 = require("ramda");
|
431
426
|
|
432
427
|
// src/providers/__generated__/operations.ts
|
433
428
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
@@ -760,6 +755,14 @@ var BlockFragmentDoc = import_graphql_tag.default`
|
|
760
755
|
height
|
761
756
|
header {
|
762
757
|
time
|
758
|
+
daHeight
|
759
|
+
stateTransitionBytecodeVersion
|
760
|
+
transactionsCount
|
761
|
+
transactionsRoot
|
762
|
+
messageOutboxRoot
|
763
|
+
eventInboxRoot
|
764
|
+
prevRoot
|
765
|
+
applicationHash
|
763
766
|
}
|
764
767
|
transactions {
|
765
768
|
id
|
@@ -1748,6 +1751,9 @@ var import_math9 = require("@fuel-ts/math");
|
|
1748
1751
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1749
1752
|
var import_utils11 = require("@fuel-ts/utils");
|
1750
1753
|
|
1754
|
+
// src/providers/message.ts
|
1755
|
+
var isMessageCoin = (message) => !("data" in message);
|
1756
|
+
|
1751
1757
|
// src/providers/resource.ts
|
1752
1758
|
var isCoin = (resource) => "id" in resource;
|
1753
1759
|
|
@@ -2122,20 +2128,22 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2122
2128
|
let reason = "";
|
2123
2129
|
if (revertReceipt) {
|
2124
2130
|
const reasonHex = (0, import_math7.bn)(revertReceipt.val).toHex();
|
2131
|
+
const lastLog = logs[logs.length - 1];
|
2132
|
+
const lastButOneLog = logs[logs.length - 2];
|
2125
2133
|
switch (reasonHex) {
|
2126
2134
|
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
2127
2135
|
reason = "require";
|
2128
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(
|
2136
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2129
2137
|
break;
|
2130
2138
|
}
|
2131
2139
|
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
2132
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2140
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2133
2141
|
reason = "assert_eq";
|
2134
2142
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
2135
2143
|
break;
|
2136
2144
|
}
|
2137
2145
|
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2138
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2146
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2139
2147
|
reason = "assert_ne";
|
2140
2148
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
2141
2149
|
break;
|
@@ -2196,7 +2204,9 @@ var import_math8 = require("@fuel-ts/math");
|
|
2196
2204
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2197
2205
|
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
2198
2206
|
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
2199
|
-
var
|
2207
|
+
var isRequestInputMessageWithoutData = (input) => input.type === import_transactions6.InputType.Message && (0, import_math8.bn)(input.data).isZero();
|
2208
|
+
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2209
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2200
2210
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2201
2211
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2202
2212
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
@@ -2492,7 +2502,7 @@ var BaseTransactionRequest = class {
|
|
2492
2502
|
* @param message - Message resource.
|
2493
2503
|
*/
|
2494
2504
|
addMessageInput(message) {
|
2495
|
-
const { recipient, sender, amount, predicate, nonce,
|
2505
|
+
const { recipient, sender, amount, predicate, nonce, predicateData } = message;
|
2496
2506
|
let witnessIndex;
|
2497
2507
|
if (message.predicate) {
|
2498
2508
|
witnessIndex = 0;
|
@@ -2507,13 +2517,16 @@ var BaseTransactionRequest = class {
|
|
2507
2517
|
type: import_transactions7.InputType.Message,
|
2508
2518
|
sender: sender.toB256(),
|
2509
2519
|
recipient: recipient.toB256(),
|
2520
|
+
data: isMessageCoin(message) ? "0x" : message.data,
|
2510
2521
|
amount,
|
2511
2522
|
witnessIndex,
|
2512
2523
|
predicate,
|
2513
2524
|
predicateData
|
2514
2525
|
};
|
2515
2526
|
this.pushInput(input);
|
2516
|
-
|
2527
|
+
if (isMessageCoin(message)) {
|
2528
|
+
this.addChangeOutput(recipient, message.assetId);
|
2529
|
+
}
|
2517
2530
|
}
|
2518
2531
|
/**
|
2519
2532
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2645,6 +2658,8 @@ var BaseTransactionRequest = class {
|
|
2645
2658
|
*
|
2646
2659
|
* @param quantities - CoinQuantity Array.
|
2647
2660
|
* @param baseAssetId - The base asset to fund the transaction.
|
2661
|
+
* @deprecated - This method is deprecated and will be removed in future versions.
|
2662
|
+
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
2648
2663
|
*/
|
2649
2664
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2650
2665
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2713,7 +2728,7 @@ var BaseTransactionRequest = class {
|
|
2713
2728
|
});
|
2714
2729
|
}
|
2715
2730
|
updatePredicateGasUsed(inputs) {
|
2716
|
-
const inputsToExtractGasUsed = inputs.filter(
|
2731
|
+
const inputsToExtractGasUsed = inputs.filter(isRequestInputCoinOrMessage);
|
2717
2732
|
this.inputs.filter(isRequestInputResource).forEach((i) => {
|
2718
2733
|
const owner = getRequestInputResourceOwner(i);
|
2719
2734
|
const correspondingInput = inputsToExtractGasUsed.find(
|
@@ -2729,6 +2744,9 @@ var BaseTransactionRequest = class {
|
|
2729
2744
|
}
|
2730
2745
|
};
|
2731
2746
|
|
2747
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2748
|
+
var import_ramda3 = require("ramda");
|
2749
|
+
|
2732
2750
|
// src/providers/transaction-request/hash-transaction.ts
|
2733
2751
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2734
2752
|
var import_hasher2 = require("@fuel-ts/hasher");
|
@@ -2803,10 +2821,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2803
2821
|
// src/providers/transaction-request/blob-transaction-request.ts
|
2804
2822
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2805
2823
|
static from(obj) {
|
2806
|
-
|
2807
|
-
return obj;
|
2808
|
-
}
|
2809
|
-
return new this(obj);
|
2824
|
+
return new this((0, import_ramda3.clone)(obj));
|
2810
2825
|
}
|
2811
2826
|
/** Type of the transaction */
|
2812
2827
|
type = import_transactions7.TransactionType.Blob;
|
@@ -2869,6 +2884,7 @@ var import_configs8 = require("@fuel-ts/address/configs");
|
|
2869
2884
|
var import_math11 = require("@fuel-ts/math");
|
2870
2885
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2871
2886
|
var import_utils16 = require("@fuel-ts/utils");
|
2887
|
+
var import_ramda4 = require("ramda");
|
2872
2888
|
|
2873
2889
|
// src/providers/transaction-request/storage-slot.ts
|
2874
2890
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2896,10 +2912,7 @@ var storageSlotify = (storageSlot) => {
|
|
2896
2912
|
// src/providers/transaction-request/create-transaction-request.ts
|
2897
2913
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
2898
2914
|
static from(obj) {
|
2899
|
-
|
2900
|
-
return obj;
|
2901
|
-
}
|
2902
|
-
return new this(obj);
|
2915
|
+
return new this((0, import_ramda4.clone)(obj));
|
2903
2916
|
}
|
2904
2917
|
/** Type of the transaction */
|
2905
2918
|
type = import_transactions9.TransactionType.Create;
|
@@ -2988,6 +3001,7 @@ var import_configs9 = require("@fuel-ts/address/configs");
|
|
2988
3001
|
var import_math12 = require("@fuel-ts/math");
|
2989
3002
|
var import_transactions10 = require("@fuel-ts/transactions");
|
2990
3003
|
var import_utils18 = require("@fuel-ts/utils");
|
3004
|
+
var import_ramda5 = require("ramda");
|
2991
3005
|
|
2992
3006
|
// src/providers/transaction-request/scripts.ts
|
2993
3007
|
var import_utils17 = require("@fuel-ts/utils");
|
@@ -3018,10 +3032,7 @@ var withdrawScript = {
|
|
3018
3032
|
// src/providers/transaction-request/script-transaction-request.ts
|
3019
3033
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3020
3034
|
static from(obj) {
|
3021
|
-
|
3022
|
-
return obj;
|
3023
|
-
}
|
3024
|
-
return new this(obj);
|
3035
|
+
return new this((0, import_ramda5.clone)(obj));
|
3025
3036
|
}
|
3026
3037
|
/** Type of the transaction */
|
3027
3038
|
type = import_transactions10.TransactionType.Script;
|
@@ -4327,6 +4338,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4327
4338
|
};
|
4328
4339
|
}
|
4329
4340
|
|
4341
|
+
// src/providers/utils/handle-gql-error-message.ts
|
4342
|
+
var import_errors16 = require("@fuel-ts/errors");
|
4343
|
+
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4344
|
+
switch (errorMessage) {
|
4345
|
+
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4346
|
+
throw new import_errors16.FuelError(
|
4347
|
+
import_errors16.ErrorCode.NOT_ENOUGH_FUNDS,
|
4348
|
+
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4349
|
+
{},
|
4350
|
+
rawError
|
4351
|
+
);
|
4352
|
+
default:
|
4353
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.INVALID_REQUEST, errorMessage);
|
4354
|
+
}
|
4355
|
+
};
|
4356
|
+
|
4330
4357
|
// src/providers/provider.ts
|
4331
4358
|
var MAX_RETRIES = 10;
|
4332
4359
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4453,6 +4480,17 @@ var _Provider = class {
|
|
4453
4480
|
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
4454
4481
|
}, retryOptions);
|
4455
4482
|
}
|
4483
|
+
static extractBasicAuth(url) {
|
4484
|
+
const parsedUrl = new URL(url);
|
4485
|
+
const username = parsedUrl.username;
|
4486
|
+
const password = parsedUrl.password;
|
4487
|
+
const urlNoBasicAuth = `${parsedUrl.origin}${parsedUrl.pathname}`;
|
4488
|
+
if (!(username && password)) {
|
4489
|
+
return { url, auth: void 0 };
|
4490
|
+
}
|
4491
|
+
const auth = `Basic ${btoa(`${username}:${password}`)}`;
|
4492
|
+
return { url: urlNoBasicAuth, auth };
|
4493
|
+
}
|
4456
4494
|
/**
|
4457
4495
|
* Creates a new instance of the Provider class. This is the recommended way to initialize a Provider.
|
4458
4496
|
*
|
@@ -4462,7 +4500,17 @@ var _Provider = class {
|
|
4462
4500
|
* @returns A promise that resolves to a Provider instance.
|
4463
4501
|
*/
|
4464
4502
|
static async create(url, options = {}) {
|
4465
|
-
const
|
4503
|
+
const { url: urlToUse, auth } = this.extractBasicAuth(url);
|
4504
|
+
const provider = new _Provider(urlToUse, {
|
4505
|
+
...options,
|
4506
|
+
requestMiddleware: async (request) => {
|
4507
|
+
if (auth) {
|
4508
|
+
request.headers ??= {};
|
4509
|
+
request.headers.Authorization = auth;
|
4510
|
+
}
|
4511
|
+
return options.requestMiddleware?.(request) ?? request;
|
4512
|
+
}
|
4513
|
+
});
|
4466
4514
|
await provider.fetchChainAndNodeInfo();
|
4467
4515
|
return provider;
|
4468
4516
|
}
|
@@ -4474,8 +4522,8 @@ var _Provider = class {
|
|
4474
4522
|
getChain() {
|
4475
4523
|
const chain = _Provider.chainInfoCache[this.url];
|
4476
4524
|
if (!chain) {
|
4477
|
-
throw new
|
4478
|
-
|
4525
|
+
throw new import_errors17.FuelError(
|
4526
|
+
import_errors17.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4479
4527
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4480
4528
|
);
|
4481
4529
|
}
|
@@ -4489,8 +4537,8 @@ var _Provider = class {
|
|
4489
4537
|
getNode() {
|
4490
4538
|
const node = _Provider.nodeInfoCache[this.url];
|
4491
4539
|
if (!node) {
|
4492
|
-
throw new
|
4493
|
-
|
4540
|
+
throw new import_errors17.FuelError(
|
4541
|
+
import_errors17.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4494
4542
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4495
4543
|
);
|
4496
4544
|
}
|
@@ -4568,10 +4616,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4568
4616
|
if ("response" in response) {
|
4569
4617
|
const graphQlResponse = response.response;
|
4570
4618
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4571
|
-
|
4572
|
-
|
4573
|
-
|
4574
|
-
);
|
4619
|
+
for (const error of graphQlResponse.errors) {
|
4620
|
+
handleGqlErrorMessage(error.message, error);
|
4621
|
+
}
|
4575
4622
|
}
|
4576
4623
|
}
|
4577
4624
|
}
|
@@ -4589,7 +4636,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4589
4636
|
}
|
4590
4637
|
return gqlClient.request(query, vars);
|
4591
4638
|
};
|
4592
|
-
|
4639
|
+
const customOperations = (requester) => ({
|
4640
|
+
getBlobs(variables) {
|
4641
|
+
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
4642
|
+
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
4643
|
+
const updatedVariables = variables.blobIds.reduce(
|
4644
|
+
(acc, blobId, i) => {
|
4645
|
+
acc[`blobId${i}`] = blobId;
|
4646
|
+
return acc;
|
4647
|
+
},
|
4648
|
+
{}
|
4649
|
+
);
|
4650
|
+
const document = import_graphql_tag2.default`
|
4651
|
+
query getBlobs(${queryParams}) {
|
4652
|
+
${blobParams}
|
4653
|
+
}
|
4654
|
+
`;
|
4655
|
+
return requester(document, updatedVariables);
|
4656
|
+
}
|
4657
|
+
});
|
4658
|
+
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
4593
4659
|
}
|
4594
4660
|
/**
|
4595
4661
|
* Returns the version of the connected node.
|
@@ -4664,14 +4730,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4664
4730
|
validateTransaction(tx, consensusParameters) {
|
4665
4731
|
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4666
4732
|
if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
|
4667
|
-
throw new
|
4668
|
-
|
4733
|
+
throw new import_errors17.FuelError(
|
4734
|
+
import_errors17.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4669
4735
|
"The transaction exceeds the maximum allowed number of inputs."
|
4670
4736
|
);
|
4671
4737
|
}
|
4672
4738
|
if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4673
|
-
throw new
|
4674
|
-
|
4739
|
+
throw new import_errors17.FuelError(
|
4740
|
+
import_errors17.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4675
4741
|
"The transaction exceeds the maximum allowed number of outputs."
|
4676
4742
|
);
|
4677
4743
|
}
|
@@ -4686,7 +4752,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4686
4752
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
4687
4753
|
* @returns A promise that resolves to the transaction response object.
|
4688
4754
|
*/
|
4689
|
-
// #region Provider-sendTransaction
|
4690
4755
|
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4691
4756
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4692
4757
|
if (estimateTxDependencies) {
|
@@ -4833,7 +4898,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4833
4898
|
missingContractIds: [],
|
4834
4899
|
dryRunStatus: void 0
|
4835
4900
|
}));
|
4836
|
-
const allRequests = (0,
|
4901
|
+
const allRequests = (0, import_ramda6.clone)(transactionRequests);
|
4837
4902
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4838
4903
|
allRequests.forEach((req, index) => {
|
4839
4904
|
if (isTransactionTypeScript(req)) {
|
@@ -4993,13 +5058,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4993
5058
|
* @returns A promise that resolves to the transaction cost object.
|
4994
5059
|
*/
|
4995
5060
|
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4996
|
-
const txRequestClone = (0,
|
5061
|
+
const txRequestClone = (0, import_ramda6.clone)(transactionRequestify(transactionRequestLike));
|
4997
5062
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4998
5063
|
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4999
5064
|
if (isScriptTransaction) {
|
5000
5065
|
txRequestClone.gasLimit = (0, import_math19.bn)(0);
|
5001
5066
|
}
|
5002
|
-
const signedRequest = (0,
|
5067
|
+
const signedRequest = (0, import_ramda6.clone)(txRequestClone);
|
5003
5068
|
let addedSignatures = 0;
|
5004
5069
|
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
5005
5070
|
const lengthBefore = signedRequest.witnesses.length;
|
@@ -5137,6 +5202,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5137
5202
|
}).filter((v) => !!v);
|
5138
5203
|
return coins;
|
5139
5204
|
}
|
5205
|
+
/**
|
5206
|
+
* Returns an array of blobIds that exist on chain, for a given array of blobIds.
|
5207
|
+
*
|
5208
|
+
* @param blobIds - blobIds to check.
|
5209
|
+
* @returns - A promise that resolves to an array of blobIds that exist on chain.
|
5210
|
+
*/
|
5211
|
+
async getBlobs(blobIds) {
|
5212
|
+
const res = await this.operations.getBlobs({ blobIds });
|
5213
|
+
const blobs = [];
|
5214
|
+
Object.keys(res).forEach((key) => {
|
5215
|
+
const val = res[key];
|
5216
|
+
blobs.push(val?.id ?? null);
|
5217
|
+
});
|
5218
|
+
return blobs.filter((v) => v);
|
5219
|
+
}
|
5140
5220
|
/**
|
5141
5221
|
* Returns block matching the given ID or height.
|
5142
5222
|
*
|
@@ -5158,11 +5238,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5158
5238
|
if (!block) {
|
5159
5239
|
return null;
|
5160
5240
|
}
|
5241
|
+
const { header, height, id, transactions } = block;
|
5161
5242
|
return {
|
5162
|
-
id
|
5163
|
-
height: (0, import_math19.bn)(
|
5164
|
-
time:
|
5165
|
-
|
5243
|
+
id,
|
5244
|
+
height: (0, import_math19.bn)(height),
|
5245
|
+
time: header.time,
|
5246
|
+
header: {
|
5247
|
+
applicationHash: header.applicationHash,
|
5248
|
+
daHeight: (0, import_math19.bn)(header.daHeight),
|
5249
|
+
eventInboxRoot: header.eventInboxRoot,
|
5250
|
+
messageOutboxRoot: header.messageOutboxRoot,
|
5251
|
+
prevRoot: header.prevRoot,
|
5252
|
+
stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
|
5253
|
+
transactionsCount: header.transactionsCount,
|
5254
|
+
transactionsRoot: header.transactionsRoot
|
5255
|
+
},
|
5256
|
+
transactionIds: transactions.map((tx) => tx.id)
|
5166
5257
|
};
|
5167
5258
|
}
|
5168
5259
|
/**
|
@@ -5184,6 +5275,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5184
5275
|
id: block.id,
|
5185
5276
|
height: (0, import_math19.bn)(block.height),
|
5186
5277
|
time: block.header.time,
|
5278
|
+
header: {
|
5279
|
+
applicationHash: block.header.applicationHash,
|
5280
|
+
daHeight: (0, import_math19.bn)(block.header.daHeight),
|
5281
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5282
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5283
|
+
prevRoot: block.header.prevRoot,
|
5284
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5285
|
+
transactionsCount: block.header.transactionsCount,
|
5286
|
+
transactionsRoot: block.header.transactionsRoot
|
5287
|
+
},
|
5187
5288
|
transactionIds: block.transactions.map((tx) => tx.id)
|
5188
5289
|
}));
|
5189
5290
|
return { blocks, pageInfo };
|
@@ -5211,6 +5312,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5211
5312
|
id: block.id,
|
5212
5313
|
height: (0, import_math19.bn)(block.height, 10),
|
5213
5314
|
time: block.header.time,
|
5315
|
+
header: {
|
5316
|
+
applicationHash: block.header.applicationHash,
|
5317
|
+
daHeight: (0, import_math19.bn)(block.header.daHeight),
|
5318
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5319
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5320
|
+
prevRoot: block.header.prevRoot,
|
5321
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5322
|
+
transactionsCount: block.header.transactionsCount,
|
5323
|
+
transactionsRoot: block.header.transactionsRoot
|
5324
|
+
},
|
5214
5325
|
transactionIds: block.transactions.map((tx) => tx.id),
|
5215
5326
|
transactions: block.transactions.map(
|
5216
5327
|
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils26.arrayify)(tx.rawPayload), 0)?.[0]
|
@@ -5228,10 +5339,18 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5228
5339
|
if (!transaction) {
|
5229
5340
|
return null;
|
5230
5341
|
}
|
5231
|
-
|
5232
|
-
|
5233
|
-
|
5234
|
-
|
5342
|
+
try {
|
5343
|
+
return new import_transactions20.TransactionCoder().decode(
|
5344
|
+
(0, import_utils26.arrayify)(transaction.rawPayload),
|
5345
|
+
0
|
5346
|
+
)?.[0];
|
5347
|
+
} catch (error) {
|
5348
|
+
if (error instanceof import_errors17.FuelError && error.code === import_errors17.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5349
|
+
console.warn("Unsupported transaction type encountered");
|
5350
|
+
return null;
|
5351
|
+
}
|
5352
|
+
throw error;
|
5353
|
+
}
|
5235
5354
|
}
|
5236
5355
|
/**
|
5237
5356
|
* Retrieves transactions based on the provided pagination arguments.
|
@@ -5243,9 +5362,17 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5243
5362
|
transactions: { edges, pageInfo }
|
5244
5363
|
} = await this.operations.getTransactions(paginationArgs);
|
5245
5364
|
const coder = new import_transactions20.TransactionCoder();
|
5246
|
-
const transactions = edges.map(
|
5247
|
-
|
5248
|
-
|
5365
|
+
const transactions = edges.map(({ node: { rawPayload } }) => {
|
5366
|
+
try {
|
5367
|
+
return coder.decode((0, import_utils26.arrayify)(rawPayload), 0)[0];
|
5368
|
+
} catch (error) {
|
5369
|
+
if (error instanceof import_errors17.FuelError && error.code === import_errors17.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5370
|
+
console.warn("Unsupported transaction type encountered");
|
5371
|
+
return null;
|
5372
|
+
}
|
5373
|
+
throw error;
|
5374
|
+
}
|
5375
|
+
}).filter((tx) => tx !== null);
|
5249
5376
|
return { transactions, pageInfo };
|
5250
5377
|
}
|
5251
5378
|
/**
|
@@ -5365,8 +5492,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5365
5492
|
nonce
|
5366
5493
|
};
|
5367
5494
|
if (commitBlockId && commitBlockHeight) {
|
5368
|
-
throw new
|
5369
|
-
|
5495
|
+
throw new import_errors17.FuelError(
|
5496
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5370
5497
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5371
5498
|
);
|
5372
5499
|
}
|
@@ -5506,10 +5633,25 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5506
5633
|
* @returns A promise that resolves to the Message object or null.
|
5507
5634
|
*/
|
5508
5635
|
async getMessageByNonce(nonce) {
|
5509
|
-
const { message } = await this.operations.getMessageByNonce({ nonce });
|
5510
|
-
if (!
|
5636
|
+
const { message: rawMessage } = await this.operations.getMessageByNonce({ nonce });
|
5637
|
+
if (!rawMessage) {
|
5511
5638
|
return null;
|
5512
5639
|
}
|
5640
|
+
const message = {
|
5641
|
+
messageId: import_transactions20.InputMessageCoder.getMessageId({
|
5642
|
+
sender: rawMessage.sender,
|
5643
|
+
recipient: rawMessage.recipient,
|
5644
|
+
nonce: rawMessage.nonce,
|
5645
|
+
amount: (0, import_math19.bn)(rawMessage.amount),
|
5646
|
+
data: rawMessage.data
|
5647
|
+
}),
|
5648
|
+
sender: import_address4.Address.fromAddressOrString(rawMessage.sender),
|
5649
|
+
recipient: import_address4.Address.fromAddressOrString(rawMessage.recipient),
|
5650
|
+
nonce: rawMessage.nonce,
|
5651
|
+
amount: (0, import_math19.bn)(rawMessage.amount),
|
5652
|
+
data: import_transactions20.InputMessageCoder.decodeData(rawMessage.data),
|
5653
|
+
daHeight: (0, import_math19.bn)(rawMessage.daHeight)
|
5654
|
+
};
|
5513
5655
|
return message;
|
5514
5656
|
}
|
5515
5657
|
/**
|
@@ -5534,26 +5676,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5534
5676
|
const { paginationLimit, inputArgs = {} } = params;
|
5535
5677
|
const { first, last, after, before } = inputArgs;
|
5536
5678
|
if (after && before) {
|
5537
|
-
throw new
|
5538
|
-
|
5679
|
+
throw new import_errors17.FuelError(
|
5680
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5539
5681
|
'Pagination arguments "after" and "before" cannot be used together'
|
5540
5682
|
);
|
5541
5683
|
}
|
5542
5684
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5543
|
-
throw new
|
5544
|
-
|
5685
|
+
throw new import_errors17.FuelError(
|
5686
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5545
5687
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5546
5688
|
);
|
5547
5689
|
}
|
5548
5690
|
if (first && before) {
|
5549
|
-
throw new
|
5550
|
-
|
5691
|
+
throw new import_errors17.FuelError(
|
5692
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5551
5693
|
'The use of pagination argument "first" with "before" is not supported'
|
5552
5694
|
);
|
5553
5695
|
}
|
5554
5696
|
if (last && after) {
|
5555
|
-
throw new
|
5556
|
-
|
5697
|
+
throw new import_errors17.FuelError(
|
5698
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5557
5699
|
'The use of pagination argument "last" with "after" is not supported'
|
5558
5700
|
);
|
5559
5701
|
}
|
@@ -5607,7 +5749,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5607
5749
|
__publicField(Provider, "nodeInfoCache", {});
|
5608
5750
|
|
5609
5751
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5610
|
-
var
|
5752
|
+
var import_errors18 = require("@fuel-ts/errors");
|
5611
5753
|
var import_math20 = require("@fuel-ts/math");
|
5612
5754
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5613
5755
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5708,7 +5850,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
5708
5850
|
|
5709
5851
|
// src/test-utils/wallet-config.ts
|
5710
5852
|
var import_crypto9 = require("@fuel-ts/crypto");
|
5711
|
-
var
|
5853
|
+
var import_errors24 = require("@fuel-ts/errors");
|
5712
5854
|
var import_utils40 = require("@fuel-ts/utils");
|
5713
5855
|
|
5714
5856
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -5719,11 +5861,12 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5719
5861
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
5720
5862
|
var import_address5 = require("@fuel-ts/address");
|
5721
5863
|
var import_crypto5 = require("@fuel-ts/crypto");
|
5722
|
-
var
|
5864
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5723
5865
|
var import_interfaces = require("@fuel-ts/interfaces");
|
5724
5866
|
var import_math22 = require("@fuel-ts/math");
|
5867
|
+
var import_transactions22 = require("@fuel-ts/transactions");
|
5725
5868
|
var import_utils33 = require("@fuel-ts/utils");
|
5726
|
-
var
|
5869
|
+
var import_ramda7 = require("ramda");
|
5727
5870
|
|
5728
5871
|
// src/providers/utils/merge-quantities.ts
|
5729
5872
|
var mergeQuantities = (...coinQuantities) => {
|
@@ -5812,7 +5955,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5812
5955
|
*/
|
5813
5956
|
get provider() {
|
5814
5957
|
if (!this._provider) {
|
5815
|
-
throw new
|
5958
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
5816
5959
|
}
|
5817
5960
|
return this._provider;
|
5818
5961
|
}
|
@@ -5930,7 +6073,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5930
6073
|
);
|
5931
6074
|
request.addResources(resources);
|
5932
6075
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5933
|
-
const requestToReestimate2 = (0,
|
6076
|
+
const requestToReestimate2 = (0, import_ramda7.clone)(request);
|
5934
6077
|
if (addedSignatures) {
|
5935
6078
|
Array.from({ length: addedSignatures }).forEach(
|
5936
6079
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -5945,7 +6088,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5945
6088
|
gasPrice
|
5946
6089
|
});
|
5947
6090
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5948
|
-
request.inputs,
|
6091
|
+
request.inputs.filter(isRequestInputResource),
|
5949
6092
|
baseAssetId,
|
5950
6093
|
baseAssetId
|
5951
6094
|
);
|
@@ -5963,13 +6106,13 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5963
6106
|
fundingAttempts += 1;
|
5964
6107
|
}
|
5965
6108
|
if (needsToBeFunded) {
|
5966
|
-
throw new
|
5967
|
-
|
6109
|
+
throw new import_errors19.FuelError(
|
6110
|
+
import_errors19.ErrorCode.NOT_ENOUGH_FUNDS,
|
5968
6111
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
5969
6112
|
);
|
5970
6113
|
}
|
5971
6114
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5972
|
-
const requestToReestimate = (0,
|
6115
|
+
const requestToReestimate = (0, import_ramda7.clone)(request);
|
5973
6116
|
if (addedSignatures) {
|
5974
6117
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5975
6118
|
}
|
@@ -6069,8 +6212,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6069
6212
|
*/
|
6070
6213
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
6071
6214
|
if ((0, import_math22.bn)(amount).lte(0)) {
|
6072
|
-
throw new
|
6073
|
-
|
6215
|
+
throw new import_errors19.FuelError(
|
6216
|
+
import_errors19.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6074
6217
|
"Transfer amount must be a positive number."
|
6075
6218
|
);
|
6076
6219
|
}
|
@@ -6145,16 +6288,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6145
6288
|
* @returns A promise that resolves to the transaction cost object.
|
6146
6289
|
*/
|
6147
6290
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
6148
|
-
const txRequestClone = (0,
|
6291
|
+
const txRequestClone = (0, import_ramda7.clone)(transactionRequestify(transactionRequestLike));
|
6149
6292
|
const baseAssetId = this.provider.getBaseAssetId();
|
6150
6293
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6151
6294
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6152
6295
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math22.bn)("100000000000000000") }];
|
6153
6296
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6154
|
-
if (
|
6297
|
+
if (input.type === import_transactions22.InputType.Coin) {
|
6155
6298
|
return input.assetId === assetId;
|
6156
6299
|
}
|
6157
|
-
if (
|
6300
|
+
if (isRequestInputMessageWithoutData(input)) {
|
6158
6301
|
return baseAssetId === assetId;
|
6159
6302
|
}
|
6160
6303
|
return false;
|
@@ -6196,7 +6339,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6196
6339
|
*/
|
6197
6340
|
async signMessage(message) {
|
6198
6341
|
if (!this._connector) {
|
6199
|
-
throw new
|
6342
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
6200
6343
|
}
|
6201
6344
|
return this._connector.signMessage(this.address.toString(), message);
|
6202
6345
|
}
|
@@ -6208,8 +6351,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6208
6351
|
*/
|
6209
6352
|
async signTransaction(transactionRequestLike) {
|
6210
6353
|
if (!this._connector) {
|
6211
|
-
throw new
|
6212
|
-
|
6354
|
+
throw new import_errors19.FuelError(
|
6355
|
+
import_errors19.ErrorCode.MISSING_CONNECTOR,
|
6213
6356
|
"A connector is required to sign transactions."
|
6214
6357
|
);
|
6215
6358
|
}
|
@@ -6268,8 +6411,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6268
6411
|
/** @hidden * */
|
6269
6412
|
validateTransferAmount(amount) {
|
6270
6413
|
if ((0, import_math22.bn)(amount).lte(0)) {
|
6271
|
-
throw new
|
6272
|
-
|
6414
|
+
throw new import_errors19.FuelError(
|
6415
|
+
import_errors19.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6273
6416
|
"Transfer amount must be a positive number."
|
6274
6417
|
);
|
6275
6418
|
}
|
@@ -6298,16 +6441,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6298
6441
|
if (!(0, import_utils33.isDefined)(setGasLimit)) {
|
6299
6442
|
request.gasLimit = gasUsed;
|
6300
6443
|
} else if (gasUsed.gt(setGasLimit)) {
|
6301
|
-
throw new
|
6302
|
-
|
6444
|
+
throw new import_errors19.FuelError(
|
6445
|
+
import_errors19.ErrorCode.GAS_LIMIT_TOO_LOW,
|
6303
6446
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6304
6447
|
);
|
6305
6448
|
}
|
6306
6449
|
if (!(0, import_utils33.isDefined)(setMaxFee)) {
|
6307
6450
|
request.maxFee = maxFee;
|
6308
6451
|
} else if (maxFee.gt(setMaxFee)) {
|
6309
|
-
throw new
|
6310
|
-
|
6452
|
+
throw new import_errors19.FuelError(
|
6453
|
+
import_errors19.ErrorCode.MAX_FEE_TOO_LOW,
|
6311
6454
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6312
6455
|
);
|
6313
6456
|
}
|
@@ -6318,7 +6461,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6318
6461
|
// src/wallet/keystore-wallet.ts
|
6319
6462
|
var import_address6 = require("@fuel-ts/address");
|
6320
6463
|
var import_crypto6 = require("@fuel-ts/crypto");
|
6321
|
-
var
|
6464
|
+
var import_errors20 = require("@fuel-ts/errors");
|
6322
6465
|
var import_utils34 = require("@fuel-ts/utils");
|
6323
6466
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6324
6467
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -6395,8 +6538,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6395
6538
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
6396
6539
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
6397
6540
|
if (mac !== macHash) {
|
6398
|
-
throw new
|
6399
|
-
|
6541
|
+
throw new import_errors20.FuelError(
|
6542
|
+
import_errors20.ErrorCode.INVALID_PASSWORD,
|
6400
6543
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6401
6544
|
);
|
6402
6545
|
}
|
@@ -6526,14 +6669,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6526
6669
|
|
6527
6670
|
// src/hdwallet/hdwallet.ts
|
6528
6671
|
var import_crypto8 = require("@fuel-ts/crypto");
|
6529
|
-
var
|
6672
|
+
var import_errors23 = require("@fuel-ts/errors");
|
6530
6673
|
var import_hasher6 = require("@fuel-ts/hasher");
|
6531
6674
|
var import_math23 = require("@fuel-ts/math");
|
6532
6675
|
var import_utils39 = require("@fuel-ts/utils");
|
6533
6676
|
|
6534
6677
|
// src/mnemonic/mnemonic.ts
|
6535
6678
|
var import_crypto7 = require("@fuel-ts/crypto");
|
6536
|
-
var
|
6679
|
+
var import_errors22 = require("@fuel-ts/errors");
|
6537
6680
|
var import_hasher5 = require("@fuel-ts/hasher");
|
6538
6681
|
var import_utils37 = require("@fuel-ts/utils");
|
6539
6682
|
|
@@ -8590,7 +8733,7 @@ var english = [
|
|
8590
8733
|
];
|
8591
8734
|
|
8592
8735
|
// src/mnemonic/utils.ts
|
8593
|
-
var
|
8736
|
+
var import_errors21 = require("@fuel-ts/errors");
|
8594
8737
|
var import_hasher4 = require("@fuel-ts/hasher");
|
8595
8738
|
var import_utils36 = require("@fuel-ts/utils");
|
8596
8739
|
function getLowerMask(bits) {
|
@@ -8639,8 +8782,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8639
8782
|
for (let i = 0; i < words.length; i += 1) {
|
8640
8783
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8641
8784
|
if (index === -1) {
|
8642
|
-
throw new
|
8643
|
-
|
8785
|
+
throw new import_errors21.FuelError(
|
8786
|
+
import_errors21.ErrorCode.INVALID_MNEMONIC,
|
8644
8787
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8645
8788
|
);
|
8646
8789
|
}
|
@@ -8656,8 +8799,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8656
8799
|
const checksumMask = getUpperMask(checksumBits);
|
8657
8800
|
const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8658
8801
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8659
|
-
throw new
|
8660
|
-
|
8802
|
+
throw new import_errors21.FuelError(
|
8803
|
+
import_errors21.ErrorCode.INVALID_CHECKSUM,
|
8661
8804
|
"Checksum validation failed for the provided mnemonic."
|
8662
8805
|
);
|
8663
8806
|
}
|
@@ -8671,16 +8814,16 @@ var TestnetPRV = "0x04358394";
|
|
8671
8814
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8672
8815
|
function assertWordList(wordlist) {
|
8673
8816
|
if (wordlist.length !== 2048) {
|
8674
|
-
throw new
|
8675
|
-
|
8817
|
+
throw new import_errors22.FuelError(
|
8818
|
+
import_errors22.ErrorCode.INVALID_WORD_LIST,
|
8676
8819
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8677
8820
|
);
|
8678
8821
|
}
|
8679
8822
|
}
|
8680
8823
|
function assertEntropy(entropy) {
|
8681
8824
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8682
|
-
throw new
|
8683
|
-
|
8825
|
+
throw new import_errors22.FuelError(
|
8826
|
+
import_errors22.ErrorCode.INVALID_ENTROPY,
|
8684
8827
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8685
8828
|
);
|
8686
8829
|
}
|
@@ -8690,7 +8833,7 @@ function assertMnemonic(words) {
|
|
8690
8833
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8691
8834
|
", "
|
8692
8835
|
)}] words, but got ${words.length}.`;
|
8693
|
-
throw new
|
8836
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
8694
8837
|
}
|
8695
8838
|
}
|
8696
8839
|
var Mnemonic = class {
|
@@ -8808,8 +8951,8 @@ var Mnemonic = class {
|
|
8808
8951
|
static masterKeysFromSeed(seed) {
|
8809
8952
|
const seedArray = (0, import_utils37.arrayify)(seed);
|
8810
8953
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8811
|
-
throw new
|
8812
|
-
|
8954
|
+
throw new import_errors22.FuelError(
|
8955
|
+
import_errors22.ErrorCode.INVALID_SEED,
|
8813
8956
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8814
8957
|
);
|
8815
8958
|
}
|
@@ -8886,7 +9029,7 @@ function isValidExtendedKey(extendedKey) {
|
|
8886
9029
|
function parsePath(path2, depth = 0) {
|
8887
9030
|
const components = path2.split("/");
|
8888
9031
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8889
|
-
throw new
|
9032
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
8890
9033
|
}
|
8891
9034
|
if (components[0] === "m") {
|
8892
9035
|
components.shift();
|
@@ -8915,8 +9058,8 @@ var HDWallet = class {
|
|
8915
9058
|
this.privateKey = (0, import_utils39.hexlify)(config.privateKey);
|
8916
9059
|
} else {
|
8917
9060
|
if (!config.publicKey) {
|
8918
|
-
throw new
|
8919
|
-
|
9061
|
+
throw new import_errors23.FuelError(
|
9062
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
8920
9063
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8921
9064
|
);
|
8922
9065
|
}
|
@@ -8945,8 +9088,8 @@ var HDWallet = class {
|
|
8945
9088
|
const data = new Uint8Array(37);
|
8946
9089
|
if (index & HARDENED_INDEX) {
|
8947
9090
|
if (!privateKey) {
|
8948
|
-
throw new
|
8949
|
-
|
9091
|
+
throw new import_errors23.FuelError(
|
9092
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
8950
9093
|
"Cannot derive a hardened index without a private Key."
|
8951
9094
|
);
|
8952
9095
|
}
|
@@ -8998,8 +9141,8 @@ var HDWallet = class {
|
|
8998
9141
|
*/
|
8999
9142
|
toExtendedKey(isPublic = false, testnet = false) {
|
9000
9143
|
if (this.depth >= 256) {
|
9001
|
-
throw new
|
9002
|
-
|
9144
|
+
throw new import_errors23.FuelError(
|
9145
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
9003
9146
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9004
9147
|
);
|
9005
9148
|
}
|
@@ -9030,10 +9173,10 @@ var HDWallet = class {
|
|
9030
9173
|
const bytes = (0, import_utils39.arrayify)(decoded);
|
9031
9174
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9032
9175
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
9033
|
-
throw new
|
9176
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
9034
9177
|
}
|
9035
9178
|
if (!validChecksum) {
|
9036
|
-
throw new
|
9179
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
9037
9180
|
}
|
9038
9181
|
const depth = bytes[4];
|
9039
9182
|
const parentFingerprint = (0, import_utils39.hexlify)(bytes.slice(5, 9));
|
@@ -9041,14 +9184,14 @@ var HDWallet = class {
|
|
9041
9184
|
const chainCode = (0, import_utils39.hexlify)(bytes.slice(13, 45));
|
9042
9185
|
const key = bytes.slice(45, 78);
|
9043
9186
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
9044
|
-
throw new
|
9045
|
-
|
9187
|
+
throw new import_errors23.FuelError(
|
9188
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
9046
9189
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
9047
9190
|
);
|
9048
9191
|
}
|
9049
9192
|
if (isPublicExtendedKey(bytes)) {
|
9050
9193
|
if (key[0] !== 3) {
|
9051
|
-
throw new
|
9194
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
9052
9195
|
}
|
9053
9196
|
return new HDWallet({
|
9054
9197
|
publicKey: key,
|
@@ -9059,7 +9202,7 @@ var HDWallet = class {
|
|
9059
9202
|
});
|
9060
9203
|
}
|
9061
9204
|
if (key[0] !== 0) {
|
9062
|
-
throw new
|
9205
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
9063
9206
|
}
|
9064
9207
|
return new HDWallet({
|
9065
9208
|
privateKey: key.slice(1),
|
@@ -9303,26 +9446,26 @@ var WalletsConfig = class {
|
|
9303
9446
|
amountPerCoin
|
9304
9447
|
}) {
|
9305
9448
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
9306
|
-
throw new
|
9307
|
-
|
9449
|
+
throw new import_errors24.FuelError(
|
9450
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9308
9451
|
"Number of wallets must be greater than zero."
|
9309
9452
|
);
|
9310
9453
|
}
|
9311
9454
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
9312
|
-
throw new
|
9313
|
-
|
9455
|
+
throw new import_errors24.FuelError(
|
9456
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9314
9457
|
"Number of assets per wallet must be greater than zero."
|
9315
9458
|
);
|
9316
9459
|
}
|
9317
9460
|
if (coinsPerAsset <= 0) {
|
9318
|
-
throw new
|
9319
|
-
|
9461
|
+
throw new import_errors24.FuelError(
|
9462
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9320
9463
|
"Number of coins per asset must be greater than zero."
|
9321
9464
|
);
|
9322
9465
|
}
|
9323
9466
|
if (amountPerCoin < 0) {
|
9324
|
-
throw new
|
9325
|
-
|
9467
|
+
throw new import_errors24.FuelError(
|
9468
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9326
9469
|
"Amount per coin must be greater than or equal to zero."
|
9327
9470
|
);
|
9328
9471
|
}
|
@@ -9354,7 +9497,7 @@ async function setupTestProviderAndWallets({
|
|
9354
9497
|
const launchNodeOptions = {
|
9355
9498
|
loggingEnabled: false,
|
9356
9499
|
...nodeOptions,
|
9357
|
-
snapshotConfig: (0,
|
9500
|
+
snapshotConfig: (0, import_ramda8.mergeDeepRight)(
|
9358
9501
|
import_utils41.defaultSnapshotConfigs,
|
9359
9502
|
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
9360
9503
|
),
|