@fuel-ts/account 0.76.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +840 -1334
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +85 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -115
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +16 -15
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +9 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +1 -0
- package/dist/providers/assets/index.d.ts.map +1 -1
- package/dist/providers/assets/types.d.ts +5 -5
- package/dist/providers/assets/types.d.ts.map +1 -1
- package/dist/providers/assets/utils/network.d.ts +4 -4
- package/dist/providers/assets/utils/network.d.ts.map +1 -1
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +23 -14
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/test-utils.global.js +817 -1308
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +64 -26
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +105 -75
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -25,7 +25,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
|
-
import { ErrorCode as
|
28
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
30
|
import { bn as bn16 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -68,7 +68,7 @@ var addAmountToAsset = (params) => {
|
|
68
68
|
|
69
69
|
// src/providers/provider.ts
|
70
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
|
-
import { ErrorCode as
|
71
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
72
72
|
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
73
73
|
import {
|
74
74
|
InputType as InputType6,
|
@@ -144,6 +144,9 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
144
144
|
time
|
145
145
|
reason
|
146
146
|
}
|
147
|
+
... on SqueezedOutStatus {
|
148
|
+
reason
|
149
|
+
}
|
147
150
|
}
|
148
151
|
`;
|
149
152
|
var TransactionFragmentFragmentDoc = gql`
|
@@ -886,7 +889,7 @@ function getSdk(requester) {
|
|
886
889
|
}
|
887
890
|
|
888
891
|
// src/providers/fuel-graphql-subscriber.ts
|
889
|
-
import { FuelError } from "@fuel-ts/errors";
|
892
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
890
893
|
import { print } from "graphql";
|
891
894
|
var _FuelGraphqlSubscriber = class {
|
892
895
|
constructor(options) {
|
@@ -921,7 +924,16 @@ var _FuelGraphqlSubscriber = class {
|
|
921
924
|
if (!text.startsWith("data:")) {
|
922
925
|
continue;
|
923
926
|
}
|
924
|
-
|
927
|
+
let data;
|
928
|
+
let errors;
|
929
|
+
try {
|
930
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
931
|
+
} catch (e) {
|
932
|
+
throw new FuelError(
|
933
|
+
ErrorCode.STREAM_PARSING_ERROR,
|
934
|
+
`Error while parsing stream data response: ${text}`
|
935
|
+
);
|
936
|
+
}
|
925
937
|
if (Array.isArray(errors)) {
|
926
938
|
throw new FuelError(
|
927
939
|
FuelError.CODES.INVALID_REQUEST,
|
@@ -947,7 +959,7 @@ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
|
947
959
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
948
960
|
|
949
961
|
// src/providers/memory-cache.ts
|
950
|
-
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
962
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
951
963
|
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
952
964
|
var cache = {};
|
953
965
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
@@ -957,7 +969,7 @@ var MemoryCache = class {
|
|
957
969
|
this.ttl = ttlInMs;
|
958
970
|
if (typeof ttlInMs !== "number" || this.ttl <= 0) {
|
959
971
|
throw new FuelError2(
|
960
|
-
|
972
|
+
ErrorCode2.INVALID_TTL,
|
961
973
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
962
974
|
);
|
963
975
|
}
|
@@ -1007,7 +1019,7 @@ var MemoryCache = class {
|
|
1007
1019
|
|
1008
1020
|
// src/providers/transaction-request/input.ts
|
1009
1021
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1010
|
-
import { ErrorCode as
|
1022
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1011
1023
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1012
1024
|
import { InputType } from "@fuel-ts/transactions";
|
1013
1025
|
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
@@ -1073,7 +1085,7 @@ var inputify = (value) => {
|
|
1073
1085
|
}
|
1074
1086
|
default: {
|
1075
1087
|
throw new FuelError3(
|
1076
|
-
|
1088
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1077
1089
|
`Invalid transaction input type: ${type}.`
|
1078
1090
|
);
|
1079
1091
|
}
|
@@ -1082,7 +1094,7 @@ var inputify = (value) => {
|
|
1082
1094
|
|
1083
1095
|
// src/providers/transaction-request/output.ts
|
1084
1096
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1085
|
-
import { ErrorCode as
|
1097
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1086
1098
|
import { bn as bn3 } from "@fuel-ts/math";
|
1087
1099
|
import { OutputType } from "@fuel-ts/transactions";
|
1088
1100
|
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
@@ -1130,7 +1142,7 @@ var outputify = (value) => {
|
|
1130
1142
|
}
|
1131
1143
|
default: {
|
1132
1144
|
throw new FuelError4(
|
1133
|
-
|
1145
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1134
1146
|
`Invalid transaction output type: ${type}.`
|
1135
1147
|
);
|
1136
1148
|
}
|
@@ -1155,7 +1167,7 @@ var isCoin = (resource) => "id" in resource;
|
|
1155
1167
|
|
1156
1168
|
// src/providers/utils/receipts.ts
|
1157
1169
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1158
|
-
import { ErrorCode as
|
1170
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1159
1171
|
import { bn as bn4 } from "@fuel-ts/math";
|
1160
1172
|
import {
|
1161
1173
|
ReceiptBurnCoder,
|
@@ -1360,12 +1372,12 @@ function assembleReceiptByType(receipt) {
|
|
1360
1372
|
return burnReceipt;
|
1361
1373
|
}
|
1362
1374
|
default:
|
1363
|
-
throw new FuelError5(
|
1375
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
1364
1376
|
}
|
1365
1377
|
}
|
1366
1378
|
|
1367
1379
|
// src/providers/utils/block-explorer.ts
|
1368
|
-
import { ErrorCode as
|
1380
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1369
1381
|
|
1370
1382
|
// src/providers/utils/gas.ts
|
1371
1383
|
import { bn as bn5 } from "@fuel-ts/math";
|
@@ -1724,7 +1736,7 @@ var BaseTransactionRequest = class {
|
|
1724
1736
|
txPointer: "0x00000000000000000000000000000000",
|
1725
1737
|
witnessIndex,
|
1726
1738
|
predicate: predicate?.bytes,
|
1727
|
-
predicateData: predicate?.
|
1739
|
+
predicateData: predicate?.predicateDataBytes
|
1728
1740
|
};
|
1729
1741
|
this.pushInput(input);
|
1730
1742
|
this.addChangeOutput(owner, assetId);
|
@@ -1757,7 +1769,7 @@ var BaseTransactionRequest = class {
|
|
1757
1769
|
amount,
|
1758
1770
|
witnessIndex,
|
1759
1771
|
predicate: predicate?.bytes,
|
1760
|
-
predicateData: predicate?.
|
1772
|
+
predicateData: predicate?.predicateDataBytes
|
1761
1773
|
};
|
1762
1774
|
this.pushInput(input);
|
1763
1775
|
this.addChangeOutput(recipient, assetId);
|
@@ -2000,11 +2012,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2000
2012
|
|
2001
2013
|
// src/providers/transaction-request/hash-transaction.ts
|
2002
2014
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2003
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2015
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2004
2016
|
import { bn as bn7 } from "@fuel-ts/math";
|
2005
2017
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2006
2018
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2007
|
-
import { sha256 } from "ethers";
|
2008
2019
|
import { clone as clone2 } from "ramda";
|
2009
2020
|
function hashTransaction(transactionRequest, chainId) {
|
2010
2021
|
const transaction = transactionRequest.toTransaction();
|
@@ -2391,7 +2402,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2402
|
};
|
2392
2403
|
|
2393
2404
|
// src/providers/transaction-request/utils.ts
|
2394
|
-
import { ErrorCode as
|
2405
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2395
2406
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2396
2407
|
var transactionRequestify = (obj) => {
|
2397
2408
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2406,13 +2417,13 @@ var transactionRequestify = (obj) => {
|
|
2406
2417
|
return CreateTransactionRequest.from(obj);
|
2407
2418
|
}
|
2408
2419
|
default: {
|
2409
|
-
throw new FuelError7(
|
2420
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2410
2421
|
}
|
2411
2422
|
}
|
2412
2423
|
};
|
2413
2424
|
|
2414
2425
|
// src/providers/transaction-response/transaction-response.ts
|
2415
|
-
import { ErrorCode as
|
2426
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2416
2427
|
import { bn as bn13 } from "@fuel-ts/math";
|
2417
2428
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2418
2429
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
@@ -2495,7 +2506,7 @@ var calculateTransactionFee = (params) => {
|
|
2495
2506
|
|
2496
2507
|
// src/providers/transaction-summary/operations.ts
|
2497
2508
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2498
|
-
import { ErrorCode as
|
2509
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2499
2510
|
import { bn as bn12 } from "@fuel-ts/math";
|
2500
2511
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2501
2512
|
|
@@ -2544,7 +2555,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2544
2555
|
};
|
2545
2556
|
|
2546
2557
|
// src/providers/transaction-summary/input.ts
|
2547
|
-
import { ErrorCode as
|
2558
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2548
2559
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2549
2560
|
function getInputsByTypes(inputs, types) {
|
2550
2561
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2583,7 +2594,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2583
2594
|
}
|
2584
2595
|
if (contractInput.type !== InputType5.Contract) {
|
2585
2596
|
throw new FuelError8(
|
2586
|
-
|
2597
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2587
2598
|
`Contract input should be of type 'contract'.`
|
2588
2599
|
);
|
2589
2600
|
}
|
@@ -2631,7 +2642,7 @@ function getTransactionTypeName(transactionType) {
|
|
2631
2642
|
return "Script" /* Script */;
|
2632
2643
|
default:
|
2633
2644
|
throw new FuelError9(
|
2634
|
-
|
2645
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2635
2646
|
`Invalid transaction type: ${transactionType}.`
|
2636
2647
|
);
|
2637
2648
|
}
|
@@ -2988,7 +2999,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
2988
2999
|
};
|
2989
3000
|
|
2990
3001
|
// src/providers/transaction-summary/status.ts
|
2991
|
-
import { ErrorCode as
|
3002
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2992
3003
|
var getTransactionStatusName = (gqlStatus) => {
|
2993
3004
|
switch (gqlStatus) {
|
2994
3005
|
case "FailureStatus":
|
@@ -3001,7 +3012,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3001
3012
|
return "squeezedout" /* squeezedout */;
|
3002
3013
|
default:
|
3003
3014
|
throw new FuelError10(
|
3004
|
-
|
3015
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3005
3016
|
`Invalid transaction status: ${gqlStatus}.`
|
3006
3017
|
);
|
3007
3018
|
}
|
@@ -3221,6 +3232,12 @@ var TransactionResponse = class {
|
|
3221
3232
|
transactionId: this.id
|
3222
3233
|
});
|
3223
3234
|
for await (const { statusChange } of subscription) {
|
3235
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3236
|
+
throw new FuelError11(
|
3237
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3238
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3239
|
+
);
|
3240
|
+
}
|
3224
3241
|
if (statusChange.type !== "SubmittedStatus") {
|
3225
3242
|
break;
|
3226
3243
|
}
|
@@ -3250,7 +3267,7 @@ var TransactionResponse = class {
|
|
3250
3267
|
const result = await this.waitForResult(contractsAbiMap);
|
3251
3268
|
if (result.isStatusFailure) {
|
3252
3269
|
throw new FuelError11(
|
3253
|
-
|
3270
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3254
3271
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3255
3272
|
);
|
3256
3273
|
}
|
@@ -3385,14 +3402,15 @@ var _Provider = class {
|
|
3385
3402
|
}
|
3386
3403
|
static getFetchFn(options) {
|
3387
3404
|
const { retryOptions, timeout } = options;
|
3388
|
-
return autoRetryFetch((...args) => {
|
3389
|
-
if (options.fetch) {
|
3390
|
-
return options.fetch(...args);
|
3391
|
-
}
|
3405
|
+
return autoRetryFetch(async (...args) => {
|
3392
3406
|
const url = args[0];
|
3393
3407
|
const request = args[1];
|
3394
3408
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3395
|
-
|
3409
|
+
let fullRequest = { ...request, signal };
|
3410
|
+
if (options.requestMiddleware) {
|
3411
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3412
|
+
}
|
3413
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3396
3414
|
}, retryOptions);
|
3397
3415
|
}
|
3398
3416
|
/**
|
@@ -3412,7 +3430,7 @@ var _Provider = class {
|
|
3412
3430
|
const chain = _Provider.chainInfoCache[this.url];
|
3413
3431
|
if (!chain) {
|
3414
3432
|
throw new FuelError12(
|
3415
|
-
|
3433
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3416
3434
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3417
3435
|
);
|
3418
3436
|
}
|
@@ -3425,7 +3443,7 @@ var _Provider = class {
|
|
3425
3443
|
const node = _Provider.nodeInfoCache[this.url];
|
3426
3444
|
if (!node) {
|
3427
3445
|
throw new FuelError12(
|
3428
|
-
|
3446
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3429
3447
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3430
3448
|
);
|
3431
3449
|
}
|
@@ -3598,6 +3616,12 @@ var _Provider = class {
|
|
3598
3616
|
if (awaitExecution) {
|
3599
3617
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3600
3618
|
for await (const { submitAndAwait } of subscription) {
|
3619
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3620
|
+
throw new FuelError12(
|
3621
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3622
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3623
|
+
);
|
3624
|
+
}
|
3601
3625
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3602
3626
|
break;
|
3603
3627
|
}
|
@@ -4108,7 +4132,7 @@ var _Provider = class {
|
|
4108
4132
|
};
|
4109
4133
|
if (commitBlockId && commitBlockHeight) {
|
4110
4134
|
throw new FuelError12(
|
4111
|
-
|
4135
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4112
4136
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4113
4137
|
);
|
4114
4138
|
}
|
@@ -4225,7 +4249,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4225
4249
|
__publicField(Provider, "nodeInfoCache", {});
|
4226
4250
|
|
4227
4251
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4228
|
-
import { ErrorCode as
|
4252
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4229
4253
|
import { bn as bn15 } from "@fuel-ts/math";
|
4230
4254
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4231
4255
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4343,7 +4367,7 @@ var Account = class extends AbstractAccount {
|
|
4343
4367
|
*/
|
4344
4368
|
get provider() {
|
4345
4369
|
if (!this._provider) {
|
4346
|
-
throw new FuelError14(
|
4370
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4347
4371
|
}
|
4348
4372
|
return this._provider;
|
4349
4373
|
}
|
@@ -4396,7 +4420,7 @@ var Account = class extends AbstractAccount {
|
|
4396
4420
|
break;
|
4397
4421
|
}
|
4398
4422
|
throw new FuelError14(
|
4399
|
-
|
4423
|
+
ErrorCode14.NOT_SUPPORTED,
|
4400
4424
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4401
4425
|
);
|
4402
4426
|
}
|
@@ -4422,7 +4446,7 @@ var Account = class extends AbstractAccount {
|
|
4422
4446
|
break;
|
4423
4447
|
}
|
4424
4448
|
throw new FuelError14(
|
4425
|
-
|
4449
|
+
ErrorCode14.NOT_SUPPORTED,
|
4426
4450
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4427
4451
|
);
|
4428
4452
|
}
|
@@ -4458,7 +4482,7 @@ var Account = class extends AbstractAccount {
|
|
4458
4482
|
break;
|
4459
4483
|
}
|
4460
4484
|
throw new FuelError14(
|
4461
|
-
|
4485
|
+
ErrorCode14.NOT_SUPPORTED,
|
4462
4486
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4463
4487
|
);
|
4464
4488
|
}
|
@@ -4563,6 +4587,12 @@ var Account = class extends AbstractAccount {
|
|
4563
4587
|
* @returns A promise that resolves to the transaction response.
|
4564
4588
|
*/
|
4565
4589
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4590
|
+
if (bn16(amount).lte(0)) {
|
4591
|
+
throw new FuelError14(
|
4592
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4593
|
+
"Transfer amount must be a positive number."
|
4594
|
+
);
|
4595
|
+
}
|
4566
4596
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4567
4597
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4568
4598
|
}
|
@@ -4576,6 +4606,12 @@ var Account = class extends AbstractAccount {
|
|
4576
4606
|
* @returns A promise that resolves to the transaction response.
|
4577
4607
|
*/
|
4578
4608
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4609
|
+
if (bn16(amount).lte(0)) {
|
4610
|
+
throw new FuelError14(
|
4611
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4612
|
+
"Transfer amount must be a positive number."
|
4613
|
+
);
|
4614
|
+
}
|
4579
4615
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4580
4616
|
const { minGasPrice } = this.provider.getGasConfig();
|
4581
4617
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4645,7 +4681,7 @@ var Account = class extends AbstractAccount {
|
|
4645
4681
|
}
|
4646
4682
|
async signMessage(message) {
|
4647
4683
|
if (!this._connector) {
|
4648
|
-
throw new FuelError14(
|
4684
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4649
4685
|
}
|
4650
4686
|
return this._connector.signMessage(this.address.toString(), message);
|
4651
4687
|
}
|
@@ -4691,13 +4727,13 @@ var Account = class extends AbstractAccount {
|
|
4691
4727
|
}) {
|
4692
4728
|
if (minGasPrice.gt(gasPrice)) {
|
4693
4729
|
throw new FuelError14(
|
4694
|
-
|
4730
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
4695
4731
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4696
4732
|
);
|
4697
4733
|
}
|
4698
4734
|
if (gasUsed.gt(gasLimit)) {
|
4699
4735
|
throw new FuelError14(
|
4700
|
-
|
4736
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
4701
4737
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4702
4738
|
);
|
4703
4739
|
}
|
@@ -4824,7 +4860,7 @@ import {
|
|
4824
4860
|
decryptJsonWalletData,
|
4825
4861
|
encryptJsonWalletData
|
4826
4862
|
} from "@fuel-ts/crypto";
|
4827
|
-
import { ErrorCode as
|
4863
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4828
4864
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4829
4865
|
import { v4 as uuidv4 } from "uuid";
|
4830
4866
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -4903,7 +4939,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4903
4939
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
4904
4940
|
if (mac !== macHash) {
|
4905
4941
|
throw new FuelError15(
|
4906
|
-
|
4942
|
+
ErrorCode15.INVALID_PASSWORD,
|
4907
4943
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
4908
4944
|
);
|
4909
4945
|
}
|
@@ -5025,24 +5061,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5025
5061
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5026
5062
|
|
5027
5063
|
// src/hdwallet/hdwallet.ts
|
5028
|
-
import { ErrorCode as
|
5064
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5065
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5029
5066
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5030
5067
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5031
|
-
import {
|
5032
|
-
toBeHex,
|
5033
|
-
dataSlice as dataSlice2,
|
5034
|
-
encodeBase58 as encodeBase582,
|
5035
|
-
decodeBase58,
|
5036
|
-
sha256 as sha2564,
|
5037
|
-
computeHmac as computeHmac2,
|
5038
|
-
ripemd160
|
5039
|
-
} from "ethers";
|
5068
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5040
5069
|
|
5041
5070
|
// src/mnemonic/mnemonic.ts
|
5042
5071
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5043
|
-
import { ErrorCode as
|
5072
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5073
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5044
5074
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5045
|
-
import { dataSlice, pbkdf2,
|
5075
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5046
5076
|
|
5047
5077
|
// src/wordlists/words/english.ts
|
5048
5078
|
var english = [
|
@@ -7097,9 +7127,9 @@ var english = [
|
|
7097
7127
|
];
|
7098
7128
|
|
7099
7129
|
// src/mnemonic/utils.ts
|
7100
|
-
import { ErrorCode as
|
7130
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7131
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7101
7132
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7102
|
-
import { sha256 as sha2562 } from "ethers";
|
7103
7133
|
function toUtf8Bytes(stri) {
|
7104
7134
|
const str = stri.normalize("NFKD");
|
7105
7135
|
const result = [];
|
@@ -7115,7 +7145,7 @@ function toUtf8Bytes(stri) {
|
|
7115
7145
|
const c2 = str.charCodeAt(i);
|
7116
7146
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7117
7147
|
throw new FuelError16(
|
7118
|
-
|
7148
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7119
7149
|
"Invalid UTF-8 in the input string."
|
7120
7150
|
);
|
7121
7151
|
}
|
@@ -7179,7 +7209,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7179
7209
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7180
7210
|
if (index === -1) {
|
7181
7211
|
throw new FuelError16(
|
7182
|
-
|
7212
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7183
7213
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7184
7214
|
);
|
7185
7215
|
}
|
@@ -7196,7 +7226,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7196
7226
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7197
7227
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7198
7228
|
throw new FuelError16(
|
7199
|
-
|
7229
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7200
7230
|
"Checksum validation failed for the provided mnemonic."
|
7201
7231
|
);
|
7202
7232
|
}
|
@@ -7211,7 +7241,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7211
7241
|
function assertWordList(wordlist) {
|
7212
7242
|
if (wordlist.length !== 2048) {
|
7213
7243
|
throw new FuelError17(
|
7214
|
-
|
7244
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7215
7245
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7216
7246
|
);
|
7217
7247
|
}
|
@@ -7219,7 +7249,7 @@ function assertWordList(wordlist) {
|
|
7219
7249
|
function assertEntropy(entropy) {
|
7220
7250
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7221
7251
|
throw new FuelError17(
|
7222
|
-
|
7252
|
+
ErrorCode17.INVALID_ENTROPY,
|
7223
7253
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7224
7254
|
);
|
7225
7255
|
}
|
@@ -7229,7 +7259,7 @@ function assertMnemonic(words) {
|
|
7229
7259
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7230
7260
|
", "
|
7231
7261
|
)}] words, but got ${words.length}.`;
|
7232
|
-
throw new FuelError17(
|
7262
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7233
7263
|
}
|
7234
7264
|
}
|
7235
7265
|
var Mnemonic = class {
|
@@ -7348,7 +7378,7 @@ var Mnemonic = class {
|
|
7348
7378
|
const seedArray = arrayify17(seed);
|
7349
7379
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7350
7380
|
throw new FuelError17(
|
7351
|
-
|
7381
|
+
ErrorCode17.INVALID_SEED,
|
7352
7382
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7353
7383
|
);
|
7354
7384
|
}
|
@@ -7425,7 +7455,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7425
7455
|
function parsePath(path2, depth = 0) {
|
7426
7456
|
const components = path2.split("/");
|
7427
7457
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7428
|
-
throw new FuelError18(
|
7458
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7429
7459
|
}
|
7430
7460
|
if (components[0] === "m") {
|
7431
7461
|
components.shift();
|
@@ -7455,7 +7485,7 @@ var HDWallet = class {
|
|
7455
7485
|
} else {
|
7456
7486
|
if (!config.publicKey) {
|
7457
7487
|
throw new FuelError18(
|
7458
|
-
|
7488
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7459
7489
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7460
7490
|
);
|
7461
7491
|
}
|
@@ -7485,7 +7515,7 @@ var HDWallet = class {
|
|
7485
7515
|
if (index & HARDENED_INDEX) {
|
7486
7516
|
if (!privateKey) {
|
7487
7517
|
throw new FuelError18(
|
7488
|
-
|
7518
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7489
7519
|
"Cannot derive a hardened index without a private Key."
|
7490
7520
|
);
|
7491
7521
|
}
|
@@ -7538,7 +7568,7 @@ var HDWallet = class {
|
|
7538
7568
|
toExtendedKey(isPublic = false, testnet = false) {
|
7539
7569
|
if (this.depth >= 256) {
|
7540
7570
|
throw new FuelError18(
|
7541
|
-
|
7571
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7542
7572
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7543
7573
|
);
|
7544
7574
|
}
|
@@ -7569,10 +7599,10 @@ var HDWallet = class {
|
|
7569
7599
|
const bytes = arrayify18(decoded);
|
7570
7600
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7571
7601
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7572
|
-
throw new FuelError18(
|
7602
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7573
7603
|
}
|
7574
7604
|
if (!validChecksum) {
|
7575
|
-
throw new FuelError18(
|
7605
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7576
7606
|
}
|
7577
7607
|
const depth = bytes[4];
|
7578
7608
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7581,13 +7611,13 @@ var HDWallet = class {
|
|
7581
7611
|
const key = bytes.slice(45, 78);
|
7582
7612
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7583
7613
|
throw new FuelError18(
|
7584
|
-
|
7614
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7585
7615
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7586
7616
|
);
|
7587
7617
|
}
|
7588
7618
|
if (isPublicExtendedKey(bytes)) {
|
7589
7619
|
if (key[0] !== 3) {
|
7590
|
-
throw new FuelError18(
|
7620
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7591
7621
|
}
|
7592
7622
|
return new HDWallet({
|
7593
7623
|
publicKey: key,
|
@@ -7598,7 +7628,7 @@ var HDWallet = class {
|
|
7598
7628
|
});
|
7599
7629
|
}
|
7600
7630
|
if (key[0] !== 0) {
|
7601
|
-
throw new FuelError18(
|
7631
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7602
7632
|
}
|
7603
7633
|
return new HDWallet({
|
7604
7634
|
privateKey: key.slice(1),
|