@fuel-ts/account 0.0.0-rc-1976-20240405090158 → 0.0.0-rc-1976-20240405092005
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/index.global.js +212 -38
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +540 -457
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +328 -240
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +212 -38
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +501 -424
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +298 -213
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,9 +24,9 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { ErrorCode as
|
27
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
29
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
30
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
31
31
|
|
32
32
|
// src/providers/coin-quantity.ts
|
@@ -66,8 +66,8 @@ var addAmountToAsset = (params) => {
|
|
66
66
|
|
67
67
|
// src/providers/provider.ts
|
68
68
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
|
-
import { ErrorCode as
|
70
|
-
import { BN, bn as
|
69
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
71
71
|
import {
|
72
72
|
InputType as InputType6,
|
73
73
|
TransactionType as TransactionType8,
|
@@ -1150,7 +1150,7 @@ var outputify = (value) => {
|
|
1150
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1151
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1152
1152
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1153
|
-
import { bn as
|
1153
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1154
1154
|
import {
|
1155
1155
|
PolicyType,
|
1156
1156
|
TransactionCoder,
|
@@ -1493,6 +1493,86 @@ function sleep(time) {
|
|
1493
1493
|
});
|
1494
1494
|
}
|
1495
1495
|
|
1496
|
+
// src/providers/utils/extract-tx-error.ts
|
1497
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1498
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1499
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1500
|
+
import {
|
1501
|
+
FAILED_REQUIRE_SIGNAL,
|
1502
|
+
FAILED_ASSERT_EQ_SIGNAL,
|
1503
|
+
FAILED_ASSERT_NE_SIGNAL,
|
1504
|
+
FAILED_ASSERT_SIGNAL,
|
1505
|
+
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1506
|
+
PANIC_REASONS,
|
1507
|
+
PANIC_DOC_URL
|
1508
|
+
} from "@fuel-ts/transactions/configs";
|
1509
|
+
var assemblePanicError = (status) => {
|
1510
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1511
|
+
const reason = status.reason;
|
1512
|
+
if (PANIC_REASONS.includes(status.reason)) {
|
1513
|
+
errorMessage = `${errorMessage}
|
1514
|
+
|
1515
|
+
You can read more about this error at:
|
1516
|
+
|
1517
|
+
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1518
|
+
}
|
1519
|
+
return { errorMessage, reason };
|
1520
|
+
};
|
1521
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1522
|
+
var assembleRevertError = (receipts, logs) => {
|
1523
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1524
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1525
|
+
let reason = "";
|
1526
|
+
if (revertReceipt) {
|
1527
|
+
const reasonHex = bn6(revertReceipt.val).toHex();
|
1528
|
+
switch (reasonHex) {
|
1529
|
+
case FAILED_REQUIRE_SIGNAL: {
|
1530
|
+
reason = "require";
|
1531
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1532
|
+
break;
|
1533
|
+
}
|
1534
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
1535
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1536
|
+
reason = "assert_eq";
|
1537
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1538
|
+
break;
|
1539
|
+
}
|
1540
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
1541
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1542
|
+
reason = "assert_ne";
|
1543
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1544
|
+
break;
|
1545
|
+
}
|
1546
|
+
case FAILED_ASSERT_SIGNAL:
|
1547
|
+
reason = "assert";
|
1548
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1549
|
+
break;
|
1550
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1551
|
+
reason = "MissingOutputChange";
|
1552
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1553
|
+
break;
|
1554
|
+
default:
|
1555
|
+
reason = "unknown";
|
1556
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1557
|
+
}
|
1558
|
+
}
|
1559
|
+
return { errorMessage, reason };
|
1560
|
+
};
|
1561
|
+
var extractTxError = (params) => {
|
1562
|
+
const { receipts, status, logs } = params;
|
1563
|
+
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1564
|
+
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1565
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1566
|
+
const metadata = {
|
1567
|
+
logs,
|
1568
|
+
receipts,
|
1569
|
+
panic: isPanic,
|
1570
|
+
revert: isRevert,
|
1571
|
+
reason
|
1572
|
+
};
|
1573
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1574
|
+
};
|
1575
|
+
|
1496
1576
|
// src/providers/transaction-request/errors.ts
|
1497
1577
|
var NoWitnessAtIndexError = class extends Error {
|
1498
1578
|
constructor(index) {
|
@@ -1546,10 +1626,10 @@ var BaseTransactionRequest = class {
|
|
1546
1626
|
witnesses,
|
1547
1627
|
baseAssetId
|
1548
1628
|
} = {}) {
|
1549
|
-
this.gasPrice =
|
1629
|
+
this.gasPrice = bn7(gasPrice);
|
1550
1630
|
this.maturity = maturity ?? 0;
|
1551
|
-
this.witnessLimit = witnessLimit ?
|
1552
|
-
this.maxFee = maxFee ?
|
1631
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1632
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1553
1633
|
this.inputs = inputs ?? [];
|
1554
1634
|
this.outputs = outputs ?? [];
|
1555
1635
|
this.witnesses = witnesses ?? [];
|
@@ -1978,13 +2058,13 @@ var BaseTransactionRequest = class {
|
|
1978
2058
|
assetId,
|
1979
2059
|
owner: resourcesOwner || Address.fromRandom(),
|
1980
2060
|
maturity: 0,
|
1981
|
-
blockCreated:
|
1982
|
-
txCreatedIdx:
|
2061
|
+
blockCreated: bn7(1),
|
2062
|
+
txCreatedIdx: bn7(1)
|
1983
2063
|
}
|
1984
2064
|
]);
|
1985
2065
|
}
|
1986
2066
|
};
|
1987
|
-
updateAssetInput(this.baseAssetId,
|
2067
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
1988
2068
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
1989
2069
|
}
|
1990
2070
|
/**
|
@@ -1995,7 +2075,7 @@ var BaseTransactionRequest = class {
|
|
1995
2075
|
*/
|
1996
2076
|
getCoinOutputsQuantities() {
|
1997
2077
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
1998
|
-
amount:
|
2078
|
+
amount: bn7(amount),
|
1999
2079
|
assetId: assetId.toString()
|
2000
2080
|
}));
|
2001
2081
|
return coinsQuantities;
|
@@ -2024,7 +2104,7 @@ var BaseTransactionRequest = class {
|
|
2024
2104
|
default:
|
2025
2105
|
return;
|
2026
2106
|
}
|
2027
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2107
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2028
2108
|
i.predicate = correspondingInput.predicate;
|
2029
2109
|
i.predicateData = correspondingInput.predicateData;
|
2030
2110
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2035,14 +2115,14 @@ var BaseTransactionRequest = class {
|
|
2035
2115
|
|
2036
2116
|
// src/providers/transaction-request/create-transaction-request.ts
|
2037
2117
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2038
|
-
import { bn as
|
2118
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2039
2119
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2040
2120
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2041
2121
|
|
2042
2122
|
// src/providers/transaction-request/hash-transaction.ts
|
2043
2123
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2044
2124
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2045
|
-
import { bn as
|
2125
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2046
2126
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2047
2127
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2048
2128
|
import { clone as clone2 } from "ramda";
|
@@ -2059,11 +2139,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2059
2139
|
blockHeight: 0,
|
2060
2140
|
txIndex: 0
|
2061
2141
|
};
|
2062
|
-
inputClone.predicateGasUsed =
|
2142
|
+
inputClone.predicateGasUsed = bn8(0);
|
2063
2143
|
return inputClone;
|
2064
2144
|
}
|
2065
2145
|
case InputType3.Message: {
|
2066
|
-
inputClone.predicateGasUsed =
|
2146
|
+
inputClone.predicateGasUsed = bn8(0);
|
2067
2147
|
return inputClone;
|
2068
2148
|
}
|
2069
2149
|
case InputType3.Contract: {
|
@@ -2090,12 +2170,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2090
2170
|
return outputClone;
|
2091
2171
|
}
|
2092
2172
|
case OutputType3.Change: {
|
2093
|
-
outputClone.amount =
|
2173
|
+
outputClone.amount = bn8(0);
|
2094
2174
|
return outputClone;
|
2095
2175
|
}
|
2096
2176
|
case OutputType3.Variable: {
|
2097
2177
|
outputClone.to = ZeroBytes325;
|
2098
|
-
outputClone.amount =
|
2178
|
+
outputClone.amount = bn8(0);
|
2099
2179
|
outputClone.assetId = ZeroBytes325;
|
2100
2180
|
return outputClone;
|
2101
2181
|
}
|
@@ -2219,7 +2299,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2219
2299
|
}
|
2220
2300
|
metadataGas(gasCosts) {
|
2221
2301
|
return calculateMetadataGasForTxCreate({
|
2222
|
-
contractBytesSize:
|
2302
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2223
2303
|
gasCosts,
|
2224
2304
|
stateRootSize: this.storageSlots.length,
|
2225
2305
|
txBytesSize: this.byteSize()
|
@@ -2231,7 +2311,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2231
2311
|
import { Interface } from "@fuel-ts/abi-coder";
|
2232
2312
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2233
2313
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2234
|
-
import { bn as
|
2314
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2235
2315
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2236
2316
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2237
2317
|
|
@@ -2285,7 +2365,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2285
2365
|
*/
|
2286
2366
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2287
2367
|
super(rest);
|
2288
|
-
this.gasLimit =
|
2368
|
+
this.gasLimit = bn10(gasLimit);
|
2289
2369
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2290
2370
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2291
2371
|
this.abis = rest.abis;
|
@@ -2433,7 +2513,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2433
2513
|
};
|
2434
2514
|
|
2435
2515
|
// src/providers/transaction-request/utils.ts
|
2436
|
-
import { ErrorCode as
|
2516
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2437
2517
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2438
2518
|
var transactionRequestify = (obj) => {
|
2439
2519
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2448,14 +2528,14 @@ var transactionRequestify = (obj) => {
|
|
2448
2528
|
return CreateTransactionRequest.from(obj);
|
2449
2529
|
}
|
2450
2530
|
default: {
|
2451
|
-
throw new
|
2531
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2452
2532
|
}
|
2453
2533
|
}
|
2454
2534
|
};
|
2455
2535
|
|
2456
2536
|
// src/providers/transaction-response/transaction-response.ts
|
2457
|
-
import { ErrorCode as
|
2458
|
-
import { bn as
|
2537
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2538
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2459
2539
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2460
2540
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2461
2541
|
|
@@ -2463,7 +2543,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2463
2543
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2464
2544
|
|
2465
2545
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2466
|
-
import { bn as
|
2546
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2467
2547
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2468
2548
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2469
2549
|
var calculateTransactionFee = (params) => {
|
@@ -2472,24 +2552,24 @@ var calculateTransactionFee = (params) => {
|
|
2472
2552
|
rawPayload,
|
2473
2553
|
consensusParameters: { gasCosts, feeParams }
|
2474
2554
|
} = params;
|
2475
|
-
const gasPerByte =
|
2476
|
-
const gasPriceFactor =
|
2555
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2556
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2477
2557
|
const transactionBytes = arrayify9(rawPayload);
|
2478
2558
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2479
2559
|
if (transaction.type === TransactionType6.Mint) {
|
2480
2560
|
return {
|
2481
|
-
fee:
|
2482
|
-
minFee:
|
2483
|
-
maxFee:
|
2484
|
-
feeFromGasUsed:
|
2561
|
+
fee: bn11(0),
|
2562
|
+
minFee: bn11(0),
|
2563
|
+
maxFee: bn11(0),
|
2564
|
+
feeFromGasUsed: bn11(0)
|
2485
2565
|
};
|
2486
2566
|
}
|
2487
2567
|
const { type, witnesses, inputs, policies } = transaction;
|
2488
|
-
let metadataGas =
|
2489
|
-
let gasLimit =
|
2568
|
+
let metadataGas = bn11(0);
|
2569
|
+
let gasLimit = bn11(0);
|
2490
2570
|
if (type === TransactionType6.Create) {
|
2491
2571
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2492
|
-
const contractBytesSize =
|
2572
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2493
2573
|
metadataGas = calculateMetadataGasForTxCreate({
|
2494
2574
|
contractBytesSize,
|
2495
2575
|
gasCosts,
|
@@ -2508,12 +2588,12 @@ var calculateTransactionFee = (params) => {
|
|
2508
2588
|
}
|
2509
2589
|
const minGas = getMinGas({
|
2510
2590
|
gasCosts,
|
2511
|
-
gasPerByte:
|
2591
|
+
gasPerByte: bn11(gasPerByte),
|
2512
2592
|
inputs,
|
2513
2593
|
metadataGas,
|
2514
2594
|
txBytesSize: transactionBytes.length
|
2515
2595
|
});
|
2516
|
-
const gasPrice =
|
2596
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2517
2597
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2518
2598
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2519
2599
|
const maxGas = getMaxGas({
|
@@ -2537,13 +2617,13 @@ var calculateTransactionFee = (params) => {
|
|
2537
2617
|
|
2538
2618
|
// src/providers/transaction-summary/operations.ts
|
2539
2619
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2540
|
-
import { ErrorCode as
|
2541
|
-
import { bn as
|
2542
|
-
import { ReceiptType as
|
2620
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2621
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2622
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2543
2623
|
|
2544
2624
|
// src/providers/transaction-summary/call.ts
|
2545
2625
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2546
|
-
import { bn as
|
2626
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2547
2627
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2548
2628
|
const abiInterface = new Interface2(abi);
|
2549
2629
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2552,7 +2632,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2552
2632
|
let encodedArgs;
|
2553
2633
|
if (functionFragment.isInputDataPointer) {
|
2554
2634
|
if (rawPayload) {
|
2555
|
-
const argsOffset =
|
2635
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2556
2636
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2557
2637
|
}
|
2558
2638
|
} else {
|
@@ -2586,7 +2666,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2586
2666
|
};
|
2587
2667
|
|
2588
2668
|
// src/providers/transaction-summary/input.ts
|
2589
|
-
import { ErrorCode as
|
2669
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2590
2670
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2591
2671
|
function getInputsByTypes(inputs, types) {
|
2592
2672
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2624,8 +2704,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2624
2704
|
return void 0;
|
2625
2705
|
}
|
2626
2706
|
if (contractInput.type !== InputType5.Contract) {
|
2627
|
-
throw new
|
2628
|
-
|
2707
|
+
throw new FuelError9(
|
2708
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2629
2709
|
`Contract input should be of type 'contract'.`
|
2630
2710
|
);
|
2631
2711
|
}
|
@@ -2672,8 +2752,8 @@ function getTransactionTypeName(transactionType) {
|
|
2672
2752
|
case TransactionType7.Script:
|
2673
2753
|
return "Script" /* Script */;
|
2674
2754
|
default:
|
2675
|
-
throw new
|
2676
|
-
|
2755
|
+
throw new FuelError10(
|
2756
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2677
2757
|
`Invalid transaction type: ${transactionType}.`
|
2678
2758
|
);
|
2679
2759
|
}
|
@@ -2692,10 +2772,10 @@ function isTypeScript(transactionType) {
|
|
2692
2772
|
return isType(transactionType, "Script" /* Script */);
|
2693
2773
|
}
|
2694
2774
|
function getReceiptsCall(receipts) {
|
2695
|
-
return getReceiptsByType(receipts,
|
2775
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2696
2776
|
}
|
2697
2777
|
function getReceiptsMessageOut(receipts) {
|
2698
|
-
return getReceiptsByType(receipts,
|
2778
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2699
2779
|
}
|
2700
2780
|
var mergeAssets = (op1, op2) => {
|
2701
2781
|
const assets1 = op1.assetsSent || [];
|
@@ -2708,7 +2788,7 @@ var mergeAssets = (op1, op2) => {
|
|
2708
2788
|
if (!matchingAsset) {
|
2709
2789
|
return asset1;
|
2710
2790
|
}
|
2711
|
-
const mergedAmount =
|
2791
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2712
2792
|
return { ...asset1, amount: mergedAmount };
|
2713
2793
|
});
|
2714
2794
|
return mergedAssets.concat(filteredAssets);
|
@@ -2891,11 +2971,11 @@ function getTransferOperations({
|
|
2891
2971
|
});
|
2892
2972
|
const transferReceipts = getReceiptsByType(
|
2893
2973
|
receipts,
|
2894
|
-
|
2974
|
+
ReceiptType4.Transfer
|
2895
2975
|
);
|
2896
2976
|
const transferOutReceipts = getReceiptsByType(
|
2897
2977
|
receipts,
|
2898
|
-
|
2978
|
+
ReceiptType4.TransferOut
|
2899
2979
|
);
|
2900
2980
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2901
2981
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -2980,17 +3060,17 @@ function getOperations({
|
|
2980
3060
|
}
|
2981
3061
|
|
2982
3062
|
// src/providers/transaction-summary/receipt.ts
|
2983
|
-
import { ReceiptType as
|
3063
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
2984
3064
|
var processGqlReceipt = (gqlReceipt) => {
|
2985
3065
|
const receipt = assembleReceiptByType(gqlReceipt);
|
2986
3066
|
switch (receipt.type) {
|
2987
|
-
case
|
3067
|
+
case ReceiptType5.ReturnData: {
|
2988
3068
|
return {
|
2989
3069
|
...receipt,
|
2990
3070
|
data: gqlReceipt.data || "0x"
|
2991
3071
|
};
|
2992
3072
|
}
|
2993
|
-
case
|
3073
|
+
case ReceiptType5.LogData: {
|
2994
3074
|
return {
|
2995
3075
|
...receipt,
|
2996
3076
|
data: gqlReceipt.data || "0x"
|
@@ -3003,7 +3083,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3003
3083
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3004
3084
|
const mintedAssets = [];
|
3005
3085
|
receipts.forEach((receipt) => {
|
3006
|
-
if (receipt.type ===
|
3086
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3007
3087
|
mintedAssets.push({
|
3008
3088
|
subId: receipt.subId,
|
3009
3089
|
contractId: receipt.contractId,
|
@@ -3017,7 +3097,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3017
3097
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3018
3098
|
const burnedAssets = [];
|
3019
3099
|
receipts.forEach((receipt) => {
|
3020
|
-
if (receipt.type ===
|
3100
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3021
3101
|
burnedAssets.push({
|
3022
3102
|
subId: receipt.subId,
|
3023
3103
|
contractId: receipt.contractId,
|
@@ -3030,7 +3110,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3030
3110
|
};
|
3031
3111
|
|
3032
3112
|
// src/providers/transaction-summary/status.ts
|
3033
|
-
import { ErrorCode as
|
3113
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3034
3114
|
var getTransactionStatusName = (gqlStatus) => {
|
3035
3115
|
switch (gqlStatus) {
|
3036
3116
|
case "FailureStatus":
|
@@ -3042,8 +3122,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3042
3122
|
case "SqueezedOutStatus":
|
3043
3123
|
return "squeezedout" /* squeezedout */;
|
3044
3124
|
default:
|
3045
|
-
throw new
|
3046
|
-
|
3125
|
+
throw new FuelError11(
|
3126
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3047
3127
|
`Invalid transaction status: ${gqlStatus}.`
|
3048
3128
|
);
|
3049
3129
|
}
|
@@ -3156,12 +3236,12 @@ function assembleTransactionSummary(params) {
|
|
3156
3236
|
|
3157
3237
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3158
3238
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3159
|
-
import { ReceiptType as
|
3239
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3160
3240
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3161
3241
|
return receipts.reduce((logs, receipt) => {
|
3162
|
-
if (receipt.type ===
|
3242
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3163
3243
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3164
|
-
const data = receipt.type ===
|
3244
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3165
3245
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3166
3246
|
logs.push(decodedLog);
|
3167
3247
|
}
|
@@ -3176,7 +3256,7 @@ var TransactionResponse = class {
|
|
3176
3256
|
/** Current provider */
|
3177
3257
|
provider;
|
3178
3258
|
/** Gas used on the transaction */
|
3179
|
-
gasUsed =
|
3259
|
+
gasUsed = bn14(0);
|
3180
3260
|
/** The graphql Transaction with receipts object. */
|
3181
3261
|
gqlTransaction;
|
3182
3262
|
abis;
|
@@ -3281,8 +3361,8 @@ var TransactionResponse = class {
|
|
3281
3361
|
});
|
3282
3362
|
for await (const { statusChange } of subscription) {
|
3283
3363
|
if (statusChange.type === "SqueezedOutStatus") {
|
3284
|
-
throw new
|
3285
|
-
|
3364
|
+
throw new FuelError12(
|
3365
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3286
3366
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3287
3367
|
);
|
3288
3368
|
}
|
@@ -3304,14 +3384,26 @@ var TransactionResponse = class {
|
|
3304
3384
|
gqlTransaction: this.gqlTransaction,
|
3305
3385
|
...transactionSummary
|
3306
3386
|
};
|
3387
|
+
let logs = [];
|
3307
3388
|
if (this.abis) {
|
3308
|
-
|
3389
|
+
logs = getDecodedLogs(
|
3309
3390
|
transactionSummary.receipts,
|
3310
3391
|
this.abis.main,
|
3311
3392
|
this.abis.otherContractsAbis
|
3312
3393
|
);
|
3313
3394
|
transactionResult.logs = logs;
|
3314
3395
|
}
|
3396
|
+
if (transactionResult.isStatusFailure) {
|
3397
|
+
const {
|
3398
|
+
receipts,
|
3399
|
+
gqlTransaction: { status }
|
3400
|
+
} = transactionResult;
|
3401
|
+
throw extractTxError({
|
3402
|
+
receipts,
|
3403
|
+
status,
|
3404
|
+
logs
|
3405
|
+
});
|
3406
|
+
}
|
3315
3407
|
return transactionResult;
|
3316
3408
|
}
|
3317
3409
|
/**
|
@@ -3320,14 +3412,7 @@ var TransactionResponse = class {
|
|
3320
3412
|
* @param contractsAbiMap - The contracts ABI map.
|
3321
3413
|
*/
|
3322
3414
|
async wait(contractsAbiMap) {
|
3323
|
-
|
3324
|
-
if (result.isStatusFailure) {
|
3325
|
-
throw new FuelError11(
|
3326
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3327
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3328
|
-
);
|
3329
|
-
}
|
3330
|
-
return result;
|
3415
|
+
return this.waitForResult(contractsAbiMap);
|
3331
3416
|
}
|
3332
3417
|
};
|
3333
3418
|
|
@@ -3389,30 +3474,30 @@ var processGqlChain = (chain) => {
|
|
3389
3474
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3390
3475
|
return {
|
3391
3476
|
name,
|
3392
|
-
baseChainHeight:
|
3477
|
+
baseChainHeight: bn15(daHeight),
|
3393
3478
|
consensusParameters: {
|
3394
|
-
contractMaxSize:
|
3395
|
-
maxInputs:
|
3396
|
-
maxOutputs:
|
3397
|
-
maxWitnesses:
|
3398
|
-
maxGasPerTx:
|
3399
|
-
maxScriptLength:
|
3400
|
-
maxScriptDataLength:
|
3401
|
-
maxStorageSlots:
|
3402
|
-
maxPredicateLength:
|
3403
|
-
maxPredicateDataLength:
|
3404
|
-
maxGasPerPredicate:
|
3405
|
-
gasPriceFactor:
|
3406
|
-
gasPerByte:
|
3407
|
-
maxMessageDataLength:
|
3408
|
-
chainId:
|
3479
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3480
|
+
maxInputs: bn15(txParams.maxInputs),
|
3481
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3482
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3483
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3484
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3485
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3486
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3487
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3488
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3489
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3490
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3491
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3492
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3493
|
+
chainId: bn15(consensusParameters.chainId),
|
3409
3494
|
baseAssetId: consensusParameters.baseAssetId,
|
3410
3495
|
gasCosts
|
3411
3496
|
},
|
3412
3497
|
gasCosts,
|
3413
3498
|
latestBlock: {
|
3414
3499
|
id: latestBlock.id,
|
3415
|
-
height:
|
3500
|
+
height: bn15(latestBlock.header.height),
|
3416
3501
|
time: latestBlock.header.time,
|
3417
3502
|
transactions: latestBlock.transactions.map((i) => ({
|
3418
3503
|
id: i.id
|
@@ -3482,8 +3567,8 @@ var _Provider = class {
|
|
3482
3567
|
getChain() {
|
3483
3568
|
const chain = _Provider.chainInfoCache[this.url];
|
3484
3569
|
if (!chain) {
|
3485
|
-
throw new
|
3486
|
-
|
3570
|
+
throw new FuelError13(
|
3571
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3487
3572
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3488
3573
|
);
|
3489
3574
|
}
|
@@ -3495,8 +3580,8 @@ var _Provider = class {
|
|
3495
3580
|
getNode() {
|
3496
3581
|
const node = _Provider.nodeInfoCache[this.url];
|
3497
3582
|
if (!node) {
|
3498
|
-
throw new
|
3499
|
-
|
3583
|
+
throw new FuelError13(
|
3584
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3500
3585
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3501
3586
|
);
|
3502
3587
|
}
|
@@ -3543,8 +3628,8 @@ var _Provider = class {
|
|
3543
3628
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3544
3629
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3545
3630
|
if (!isMajorSupported || !isMinorSupported) {
|
3546
|
-
throw new
|
3547
|
-
|
3631
|
+
throw new FuelError13(
|
3632
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3548
3633
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3549
3634
|
);
|
3550
3635
|
}
|
@@ -3607,7 +3692,7 @@ var _Provider = class {
|
|
3607
3692
|
*/
|
3608
3693
|
async getBlockNumber() {
|
3609
3694
|
const { chain } = await this.operations.getChain();
|
3610
|
-
return
|
3695
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3611
3696
|
}
|
3612
3697
|
/**
|
3613
3698
|
* Returns the chain information.
|
@@ -3617,9 +3702,9 @@ var _Provider = class {
|
|
3617
3702
|
async fetchNode() {
|
3618
3703
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3619
3704
|
const processedNodeInfo = {
|
3620
|
-
maxDepth:
|
3621
|
-
maxTx:
|
3622
|
-
minGasPrice:
|
3705
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3706
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3707
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3623
3708
|
nodeVersion: nodeInfo.nodeVersion,
|
3624
3709
|
utxoValidation: nodeInfo.utxoValidation,
|
3625
3710
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3685,8 +3770,8 @@ var _Provider = class {
|
|
3685
3770
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3686
3771
|
for await (const { submitAndAwait } of subscription) {
|
3687
3772
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3688
|
-
throw new
|
3689
|
-
|
3773
|
+
throw new FuelError13(
|
3774
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3690
3775
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3691
3776
|
);
|
3692
3777
|
}
|
@@ -3753,7 +3838,7 @@ var _Provider = class {
|
|
3753
3838
|
} = response;
|
3754
3839
|
if (inputs) {
|
3755
3840
|
inputs.forEach((input, index) => {
|
3756
|
-
if ("predicateGasUsed" in input &&
|
3841
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3757
3842
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3758
3843
|
}
|
3759
3844
|
});
|
@@ -3866,7 +3951,7 @@ var _Provider = class {
|
|
3866
3951
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3867
3952
|
if (estimatePredicates) {
|
3868
3953
|
if (isScriptTransaction) {
|
3869
|
-
txRequestClone.gasLimit =
|
3954
|
+
txRequestClone.gasLimit = bn15(0);
|
3870
3955
|
}
|
3871
3956
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3872
3957
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3882,8 +3967,8 @@ var _Provider = class {
|
|
3882
3967
|
let missingContractIds = [];
|
3883
3968
|
let outputVariables = 0;
|
3884
3969
|
if (isScriptTransaction && estimateTxDependencies) {
|
3885
|
-
txRequestClone.gasPrice =
|
3886
|
-
txRequestClone.gasLimit =
|
3970
|
+
txRequestClone.gasPrice = bn15(0);
|
3971
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3887
3972
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3888
3973
|
receipts = result.receipts;
|
3889
3974
|
outputVariables = result.outputVariables;
|
@@ -3945,11 +4030,11 @@ var _Provider = class {
|
|
3945
4030
|
return coins.map((coin) => ({
|
3946
4031
|
id: coin.utxoId,
|
3947
4032
|
assetId: coin.assetId,
|
3948
|
-
amount:
|
4033
|
+
amount: bn15(coin.amount),
|
3949
4034
|
owner: Address2.fromAddressOrString(coin.owner),
|
3950
|
-
maturity:
|
3951
|
-
blockCreated:
|
3952
|
-
txCreatedIdx:
|
4035
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4036
|
+
blockCreated: bn15(coin.blockCreated),
|
4037
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3953
4038
|
}));
|
3954
4039
|
}
|
3955
4040
|
/**
|
@@ -3986,9 +4071,9 @@ var _Provider = class {
|
|
3986
4071
|
switch (coin.__typename) {
|
3987
4072
|
case "MessageCoin":
|
3988
4073
|
return {
|
3989
|
-
amount:
|
4074
|
+
amount: bn15(coin.amount),
|
3990
4075
|
assetId: coin.assetId,
|
3991
|
-
daHeight:
|
4076
|
+
daHeight: bn15(coin.daHeight),
|
3992
4077
|
sender: Address2.fromAddressOrString(coin.sender),
|
3993
4078
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
3994
4079
|
nonce: coin.nonce
|
@@ -3996,12 +4081,12 @@ var _Provider = class {
|
|
3996
4081
|
case "Coin":
|
3997
4082
|
return {
|
3998
4083
|
id: coin.utxoId,
|
3999
|
-
amount:
|
4084
|
+
amount: bn15(coin.amount),
|
4000
4085
|
assetId: coin.assetId,
|
4001
4086
|
owner: Address2.fromAddressOrString(coin.owner),
|
4002
|
-
maturity:
|
4003
|
-
blockCreated:
|
4004
|
-
txCreatedIdx:
|
4087
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4088
|
+
blockCreated: bn15(coin.blockCreated),
|
4089
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4005
4090
|
};
|
4006
4091
|
default:
|
4007
4092
|
return null;
|
@@ -4018,13 +4103,13 @@ var _Provider = class {
|
|
4018
4103
|
async getBlock(idOrHeight) {
|
4019
4104
|
let variables;
|
4020
4105
|
if (typeof idOrHeight === "number") {
|
4021
|
-
variables = { height:
|
4106
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4022
4107
|
} else if (idOrHeight === "latest") {
|
4023
4108
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4024
4109
|
} else if (idOrHeight.length === 66) {
|
4025
4110
|
variables = { blockId: idOrHeight };
|
4026
4111
|
} else {
|
4027
|
-
variables = { blockId:
|
4112
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4028
4113
|
}
|
4029
4114
|
const { block } = await this.operations.getBlock(variables);
|
4030
4115
|
if (!block) {
|
@@ -4032,7 +4117,7 @@ var _Provider = class {
|
|
4032
4117
|
}
|
4033
4118
|
return {
|
4034
4119
|
id: block.id,
|
4035
|
-
height:
|
4120
|
+
height: bn15(block.header.height),
|
4036
4121
|
time: block.header.time,
|
4037
4122
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4038
4123
|
};
|
@@ -4047,7 +4132,7 @@ var _Provider = class {
|
|
4047
4132
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4048
4133
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4049
4134
|
id: block.id,
|
4050
|
-
height:
|
4135
|
+
height: bn15(block.header.height),
|
4051
4136
|
time: block.header.time,
|
4052
4137
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4053
4138
|
}));
|
@@ -4062,7 +4147,7 @@ var _Provider = class {
|
|
4062
4147
|
async getBlockWithTransactions(idOrHeight) {
|
4063
4148
|
let variables;
|
4064
4149
|
if (typeof idOrHeight === "number") {
|
4065
|
-
variables = { blockHeight:
|
4150
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4066
4151
|
} else if (idOrHeight === "latest") {
|
4067
4152
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4068
4153
|
} else {
|
@@ -4074,7 +4159,7 @@ var _Provider = class {
|
|
4074
4159
|
}
|
4075
4160
|
return {
|
4076
4161
|
id: block.id,
|
4077
|
-
height:
|
4162
|
+
height: bn15(block.header.height, 10),
|
4078
4163
|
time: block.header.time,
|
4079
4164
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4080
4165
|
transactions: block.transactions.map(
|
@@ -4123,7 +4208,7 @@ var _Provider = class {
|
|
4123
4208
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4124
4209
|
asset: hexlify12(assetId)
|
4125
4210
|
});
|
4126
|
-
return
|
4211
|
+
return bn15(contractBalance.amount, 10);
|
4127
4212
|
}
|
4128
4213
|
/**
|
4129
4214
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4137,7 +4222,7 @@ var _Provider = class {
|
|
4137
4222
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4138
4223
|
assetId: hexlify12(assetId)
|
4139
4224
|
});
|
4140
|
-
return
|
4225
|
+
return bn15(balance.amount, 10);
|
4141
4226
|
}
|
4142
4227
|
/**
|
4143
4228
|
* Returns balances for the given owner.
|
@@ -4155,7 +4240,7 @@ var _Provider = class {
|
|
4155
4240
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4156
4241
|
return balances.map((balance) => ({
|
4157
4242
|
assetId: balance.assetId,
|
4158
|
-
amount:
|
4243
|
+
amount: bn15(balance.amount)
|
4159
4244
|
}));
|
4160
4245
|
}
|
4161
4246
|
/**
|
@@ -4177,15 +4262,15 @@ var _Provider = class {
|
|
4177
4262
|
sender: message.sender,
|
4178
4263
|
recipient: message.recipient,
|
4179
4264
|
nonce: message.nonce,
|
4180
|
-
amount:
|
4265
|
+
amount: bn15(message.amount),
|
4181
4266
|
data: message.data
|
4182
4267
|
}),
|
4183
4268
|
sender: Address2.fromAddressOrString(message.sender),
|
4184
4269
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4185
4270
|
nonce: message.nonce,
|
4186
|
-
amount:
|
4271
|
+
amount: bn15(message.amount),
|
4187
4272
|
data: InputMessageCoder.decodeData(message.data),
|
4188
|
-
daHeight:
|
4273
|
+
daHeight: bn15(message.daHeight)
|
4189
4274
|
}));
|
4190
4275
|
}
|
4191
4276
|
/**
|
@@ -4203,8 +4288,8 @@ var _Provider = class {
|
|
4203
4288
|
nonce
|
4204
4289
|
};
|
4205
4290
|
if (commitBlockId && commitBlockHeight) {
|
4206
|
-
throw new
|
4207
|
-
|
4291
|
+
throw new FuelError13(
|
4292
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4208
4293
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4209
4294
|
);
|
4210
4295
|
}
|
@@ -4238,41 +4323,41 @@ var _Provider = class {
|
|
4238
4323
|
} = result.messageProof;
|
4239
4324
|
return {
|
4240
4325
|
messageProof: {
|
4241
|
-
proofIndex:
|
4326
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4242
4327
|
proofSet: messageProof.proofSet
|
4243
4328
|
},
|
4244
4329
|
blockProof: {
|
4245
|
-
proofIndex:
|
4330
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4246
4331
|
proofSet: blockProof.proofSet
|
4247
4332
|
},
|
4248
4333
|
messageBlockHeader: {
|
4249
4334
|
id: messageBlockHeader.id,
|
4250
|
-
daHeight:
|
4251
|
-
transactionsCount:
|
4335
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4336
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4252
4337
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4253
|
-
height:
|
4338
|
+
height: bn15(messageBlockHeader.height),
|
4254
4339
|
prevRoot: messageBlockHeader.prevRoot,
|
4255
4340
|
time: messageBlockHeader.time,
|
4256
4341
|
applicationHash: messageBlockHeader.applicationHash,
|
4257
4342
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4258
|
-
messageReceiptCount:
|
4343
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4259
4344
|
},
|
4260
4345
|
commitBlockHeader: {
|
4261
4346
|
id: commitBlockHeader.id,
|
4262
|
-
daHeight:
|
4263
|
-
transactionsCount:
|
4347
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4348
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4264
4349
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4265
|
-
height:
|
4350
|
+
height: bn15(commitBlockHeader.height),
|
4266
4351
|
prevRoot: commitBlockHeader.prevRoot,
|
4267
4352
|
time: commitBlockHeader.time,
|
4268
4353
|
applicationHash: commitBlockHeader.applicationHash,
|
4269
4354
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4270
|
-
messageReceiptCount:
|
4355
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4271
4356
|
},
|
4272
4357
|
sender: Address2.fromAddressOrString(sender),
|
4273
4358
|
recipient: Address2.fromAddressOrString(recipient),
|
4274
4359
|
nonce,
|
4275
|
-
amount:
|
4360
|
+
amount: bn15(amount),
|
4276
4361
|
data
|
4277
4362
|
};
|
4278
4363
|
}
|
@@ -4295,10 +4380,10 @@ var _Provider = class {
|
|
4295
4380
|
*/
|
4296
4381
|
async produceBlocks(amount, startTime) {
|
4297
4382
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4298
|
-
blocksToProduce:
|
4383
|
+
blocksToProduce: bn15(amount).toString(10),
|
4299
4384
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4300
4385
|
});
|
4301
|
-
return
|
4386
|
+
return bn15(latestBlockHeight);
|
4302
4387
|
}
|
4303
4388
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4304
4389
|
async getTransactionResponse(transactionId) {
|
@@ -4321,8 +4406,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4321
4406
|
__publicField(Provider, "nodeInfoCache", {});
|
4322
4407
|
|
4323
4408
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4324
|
-
import { ErrorCode as
|
4325
|
-
import { bn as
|
4409
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4410
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4326
4411
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4327
4412
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4328
4413
|
|
@@ -4439,7 +4524,7 @@ var Account = class extends AbstractAccount {
|
|
4439
4524
|
*/
|
4440
4525
|
get provider() {
|
4441
4526
|
if (!this._provider) {
|
4442
|
-
throw new
|
4527
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4443
4528
|
}
|
4444
4529
|
return this._provider;
|
4445
4530
|
}
|
@@ -4491,8 +4576,8 @@ var Account = class extends AbstractAccount {
|
|
4491
4576
|
if (!hasNextPage) {
|
4492
4577
|
break;
|
4493
4578
|
}
|
4494
|
-
throw new
|
4495
|
-
|
4579
|
+
throw new FuelError15(
|
4580
|
+
ErrorCode15.NOT_SUPPORTED,
|
4496
4581
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4497
4582
|
);
|
4498
4583
|
}
|
@@ -4517,8 +4602,8 @@ var Account = class extends AbstractAccount {
|
|
4517
4602
|
if (!hasNextPage) {
|
4518
4603
|
break;
|
4519
4604
|
}
|
4520
|
-
throw new
|
4521
|
-
|
4605
|
+
throw new FuelError15(
|
4606
|
+
ErrorCode15.NOT_SUPPORTED,
|
4522
4607
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4523
4608
|
);
|
4524
4609
|
}
|
@@ -4554,8 +4639,8 @@ var Account = class extends AbstractAccount {
|
|
4554
4639
|
if (!hasNextPage) {
|
4555
4640
|
break;
|
4556
4641
|
}
|
4557
|
-
throw new
|
4558
|
-
|
4642
|
+
throw new FuelError15(
|
4643
|
+
ErrorCode15.NOT_SUPPORTED,
|
4559
4644
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4560
4645
|
);
|
4561
4646
|
}
|
@@ -4572,7 +4657,7 @@ var Account = class extends AbstractAccount {
|
|
4572
4657
|
async fund(request, coinQuantities, fee) {
|
4573
4658
|
const baseAssetId = this.provider.getBaseAssetId();
|
4574
4659
|
const updatedQuantities = addAmountToAsset({
|
4575
|
-
amount:
|
4660
|
+
amount: bn17(fee),
|
4576
4661
|
assetId: baseAssetId,
|
4577
4662
|
coinQuantities
|
4578
4663
|
});
|
@@ -4580,7 +4665,7 @@ var Account = class extends AbstractAccount {
|
|
4580
4665
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4581
4666
|
quantitiesDict[assetId] = {
|
4582
4667
|
required: amount,
|
4583
|
-
owned:
|
4668
|
+
owned: bn17(0)
|
4584
4669
|
};
|
4585
4670
|
});
|
4586
4671
|
const cachedUtxos = [];
|
@@ -4593,7 +4678,7 @@ var Account = class extends AbstractAccount {
|
|
4593
4678
|
if (isCoin2) {
|
4594
4679
|
const assetId = String(input.assetId);
|
4595
4680
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4596
|
-
const amount =
|
4681
|
+
const amount = bn17(input.amount);
|
4597
4682
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4598
4683
|
cachedUtxos.push(input.id);
|
4599
4684
|
}
|
@@ -4640,8 +4725,8 @@ var Account = class extends AbstractAccount {
|
|
4640
4725
|
estimateTxDependencies: true,
|
4641
4726
|
resourcesOwner: this
|
4642
4727
|
});
|
4643
|
-
request.gasPrice =
|
4644
|
-
request.gasLimit =
|
4728
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4729
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4645
4730
|
this.validateGas({
|
4646
4731
|
gasUsed,
|
4647
4732
|
gasPrice: request.gasPrice,
|
@@ -4662,9 +4747,9 @@ var Account = class extends AbstractAccount {
|
|
4662
4747
|
* @returns A promise that resolves to the transaction response.
|
4663
4748
|
*/
|
4664
4749
|
async transfer(destination, amount, assetId, txParams = {}) {
|
4665
|
-
if (
|
4666
|
-
throw new
|
4667
|
-
|
4750
|
+
if (bn17(amount).lte(0)) {
|
4751
|
+
throw new FuelError15(
|
4752
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4668
4753
|
"Transfer amount must be a positive number."
|
4669
4754
|
);
|
4670
4755
|
}
|
@@ -4682,9 +4767,9 @@ var Account = class extends AbstractAccount {
|
|
4682
4767
|
* @returns A promise that resolves to the transaction response.
|
4683
4768
|
*/
|
4684
4769
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4685
|
-
if (
|
4686
|
-
throw new
|
4687
|
-
|
4770
|
+
if (bn17(amount).lte(0)) {
|
4771
|
+
throw new FuelError15(
|
4772
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4688
4773
|
"Transfer amount must be a positive number."
|
4689
4774
|
);
|
4690
4775
|
}
|
@@ -4694,7 +4779,7 @@ var Account = class extends AbstractAccount {
|
|
4694
4779
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4695
4780
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4696
4781
|
hexlifiedContractId: contractAddress.toB256(),
|
4697
|
-
amountToTransfer:
|
4782
|
+
amountToTransfer: bn17(amount),
|
4698
4783
|
assetId: assetIdToTransfer
|
4699
4784
|
});
|
4700
4785
|
const request = new ScriptTransactionRequest({
|
@@ -4705,9 +4790,9 @@ var Account = class extends AbstractAccount {
|
|
4705
4790
|
request.addContractInputAndOutput(contractAddress);
|
4706
4791
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4707
4792
|
request,
|
4708
|
-
[{ amount:
|
4793
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4709
4794
|
);
|
4710
|
-
request.gasLimit =
|
4795
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4711
4796
|
this.validateGas({
|
4712
4797
|
gasUsed,
|
4713
4798
|
gasPrice: request.gasPrice,
|
@@ -4733,7 +4818,7 @@ var Account = class extends AbstractAccount {
|
|
4733
4818
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4734
4819
|
);
|
4735
4820
|
const amountDataArray = arrayify14(
|
4736
|
-
"0x".concat(
|
4821
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
4737
4822
|
);
|
4738
4823
|
const script = new Uint8Array([
|
4739
4824
|
...arrayify14(withdrawScript.bytes),
|
@@ -4742,12 +4827,12 @@ var Account = class extends AbstractAccount {
|
|
4742
4827
|
]);
|
4743
4828
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4744
4829
|
const request = new ScriptTransactionRequest(params);
|
4745
|
-
const forwardingQuantities = [{ amount:
|
4830
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4746
4831
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4747
4832
|
request,
|
4748
4833
|
forwardingQuantities
|
4749
4834
|
);
|
4750
|
-
request.gasLimit =
|
4835
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4751
4836
|
this.validateGas({
|
4752
4837
|
gasUsed,
|
4753
4838
|
gasPrice: request.gasPrice,
|
@@ -4759,7 +4844,7 @@ var Account = class extends AbstractAccount {
|
|
4759
4844
|
}
|
4760
4845
|
async signMessage(message) {
|
4761
4846
|
if (!this._connector) {
|
4762
|
-
throw new
|
4847
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4763
4848
|
}
|
4764
4849
|
return this._connector.signMessage(this.address.toString(), message);
|
4765
4850
|
}
|
@@ -4771,8 +4856,8 @@ var Account = class extends AbstractAccount {
|
|
4771
4856
|
*/
|
4772
4857
|
async signTransaction(transactionRequestLike) {
|
4773
4858
|
if (!this._connector) {
|
4774
|
-
throw new
|
4775
|
-
|
4859
|
+
throw new FuelError15(
|
4860
|
+
ErrorCode15.MISSING_CONNECTOR,
|
4776
4861
|
"A connector is required to sign transactions."
|
4777
4862
|
);
|
4778
4863
|
}
|
@@ -4819,14 +4904,14 @@ var Account = class extends AbstractAccount {
|
|
4819
4904
|
minGasPrice
|
4820
4905
|
}) {
|
4821
4906
|
if (minGasPrice.gt(gasPrice)) {
|
4822
|
-
throw new
|
4823
|
-
|
4907
|
+
throw new FuelError15(
|
4908
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4824
4909
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4825
4910
|
);
|
4826
4911
|
}
|
4827
4912
|
if (gasUsed.gt(gasLimit)) {
|
4828
|
-
throw new
|
4829
|
-
|
4913
|
+
throw new FuelError15(
|
4914
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
4830
4915
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4831
4916
|
);
|
4832
4917
|
}
|
@@ -4953,7 +5038,7 @@ import {
|
|
4953
5038
|
decryptJsonWalletData,
|
4954
5039
|
encryptJsonWalletData
|
4955
5040
|
} from "@fuel-ts/crypto";
|
4956
|
-
import { ErrorCode as
|
5041
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4957
5042
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4958
5043
|
import { v4 as uuidv4 } from "uuid";
|
4959
5044
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5031,8 +5116,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5031
5116
|
const macHashUint8Array = keccak256(data);
|
5032
5117
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5033
5118
|
if (mac !== macHash) {
|
5034
|
-
throw new
|
5035
|
-
|
5119
|
+
throw new FuelError16(
|
5120
|
+
ErrorCode16.INVALID_PASSWORD,
|
5036
5121
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5037
5122
|
);
|
5038
5123
|
}
|
@@ -5154,15 +5239,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5154
5239
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5155
5240
|
|
5156
5241
|
// src/hdwallet/hdwallet.ts
|
5157
|
-
import { ErrorCode as
|
5242
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5158
5243
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5159
|
-
import { bn as
|
5244
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5160
5245
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5161
5246
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5162
5247
|
|
5163
5248
|
// src/mnemonic/mnemonic.ts
|
5164
5249
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5165
|
-
import { ErrorCode as
|
5250
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5166
5251
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5167
5252
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5168
5253
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7220,7 +7305,7 @@ var english = [
|
|
7220
7305
|
];
|
7221
7306
|
|
7222
7307
|
// src/mnemonic/utils.ts
|
7223
|
-
import { ErrorCode as
|
7308
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7224
7309
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7225
7310
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7226
7311
|
function toUtf8Bytes(stri) {
|
@@ -7237,8 +7322,8 @@ function toUtf8Bytes(stri) {
|
|
7237
7322
|
i += 1;
|
7238
7323
|
const c2 = str.charCodeAt(i);
|
7239
7324
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7240
|
-
throw new
|
7241
|
-
|
7325
|
+
throw new FuelError17(
|
7326
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7242
7327
|
"Invalid UTF-8 in the input string."
|
7243
7328
|
);
|
7244
7329
|
}
|
@@ -7301,8 +7386,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7301
7386
|
for (let i = 0; i < words.length; i += 1) {
|
7302
7387
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7303
7388
|
if (index === -1) {
|
7304
|
-
throw new
|
7305
|
-
|
7389
|
+
throw new FuelError17(
|
7390
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7306
7391
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7307
7392
|
);
|
7308
7393
|
}
|
@@ -7318,8 +7403,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7318
7403
|
const checksumMask = getUpperMask(checksumBits);
|
7319
7404
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7320
7405
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7321
|
-
throw new
|
7322
|
-
|
7406
|
+
throw new FuelError17(
|
7407
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7323
7408
|
"Checksum validation failed for the provided mnemonic."
|
7324
7409
|
);
|
7325
7410
|
}
|
@@ -7333,16 +7418,16 @@ var TestnetPRV = "0x04358394";
|
|
7333
7418
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7334
7419
|
function assertWordList(wordlist) {
|
7335
7420
|
if (wordlist.length !== 2048) {
|
7336
|
-
throw new
|
7337
|
-
|
7421
|
+
throw new FuelError18(
|
7422
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7338
7423
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7339
7424
|
);
|
7340
7425
|
}
|
7341
7426
|
}
|
7342
7427
|
function assertEntropy(entropy) {
|
7343
7428
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7344
|
-
throw new
|
7345
|
-
|
7429
|
+
throw new FuelError18(
|
7430
|
+
ErrorCode18.INVALID_ENTROPY,
|
7346
7431
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7347
7432
|
);
|
7348
7433
|
}
|
@@ -7352,7 +7437,7 @@ function assertMnemonic(words) {
|
|
7352
7437
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7353
7438
|
", "
|
7354
7439
|
)}] words, but got ${words.length}.`;
|
7355
|
-
throw new
|
7440
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7356
7441
|
}
|
7357
7442
|
}
|
7358
7443
|
var Mnemonic = class {
|
@@ -7470,8 +7555,8 @@ var Mnemonic = class {
|
|
7470
7555
|
static masterKeysFromSeed(seed) {
|
7471
7556
|
const seedArray = arrayify17(seed);
|
7472
7557
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7473
|
-
throw new
|
7474
|
-
|
7558
|
+
throw new FuelError18(
|
7559
|
+
ErrorCode18.INVALID_SEED,
|
7475
7560
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7476
7561
|
);
|
7477
7562
|
}
|
@@ -7548,7 +7633,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7548
7633
|
function parsePath(path2, depth = 0) {
|
7549
7634
|
const components = path2.split("/");
|
7550
7635
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7551
|
-
throw new
|
7636
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7552
7637
|
}
|
7553
7638
|
if (components[0] === "m") {
|
7554
7639
|
components.shift();
|
@@ -7577,8 +7662,8 @@ var HDWallet = class {
|
|
7577
7662
|
this.privateKey = hexlify17(config.privateKey);
|
7578
7663
|
} else {
|
7579
7664
|
if (!config.publicKey) {
|
7580
|
-
throw new
|
7581
|
-
|
7665
|
+
throw new FuelError19(
|
7666
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7582
7667
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7583
7668
|
);
|
7584
7669
|
}
|
@@ -7607,8 +7692,8 @@ var HDWallet = class {
|
|
7607
7692
|
const data = new Uint8Array(37);
|
7608
7693
|
if (index & HARDENED_INDEX) {
|
7609
7694
|
if (!privateKey) {
|
7610
|
-
throw new
|
7611
|
-
|
7695
|
+
throw new FuelError19(
|
7696
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7612
7697
|
"Cannot derive a hardened index without a private Key."
|
7613
7698
|
);
|
7614
7699
|
}
|
@@ -7622,7 +7707,7 @@ var HDWallet = class {
|
|
7622
7707
|
const IR = bytes.slice(32);
|
7623
7708
|
if (privateKey) {
|
7624
7709
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7625
|
-
const ki =
|
7710
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7626
7711
|
return new HDWallet({
|
7627
7712
|
privateKey: ki,
|
7628
7713
|
chainCode: IR,
|
@@ -7660,8 +7745,8 @@ var HDWallet = class {
|
|
7660
7745
|
*/
|
7661
7746
|
toExtendedKey(isPublic = false, testnet = false) {
|
7662
7747
|
if (this.depth >= 256) {
|
7663
|
-
throw new
|
7664
|
-
|
7748
|
+
throw new FuelError19(
|
7749
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7665
7750
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7666
7751
|
);
|
7667
7752
|
}
|
@@ -7692,10 +7777,10 @@ var HDWallet = class {
|
|
7692
7777
|
const bytes = arrayify18(decoded);
|
7693
7778
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7694
7779
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7695
|
-
throw new
|
7780
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7696
7781
|
}
|
7697
7782
|
if (!validChecksum) {
|
7698
|
-
throw new
|
7783
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7699
7784
|
}
|
7700
7785
|
const depth = bytes[4];
|
7701
7786
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7703,14 +7788,14 @@ var HDWallet = class {
|
|
7703
7788
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7704
7789
|
const key = bytes.slice(45, 78);
|
7705
7790
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7706
|
-
throw new
|
7707
|
-
|
7791
|
+
throw new FuelError19(
|
7792
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7708
7793
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7709
7794
|
);
|
7710
7795
|
}
|
7711
7796
|
if (isPublicExtendedKey(bytes)) {
|
7712
7797
|
if (key[0] !== 3) {
|
7713
|
-
throw new
|
7798
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
7714
7799
|
}
|
7715
7800
|
return new HDWallet({
|
7716
7801
|
publicKey: key,
|
@@ -7721,7 +7806,7 @@ var HDWallet = class {
|
|
7721
7806
|
});
|
7722
7807
|
}
|
7723
7808
|
if (key[0] !== 0) {
|
7724
|
-
throw new
|
7809
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
7725
7810
|
}
|
7726
7811
|
return new HDWallet({
|
7727
7812
|
privateKey: key.slice(1),
|