@fuel-ts/account 0.94.3 → 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.map +1 -1
- package/dist/index.global.js +352 -268
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +307 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -167
- 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 +196 -118
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +262 -134
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +260 -132
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -311,20 +311,14 @@ var launchNode = async ({
|
|
311
311
|
const rows = text.split("\n");
|
312
312
|
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
313
313
|
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
snapshotDir: snapshotDirToUse,
|
323
|
-
pid: child.pid
|
324
|
-
})
|
325
|
-
),
|
326
|
-
500
|
327
|
-
);
|
314
|
+
resolve({
|
315
|
+
cleanup,
|
316
|
+
ip: realIp,
|
317
|
+
port: realPort,
|
318
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
319
|
+
snapshotDir: snapshotDirToUse,
|
320
|
+
pid: child.pid
|
321
|
+
});
|
328
322
|
}
|
329
323
|
if (/error/i.test(text)) {
|
330
324
|
console.log(text);
|
@@ -382,14 +376,15 @@ var addAmountToCoinQuantities = (params) => {
|
|
382
376
|
|
383
377
|
// src/providers/provider.ts
|
384
378
|
import { Address as Address3 } from "@fuel-ts/address";
|
385
|
-
import { ErrorCode as
|
379
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError16 } from "@fuel-ts/errors";
|
386
380
|
import { BN as BN2, bn as bn17 } from "@fuel-ts/math";
|
387
381
|
import { InputType as InputType7, InputMessageCoder, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
388
382
|
import { arrayify as arrayify12, hexlify as hexlify14, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
389
383
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
390
384
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
391
385
|
import { GraphQLClient } from "graphql-request";
|
392
|
-
import
|
386
|
+
import gql2 from "graphql-tag";
|
387
|
+
import { clone as clone6 } from "ramda";
|
393
388
|
|
394
389
|
// src/providers/__generated__/operations.ts
|
395
390
|
import gql from "graphql-tag";
|
@@ -722,6 +717,14 @@ var BlockFragmentDoc = gql`
|
|
722
717
|
height
|
723
718
|
header {
|
724
719
|
time
|
720
|
+
daHeight
|
721
|
+
stateTransitionBytecodeVersion
|
722
|
+
transactionsCount
|
723
|
+
transactionsRoot
|
724
|
+
messageOutboxRoot
|
725
|
+
eventInboxRoot
|
726
|
+
prevRoot
|
727
|
+
applicationHash
|
725
728
|
}
|
726
729
|
transactions {
|
727
730
|
id
|
@@ -1716,6 +1719,9 @@ import {
|
|
1716
1719
|
} from "@fuel-ts/transactions";
|
1717
1720
|
import { concat as concat2, hexlify as hexlify9, isDefined } from "@fuel-ts/utils";
|
1718
1721
|
|
1722
|
+
// src/providers/message.ts
|
1723
|
+
var isMessageCoin = (message) => !("data" in message);
|
1724
|
+
|
1719
1725
|
// src/providers/resource.ts
|
1720
1726
|
var isCoin = (resource) => "id" in resource;
|
1721
1727
|
|
@@ -2103,20 +2109,22 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2103
2109
|
let reason = "";
|
2104
2110
|
if (revertReceipt) {
|
2105
2111
|
const reasonHex = bn6(revertReceipt.val).toHex();
|
2112
|
+
const lastLog = logs[logs.length - 1];
|
2113
|
+
const lastButOneLog = logs[logs.length - 2];
|
2106
2114
|
switch (reasonHex) {
|
2107
2115
|
case FAILED_REQUIRE_SIGNAL: {
|
2108
2116
|
reason = "require";
|
2109
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(
|
2117
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2110
2118
|
break;
|
2111
2119
|
}
|
2112
2120
|
case FAILED_ASSERT_EQ_SIGNAL: {
|
2113
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2121
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2114
2122
|
reason = "assert_eq";
|
2115
2123
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
2116
2124
|
break;
|
2117
2125
|
}
|
2118
2126
|
case FAILED_ASSERT_NE_SIGNAL: {
|
2119
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2127
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2120
2128
|
reason = "assert_ne";
|
2121
2129
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
2122
2130
|
break;
|
@@ -2177,7 +2185,9 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
2177
2185
|
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
2178
2186
|
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2179
2187
|
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2180
|
-
var
|
2188
|
+
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
2189
|
+
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2190
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2181
2191
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2182
2192
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2183
2193
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
@@ -2473,7 +2483,7 @@ var BaseTransactionRequest = class {
|
|
2473
2483
|
* @param message - Message resource.
|
2474
2484
|
*/
|
2475
2485
|
addMessageInput(message) {
|
2476
|
-
const { recipient, sender, amount, predicate, nonce,
|
2486
|
+
const { recipient, sender, amount, predicate, nonce, predicateData } = message;
|
2477
2487
|
let witnessIndex;
|
2478
2488
|
if (message.predicate) {
|
2479
2489
|
witnessIndex = 0;
|
@@ -2488,13 +2498,16 @@ var BaseTransactionRequest = class {
|
|
2488
2498
|
type: InputType3.Message,
|
2489
2499
|
sender: sender.toB256(),
|
2490
2500
|
recipient: recipient.toB256(),
|
2501
|
+
data: isMessageCoin(message) ? "0x" : message.data,
|
2491
2502
|
amount,
|
2492
2503
|
witnessIndex,
|
2493
2504
|
predicate,
|
2494
2505
|
predicateData
|
2495
2506
|
};
|
2496
2507
|
this.pushInput(input);
|
2497
|
-
|
2508
|
+
if (isMessageCoin(message)) {
|
2509
|
+
this.addChangeOutput(recipient, message.assetId);
|
2510
|
+
}
|
2498
2511
|
}
|
2499
2512
|
/**
|
2500
2513
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2626,6 +2639,8 @@ var BaseTransactionRequest = class {
|
|
2626
2639
|
*
|
2627
2640
|
* @param quantities - CoinQuantity Array.
|
2628
2641
|
* @param baseAssetId - The base asset to fund the transaction.
|
2642
|
+
* @deprecated - This method is deprecated and will be removed in future versions.
|
2643
|
+
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
2629
2644
|
*/
|
2630
2645
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2631
2646
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2694,7 +2709,7 @@ var BaseTransactionRequest = class {
|
|
2694
2709
|
});
|
2695
2710
|
}
|
2696
2711
|
updatePredicateGasUsed(inputs) {
|
2697
|
-
const inputsToExtractGasUsed = inputs.filter(
|
2712
|
+
const inputsToExtractGasUsed = inputs.filter(isRequestInputCoinOrMessage);
|
2698
2713
|
this.inputs.filter(isRequestInputResource).forEach((i) => {
|
2699
2714
|
const owner = getRequestInputResourceOwner(i);
|
2700
2715
|
const correspondingInput = inputsToExtractGasUsed.find(
|
@@ -2710,6 +2725,9 @@ var BaseTransactionRequest = class {
|
|
2710
2725
|
}
|
2711
2726
|
};
|
2712
2727
|
|
2728
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2729
|
+
import { clone as clone3 } from "ramda";
|
2730
|
+
|
2713
2731
|
// src/providers/transaction-request/hash-transaction.ts
|
2714
2732
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2715
2733
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
@@ -2784,10 +2802,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2784
2802
|
// src/providers/transaction-request/blob-transaction-request.ts
|
2785
2803
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2786
2804
|
static from(obj) {
|
2787
|
-
|
2788
|
-
return obj;
|
2789
|
-
}
|
2790
|
-
return new this(obj);
|
2805
|
+
return new this(clone3(obj));
|
2791
2806
|
}
|
2792
2807
|
/** Type of the transaction */
|
2793
2808
|
type = TransactionType.Blob;
|
@@ -2850,6 +2865,7 @@ import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
|
2850
2865
|
import { bn as bn10 } from "@fuel-ts/math";
|
2851
2866
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2852
2867
|
import { arrayify as arrayify7, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2868
|
+
import { clone as clone4 } from "ramda";
|
2853
2869
|
|
2854
2870
|
// src/providers/transaction-request/storage-slot.ts
|
2855
2871
|
import { arrayify as arrayify6, hexlify as hexlify10 } from "@fuel-ts/utils";
|
@@ -2877,10 +2893,7 @@ var storageSlotify = (storageSlot) => {
|
|
2877
2893
|
// src/providers/transaction-request/create-transaction-request.ts
|
2878
2894
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
2879
2895
|
static from(obj) {
|
2880
|
-
|
2881
|
-
return obj;
|
2882
|
-
}
|
2883
|
-
return new this(obj);
|
2896
|
+
return new this(clone4(obj));
|
2884
2897
|
}
|
2885
2898
|
/** Type of the transaction */
|
2886
2899
|
type = TransactionType3.Create;
|
@@ -2969,6 +2982,7 @@ import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
|
2969
2982
|
import { bn as bn11 } from "@fuel-ts/math";
|
2970
2983
|
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2971
2984
|
import { arrayify as arrayify9, hexlify as hexlify12 } from "@fuel-ts/utils";
|
2985
|
+
import { clone as clone5 } from "ramda";
|
2972
2986
|
|
2973
2987
|
// src/providers/transaction-request/scripts.ts
|
2974
2988
|
import { arrayify as arrayify8 } from "@fuel-ts/utils";
|
@@ -2999,10 +3013,7 @@ var withdrawScript = {
|
|
2999
3013
|
// src/providers/transaction-request/script-transaction-request.ts
|
3000
3014
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3001
3015
|
static from(obj) {
|
3002
|
-
|
3003
|
-
return obj;
|
3004
|
-
}
|
3005
|
-
return new this(obj);
|
3016
|
+
return new this(clone5(obj));
|
3006
3017
|
}
|
3007
3018
|
/** Type of the transaction */
|
3008
3019
|
type = TransactionType4.Script;
|
@@ -4308,6 +4319,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4308
4319
|
};
|
4309
4320
|
}
|
4310
4321
|
|
4322
|
+
// src/providers/utils/handle-gql-error-message.ts
|
4323
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4324
|
+
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4325
|
+
switch (errorMessage) {
|
4326
|
+
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4327
|
+
throw new FuelError15(
|
4328
|
+
ErrorCode13.NOT_ENOUGH_FUNDS,
|
4329
|
+
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4330
|
+
{},
|
4331
|
+
rawError
|
4332
|
+
);
|
4333
|
+
default:
|
4334
|
+
throw new FuelError15(ErrorCode13.INVALID_REQUEST, errorMessage);
|
4335
|
+
}
|
4336
|
+
};
|
4337
|
+
|
4311
4338
|
// src/providers/provider.ts
|
4312
4339
|
var MAX_RETRIES = 10;
|
4313
4340
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4434,6 +4461,17 @@ var _Provider = class {
|
|
4434
4461
|
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
4435
4462
|
}, retryOptions);
|
4436
4463
|
}
|
4464
|
+
static extractBasicAuth(url) {
|
4465
|
+
const parsedUrl = new URL(url);
|
4466
|
+
const username = parsedUrl.username;
|
4467
|
+
const password = parsedUrl.password;
|
4468
|
+
const urlNoBasicAuth = `${parsedUrl.origin}${parsedUrl.pathname}`;
|
4469
|
+
if (!(username && password)) {
|
4470
|
+
return { url, auth: void 0 };
|
4471
|
+
}
|
4472
|
+
const auth = `Basic ${btoa(`${username}:${password}`)}`;
|
4473
|
+
return { url: urlNoBasicAuth, auth };
|
4474
|
+
}
|
4437
4475
|
/**
|
4438
4476
|
* Creates a new instance of the Provider class. This is the recommended way to initialize a Provider.
|
4439
4477
|
*
|
@@ -4443,7 +4481,17 @@ var _Provider = class {
|
|
4443
4481
|
* @returns A promise that resolves to a Provider instance.
|
4444
4482
|
*/
|
4445
4483
|
static async create(url, options = {}) {
|
4446
|
-
const
|
4484
|
+
const { url: urlToUse, auth } = this.extractBasicAuth(url);
|
4485
|
+
const provider = new _Provider(urlToUse, {
|
4486
|
+
...options,
|
4487
|
+
requestMiddleware: async (request) => {
|
4488
|
+
if (auth) {
|
4489
|
+
request.headers ??= {};
|
4490
|
+
request.headers.Authorization = auth;
|
4491
|
+
}
|
4492
|
+
return options.requestMiddleware?.(request) ?? request;
|
4493
|
+
}
|
4494
|
+
});
|
4447
4495
|
await provider.fetchChainAndNodeInfo();
|
4448
4496
|
return provider;
|
4449
4497
|
}
|
@@ -4455,8 +4503,8 @@ var _Provider = class {
|
|
4455
4503
|
getChain() {
|
4456
4504
|
const chain = _Provider.chainInfoCache[this.url];
|
4457
4505
|
if (!chain) {
|
4458
|
-
throw new
|
4459
|
-
|
4506
|
+
throw new FuelError16(
|
4507
|
+
ErrorCode14.CHAIN_INFO_CACHE_EMPTY,
|
4460
4508
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4461
4509
|
);
|
4462
4510
|
}
|
@@ -4470,8 +4518,8 @@ var _Provider = class {
|
|
4470
4518
|
getNode() {
|
4471
4519
|
const node = _Provider.nodeInfoCache[this.url];
|
4472
4520
|
if (!node) {
|
4473
|
-
throw new
|
4474
|
-
|
4521
|
+
throw new FuelError16(
|
4522
|
+
ErrorCode14.NODE_INFO_CACHE_EMPTY,
|
4475
4523
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4476
4524
|
);
|
4477
4525
|
}
|
@@ -4549,10 +4597,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4549
4597
|
if ("response" in response) {
|
4550
4598
|
const graphQlResponse = response.response;
|
4551
4599
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4552
|
-
|
4553
|
-
|
4554
|
-
|
4555
|
-
);
|
4600
|
+
for (const error of graphQlResponse.errors) {
|
4601
|
+
handleGqlErrorMessage(error.message, error);
|
4602
|
+
}
|
4556
4603
|
}
|
4557
4604
|
}
|
4558
4605
|
}
|
@@ -4570,7 +4617,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4570
4617
|
}
|
4571
4618
|
return gqlClient.request(query, vars);
|
4572
4619
|
};
|
4573
|
-
|
4620
|
+
const customOperations = (requester) => ({
|
4621
|
+
getBlobs(variables) {
|
4622
|
+
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
4623
|
+
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
4624
|
+
const updatedVariables = variables.blobIds.reduce(
|
4625
|
+
(acc, blobId, i) => {
|
4626
|
+
acc[`blobId${i}`] = blobId;
|
4627
|
+
return acc;
|
4628
|
+
},
|
4629
|
+
{}
|
4630
|
+
);
|
4631
|
+
const document = gql2`
|
4632
|
+
query getBlobs(${queryParams}) {
|
4633
|
+
${blobParams}
|
4634
|
+
}
|
4635
|
+
`;
|
4636
|
+
return requester(document, updatedVariables);
|
4637
|
+
}
|
4638
|
+
});
|
4639
|
+
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
4574
4640
|
}
|
4575
4641
|
/**
|
4576
4642
|
* Returns the version of the connected node.
|
@@ -4645,14 +4711,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4645
4711
|
validateTransaction(tx, consensusParameters) {
|
4646
4712
|
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4647
4713
|
if (bn17(tx.inputs.length).gt(maxInputs)) {
|
4648
|
-
throw new
|
4649
|
-
|
4714
|
+
throw new FuelError16(
|
4715
|
+
ErrorCode14.MAX_INPUTS_EXCEEDED,
|
4650
4716
|
"The transaction exceeds the maximum allowed number of inputs."
|
4651
4717
|
);
|
4652
4718
|
}
|
4653
4719
|
if (bn17(tx.outputs.length).gt(maxOutputs)) {
|
4654
|
-
throw new
|
4655
|
-
|
4720
|
+
throw new FuelError16(
|
4721
|
+
ErrorCode14.MAX_OUTPUTS_EXCEEDED,
|
4656
4722
|
"The transaction exceeds the maximum allowed number of outputs."
|
4657
4723
|
);
|
4658
4724
|
}
|
@@ -4813,7 +4879,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4813
4879
|
missingContractIds: [],
|
4814
4880
|
dryRunStatus: void 0
|
4815
4881
|
}));
|
4816
|
-
const allRequests =
|
4882
|
+
const allRequests = clone6(transactionRequests);
|
4817
4883
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4818
4884
|
allRequests.forEach((req, index) => {
|
4819
4885
|
if (isTransactionTypeScript(req)) {
|
@@ -4973,13 +5039,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4973
5039
|
* @returns A promise that resolves to the transaction cost object.
|
4974
5040
|
*/
|
4975
5041
|
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4976
|
-
const txRequestClone =
|
5042
|
+
const txRequestClone = clone6(transactionRequestify(transactionRequestLike));
|
4977
5043
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4978
5044
|
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4979
5045
|
if (isScriptTransaction) {
|
4980
5046
|
txRequestClone.gasLimit = bn17(0);
|
4981
5047
|
}
|
4982
|
-
const signedRequest =
|
5048
|
+
const signedRequest = clone6(txRequestClone);
|
4983
5049
|
let addedSignatures = 0;
|
4984
5050
|
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
4985
5051
|
const lengthBefore = signedRequest.witnesses.length;
|
@@ -5117,6 +5183,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5117
5183
|
}).filter((v) => !!v);
|
5118
5184
|
return coins;
|
5119
5185
|
}
|
5186
|
+
/**
|
5187
|
+
* Returns an array of blobIds that exist on chain, for a given array of blobIds.
|
5188
|
+
*
|
5189
|
+
* @param blobIds - blobIds to check.
|
5190
|
+
* @returns - A promise that resolves to an array of blobIds that exist on chain.
|
5191
|
+
*/
|
5192
|
+
async getBlobs(blobIds) {
|
5193
|
+
const res = await this.operations.getBlobs({ blobIds });
|
5194
|
+
const blobs = [];
|
5195
|
+
Object.keys(res).forEach((key) => {
|
5196
|
+
const val = res[key];
|
5197
|
+
blobs.push(val?.id ?? null);
|
5198
|
+
});
|
5199
|
+
return blobs.filter((v) => v);
|
5200
|
+
}
|
5120
5201
|
/**
|
5121
5202
|
* Returns block matching the given ID or height.
|
5122
5203
|
*
|
@@ -5138,11 +5219,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5138
5219
|
if (!block) {
|
5139
5220
|
return null;
|
5140
5221
|
}
|
5222
|
+
const { header, height, id, transactions } = block;
|
5141
5223
|
return {
|
5142
|
-
id
|
5143
|
-
height: bn17(
|
5144
|
-
time:
|
5145
|
-
|
5224
|
+
id,
|
5225
|
+
height: bn17(height),
|
5226
|
+
time: header.time,
|
5227
|
+
header: {
|
5228
|
+
applicationHash: header.applicationHash,
|
5229
|
+
daHeight: bn17(header.daHeight),
|
5230
|
+
eventInboxRoot: header.eventInboxRoot,
|
5231
|
+
messageOutboxRoot: header.messageOutboxRoot,
|
5232
|
+
prevRoot: header.prevRoot,
|
5233
|
+
stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
|
5234
|
+
transactionsCount: header.transactionsCount,
|
5235
|
+
transactionsRoot: header.transactionsRoot
|
5236
|
+
},
|
5237
|
+
transactionIds: transactions.map((tx) => tx.id)
|
5146
5238
|
};
|
5147
5239
|
}
|
5148
5240
|
/**
|
@@ -5164,6 +5256,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5164
5256
|
id: block.id,
|
5165
5257
|
height: bn17(block.height),
|
5166
5258
|
time: block.header.time,
|
5259
|
+
header: {
|
5260
|
+
applicationHash: block.header.applicationHash,
|
5261
|
+
daHeight: bn17(block.header.daHeight),
|
5262
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5263
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5264
|
+
prevRoot: block.header.prevRoot,
|
5265
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5266
|
+
transactionsCount: block.header.transactionsCount,
|
5267
|
+
transactionsRoot: block.header.transactionsRoot
|
5268
|
+
},
|
5167
5269
|
transactionIds: block.transactions.map((tx) => tx.id)
|
5168
5270
|
}));
|
5169
5271
|
return { blocks, pageInfo };
|
@@ -5191,6 +5293,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5191
5293
|
id: block.id,
|
5192
5294
|
height: bn17(block.height, 10),
|
5193
5295
|
time: block.header.time,
|
5296
|
+
header: {
|
5297
|
+
applicationHash: block.header.applicationHash,
|
5298
|
+
daHeight: bn17(block.header.daHeight),
|
5299
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5300
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5301
|
+
prevRoot: block.header.prevRoot,
|
5302
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5303
|
+
transactionsCount: block.header.transactionsCount,
|
5304
|
+
transactionsRoot: block.header.transactionsRoot
|
5305
|
+
},
|
5194
5306
|
transactionIds: block.transactions.map((tx) => tx.id),
|
5195
5307
|
transactions: block.transactions.map(
|
5196
5308
|
(tx) => new TransactionCoder5().decode(arrayify12(tx.rawPayload), 0)?.[0]
|
@@ -5214,7 +5326,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5214
5326
|
0
|
5215
5327
|
)?.[0];
|
5216
5328
|
} catch (error) {
|
5217
|
-
if (error instanceof
|
5329
|
+
if (error instanceof FuelError16 && error.code === ErrorCode14.UNSUPPORTED_TRANSACTION_TYPE) {
|
5218
5330
|
console.warn("Unsupported transaction type encountered");
|
5219
5331
|
return null;
|
5220
5332
|
}
|
@@ -5235,7 +5347,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5235
5347
|
try {
|
5236
5348
|
return coder.decode(arrayify12(rawPayload), 0)[0];
|
5237
5349
|
} catch (error) {
|
5238
|
-
if (error instanceof
|
5350
|
+
if (error instanceof FuelError16 && error.code === ErrorCode14.UNSUPPORTED_TRANSACTION_TYPE) {
|
5239
5351
|
console.warn("Unsupported transaction type encountered");
|
5240
5352
|
return null;
|
5241
5353
|
}
|
@@ -5361,8 +5473,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5361
5473
|
nonce
|
5362
5474
|
};
|
5363
5475
|
if (commitBlockId && commitBlockHeight) {
|
5364
|
-
throw new
|
5365
|
-
|
5476
|
+
throw new FuelError16(
|
5477
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5366
5478
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5367
5479
|
);
|
5368
5480
|
}
|
@@ -5502,10 +5614,25 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5502
5614
|
* @returns A promise that resolves to the Message object or null.
|
5503
5615
|
*/
|
5504
5616
|
async getMessageByNonce(nonce) {
|
5505
|
-
const { message } = await this.operations.getMessageByNonce({ nonce });
|
5506
|
-
if (!
|
5617
|
+
const { message: rawMessage } = await this.operations.getMessageByNonce({ nonce });
|
5618
|
+
if (!rawMessage) {
|
5507
5619
|
return null;
|
5508
5620
|
}
|
5621
|
+
const message = {
|
5622
|
+
messageId: InputMessageCoder.getMessageId({
|
5623
|
+
sender: rawMessage.sender,
|
5624
|
+
recipient: rawMessage.recipient,
|
5625
|
+
nonce: rawMessage.nonce,
|
5626
|
+
amount: bn17(rawMessage.amount),
|
5627
|
+
data: rawMessage.data
|
5628
|
+
}),
|
5629
|
+
sender: Address3.fromAddressOrString(rawMessage.sender),
|
5630
|
+
recipient: Address3.fromAddressOrString(rawMessage.recipient),
|
5631
|
+
nonce: rawMessage.nonce,
|
5632
|
+
amount: bn17(rawMessage.amount),
|
5633
|
+
data: InputMessageCoder.decodeData(rawMessage.data),
|
5634
|
+
daHeight: bn17(rawMessage.daHeight)
|
5635
|
+
};
|
5509
5636
|
return message;
|
5510
5637
|
}
|
5511
5638
|
/**
|
@@ -5530,26 +5657,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5530
5657
|
const { paginationLimit, inputArgs = {} } = params;
|
5531
5658
|
const { first, last, after, before } = inputArgs;
|
5532
5659
|
if (after && before) {
|
5533
|
-
throw new
|
5534
|
-
|
5660
|
+
throw new FuelError16(
|
5661
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5535
5662
|
'Pagination arguments "after" and "before" cannot be used together'
|
5536
5663
|
);
|
5537
5664
|
}
|
5538
5665
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5539
|
-
throw new
|
5540
|
-
|
5666
|
+
throw new FuelError16(
|
5667
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5541
5668
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5542
5669
|
);
|
5543
5670
|
}
|
5544
5671
|
if (first && before) {
|
5545
|
-
throw new
|
5546
|
-
|
5672
|
+
throw new FuelError16(
|
5673
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5547
5674
|
'The use of pagination argument "first" with "before" is not supported'
|
5548
5675
|
);
|
5549
5676
|
}
|
5550
5677
|
if (last && after) {
|
5551
|
-
throw new
|
5552
|
-
|
5678
|
+
throw new FuelError16(
|
5679
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5553
5680
|
'The use of pagination argument "last" with "after" is not supported'
|
5554
5681
|
);
|
5555
5682
|
}
|
@@ -5603,7 +5730,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5603
5730
|
__publicField(Provider, "nodeInfoCache", {});
|
5604
5731
|
|
5605
5732
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5606
|
-
import { ErrorCode as
|
5733
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5607
5734
|
import { bn as bn18 } from "@fuel-ts/math";
|
5608
5735
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
5609
5736
|
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
@@ -5704,7 +5831,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
5704
5831
|
|
5705
5832
|
// src/test-utils/wallet-config.ts
|
5706
5833
|
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
5707
|
-
import { FuelError as
|
5834
|
+
import { FuelError as FuelError23 } from "@fuel-ts/errors";
|
5708
5835
|
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify21 } from "@fuel-ts/utils";
|
5709
5836
|
|
5710
5837
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -5715,11 +5842,12 @@ import { hexlify as hexlify18 } from "@fuel-ts/utils";
|
|
5715
5842
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
5716
5843
|
import { Address as Address4 } from "@fuel-ts/address";
|
5717
5844
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
5718
|
-
import { ErrorCode as
|
5845
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5719
5846
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
5720
5847
|
import { bn as bn19 } from "@fuel-ts/math";
|
5848
|
+
import { InputType as InputType8 } from "@fuel-ts/transactions";
|
5721
5849
|
import { arrayify as arrayify15, hexlify as hexlify16, isDefined as isDefined3 } from "@fuel-ts/utils";
|
5722
|
-
import { clone as
|
5850
|
+
import { clone as clone7 } from "ramda";
|
5723
5851
|
|
5724
5852
|
// src/providers/utils/merge-quantities.ts
|
5725
5853
|
var mergeQuantities = (...coinQuantities) => {
|
@@ -5808,7 +5936,7 @@ var Account = class extends AbstractAccount {
|
|
5808
5936
|
*/
|
5809
5937
|
get provider() {
|
5810
5938
|
if (!this._provider) {
|
5811
|
-
throw new
|
5939
|
+
throw new FuelError18(ErrorCode16.MISSING_PROVIDER, "Provider not set");
|
5812
5940
|
}
|
5813
5941
|
return this._provider;
|
5814
5942
|
}
|
@@ -5926,7 +6054,7 @@ var Account = class extends AbstractAccount {
|
|
5926
6054
|
);
|
5927
6055
|
request.addResources(resources);
|
5928
6056
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5929
|
-
const requestToReestimate2 =
|
6057
|
+
const requestToReestimate2 = clone7(request);
|
5930
6058
|
if (addedSignatures) {
|
5931
6059
|
Array.from({ length: addedSignatures }).forEach(
|
5932
6060
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -5941,7 +6069,7 @@ var Account = class extends AbstractAccount {
|
|
5941
6069
|
gasPrice
|
5942
6070
|
});
|
5943
6071
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5944
|
-
request.inputs,
|
6072
|
+
request.inputs.filter(isRequestInputResource),
|
5945
6073
|
baseAssetId,
|
5946
6074
|
baseAssetId
|
5947
6075
|
);
|
@@ -5959,13 +6087,13 @@ var Account = class extends AbstractAccount {
|
|
5959
6087
|
fundingAttempts += 1;
|
5960
6088
|
}
|
5961
6089
|
if (needsToBeFunded) {
|
5962
|
-
throw new
|
5963
|
-
|
6090
|
+
throw new FuelError18(
|
6091
|
+
ErrorCode16.NOT_ENOUGH_FUNDS,
|
5964
6092
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
5965
6093
|
);
|
5966
6094
|
}
|
5967
6095
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5968
|
-
const requestToReestimate =
|
6096
|
+
const requestToReestimate = clone7(request);
|
5969
6097
|
if (addedSignatures) {
|
5970
6098
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5971
6099
|
}
|
@@ -6065,8 +6193,8 @@ var Account = class extends AbstractAccount {
|
|
6065
6193
|
*/
|
6066
6194
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
6067
6195
|
if (bn19(amount).lte(0)) {
|
6068
|
-
throw new
|
6069
|
-
|
6196
|
+
throw new FuelError18(
|
6197
|
+
ErrorCode16.INVALID_TRANSFER_AMOUNT,
|
6070
6198
|
"Transfer amount must be a positive number."
|
6071
6199
|
);
|
6072
6200
|
}
|
@@ -6141,16 +6269,16 @@ var Account = class extends AbstractAccount {
|
|
6141
6269
|
* @returns A promise that resolves to the transaction cost object.
|
6142
6270
|
*/
|
6143
6271
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
6144
|
-
const txRequestClone =
|
6272
|
+
const txRequestClone = clone7(transactionRequestify(transactionRequestLike));
|
6145
6273
|
const baseAssetId = this.provider.getBaseAssetId();
|
6146
6274
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6147
6275
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6148
6276
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn19("100000000000000000") }];
|
6149
6277
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6150
|
-
if (
|
6278
|
+
if (input.type === InputType8.Coin) {
|
6151
6279
|
return input.assetId === assetId;
|
6152
6280
|
}
|
6153
|
-
if (
|
6281
|
+
if (isRequestInputMessageWithoutData(input)) {
|
6154
6282
|
return baseAssetId === assetId;
|
6155
6283
|
}
|
6156
6284
|
return false;
|
@@ -6192,7 +6320,7 @@ var Account = class extends AbstractAccount {
|
|
6192
6320
|
*/
|
6193
6321
|
async signMessage(message) {
|
6194
6322
|
if (!this._connector) {
|
6195
|
-
throw new
|
6323
|
+
throw new FuelError18(ErrorCode16.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
6196
6324
|
}
|
6197
6325
|
return this._connector.signMessage(this.address.toString(), message);
|
6198
6326
|
}
|
@@ -6204,8 +6332,8 @@ var Account = class extends AbstractAccount {
|
|
6204
6332
|
*/
|
6205
6333
|
async signTransaction(transactionRequestLike) {
|
6206
6334
|
if (!this._connector) {
|
6207
|
-
throw new
|
6208
|
-
|
6335
|
+
throw new FuelError18(
|
6336
|
+
ErrorCode16.MISSING_CONNECTOR,
|
6209
6337
|
"A connector is required to sign transactions."
|
6210
6338
|
);
|
6211
6339
|
}
|
@@ -6264,8 +6392,8 @@ var Account = class extends AbstractAccount {
|
|
6264
6392
|
/** @hidden * */
|
6265
6393
|
validateTransferAmount(amount) {
|
6266
6394
|
if (bn19(amount).lte(0)) {
|
6267
|
-
throw new
|
6268
|
-
|
6395
|
+
throw new FuelError18(
|
6396
|
+
ErrorCode16.INVALID_TRANSFER_AMOUNT,
|
6269
6397
|
"Transfer amount must be a positive number."
|
6270
6398
|
);
|
6271
6399
|
}
|
@@ -6294,16 +6422,16 @@ var Account = class extends AbstractAccount {
|
|
6294
6422
|
if (!isDefined3(setGasLimit)) {
|
6295
6423
|
request.gasLimit = gasUsed;
|
6296
6424
|
} else if (gasUsed.gt(setGasLimit)) {
|
6297
|
-
throw new
|
6298
|
-
|
6425
|
+
throw new FuelError18(
|
6426
|
+
ErrorCode16.GAS_LIMIT_TOO_LOW,
|
6299
6427
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6300
6428
|
);
|
6301
6429
|
}
|
6302
6430
|
if (!isDefined3(setMaxFee)) {
|
6303
6431
|
request.maxFee = maxFee;
|
6304
6432
|
} else if (maxFee.gt(setMaxFee)) {
|
6305
|
-
throw new
|
6306
|
-
|
6433
|
+
throw new FuelError18(
|
6434
|
+
ErrorCode16.MAX_FEE_TOO_LOW,
|
6307
6435
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6308
6436
|
);
|
6309
6437
|
}
|
@@ -6323,7 +6451,7 @@ import {
|
|
6323
6451
|
encryptJsonWalletData,
|
6324
6452
|
randomUUID as randomUUID2
|
6325
6453
|
} from "@fuel-ts/crypto";
|
6326
|
-
import { ErrorCode as
|
6454
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError19 } from "@fuel-ts/errors";
|
6327
6455
|
import { hexlify as hexlify17 } from "@fuel-ts/utils";
|
6328
6456
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6329
6457
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -6400,8 +6528,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6400
6528
|
const macHashUint8Array = keccak256(data);
|
6401
6529
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
6402
6530
|
if (mac !== macHash) {
|
6403
|
-
throw new
|
6404
|
-
|
6531
|
+
throw new FuelError19(
|
6532
|
+
ErrorCode17.INVALID_PASSWORD,
|
6405
6533
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6406
6534
|
);
|
6407
6535
|
}
|
@@ -6531,14 +6659,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6531
6659
|
|
6532
6660
|
// src/hdwallet/hdwallet.ts
|
6533
6661
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
6534
|
-
import { ErrorCode as
|
6662
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
|
6535
6663
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
6536
6664
|
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
6537
6665
|
import { arrayify as arrayify18, hexlify as hexlify20, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
6538
6666
|
|
6539
6667
|
// src/mnemonic/mnemonic.ts
|
6540
6668
|
import { randomBytes as randomBytes7, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
6541
|
-
import { ErrorCode as
|
6669
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
|
6542
6670
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
6543
6671
|
import { arrayify as arrayify17, hexlify as hexlify19, concat as concat4, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
6544
6672
|
|
@@ -8595,7 +8723,7 @@ var english = [
|
|
8595
8723
|
];
|
8596
8724
|
|
8597
8725
|
// src/mnemonic/utils.ts
|
8598
|
-
import { ErrorCode as
|
8726
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8599
8727
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
8600
8728
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
8601
8729
|
function getLowerMask(bits) {
|
@@ -8644,8 +8772,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8644
8772
|
for (let i = 0; i < words.length; i += 1) {
|
8645
8773
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8646
8774
|
if (index === -1) {
|
8647
|
-
throw new
|
8648
|
-
|
8775
|
+
throw new FuelError20(
|
8776
|
+
ErrorCode18.INVALID_MNEMONIC,
|
8649
8777
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8650
8778
|
);
|
8651
8779
|
}
|
@@ -8661,8 +8789,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8661
8789
|
const checksumMask = getUpperMask(checksumBits);
|
8662
8790
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8663
8791
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8664
|
-
throw new
|
8665
|
-
|
8792
|
+
throw new FuelError20(
|
8793
|
+
ErrorCode18.INVALID_CHECKSUM,
|
8666
8794
|
"Checksum validation failed for the provided mnemonic."
|
8667
8795
|
);
|
8668
8796
|
}
|
@@ -8676,16 +8804,16 @@ var TestnetPRV = "0x04358394";
|
|
8676
8804
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8677
8805
|
function assertWordList(wordlist) {
|
8678
8806
|
if (wordlist.length !== 2048) {
|
8679
|
-
throw new
|
8680
|
-
|
8807
|
+
throw new FuelError21(
|
8808
|
+
ErrorCode19.INVALID_WORD_LIST,
|
8681
8809
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8682
8810
|
);
|
8683
8811
|
}
|
8684
8812
|
}
|
8685
8813
|
function assertEntropy(entropy) {
|
8686
8814
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8687
|
-
throw new
|
8688
|
-
|
8815
|
+
throw new FuelError21(
|
8816
|
+
ErrorCode19.INVALID_ENTROPY,
|
8689
8817
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8690
8818
|
);
|
8691
8819
|
}
|
@@ -8695,7 +8823,7 @@ function assertMnemonic(words) {
|
|
8695
8823
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8696
8824
|
", "
|
8697
8825
|
)}] words, but got ${words.length}.`;
|
8698
|
-
throw new
|
8826
|
+
throw new FuelError21(ErrorCode19.INVALID_MNEMONIC, errorMsg);
|
8699
8827
|
}
|
8700
8828
|
}
|
8701
8829
|
var Mnemonic = class {
|
@@ -8813,8 +8941,8 @@ var Mnemonic = class {
|
|
8813
8941
|
static masterKeysFromSeed(seed) {
|
8814
8942
|
const seedArray = arrayify17(seed);
|
8815
8943
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8816
|
-
throw new
|
8817
|
-
|
8944
|
+
throw new FuelError21(
|
8945
|
+
ErrorCode19.INVALID_SEED,
|
8818
8946
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8819
8947
|
);
|
8820
8948
|
}
|
@@ -8891,7 +9019,7 @@ function isValidExtendedKey(extendedKey) {
|
|
8891
9019
|
function parsePath(path2, depth = 0) {
|
8892
9020
|
const components = path2.split("/");
|
8893
9021
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8894
|
-
throw new
|
9022
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
8895
9023
|
}
|
8896
9024
|
if (components[0] === "m") {
|
8897
9025
|
components.shift();
|
@@ -8920,8 +9048,8 @@ var HDWallet = class {
|
|
8920
9048
|
this.privateKey = hexlify20(config.privateKey);
|
8921
9049
|
} else {
|
8922
9050
|
if (!config.publicKey) {
|
8923
|
-
throw new
|
8924
|
-
|
9051
|
+
throw new FuelError22(
|
9052
|
+
ErrorCode20.HD_WALLET_ERROR,
|
8925
9053
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8926
9054
|
);
|
8927
9055
|
}
|
@@ -8950,8 +9078,8 @@ var HDWallet = class {
|
|
8950
9078
|
const data = new Uint8Array(37);
|
8951
9079
|
if (index & HARDENED_INDEX) {
|
8952
9080
|
if (!privateKey) {
|
8953
|
-
throw new
|
8954
|
-
|
9081
|
+
throw new FuelError22(
|
9082
|
+
ErrorCode20.HD_WALLET_ERROR,
|
8955
9083
|
"Cannot derive a hardened index without a private Key."
|
8956
9084
|
);
|
8957
9085
|
}
|
@@ -9003,8 +9131,8 @@ var HDWallet = class {
|
|
9003
9131
|
*/
|
9004
9132
|
toExtendedKey(isPublic = false, testnet = false) {
|
9005
9133
|
if (this.depth >= 256) {
|
9006
|
-
throw new
|
9007
|
-
|
9134
|
+
throw new FuelError22(
|
9135
|
+
ErrorCode20.HD_WALLET_ERROR,
|
9008
9136
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9009
9137
|
);
|
9010
9138
|
}
|
@@ -9035,10 +9163,10 @@ var HDWallet = class {
|
|
9035
9163
|
const bytes = arrayify18(decoded);
|
9036
9164
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9037
9165
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
9038
|
-
throw new
|
9166
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
9039
9167
|
}
|
9040
9168
|
if (!validChecksum) {
|
9041
|
-
throw new
|
9169
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
9042
9170
|
}
|
9043
9171
|
const depth = bytes[4];
|
9044
9172
|
const parentFingerprint = hexlify20(bytes.slice(5, 9));
|
@@ -9046,14 +9174,14 @@ var HDWallet = class {
|
|
9046
9174
|
const chainCode = hexlify20(bytes.slice(13, 45));
|
9047
9175
|
const key = bytes.slice(45, 78);
|
9048
9176
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
9049
|
-
throw new
|
9050
|
-
|
9177
|
+
throw new FuelError22(
|
9178
|
+
ErrorCode20.HD_WALLET_ERROR,
|
9051
9179
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
9052
9180
|
);
|
9053
9181
|
}
|
9054
9182
|
if (isPublicExtendedKey(bytes)) {
|
9055
9183
|
if (key[0] !== 3) {
|
9056
|
-
throw new
|
9184
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Invalid public extended key.");
|
9057
9185
|
}
|
9058
9186
|
return new HDWallet({
|
9059
9187
|
publicKey: key,
|
@@ -9064,7 +9192,7 @@ var HDWallet = class {
|
|
9064
9192
|
});
|
9065
9193
|
}
|
9066
9194
|
if (key[0] !== 0) {
|
9067
|
-
throw new
|
9195
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Invalid private extended key.");
|
9068
9196
|
}
|
9069
9197
|
return new HDWallet({
|
9070
9198
|
privateKey: key.slice(1),
|
@@ -9308,26 +9436,26 @@ var WalletsConfig = class {
|
|
9308
9436
|
amountPerCoin
|
9309
9437
|
}) {
|
9310
9438
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
9311
|
-
throw new
|
9312
|
-
|
9439
|
+
throw new FuelError23(
|
9440
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9313
9441
|
"Number of wallets must be greater than zero."
|
9314
9442
|
);
|
9315
9443
|
}
|
9316
9444
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
9317
|
-
throw new
|
9318
|
-
|
9445
|
+
throw new FuelError23(
|
9446
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9319
9447
|
"Number of assets per wallet must be greater than zero."
|
9320
9448
|
);
|
9321
9449
|
}
|
9322
9450
|
if (coinsPerAsset <= 0) {
|
9323
|
-
throw new
|
9324
|
-
|
9451
|
+
throw new FuelError23(
|
9452
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9325
9453
|
"Number of coins per asset must be greater than zero."
|
9326
9454
|
);
|
9327
9455
|
}
|
9328
9456
|
if (amountPerCoin < 0) {
|
9329
|
-
throw new
|
9330
|
-
|
9457
|
+
throw new FuelError23(
|
9458
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9331
9459
|
"Amount per coin must be greater than or equal to zero."
|
9332
9460
|
);
|
9333
9461
|
}
|