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