@fuel-ts/account 0.76.3 → 0.78.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 +7 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +10 -0
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +906 -1340
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +151 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +211 -121
- 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 +25 -15
- 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-request/transaction-request.d.ts +20 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/test-utils.global.js +871 -1314
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +118 -32
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +159 -81
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -30,7 +30,7 @@ var __privateMethod = (obj, member, method) => {
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
|
-
import { ErrorCode as
|
33
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
35
|
import { bn as bn16 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -73,7 +73,7 @@ var addAmountToAsset = (params) => {
|
|
73
73
|
|
74
74
|
// src/providers/provider.ts
|
75
75
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
|
-
import { ErrorCode as
|
76
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
77
77
|
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
78
78
|
import {
|
79
79
|
InputType as InputType6,
|
@@ -149,6 +149,9 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
149
149
|
time
|
150
150
|
reason
|
151
151
|
}
|
152
|
+
... on SqueezedOutStatus {
|
153
|
+
reason
|
154
|
+
}
|
152
155
|
}
|
153
156
|
`;
|
154
157
|
var TransactionFragmentFragmentDoc = gql`
|
@@ -891,7 +894,7 @@ function getSdk(requester) {
|
|
891
894
|
}
|
892
895
|
|
893
896
|
// src/providers/fuel-graphql-subscriber.ts
|
894
|
-
import { FuelError } from "@fuel-ts/errors";
|
897
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
895
898
|
import { print } from "graphql";
|
896
899
|
var _FuelGraphqlSubscriber = class {
|
897
900
|
constructor(options) {
|
@@ -926,7 +929,16 @@ var _FuelGraphqlSubscriber = class {
|
|
926
929
|
if (!text.startsWith("data:")) {
|
927
930
|
continue;
|
928
931
|
}
|
929
|
-
|
932
|
+
let data;
|
933
|
+
let errors;
|
934
|
+
try {
|
935
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
936
|
+
} catch (e) {
|
937
|
+
throw new FuelError(
|
938
|
+
ErrorCode.STREAM_PARSING_ERROR,
|
939
|
+
`Error while parsing stream data response: ${text}`
|
940
|
+
);
|
941
|
+
}
|
930
942
|
if (Array.isArray(errors)) {
|
931
943
|
throw new FuelError(
|
932
944
|
FuelError.CODES.INVALID_REQUEST,
|
@@ -952,7 +964,7 @@ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
|
952
964
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
953
965
|
|
954
966
|
// src/providers/memory-cache.ts
|
955
|
-
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
967
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
956
968
|
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
957
969
|
var cache = {};
|
958
970
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
@@ -962,7 +974,7 @@ var MemoryCache = class {
|
|
962
974
|
this.ttl = ttlInMs;
|
963
975
|
if (typeof ttlInMs !== "number" || this.ttl <= 0) {
|
964
976
|
throw new FuelError2(
|
965
|
-
|
977
|
+
ErrorCode2.INVALID_TTL,
|
966
978
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
967
979
|
);
|
968
980
|
}
|
@@ -1012,7 +1024,7 @@ var MemoryCache = class {
|
|
1012
1024
|
|
1013
1025
|
// src/providers/transaction-request/input.ts
|
1014
1026
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1015
|
-
import { ErrorCode as
|
1027
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1016
1028
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1017
1029
|
import { InputType } from "@fuel-ts/transactions";
|
1018
1030
|
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
@@ -1078,7 +1090,7 @@ var inputify = (value) => {
|
|
1078
1090
|
}
|
1079
1091
|
default: {
|
1080
1092
|
throw new FuelError3(
|
1081
|
-
|
1093
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1082
1094
|
`Invalid transaction input type: ${type}.`
|
1083
1095
|
);
|
1084
1096
|
}
|
@@ -1087,7 +1099,7 @@ var inputify = (value) => {
|
|
1087
1099
|
|
1088
1100
|
// src/providers/transaction-request/output.ts
|
1089
1101
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1090
|
-
import { ErrorCode as
|
1102
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1091
1103
|
import { bn as bn3 } from "@fuel-ts/math";
|
1092
1104
|
import { OutputType } from "@fuel-ts/transactions";
|
1093
1105
|
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
@@ -1135,7 +1147,7 @@ var outputify = (value) => {
|
|
1135
1147
|
}
|
1136
1148
|
default: {
|
1137
1149
|
throw new FuelError4(
|
1138
|
-
|
1150
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1139
1151
|
`Invalid transaction output type: ${type}.`
|
1140
1152
|
);
|
1141
1153
|
}
|
@@ -1163,7 +1175,7 @@ var isMessage = (resource) => "recipient" in resource;
|
|
1163
1175
|
|
1164
1176
|
// src/providers/utils/receipts.ts
|
1165
1177
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1166
|
-
import { ErrorCode as
|
1178
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1167
1179
|
import { bn as bn4 } from "@fuel-ts/math";
|
1168
1180
|
import {
|
1169
1181
|
ReceiptBurnCoder,
|
@@ -1368,12 +1380,12 @@ function assembleReceiptByType(receipt) {
|
|
1368
1380
|
return burnReceipt;
|
1369
1381
|
}
|
1370
1382
|
default:
|
1371
|
-
throw new FuelError5(
|
1383
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
1372
1384
|
}
|
1373
1385
|
}
|
1374
1386
|
|
1375
1387
|
// src/providers/utils/block-explorer.ts
|
1376
|
-
import { ErrorCode as
|
1388
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1377
1389
|
var DEFAULT_BLOCK_EXPLORER_URL = "https://fuellabs.github.io/block-explorer-v2";
|
1378
1390
|
var getPathFromInput = (key, value) => {
|
1379
1391
|
const pathMap = {
|
@@ -1408,14 +1420,14 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1408
1420
|
const hasAnyDefinedValues = definedValues.length > 0;
|
1409
1421
|
if (definedValues.length > 1) {
|
1410
1422
|
throw new FuelError6(
|
1411
|
-
|
1423
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1412
1424
|
`Only one of the following can be passed in to buildBlockExplorerUrl: ${customInputParams.map((param) => param.key).join(", ")}.`
|
1413
1425
|
);
|
1414
1426
|
}
|
1415
1427
|
if (path && definedValues.length > 0) {
|
1416
1428
|
const inputKeys = customInputParams.map(({ key }) => key).join(", ");
|
1417
1429
|
throw new FuelError6(
|
1418
|
-
|
1430
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1419
1431
|
`You cannot pass in a path to 'buildBlockExplorerUrl' along with any of the following: ${inputKeys}.`
|
1420
1432
|
);
|
1421
1433
|
}
|
@@ -1691,13 +1703,27 @@ var BaseTransactionRequest = class {
|
|
1691
1703
|
this.outputs.push(output);
|
1692
1704
|
return this.outputs.length - 1;
|
1693
1705
|
}
|
1706
|
+
/**
|
1707
|
+
* @hidden
|
1708
|
+
*
|
1709
|
+
* Pushes a witness to the list and returns the index
|
1710
|
+
*
|
1711
|
+
* @param signature - The signature to add to the witness.
|
1712
|
+
* @returns The index of the created witness.
|
1713
|
+
*/
|
1714
|
+
addWitness(signature) {
|
1715
|
+
this.witnesses.push(signature);
|
1716
|
+
return this.witnesses.length - 1;
|
1717
|
+
}
|
1694
1718
|
/**
|
1695
1719
|
* @hidden
|
1696
1720
|
*
|
1697
1721
|
* Creates an empty witness without any side effects and returns the index
|
1722
|
+
*
|
1723
|
+
* @returns The index of the created witness.
|
1698
1724
|
*/
|
1699
|
-
|
1700
|
-
this.
|
1725
|
+
addEmptyWitness() {
|
1726
|
+
this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
|
1701
1727
|
return this.witnesses.length - 1;
|
1702
1728
|
}
|
1703
1729
|
/**
|
@@ -1726,6 +1752,21 @@ var BaseTransactionRequest = class {
|
|
1726
1752
|
}
|
1727
1753
|
this.witnesses[index] = witness;
|
1728
1754
|
}
|
1755
|
+
/**
|
1756
|
+
* Helper function to add an external signature to the transaction.
|
1757
|
+
*
|
1758
|
+
* @param account - The account/s to sign to the transaction.
|
1759
|
+
* @returns The transaction with the signature witness added.
|
1760
|
+
*/
|
1761
|
+
async addAccountWitnesses(account) {
|
1762
|
+
const accounts = Array.isArray(account) ? account : [account];
|
1763
|
+
await Promise.all(
|
1764
|
+
accounts.map(async (acc) => {
|
1765
|
+
this.addWitness(await acc.signTransaction(this));
|
1766
|
+
})
|
1767
|
+
);
|
1768
|
+
return this;
|
1769
|
+
}
|
1729
1770
|
/**
|
1730
1771
|
* Gets the coin inputs for a transaction.
|
1731
1772
|
*
|
@@ -1791,7 +1832,7 @@ var BaseTransactionRequest = class {
|
|
1791
1832
|
} else {
|
1792
1833
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
1793
1834
|
if (typeof witnessIndex !== "number") {
|
1794
|
-
witnessIndex = this.
|
1835
|
+
witnessIndex = this.addEmptyWitness();
|
1795
1836
|
}
|
1796
1837
|
}
|
1797
1838
|
const input = {
|
@@ -1803,7 +1844,7 @@ var BaseTransactionRequest = class {
|
|
1803
1844
|
txPointer: "0x00000000000000000000000000000000",
|
1804
1845
|
witnessIndex,
|
1805
1846
|
predicate: predicate?.bytes,
|
1806
|
-
predicateData: predicate?.
|
1847
|
+
predicateData: predicate?.predicateDataBytes
|
1807
1848
|
};
|
1808
1849
|
this.pushInput(input);
|
1809
1850
|
this.addChangeOutput(owner, assetId);
|
@@ -1825,7 +1866,7 @@ var BaseTransactionRequest = class {
|
|
1825
1866
|
} else {
|
1826
1867
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
1827
1868
|
if (typeof witnessIndex !== "number") {
|
1828
|
-
witnessIndex = this.
|
1869
|
+
witnessIndex = this.addEmptyWitness();
|
1829
1870
|
}
|
1830
1871
|
}
|
1831
1872
|
const input = {
|
@@ -1836,7 +1877,7 @@ var BaseTransactionRequest = class {
|
|
1836
1877
|
amount,
|
1837
1878
|
witnessIndex,
|
1838
1879
|
predicate: predicate?.bytes,
|
1839
|
-
predicateData: predicate?.
|
1880
|
+
predicateData: predicate?.predicateDataBytes
|
1840
1881
|
};
|
1841
1882
|
this.pushInput(input);
|
1842
1883
|
this.addChangeOutput(recipient, assetId);
|
@@ -2079,11 +2120,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2079
2120
|
|
2080
2121
|
// src/providers/transaction-request/hash-transaction.ts
|
2081
2122
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2082
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2123
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2083
2124
|
import { bn as bn7 } from "@fuel-ts/math";
|
2084
2125
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2085
2126
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2086
|
-
import { sha256 } from "ethers";
|
2087
2127
|
import { clone as clone2 } from "ramda";
|
2088
2128
|
function hashTransaction(transactionRequest, chainId) {
|
2089
2129
|
const transaction = transactionRequest.toTransaction();
|
@@ -2470,7 +2510,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2470
2510
|
};
|
2471
2511
|
|
2472
2512
|
// src/providers/transaction-request/utils.ts
|
2473
|
-
import { ErrorCode as
|
2513
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2474
2514
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2475
2515
|
var transactionRequestify = (obj) => {
|
2476
2516
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2485,13 +2525,13 @@ var transactionRequestify = (obj) => {
|
|
2485
2525
|
return CreateTransactionRequest.from(obj);
|
2486
2526
|
}
|
2487
2527
|
default: {
|
2488
|
-
throw new FuelError7(
|
2528
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2489
2529
|
}
|
2490
2530
|
}
|
2491
2531
|
};
|
2492
2532
|
|
2493
2533
|
// src/providers/transaction-response/transaction-response.ts
|
2494
|
-
import { ErrorCode as
|
2534
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2495
2535
|
import { bn as bn13 } from "@fuel-ts/math";
|
2496
2536
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2497
2537
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
@@ -2574,7 +2614,7 @@ var calculateTransactionFee = (params) => {
|
|
2574
2614
|
|
2575
2615
|
// src/providers/transaction-summary/operations.ts
|
2576
2616
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2577
|
-
import { ErrorCode as
|
2617
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2578
2618
|
import { bn as bn12 } from "@fuel-ts/math";
|
2579
2619
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2580
2620
|
|
@@ -2623,7 +2663,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2623
2663
|
};
|
2624
2664
|
|
2625
2665
|
// src/providers/transaction-summary/input.ts
|
2626
|
-
import { ErrorCode as
|
2666
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2627
2667
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2628
2668
|
function getInputsByTypes(inputs, types) {
|
2629
2669
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2662,7 +2702,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2662
2702
|
}
|
2663
2703
|
if (contractInput.type !== InputType5.Contract) {
|
2664
2704
|
throw new FuelError8(
|
2665
|
-
|
2705
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2666
2706
|
`Contract input should be of type 'contract'.`
|
2667
2707
|
);
|
2668
2708
|
}
|
@@ -2751,7 +2791,7 @@ function getTransactionTypeName(transactionType) {
|
|
2751
2791
|
return "Script" /* Script */;
|
2752
2792
|
default:
|
2753
2793
|
throw new FuelError9(
|
2754
|
-
|
2794
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2755
2795
|
`Invalid transaction type: ${transactionType}.`
|
2756
2796
|
);
|
2757
2797
|
}
|
@@ -3114,7 +3154,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3114
3154
|
};
|
3115
3155
|
|
3116
3156
|
// src/providers/transaction-summary/status.ts
|
3117
|
-
import { ErrorCode as
|
3157
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3118
3158
|
var getTransactionStatusName = (gqlStatus) => {
|
3119
3159
|
switch (gqlStatus) {
|
3120
3160
|
case "FailureStatus":
|
@@ -3127,7 +3167,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3127
3167
|
return "squeezedout" /* squeezedout */;
|
3128
3168
|
default:
|
3129
3169
|
throw new FuelError10(
|
3130
|
-
|
3170
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3131
3171
|
`Invalid transaction status: ${gqlStatus}.`
|
3132
3172
|
);
|
3133
3173
|
}
|
@@ -3347,6 +3387,12 @@ var TransactionResponse = class {
|
|
3347
3387
|
transactionId: this.id
|
3348
3388
|
});
|
3349
3389
|
for await (const { statusChange } of subscription) {
|
3390
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3391
|
+
throw new FuelError11(
|
3392
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3393
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3394
|
+
);
|
3395
|
+
}
|
3350
3396
|
if (statusChange.type !== "SubmittedStatus") {
|
3351
3397
|
break;
|
3352
3398
|
}
|
@@ -3376,7 +3422,7 @@ var TransactionResponse = class {
|
|
3376
3422
|
const result = await this.waitForResult(contractsAbiMap);
|
3377
3423
|
if (result.isStatusFailure) {
|
3378
3424
|
throw new FuelError11(
|
3379
|
-
|
3425
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3380
3426
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3381
3427
|
);
|
3382
3428
|
}
|
@@ -3524,14 +3570,15 @@ var _Provider = class {
|
|
3524
3570
|
}
|
3525
3571
|
static getFetchFn(options) {
|
3526
3572
|
const { retryOptions, timeout } = options;
|
3527
|
-
return autoRetryFetch((...args) => {
|
3528
|
-
if (options.fetch) {
|
3529
|
-
return options.fetch(...args);
|
3530
|
-
}
|
3573
|
+
return autoRetryFetch(async (...args) => {
|
3531
3574
|
const url = args[0];
|
3532
3575
|
const request = args[1];
|
3533
3576
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3534
|
-
|
3577
|
+
let fullRequest = { ...request, signal };
|
3578
|
+
if (options.requestMiddleware) {
|
3579
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3580
|
+
}
|
3581
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3535
3582
|
}, retryOptions);
|
3536
3583
|
}
|
3537
3584
|
/**
|
@@ -3551,7 +3598,7 @@ var _Provider = class {
|
|
3551
3598
|
const chain = _Provider.chainInfoCache[this.url];
|
3552
3599
|
if (!chain) {
|
3553
3600
|
throw new FuelError12(
|
3554
|
-
|
3601
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3555
3602
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3556
3603
|
);
|
3557
3604
|
}
|
@@ -3564,7 +3611,7 @@ var _Provider = class {
|
|
3564
3611
|
const node = _Provider.nodeInfoCache[this.url];
|
3565
3612
|
if (!node) {
|
3566
3613
|
throw new FuelError12(
|
3567
|
-
|
3614
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3568
3615
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3569
3616
|
);
|
3570
3617
|
}
|
@@ -3737,6 +3784,12 @@ var _Provider = class {
|
|
3737
3784
|
if (awaitExecution) {
|
3738
3785
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3739
3786
|
for await (const { submitAndAwait } of subscription) {
|
3787
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3788
|
+
throw new FuelError12(
|
3789
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3790
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3791
|
+
);
|
3792
|
+
}
|
3740
3793
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3741
3794
|
break;
|
3742
3795
|
}
|
@@ -3900,7 +3953,8 @@ var _Provider = class {
|
|
3900
3953
|
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3901
3954
|
estimateTxDependencies = true,
|
3902
3955
|
estimatePredicates = true,
|
3903
|
-
resourcesOwner
|
3956
|
+
resourcesOwner,
|
3957
|
+
signatureCallback
|
3904
3958
|
} = {}) {
|
3905
3959
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3906
3960
|
const chainInfo = this.getChain();
|
@@ -3919,6 +3973,9 @@ var _Provider = class {
|
|
3919
3973
|
}
|
3920
3974
|
await this.estimatePredicates(txRequestClone);
|
3921
3975
|
}
|
3976
|
+
if (signatureCallback && isScriptTransaction) {
|
3977
|
+
await signatureCallback(txRequestClone);
|
3978
|
+
}
|
3922
3979
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3923
3980
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3924
3981
|
let receipts = [];
|
@@ -4247,7 +4304,7 @@ var _Provider = class {
|
|
4247
4304
|
};
|
4248
4305
|
if (commitBlockId && commitBlockHeight) {
|
4249
4306
|
throw new FuelError12(
|
4250
|
-
|
4307
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4251
4308
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4252
4309
|
);
|
4253
4310
|
}
|
@@ -4364,7 +4421,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4364
4421
|
__publicField(Provider, "nodeInfoCache", {});
|
4365
4422
|
|
4366
4423
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4367
|
-
import { ErrorCode as
|
4424
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4368
4425
|
import { bn as bn15 } from "@fuel-ts/math";
|
4369
4426
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4370
4427
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4375,7 +4432,7 @@ async function getTransactionSummary(params) {
|
|
4375
4432
|
});
|
4376
4433
|
if (!gqlTransaction) {
|
4377
4434
|
throw new FuelError13(
|
4378
|
-
|
4435
|
+
ErrorCode13.TRANSACTION_NOT_FOUND,
|
4379
4436
|
`Transaction not found for given id: ${id}.`
|
4380
4437
|
);
|
4381
4438
|
}
|
@@ -4648,7 +4705,7 @@ var Account = class extends AbstractAccount {
|
|
4648
4705
|
*/
|
4649
4706
|
get provider() {
|
4650
4707
|
if (!this._provider) {
|
4651
|
-
throw new FuelError14(
|
4708
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4652
4709
|
}
|
4653
4710
|
return this._provider;
|
4654
4711
|
}
|
@@ -4701,7 +4758,7 @@ var Account = class extends AbstractAccount {
|
|
4701
4758
|
break;
|
4702
4759
|
}
|
4703
4760
|
throw new FuelError14(
|
4704
|
-
|
4761
|
+
ErrorCode14.NOT_SUPPORTED,
|
4705
4762
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4706
4763
|
);
|
4707
4764
|
}
|
@@ -4727,7 +4784,7 @@ var Account = class extends AbstractAccount {
|
|
4727
4784
|
break;
|
4728
4785
|
}
|
4729
4786
|
throw new FuelError14(
|
4730
|
-
|
4787
|
+
ErrorCode14.NOT_SUPPORTED,
|
4731
4788
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4732
4789
|
);
|
4733
4790
|
}
|
@@ -4763,7 +4820,7 @@ var Account = class extends AbstractAccount {
|
|
4763
4820
|
break;
|
4764
4821
|
}
|
4765
4822
|
throw new FuelError14(
|
4766
|
-
|
4823
|
+
ErrorCode14.NOT_SUPPORTED,
|
4767
4824
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4768
4825
|
);
|
4769
4826
|
}
|
@@ -4868,6 +4925,12 @@ var Account = class extends AbstractAccount {
|
|
4868
4925
|
* @returns A promise that resolves to the transaction response.
|
4869
4926
|
*/
|
4870
4927
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4928
|
+
if (bn16(amount).lte(0)) {
|
4929
|
+
throw new FuelError14(
|
4930
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4931
|
+
"Transfer amount must be a positive number."
|
4932
|
+
);
|
4933
|
+
}
|
4871
4934
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4872
4935
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4873
4936
|
}
|
@@ -4881,6 +4944,12 @@ var Account = class extends AbstractAccount {
|
|
4881
4944
|
* @returns A promise that resolves to the transaction response.
|
4882
4945
|
*/
|
4883
4946
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4947
|
+
if (bn16(amount).lte(0)) {
|
4948
|
+
throw new FuelError14(
|
4949
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4950
|
+
"Transfer amount must be a positive number."
|
4951
|
+
);
|
4952
|
+
}
|
4884
4953
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4885
4954
|
const { minGasPrice } = this.provider.getGasConfig();
|
4886
4955
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4950,10 +5019,25 @@ var Account = class extends AbstractAccount {
|
|
4950
5019
|
}
|
4951
5020
|
async signMessage(message) {
|
4952
5021
|
if (!this._connector) {
|
4953
|
-
throw new FuelError14(
|
5022
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4954
5023
|
}
|
4955
5024
|
return this._connector.signMessage(this.address.toString(), message);
|
4956
5025
|
}
|
5026
|
+
/**
|
5027
|
+
* Signs a transaction with the wallet's private key.
|
5028
|
+
*
|
5029
|
+
* @param transactionRequestLike - The transaction request to sign.
|
5030
|
+
* @returns A promise that resolves to the signature of the transaction.
|
5031
|
+
*/
|
5032
|
+
async signTransaction(transactionRequestLike) {
|
5033
|
+
if (!this._connector) {
|
5034
|
+
throw new FuelError14(
|
5035
|
+
ErrorCode14.MISSING_CONNECTOR,
|
5036
|
+
"A connector is required to sign transactions."
|
5037
|
+
);
|
5038
|
+
}
|
5039
|
+
return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
|
5040
|
+
}
|
4957
5041
|
/**
|
4958
5042
|
* Sends a transaction to the network.
|
4959
5043
|
*
|
@@ -4996,13 +5080,13 @@ var Account = class extends AbstractAccount {
|
|
4996
5080
|
}) {
|
4997
5081
|
if (minGasPrice.gt(gasPrice)) {
|
4998
5082
|
throw new FuelError14(
|
4999
|
-
|
5083
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5000
5084
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5001
5085
|
);
|
5002
5086
|
}
|
5003
5087
|
if (gasUsed.gt(gasLimit)) {
|
5004
5088
|
throw new FuelError14(
|
5005
|
-
|
5089
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
5006
5090
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5007
5091
|
);
|
5008
5092
|
}
|
@@ -5133,7 +5217,7 @@ import {
|
|
5133
5217
|
decryptJsonWalletData,
|
5134
5218
|
encryptJsonWalletData
|
5135
5219
|
} from "@fuel-ts/crypto";
|
5136
|
-
import { ErrorCode as
|
5220
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5137
5221
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5138
5222
|
import { v4 as uuidv4 } from "uuid";
|
5139
5223
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5212,7 +5296,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5212
5296
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5213
5297
|
if (mac !== macHash) {
|
5214
5298
|
throw new FuelError15(
|
5215
|
-
|
5299
|
+
ErrorCode15.INVALID_PASSWORD,
|
5216
5300
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5217
5301
|
);
|
5218
5302
|
}
|
@@ -5272,7 +5356,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5272
5356
|
*/
|
5273
5357
|
async signTransaction(transactionRequestLike) {
|
5274
5358
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5275
|
-
const chainId = this.provider.
|
5359
|
+
const chainId = this.provider.getChainId();
|
5276
5360
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5277
5361
|
const signature = await this.signer().sign(hashedTransaction);
|
5278
5362
|
return hexlify15(signature);
|
@@ -5334,24 +5418,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5334
5418
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5335
5419
|
|
5336
5420
|
// src/hdwallet/hdwallet.ts
|
5337
|
-
import { ErrorCode as
|
5421
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5422
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5338
5423
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5339
5424
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5340
|
-
import {
|
5341
|
-
toBeHex,
|
5342
|
-
dataSlice as dataSlice2,
|
5343
|
-
encodeBase58 as encodeBase582,
|
5344
|
-
decodeBase58,
|
5345
|
-
sha256 as sha2564,
|
5346
|
-
computeHmac as computeHmac2,
|
5347
|
-
ripemd160
|
5348
|
-
} from "ethers";
|
5425
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5349
5426
|
|
5350
5427
|
// src/mnemonic/mnemonic.ts
|
5351
5428
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5352
|
-
import { ErrorCode as
|
5429
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5430
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5353
5431
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5354
|
-
import { dataSlice, pbkdf2,
|
5432
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5355
5433
|
|
5356
5434
|
// src/wordlists/words/english.ts
|
5357
5435
|
var english = [
|
@@ -7412,9 +7490,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7412
7490
|
})(Language || {});
|
7413
7491
|
|
7414
7492
|
// src/mnemonic/utils.ts
|
7415
|
-
import { ErrorCode as
|
7493
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7494
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7416
7495
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7417
|
-
import { sha256 as sha2562 } from "ethers";
|
7418
7496
|
function toUtf8Bytes(stri) {
|
7419
7497
|
const str = stri.normalize("NFKD");
|
7420
7498
|
const result = [];
|
@@ -7430,7 +7508,7 @@ function toUtf8Bytes(stri) {
|
|
7430
7508
|
const c2 = str.charCodeAt(i);
|
7431
7509
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7432
7510
|
throw new FuelError16(
|
7433
|
-
|
7511
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7434
7512
|
"Invalid UTF-8 in the input string."
|
7435
7513
|
);
|
7436
7514
|
}
|
@@ -7494,7 +7572,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7494
7572
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7495
7573
|
if (index === -1) {
|
7496
7574
|
throw new FuelError16(
|
7497
|
-
|
7575
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7498
7576
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7499
7577
|
);
|
7500
7578
|
}
|
@@ -7511,7 +7589,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7511
7589
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7512
7590
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7513
7591
|
throw new FuelError16(
|
7514
|
-
|
7592
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7515
7593
|
"Checksum validation failed for the provided mnemonic."
|
7516
7594
|
);
|
7517
7595
|
}
|
@@ -7526,7 +7604,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7526
7604
|
function assertWordList(wordlist) {
|
7527
7605
|
if (wordlist.length !== 2048) {
|
7528
7606
|
throw new FuelError17(
|
7529
|
-
|
7607
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7530
7608
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7531
7609
|
);
|
7532
7610
|
}
|
@@ -7534,7 +7612,7 @@ function assertWordList(wordlist) {
|
|
7534
7612
|
function assertEntropy(entropy) {
|
7535
7613
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7536
7614
|
throw new FuelError17(
|
7537
|
-
|
7615
|
+
ErrorCode17.INVALID_ENTROPY,
|
7538
7616
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7539
7617
|
);
|
7540
7618
|
}
|
@@ -7544,7 +7622,7 @@ function assertMnemonic(words) {
|
|
7544
7622
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7545
7623
|
", "
|
7546
7624
|
)}] words, but got ${words.length}.`;
|
7547
|
-
throw new FuelError17(
|
7625
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7548
7626
|
}
|
7549
7627
|
}
|
7550
7628
|
var Mnemonic = class {
|
@@ -7663,7 +7741,7 @@ var Mnemonic = class {
|
|
7663
7741
|
const seedArray = arrayify17(seed);
|
7664
7742
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7665
7743
|
throw new FuelError17(
|
7666
|
-
|
7744
|
+
ErrorCode17.INVALID_SEED,
|
7667
7745
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7668
7746
|
);
|
7669
7747
|
}
|
@@ -7740,7 +7818,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7740
7818
|
function parsePath(path, depth = 0) {
|
7741
7819
|
const components = path.split("/");
|
7742
7820
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7743
|
-
throw new FuelError18(
|
7821
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7744
7822
|
}
|
7745
7823
|
if (components[0] === "m") {
|
7746
7824
|
components.shift();
|
@@ -7770,7 +7848,7 @@ var HDWallet = class {
|
|
7770
7848
|
} else {
|
7771
7849
|
if (!config.publicKey) {
|
7772
7850
|
throw new FuelError18(
|
7773
|
-
|
7851
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7774
7852
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7775
7853
|
);
|
7776
7854
|
}
|
@@ -7800,7 +7878,7 @@ var HDWallet = class {
|
|
7800
7878
|
if (index & HARDENED_INDEX) {
|
7801
7879
|
if (!privateKey) {
|
7802
7880
|
throw new FuelError18(
|
7803
|
-
|
7881
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7804
7882
|
"Cannot derive a hardened index without a private Key."
|
7805
7883
|
);
|
7806
7884
|
}
|
@@ -7853,7 +7931,7 @@ var HDWallet = class {
|
|
7853
7931
|
toExtendedKey(isPublic = false, testnet = false) {
|
7854
7932
|
if (this.depth >= 256) {
|
7855
7933
|
throw new FuelError18(
|
7856
|
-
|
7934
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7857
7935
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7858
7936
|
);
|
7859
7937
|
}
|
@@ -7884,10 +7962,10 @@ var HDWallet = class {
|
|
7884
7962
|
const bytes = arrayify18(decoded);
|
7885
7963
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7886
7964
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7887
|
-
throw new FuelError18(
|
7965
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7888
7966
|
}
|
7889
7967
|
if (!validChecksum) {
|
7890
|
-
throw new FuelError18(
|
7968
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7891
7969
|
}
|
7892
7970
|
const depth = bytes[4];
|
7893
7971
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7896,13 +7974,13 @@ var HDWallet = class {
|
|
7896
7974
|
const key = bytes.slice(45, 78);
|
7897
7975
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7898
7976
|
throw new FuelError18(
|
7899
|
-
|
7977
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7900
7978
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7901
7979
|
);
|
7902
7980
|
}
|
7903
7981
|
if (isPublicExtendedKey(bytes)) {
|
7904
7982
|
if (key[0] !== 3) {
|
7905
|
-
throw new FuelError18(
|
7983
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7906
7984
|
}
|
7907
7985
|
return new HDWallet({
|
7908
7986
|
publicKey: key,
|
@@ -7913,7 +7991,7 @@ var HDWallet = class {
|
|
7913
7991
|
});
|
7914
7992
|
}
|
7915
7993
|
if (key[0] !== 0) {
|
7916
|
-
throw new FuelError18(
|
7994
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7917
7995
|
}
|
7918
7996
|
return new HDWallet({
|
7919
7997
|
privateKey: key.slice(1),
|
@@ -8081,7 +8159,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8081
8159
|
// src/wallet-manager/wallet-manager.ts
|
8082
8160
|
import { Address as Address8 } from "@fuel-ts/address";
|
8083
8161
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8084
|
-
import { ErrorCode as
|
8162
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8085
8163
|
import { EventEmitter } from "events";
|
8086
8164
|
|
8087
8165
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8104,7 +8182,7 @@ var MemoryStorage = class {
|
|
8104
8182
|
|
8105
8183
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8106
8184
|
import { Address as Address6 } from "@fuel-ts/address";
|
8107
|
-
import { ErrorCode as
|
8185
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
8108
8186
|
var _secret;
|
8109
8187
|
var MnemonicVault = class {
|
8110
8188
|
constructor(options) {
|
@@ -8161,7 +8239,7 @@ var MnemonicVault = class {
|
|
8161
8239
|
numberOfAccounts += 1;
|
8162
8240
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8163
8241
|
throw new FuelError19(
|
8164
|
-
|
8242
|
+
ErrorCode19.WALLET_MANAGER_ERROR,
|
8165
8243
|
`Account with address '${address}' not found in derived wallets.`
|
8166
8244
|
);
|
8167
8245
|
}
|
@@ -8175,7 +8253,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8175
8253
|
|
8176
8254
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8177
8255
|
import { Address as Address7 } from "@fuel-ts/address";
|
8178
|
-
import { ErrorCode as
|
8256
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8179
8257
|
var _privateKeys;
|
8180
8258
|
var PrivateKeyVault = class {
|
8181
8259
|
/**
|
@@ -8217,7 +8295,7 @@ var PrivateKeyVault = class {
|
|
8217
8295
|
);
|
8218
8296
|
if (!privateKey) {
|
8219
8297
|
throw new FuelError20(
|
8220
|
-
|
8298
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8221
8299
|
`No private key found for address '${address}'.`
|
8222
8300
|
);
|
8223
8301
|
}
|
@@ -8241,7 +8319,7 @@ var ERROR_MESSAGES = {
|
|
8241
8319
|
};
|
8242
8320
|
function assert(condition, message) {
|
8243
8321
|
if (!condition) {
|
8244
|
-
throw new FuelError21(
|
8322
|
+
throw new FuelError21(ErrorCode21.WALLET_MANAGER_ERROR, message);
|
8245
8323
|
}
|
8246
8324
|
}
|
8247
8325
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8467,25 +8545,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8467
8545
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8468
8546
|
|
8469
8547
|
// src/wallet-manager/types.ts
|
8470
|
-
import { ErrorCode as
|
8548
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8471
8549
|
var Vault = class {
|
8472
8550
|
constructor(_options) {
|
8473
|
-
throw new FuelError22(
|
8551
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8474
8552
|
}
|
8475
8553
|
serialize() {
|
8476
|
-
throw new FuelError22(
|
8554
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8477
8555
|
}
|
8478
8556
|
getAccounts() {
|
8479
|
-
throw new FuelError22(
|
8557
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8480
8558
|
}
|
8481
8559
|
addAccount() {
|
8482
|
-
throw new FuelError22(
|
8560
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8483
8561
|
}
|
8484
8562
|
exportAccount(_address) {
|
8485
|
-
throw new FuelError22(
|
8563
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8486
8564
|
}
|
8487
8565
|
getWallet(_address) {
|
8488
|
-
throw new FuelError22(
|
8566
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8489
8567
|
}
|
8490
8568
|
};
|
8491
8569
|
__publicField(Vault, "type");
|
@@ -8502,7 +8580,7 @@ import {
|
|
8502
8580
|
} from "@fuel-ts/abi-coder";
|
8503
8581
|
import { Address as Address9 } from "@fuel-ts/address";
|
8504
8582
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8505
|
-
import { ErrorCode as
|
8583
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8506
8584
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8507
8585
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8508
8586
|
|
@@ -8522,27 +8600,37 @@ var getPredicateRoot = (bytecode) => {
|
|
8522
8600
|
// src/predicate/predicate.ts
|
8523
8601
|
var Predicate = class extends Account {
|
8524
8602
|
bytes;
|
8525
|
-
|
8526
|
-
|
8603
|
+
predicateDataBytes = Uint8Array.from([]);
|
8604
|
+
predicateData = [];
|
8527
8605
|
interface;
|
8528
8606
|
/**
|
8529
8607
|
* Creates an instance of the Predicate class.
|
8530
8608
|
*
|
8531
|
-
* @param
|
8609
|
+
* @param bytecode - The bytecode of the predicate.
|
8610
|
+
* @param abi - The JSON ABI of the predicate.
|
8532
8611
|
* @param provider - The provider used to interact with the blockchain.
|
8533
|
-
* @param
|
8612
|
+
* @param inputData - The predicate input data (optional).
|
8534
8613
|
* @param configurableConstants - Optional configurable constants for the predicate.
|
8535
8614
|
*/
|
8536
|
-
constructor(
|
8615
|
+
constructor({
|
8616
|
+
bytecode,
|
8617
|
+
abi,
|
8618
|
+
provider,
|
8619
|
+
inputData,
|
8620
|
+
configurableConstants
|
8621
|
+
}) {
|
8537
8622
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
8538
|
-
|
8539
|
-
|
8623
|
+
bytecode,
|
8624
|
+
abi,
|
8540
8625
|
configurableConstants
|
8541
8626
|
);
|
8542
8627
|
const address = Address9.fromB256(getPredicateRoot(predicateBytes));
|
8543
8628
|
super(address, provider);
|
8544
8629
|
this.bytes = predicateBytes;
|
8545
8630
|
this.interface = predicateInterface;
|
8631
|
+
if (inputData !== void 0 && inputData.length > 0) {
|
8632
|
+
this.predicateData = inputData;
|
8633
|
+
}
|
8546
8634
|
}
|
8547
8635
|
/**
|
8548
8636
|
* Populates the transaction data with predicate data.
|
@@ -8594,18 +8682,8 @@ var Predicate = class extends Account {
|
|
8594
8682
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8595
8683
|
return super.simulateTransaction(transactionRequest);
|
8596
8684
|
}
|
8597
|
-
/**
|
8598
|
-
* Sets data for the predicate.
|
8599
|
-
*
|
8600
|
-
* @param args - Arguments for the predicate function.
|
8601
|
-
* @returns The Predicate instance with updated predicate data.
|
8602
|
-
*/
|
8603
|
-
setData(...args) {
|
8604
|
-
this.predicateArgs = args;
|
8605
|
-
return this;
|
8606
|
-
}
|
8607
8685
|
getPredicateData(policiesLength) {
|
8608
|
-
if (!this.
|
8686
|
+
if (!this.predicateData.length) {
|
8609
8687
|
return new Uint8Array();
|
8610
8688
|
}
|
8611
8689
|
const mainFn = this.interface?.functions.main;
|
@@ -8614,7 +8692,7 @@ var Predicate = class extends Account {
|
|
8614
8692
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8615
8693
|
});
|
8616
8694
|
const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
|
8617
|
-
return mainFn?.encodeArguments(this.
|
8695
|
+
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
8618
8696
|
}
|
8619
8697
|
/**
|
8620
8698
|
* Processes the predicate data and returns the altered bytecode and interface.
|
@@ -8631,7 +8709,7 @@ var Predicate = class extends Account {
|
|
8631
8709
|
abiInterface = new Interface3(jsonAbi);
|
8632
8710
|
if (abiInterface.functions.main === void 0) {
|
8633
8711
|
throw new FuelError23(
|
8634
|
-
|
8712
|
+
ErrorCode23.ABI_MAIN_METHOD_MISSING,
|
8635
8713
|
'Cannot use ABI without "main" function.'
|
8636
8714
|
);
|
8637
8715
|
}
|
@@ -8677,7 +8755,7 @@ var Predicate = class extends Account {
|
|
8677
8755
|
});
|
8678
8756
|
} catch (err) {
|
8679
8757
|
throw new FuelError23(
|
8680
|
-
|
8758
|
+
ErrorCode23.INVALID_CONFIGURABLE_CONSTANTS,
|
8681
8759
|
`Error setting configurable constants: ${err.message}.`
|
8682
8760
|
);
|
8683
8761
|
}
|
@@ -8686,7 +8764,7 @@ var Predicate = class extends Account {
|
|
8686
8764
|
};
|
8687
8765
|
|
8688
8766
|
// src/connectors/fuel.ts
|
8689
|
-
import { ErrorCode as
|
8767
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8690
8768
|
|
8691
8769
|
// src/connectors/fuel-connector.ts
|
8692
8770
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -8825,6 +8903,18 @@ var FuelConnector = class extends EventEmitter2 {
|
|
8825
8903
|
async signMessage(_address, _message) {
|
8826
8904
|
throw new Error("Method not implemented.");
|
8827
8905
|
}
|
8906
|
+
/**
|
8907
|
+
* Should start the sign transaction process and return
|
8908
|
+
* the signed transaction.
|
8909
|
+
*
|
8910
|
+
* @param address - The address to sign the transaction
|
8911
|
+
* @param transaction - The transaction to sign
|
8912
|
+
*
|
8913
|
+
* @returns Transaction signature
|
8914
|
+
*/
|
8915
|
+
async signTransaction(_address, _transaction) {
|
8916
|
+
throw new Error("Method not implemented.");
|
8917
|
+
}
|
8828
8918
|
/**
|
8829
8919
|
* Should start the send transaction process and return
|
8830
8920
|
* the transaction id submitted to the network.
|
@@ -9307,7 +9397,7 @@ var _Fuel = class extends FuelConnector {
|
|
9307
9397
|
const currentNetwork = await this.currentNetwork();
|
9308
9398
|
provider = await Provider.create(currentNetwork.url);
|
9309
9399
|
} else {
|
9310
|
-
throw new FuelError24(
|
9400
|
+
throw new FuelError24(ErrorCode24.INVALID_PROVIDER, "Provider is not valid.");
|
9311
9401
|
}
|
9312
9402
|
return provider;
|
9313
9403
|
}
|