@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/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";
|
@@ -1612,13 +1624,27 @@ var BaseTransactionRequest = class {
|
|
1612
1624
|
this.outputs.push(output);
|
1613
1625
|
return this.outputs.length - 1;
|
1614
1626
|
}
|
1627
|
+
/**
|
1628
|
+
* @hidden
|
1629
|
+
*
|
1630
|
+
* Pushes a witness to the list and returns the index
|
1631
|
+
*
|
1632
|
+
* @param signature - The signature to add to the witness.
|
1633
|
+
* @returns The index of the created witness.
|
1634
|
+
*/
|
1635
|
+
addWitness(signature) {
|
1636
|
+
this.witnesses.push(signature);
|
1637
|
+
return this.witnesses.length - 1;
|
1638
|
+
}
|
1615
1639
|
/**
|
1616
1640
|
* @hidden
|
1617
1641
|
*
|
1618
1642
|
* Creates an empty witness without any side effects and returns the index
|
1643
|
+
*
|
1644
|
+
* @returns The index of the created witness.
|
1619
1645
|
*/
|
1620
|
-
|
1621
|
-
this.
|
1646
|
+
addEmptyWitness() {
|
1647
|
+
this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
|
1622
1648
|
return this.witnesses.length - 1;
|
1623
1649
|
}
|
1624
1650
|
/**
|
@@ -1647,6 +1673,21 @@ var BaseTransactionRequest = class {
|
|
1647
1673
|
}
|
1648
1674
|
this.witnesses[index] = witness;
|
1649
1675
|
}
|
1676
|
+
/**
|
1677
|
+
* Helper function to add an external signature to the transaction.
|
1678
|
+
*
|
1679
|
+
* @param account - The account/s to sign to the transaction.
|
1680
|
+
* @returns The transaction with the signature witness added.
|
1681
|
+
*/
|
1682
|
+
async addAccountWitnesses(account) {
|
1683
|
+
const accounts = Array.isArray(account) ? account : [account];
|
1684
|
+
await Promise.all(
|
1685
|
+
accounts.map(async (acc) => {
|
1686
|
+
this.addWitness(await acc.signTransaction(this));
|
1687
|
+
})
|
1688
|
+
);
|
1689
|
+
return this;
|
1690
|
+
}
|
1650
1691
|
/**
|
1651
1692
|
* Gets the coin inputs for a transaction.
|
1652
1693
|
*
|
@@ -1712,7 +1753,7 @@ var BaseTransactionRequest = class {
|
|
1712
1753
|
} else {
|
1713
1754
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
1714
1755
|
if (typeof witnessIndex !== "number") {
|
1715
|
-
witnessIndex = this.
|
1756
|
+
witnessIndex = this.addEmptyWitness();
|
1716
1757
|
}
|
1717
1758
|
}
|
1718
1759
|
const input = {
|
@@ -1724,7 +1765,7 @@ var BaseTransactionRequest = class {
|
|
1724
1765
|
txPointer: "0x00000000000000000000000000000000",
|
1725
1766
|
witnessIndex,
|
1726
1767
|
predicate: predicate?.bytes,
|
1727
|
-
predicateData: predicate?.
|
1768
|
+
predicateData: predicate?.predicateDataBytes
|
1728
1769
|
};
|
1729
1770
|
this.pushInput(input);
|
1730
1771
|
this.addChangeOutput(owner, assetId);
|
@@ -1746,7 +1787,7 @@ var BaseTransactionRequest = class {
|
|
1746
1787
|
} else {
|
1747
1788
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
1748
1789
|
if (typeof witnessIndex !== "number") {
|
1749
|
-
witnessIndex = this.
|
1790
|
+
witnessIndex = this.addEmptyWitness();
|
1750
1791
|
}
|
1751
1792
|
}
|
1752
1793
|
const input = {
|
@@ -1757,7 +1798,7 @@ var BaseTransactionRequest = class {
|
|
1757
1798
|
amount,
|
1758
1799
|
witnessIndex,
|
1759
1800
|
predicate: predicate?.bytes,
|
1760
|
-
predicateData: predicate?.
|
1801
|
+
predicateData: predicate?.predicateDataBytes
|
1761
1802
|
};
|
1762
1803
|
this.pushInput(input);
|
1763
1804
|
this.addChangeOutput(recipient, assetId);
|
@@ -2000,11 +2041,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2000
2041
|
|
2001
2042
|
// src/providers/transaction-request/hash-transaction.ts
|
2002
2043
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2003
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2044
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2004
2045
|
import { bn as bn7 } from "@fuel-ts/math";
|
2005
2046
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2006
2047
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2007
|
-
import { sha256 } from "ethers";
|
2008
2048
|
import { clone as clone2 } from "ramda";
|
2009
2049
|
function hashTransaction(transactionRequest, chainId) {
|
2010
2050
|
const transaction = transactionRequest.toTransaction();
|
@@ -2391,7 +2431,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2431
|
};
|
2392
2432
|
|
2393
2433
|
// src/providers/transaction-request/utils.ts
|
2394
|
-
import { ErrorCode as
|
2434
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2395
2435
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2396
2436
|
var transactionRequestify = (obj) => {
|
2397
2437
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2406,13 +2446,13 @@ var transactionRequestify = (obj) => {
|
|
2406
2446
|
return CreateTransactionRequest.from(obj);
|
2407
2447
|
}
|
2408
2448
|
default: {
|
2409
|
-
throw new FuelError7(
|
2449
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2410
2450
|
}
|
2411
2451
|
}
|
2412
2452
|
};
|
2413
2453
|
|
2414
2454
|
// src/providers/transaction-response/transaction-response.ts
|
2415
|
-
import { ErrorCode as
|
2455
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2416
2456
|
import { bn as bn13 } from "@fuel-ts/math";
|
2417
2457
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2418
2458
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
@@ -2495,7 +2535,7 @@ var calculateTransactionFee = (params) => {
|
|
2495
2535
|
|
2496
2536
|
// src/providers/transaction-summary/operations.ts
|
2497
2537
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2498
|
-
import { ErrorCode as
|
2538
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2499
2539
|
import { bn as bn12 } from "@fuel-ts/math";
|
2500
2540
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2501
2541
|
|
@@ -2544,7 +2584,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2544
2584
|
};
|
2545
2585
|
|
2546
2586
|
// src/providers/transaction-summary/input.ts
|
2547
|
-
import { ErrorCode as
|
2587
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2548
2588
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2549
2589
|
function getInputsByTypes(inputs, types) {
|
2550
2590
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2583,7 +2623,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2583
2623
|
}
|
2584
2624
|
if (contractInput.type !== InputType5.Contract) {
|
2585
2625
|
throw new FuelError8(
|
2586
|
-
|
2626
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2587
2627
|
`Contract input should be of type 'contract'.`
|
2588
2628
|
);
|
2589
2629
|
}
|
@@ -2631,7 +2671,7 @@ function getTransactionTypeName(transactionType) {
|
|
2631
2671
|
return "Script" /* Script */;
|
2632
2672
|
default:
|
2633
2673
|
throw new FuelError9(
|
2634
|
-
|
2674
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2635
2675
|
`Invalid transaction type: ${transactionType}.`
|
2636
2676
|
);
|
2637
2677
|
}
|
@@ -2988,7 +3028,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
2988
3028
|
};
|
2989
3029
|
|
2990
3030
|
// src/providers/transaction-summary/status.ts
|
2991
|
-
import { ErrorCode as
|
3031
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2992
3032
|
var getTransactionStatusName = (gqlStatus) => {
|
2993
3033
|
switch (gqlStatus) {
|
2994
3034
|
case "FailureStatus":
|
@@ -3001,7 +3041,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3001
3041
|
return "squeezedout" /* squeezedout */;
|
3002
3042
|
default:
|
3003
3043
|
throw new FuelError10(
|
3004
|
-
|
3044
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3005
3045
|
`Invalid transaction status: ${gqlStatus}.`
|
3006
3046
|
);
|
3007
3047
|
}
|
@@ -3221,6 +3261,12 @@ var TransactionResponse = class {
|
|
3221
3261
|
transactionId: this.id
|
3222
3262
|
});
|
3223
3263
|
for await (const { statusChange } of subscription) {
|
3264
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3265
|
+
throw new FuelError11(
|
3266
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3267
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3268
|
+
);
|
3269
|
+
}
|
3224
3270
|
if (statusChange.type !== "SubmittedStatus") {
|
3225
3271
|
break;
|
3226
3272
|
}
|
@@ -3250,7 +3296,7 @@ var TransactionResponse = class {
|
|
3250
3296
|
const result = await this.waitForResult(contractsAbiMap);
|
3251
3297
|
if (result.isStatusFailure) {
|
3252
3298
|
throw new FuelError11(
|
3253
|
-
|
3299
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3254
3300
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3255
3301
|
);
|
3256
3302
|
}
|
@@ -3385,14 +3431,15 @@ var _Provider = class {
|
|
3385
3431
|
}
|
3386
3432
|
static getFetchFn(options) {
|
3387
3433
|
const { retryOptions, timeout } = options;
|
3388
|
-
return autoRetryFetch((...args) => {
|
3389
|
-
if (options.fetch) {
|
3390
|
-
return options.fetch(...args);
|
3391
|
-
}
|
3434
|
+
return autoRetryFetch(async (...args) => {
|
3392
3435
|
const url = args[0];
|
3393
3436
|
const request = args[1];
|
3394
3437
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3395
|
-
|
3438
|
+
let fullRequest = { ...request, signal };
|
3439
|
+
if (options.requestMiddleware) {
|
3440
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3441
|
+
}
|
3442
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3396
3443
|
}, retryOptions);
|
3397
3444
|
}
|
3398
3445
|
/**
|
@@ -3412,7 +3459,7 @@ var _Provider = class {
|
|
3412
3459
|
const chain = _Provider.chainInfoCache[this.url];
|
3413
3460
|
if (!chain) {
|
3414
3461
|
throw new FuelError12(
|
3415
|
-
|
3462
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3416
3463
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3417
3464
|
);
|
3418
3465
|
}
|
@@ -3425,7 +3472,7 @@ var _Provider = class {
|
|
3425
3472
|
const node = _Provider.nodeInfoCache[this.url];
|
3426
3473
|
if (!node) {
|
3427
3474
|
throw new FuelError12(
|
3428
|
-
|
3475
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3429
3476
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3430
3477
|
);
|
3431
3478
|
}
|
@@ -3598,6 +3645,12 @@ var _Provider = class {
|
|
3598
3645
|
if (awaitExecution) {
|
3599
3646
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3600
3647
|
for await (const { submitAndAwait } of subscription) {
|
3648
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3649
|
+
throw new FuelError12(
|
3650
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3651
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3652
|
+
);
|
3653
|
+
}
|
3601
3654
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3602
3655
|
break;
|
3603
3656
|
}
|
@@ -3761,7 +3814,8 @@ var _Provider = class {
|
|
3761
3814
|
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3762
3815
|
estimateTxDependencies = true,
|
3763
3816
|
estimatePredicates = true,
|
3764
|
-
resourcesOwner
|
3817
|
+
resourcesOwner,
|
3818
|
+
signatureCallback
|
3765
3819
|
} = {}) {
|
3766
3820
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3767
3821
|
const chainInfo = this.getChain();
|
@@ -3780,6 +3834,9 @@ var _Provider = class {
|
|
3780
3834
|
}
|
3781
3835
|
await this.estimatePredicates(txRequestClone);
|
3782
3836
|
}
|
3837
|
+
if (signatureCallback && isScriptTransaction) {
|
3838
|
+
await signatureCallback(txRequestClone);
|
3839
|
+
}
|
3783
3840
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3784
3841
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3785
3842
|
let receipts = [];
|
@@ -4108,7 +4165,7 @@ var _Provider = class {
|
|
4108
4165
|
};
|
4109
4166
|
if (commitBlockId && commitBlockHeight) {
|
4110
4167
|
throw new FuelError12(
|
4111
|
-
|
4168
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4112
4169
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4113
4170
|
);
|
4114
4171
|
}
|
@@ -4225,7 +4282,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4225
4282
|
__publicField(Provider, "nodeInfoCache", {});
|
4226
4283
|
|
4227
4284
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4228
|
-
import { ErrorCode as
|
4285
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4229
4286
|
import { bn as bn15 } from "@fuel-ts/math";
|
4230
4287
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4231
4288
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4343,7 +4400,7 @@ var Account = class extends AbstractAccount {
|
|
4343
4400
|
*/
|
4344
4401
|
get provider() {
|
4345
4402
|
if (!this._provider) {
|
4346
|
-
throw new FuelError14(
|
4403
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4347
4404
|
}
|
4348
4405
|
return this._provider;
|
4349
4406
|
}
|
@@ -4396,7 +4453,7 @@ var Account = class extends AbstractAccount {
|
|
4396
4453
|
break;
|
4397
4454
|
}
|
4398
4455
|
throw new FuelError14(
|
4399
|
-
|
4456
|
+
ErrorCode14.NOT_SUPPORTED,
|
4400
4457
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4401
4458
|
);
|
4402
4459
|
}
|
@@ -4422,7 +4479,7 @@ var Account = class extends AbstractAccount {
|
|
4422
4479
|
break;
|
4423
4480
|
}
|
4424
4481
|
throw new FuelError14(
|
4425
|
-
|
4482
|
+
ErrorCode14.NOT_SUPPORTED,
|
4426
4483
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4427
4484
|
);
|
4428
4485
|
}
|
@@ -4458,7 +4515,7 @@ var Account = class extends AbstractAccount {
|
|
4458
4515
|
break;
|
4459
4516
|
}
|
4460
4517
|
throw new FuelError14(
|
4461
|
-
|
4518
|
+
ErrorCode14.NOT_SUPPORTED,
|
4462
4519
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4463
4520
|
);
|
4464
4521
|
}
|
@@ -4563,6 +4620,12 @@ var Account = class extends AbstractAccount {
|
|
4563
4620
|
* @returns A promise that resolves to the transaction response.
|
4564
4621
|
*/
|
4565
4622
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4623
|
+
if (bn16(amount).lte(0)) {
|
4624
|
+
throw new FuelError14(
|
4625
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4626
|
+
"Transfer amount must be a positive number."
|
4627
|
+
);
|
4628
|
+
}
|
4566
4629
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4567
4630
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4568
4631
|
}
|
@@ -4576,6 +4639,12 @@ var Account = class extends AbstractAccount {
|
|
4576
4639
|
* @returns A promise that resolves to the transaction response.
|
4577
4640
|
*/
|
4578
4641
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4642
|
+
if (bn16(amount).lte(0)) {
|
4643
|
+
throw new FuelError14(
|
4644
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4645
|
+
"Transfer amount must be a positive number."
|
4646
|
+
);
|
4647
|
+
}
|
4579
4648
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4580
4649
|
const { minGasPrice } = this.provider.getGasConfig();
|
4581
4650
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4645,10 +4714,25 @@ var Account = class extends AbstractAccount {
|
|
4645
4714
|
}
|
4646
4715
|
async signMessage(message) {
|
4647
4716
|
if (!this._connector) {
|
4648
|
-
throw new FuelError14(
|
4717
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4649
4718
|
}
|
4650
4719
|
return this._connector.signMessage(this.address.toString(), message);
|
4651
4720
|
}
|
4721
|
+
/**
|
4722
|
+
* Signs a transaction with the wallet's private key.
|
4723
|
+
*
|
4724
|
+
* @param transactionRequestLike - The transaction request to sign.
|
4725
|
+
* @returns A promise that resolves to the signature of the transaction.
|
4726
|
+
*/
|
4727
|
+
async signTransaction(transactionRequestLike) {
|
4728
|
+
if (!this._connector) {
|
4729
|
+
throw new FuelError14(
|
4730
|
+
ErrorCode14.MISSING_CONNECTOR,
|
4731
|
+
"A connector is required to sign transactions."
|
4732
|
+
);
|
4733
|
+
}
|
4734
|
+
return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
|
4735
|
+
}
|
4652
4736
|
/**
|
4653
4737
|
* Sends a transaction to the network.
|
4654
4738
|
*
|
@@ -4691,13 +4775,13 @@ var Account = class extends AbstractAccount {
|
|
4691
4775
|
}) {
|
4692
4776
|
if (minGasPrice.gt(gasPrice)) {
|
4693
4777
|
throw new FuelError14(
|
4694
|
-
|
4778
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
4695
4779
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4696
4780
|
);
|
4697
4781
|
}
|
4698
4782
|
if (gasUsed.gt(gasLimit)) {
|
4699
4783
|
throw new FuelError14(
|
4700
|
-
|
4784
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
4701
4785
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4702
4786
|
);
|
4703
4787
|
}
|
@@ -4824,7 +4908,7 @@ import {
|
|
4824
4908
|
decryptJsonWalletData,
|
4825
4909
|
encryptJsonWalletData
|
4826
4910
|
} from "@fuel-ts/crypto";
|
4827
|
-
import { ErrorCode as
|
4911
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4828
4912
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4829
4913
|
import { v4 as uuidv4 } from "uuid";
|
4830
4914
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -4903,7 +4987,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4903
4987
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
4904
4988
|
if (mac !== macHash) {
|
4905
4989
|
throw new FuelError15(
|
4906
|
-
|
4990
|
+
ErrorCode15.INVALID_PASSWORD,
|
4907
4991
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
4908
4992
|
);
|
4909
4993
|
}
|
@@ -4963,7 +5047,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4963
5047
|
*/
|
4964
5048
|
async signTransaction(transactionRequestLike) {
|
4965
5049
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4966
|
-
const chainId = this.provider.
|
5050
|
+
const chainId = this.provider.getChainId();
|
4967
5051
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
4968
5052
|
const signature = await this.signer().sign(hashedTransaction);
|
4969
5053
|
return hexlify15(signature);
|
@@ -5025,24 +5109,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5025
5109
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5026
5110
|
|
5027
5111
|
// src/hdwallet/hdwallet.ts
|
5028
|
-
import { ErrorCode as
|
5112
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5113
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5029
5114
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5030
5115
|
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";
|
5116
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5040
5117
|
|
5041
5118
|
// src/mnemonic/mnemonic.ts
|
5042
5119
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5043
|
-
import { ErrorCode as
|
5120
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5121
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5044
5122
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5045
|
-
import { dataSlice, pbkdf2,
|
5123
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5046
5124
|
|
5047
5125
|
// src/wordlists/words/english.ts
|
5048
5126
|
var english = [
|
@@ -7097,9 +7175,9 @@ var english = [
|
|
7097
7175
|
];
|
7098
7176
|
|
7099
7177
|
// src/mnemonic/utils.ts
|
7100
|
-
import { ErrorCode as
|
7178
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7179
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7101
7180
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7102
|
-
import { sha256 as sha2562 } from "ethers";
|
7103
7181
|
function toUtf8Bytes(stri) {
|
7104
7182
|
const str = stri.normalize("NFKD");
|
7105
7183
|
const result = [];
|
@@ -7115,7 +7193,7 @@ function toUtf8Bytes(stri) {
|
|
7115
7193
|
const c2 = str.charCodeAt(i);
|
7116
7194
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7117
7195
|
throw new FuelError16(
|
7118
|
-
|
7196
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7119
7197
|
"Invalid UTF-8 in the input string."
|
7120
7198
|
);
|
7121
7199
|
}
|
@@ -7179,7 +7257,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7179
7257
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7180
7258
|
if (index === -1) {
|
7181
7259
|
throw new FuelError16(
|
7182
|
-
|
7260
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7183
7261
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7184
7262
|
);
|
7185
7263
|
}
|
@@ -7196,7 +7274,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7196
7274
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7197
7275
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7198
7276
|
throw new FuelError16(
|
7199
|
-
|
7277
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7200
7278
|
"Checksum validation failed for the provided mnemonic."
|
7201
7279
|
);
|
7202
7280
|
}
|
@@ -7211,7 +7289,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7211
7289
|
function assertWordList(wordlist) {
|
7212
7290
|
if (wordlist.length !== 2048) {
|
7213
7291
|
throw new FuelError17(
|
7214
|
-
|
7292
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7215
7293
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7216
7294
|
);
|
7217
7295
|
}
|
@@ -7219,7 +7297,7 @@ function assertWordList(wordlist) {
|
|
7219
7297
|
function assertEntropy(entropy) {
|
7220
7298
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7221
7299
|
throw new FuelError17(
|
7222
|
-
|
7300
|
+
ErrorCode17.INVALID_ENTROPY,
|
7223
7301
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7224
7302
|
);
|
7225
7303
|
}
|
@@ -7229,7 +7307,7 @@ function assertMnemonic(words) {
|
|
7229
7307
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7230
7308
|
", "
|
7231
7309
|
)}] words, but got ${words.length}.`;
|
7232
|
-
throw new FuelError17(
|
7310
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7233
7311
|
}
|
7234
7312
|
}
|
7235
7313
|
var Mnemonic = class {
|
@@ -7348,7 +7426,7 @@ var Mnemonic = class {
|
|
7348
7426
|
const seedArray = arrayify17(seed);
|
7349
7427
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7350
7428
|
throw new FuelError17(
|
7351
|
-
|
7429
|
+
ErrorCode17.INVALID_SEED,
|
7352
7430
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7353
7431
|
);
|
7354
7432
|
}
|
@@ -7425,7 +7503,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7425
7503
|
function parsePath(path2, depth = 0) {
|
7426
7504
|
const components = path2.split("/");
|
7427
7505
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7428
|
-
throw new FuelError18(
|
7506
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7429
7507
|
}
|
7430
7508
|
if (components[0] === "m") {
|
7431
7509
|
components.shift();
|
@@ -7455,7 +7533,7 @@ var HDWallet = class {
|
|
7455
7533
|
} else {
|
7456
7534
|
if (!config.publicKey) {
|
7457
7535
|
throw new FuelError18(
|
7458
|
-
|
7536
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7459
7537
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7460
7538
|
);
|
7461
7539
|
}
|
@@ -7485,7 +7563,7 @@ var HDWallet = class {
|
|
7485
7563
|
if (index & HARDENED_INDEX) {
|
7486
7564
|
if (!privateKey) {
|
7487
7565
|
throw new FuelError18(
|
7488
|
-
|
7566
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7489
7567
|
"Cannot derive a hardened index without a private Key."
|
7490
7568
|
);
|
7491
7569
|
}
|
@@ -7538,7 +7616,7 @@ var HDWallet = class {
|
|
7538
7616
|
toExtendedKey(isPublic = false, testnet = false) {
|
7539
7617
|
if (this.depth >= 256) {
|
7540
7618
|
throw new FuelError18(
|
7541
|
-
|
7619
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7542
7620
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7543
7621
|
);
|
7544
7622
|
}
|
@@ -7569,10 +7647,10 @@ var HDWallet = class {
|
|
7569
7647
|
const bytes = arrayify18(decoded);
|
7570
7648
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7571
7649
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7572
|
-
throw new FuelError18(
|
7650
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7573
7651
|
}
|
7574
7652
|
if (!validChecksum) {
|
7575
|
-
throw new FuelError18(
|
7653
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7576
7654
|
}
|
7577
7655
|
const depth = bytes[4];
|
7578
7656
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7581,13 +7659,13 @@ var HDWallet = class {
|
|
7581
7659
|
const key = bytes.slice(45, 78);
|
7582
7660
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7583
7661
|
throw new FuelError18(
|
7584
|
-
|
7662
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7585
7663
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7586
7664
|
);
|
7587
7665
|
}
|
7588
7666
|
if (isPublicExtendedKey(bytes)) {
|
7589
7667
|
if (key[0] !== 3) {
|
7590
|
-
throw new FuelError18(
|
7668
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7591
7669
|
}
|
7592
7670
|
return new HDWallet({
|
7593
7671
|
publicKey: key,
|
@@ -7598,7 +7676,7 @@ var HDWallet = class {
|
|
7598
7676
|
});
|
7599
7677
|
}
|
7600
7678
|
if (key[0] !== 0) {
|
7601
|
-
throw new FuelError18(
|
7679
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7602
7680
|
}
|
7603
7681
|
return new HDWallet({
|
7604
7682
|
privateKey: key.slice(1),
|