@fuel-ts/account 0.0.0-rc-1895-20240328113714 → 0.0.0-rc-1964-20240328124253
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 +10 -126
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +468 -541
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -318
- 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 +10 -126
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +434 -501
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +213 -288
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/providers/utils/extract-tx-error.d.ts +0 -14
- package/dist/providers/utils/extract-tx-error.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -25,9 +25,9 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
|
-
import { ErrorCode as
|
28
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
30
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
32
|
|
33
33
|
// src/providers/coin-quantity.ts
|
@@ -68,8 +68,8 @@ var addAmountToAsset = (params) => {
|
|
68
68
|
|
69
69
|
// src/providers/provider.ts
|
70
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
|
-
import { ErrorCode as
|
72
|
-
import { BN, bn as
|
71
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
72
|
+
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
73
73
|
import {
|
74
74
|
InputType as InputType6,
|
75
75
|
TransactionType as TransactionType8,
|
@@ -1152,7 +1152,7 @@ var outputify = (value) => {
|
|
1152
1152
|
// src/providers/transaction-request/transaction-request.ts
|
1153
1153
|
import { Address, addressify } from "@fuel-ts/address";
|
1154
1154
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1155
|
-
import { bn as
|
1155
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1156
1156
|
import {
|
1157
1157
|
PolicyType,
|
1158
1158
|
TransactionCoder,
|
@@ -1495,76 +1495,6 @@ function sleep(time) {
|
|
1495
1495
|
});
|
1496
1496
|
}
|
1497
1497
|
|
1498
|
-
// src/providers/utils/extract-tx-error.ts
|
1499
|
-
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1500
|
-
import { bn as bn6 } from "@fuel-ts/math";
|
1501
|
-
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1502
|
-
import {
|
1503
|
-
FAILED_REQUIRE_SIGNAL,
|
1504
|
-
FAILED_ASSERT_EQ_SIGNAL,
|
1505
|
-
FAILED_ASSERT_NE_SIGNAL,
|
1506
|
-
FAILED_ASSERT_SIGNAL,
|
1507
|
-
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1508
|
-
PANIC_REASONS,
|
1509
|
-
PANIC_DOC_URL
|
1510
|
-
} from "@fuel-ts/transactions/configs";
|
1511
|
-
var assemblePanicError = (status) => {
|
1512
|
-
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1513
|
-
if (PANIC_REASONS.includes(status.reason)) {
|
1514
|
-
errorMessage = `${errorMessage}
|
1515
|
-
|
1516
|
-
You can read more about this error at:
|
1517
|
-
|
1518
|
-
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1519
|
-
}
|
1520
|
-
return errorMessage;
|
1521
|
-
};
|
1522
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1523
|
-
var assembleRevertError = (receipts, logs) => {
|
1524
|
-
let errorMessage = "The transaction reverted with an unknown reason.";
|
1525
|
-
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1526
|
-
if (revertReceipt) {
|
1527
|
-
const reasonHex = bn6(revertReceipt.val).toHex();
|
1528
|
-
switch (reasonHex) {
|
1529
|
-
case FAILED_REQUIRE_SIGNAL: {
|
1530
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1531
|
-
break;
|
1532
|
-
}
|
1533
|
-
case FAILED_ASSERT_EQ_SIGNAL: {
|
1534
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1535
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1536
|
-
break;
|
1537
|
-
}
|
1538
|
-
case FAILED_ASSERT_NE_SIGNAL: {
|
1539
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1540
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1541
|
-
break;
|
1542
|
-
}
|
1543
|
-
case FAILED_ASSERT_SIGNAL:
|
1544
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1545
|
-
break;
|
1546
|
-
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1547
|
-
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1548
|
-
break;
|
1549
|
-
default:
|
1550
|
-
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1551
|
-
}
|
1552
|
-
}
|
1553
|
-
return errorMessage;
|
1554
|
-
};
|
1555
|
-
var extractTxError = (params) => {
|
1556
|
-
const { receipts, status, logs } = params;
|
1557
|
-
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1558
|
-
let err = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1559
|
-
err += `
|
1560
|
-
|
1561
|
-
logs: ${JSON.stringify(logs, null, 2)}`;
|
1562
|
-
err += `
|
1563
|
-
|
1564
|
-
receipts: ${JSON.stringify(receipts, null, 2)}`;
|
1565
|
-
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, err);
|
1566
|
-
};
|
1567
|
-
|
1568
1498
|
// src/providers/transaction-request/errors.ts
|
1569
1499
|
var NoWitnessAtIndexError = class extends Error {
|
1570
1500
|
constructor(index) {
|
@@ -1615,10 +1545,10 @@ var BaseTransactionRequest = class {
|
|
1615
1545
|
outputs,
|
1616
1546
|
witnesses
|
1617
1547
|
} = {}) {
|
1618
|
-
this.gasPrice =
|
1548
|
+
this.gasPrice = bn6(gasPrice);
|
1619
1549
|
this.maturity = maturity ?? 0;
|
1620
|
-
this.witnessLimit = witnessLimit ?
|
1621
|
-
this.maxFee = maxFee ?
|
1550
|
+
this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
|
1551
|
+
this.maxFee = maxFee ? bn6(maxFee) : void 0;
|
1622
1552
|
this.inputs = inputs ?? [];
|
1623
1553
|
this.outputs = outputs ?? [];
|
1624
1554
|
this.witnesses = witnesses ?? [];
|
@@ -2048,13 +1978,13 @@ var BaseTransactionRequest = class {
|
|
2048
1978
|
assetId,
|
2049
1979
|
owner: resourcesOwner || Address.fromRandom(),
|
2050
1980
|
maturity: 0,
|
2051
|
-
blockCreated:
|
2052
|
-
txCreatedIdx:
|
1981
|
+
blockCreated: bn6(1),
|
1982
|
+
txCreatedIdx: bn6(1)
|
2053
1983
|
}
|
2054
1984
|
]);
|
2055
1985
|
}
|
2056
1986
|
};
|
2057
|
-
updateAssetInput(BaseAssetId2,
|
1987
|
+
updateAssetInput(BaseAssetId2, bn6(1e11));
|
2058
1988
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2059
1989
|
}
|
2060
1990
|
/**
|
@@ -2065,7 +1995,7 @@ var BaseTransactionRequest = class {
|
|
2065
1995
|
*/
|
2066
1996
|
getCoinOutputsQuantities() {
|
2067
1997
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2068
|
-
amount:
|
1998
|
+
amount: bn6(amount),
|
2069
1999
|
assetId: assetId.toString()
|
2070
2000
|
}));
|
2071
2001
|
return coinsQuantities;
|
@@ -2094,7 +2024,7 @@ var BaseTransactionRequest = class {
|
|
2094
2024
|
default:
|
2095
2025
|
return;
|
2096
2026
|
}
|
2097
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2027
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
2098
2028
|
i.predicate = correspondingInput.predicate;
|
2099
2029
|
i.predicateData = correspondingInput.predicateData;
|
2100
2030
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2105,14 +2035,14 @@ var BaseTransactionRequest = class {
|
|
2105
2035
|
|
2106
2036
|
// src/providers/transaction-request/create-transaction-request.ts
|
2107
2037
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2108
|
-
import { bn as
|
2038
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2109
2039
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2110
2040
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2111
2041
|
|
2112
2042
|
// src/providers/transaction-request/hash-transaction.ts
|
2113
2043
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2114
2044
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2115
|
-
import { bn as
|
2045
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
2116
2046
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2117
2047
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2118
2048
|
import { clone as clone2 } from "ramda";
|
@@ -2129,11 +2059,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2129
2059
|
blockHeight: 0,
|
2130
2060
|
txIndex: 0
|
2131
2061
|
};
|
2132
|
-
inputClone.predicateGasUsed =
|
2062
|
+
inputClone.predicateGasUsed = bn7(0);
|
2133
2063
|
return inputClone;
|
2134
2064
|
}
|
2135
2065
|
case InputType3.Message: {
|
2136
|
-
inputClone.predicateGasUsed =
|
2066
|
+
inputClone.predicateGasUsed = bn7(0);
|
2137
2067
|
return inputClone;
|
2138
2068
|
}
|
2139
2069
|
case InputType3.Contract: {
|
@@ -2160,12 +2090,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2160
2090
|
return outputClone;
|
2161
2091
|
}
|
2162
2092
|
case OutputType3.Change: {
|
2163
|
-
outputClone.amount =
|
2093
|
+
outputClone.amount = bn7(0);
|
2164
2094
|
return outputClone;
|
2165
2095
|
}
|
2166
2096
|
case OutputType3.Variable: {
|
2167
2097
|
outputClone.to = ZeroBytes325;
|
2168
|
-
outputClone.amount =
|
2098
|
+
outputClone.amount = bn7(0);
|
2169
2099
|
outputClone.assetId = ZeroBytes325;
|
2170
2100
|
return outputClone;
|
2171
2101
|
}
|
@@ -2289,7 +2219,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2289
2219
|
}
|
2290
2220
|
metadataGas(gasCosts) {
|
2291
2221
|
return calculateMetadataGasForTxCreate({
|
2292
|
-
contractBytesSize:
|
2222
|
+
contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2293
2223
|
gasCosts,
|
2294
2224
|
stateRootSize: this.storageSlots.length,
|
2295
2225
|
txBytesSize: this.byteSize()
|
@@ -2301,7 +2231,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2301
2231
|
import { Interface } from "@fuel-ts/abi-coder";
|
2302
2232
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2303
2233
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2304
|
-
import { bn as
|
2234
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2305
2235
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2306
2236
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2307
2237
|
|
@@ -2355,7 +2285,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2355
2285
|
*/
|
2356
2286
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2357
2287
|
super(rest);
|
2358
|
-
this.gasLimit =
|
2288
|
+
this.gasLimit = bn9(gasLimit);
|
2359
2289
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2360
2290
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2361
2291
|
this.abis = rest.abis;
|
@@ -2503,7 +2433,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2503
2433
|
};
|
2504
2434
|
|
2505
2435
|
// src/providers/transaction-request/utils.ts
|
2506
|
-
import { ErrorCode as
|
2436
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2507
2437
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2508
2438
|
var transactionRequestify = (obj) => {
|
2509
2439
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2518,14 +2448,14 @@ var transactionRequestify = (obj) => {
|
|
2518
2448
|
return CreateTransactionRequest.from(obj);
|
2519
2449
|
}
|
2520
2450
|
default: {
|
2521
|
-
throw new
|
2451
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2522
2452
|
}
|
2523
2453
|
}
|
2524
2454
|
};
|
2525
2455
|
|
2526
2456
|
// src/providers/transaction-response/transaction-response.ts
|
2527
|
-
import { ErrorCode as
|
2528
|
-
import { bn as
|
2457
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2458
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2529
2459
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2530
2460
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2531
2461
|
|
@@ -2533,7 +2463,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2533
2463
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2534
2464
|
|
2535
2465
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2536
|
-
import { bn as
|
2466
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2537
2467
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2538
2468
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2539
2469
|
var calculateTransactionFee = (params) => {
|
@@ -2542,24 +2472,24 @@ var calculateTransactionFee = (params) => {
|
|
2542
2472
|
rawPayload,
|
2543
2473
|
consensusParameters: { gasCosts, feeParams }
|
2544
2474
|
} = params;
|
2545
|
-
const gasPerByte =
|
2546
|
-
const gasPriceFactor =
|
2475
|
+
const gasPerByte = bn10(feeParams.gasPerByte);
|
2476
|
+
const gasPriceFactor = bn10(feeParams.gasPriceFactor);
|
2547
2477
|
const transactionBytes = arrayify9(rawPayload);
|
2548
2478
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2549
2479
|
if (transaction.type === TransactionType6.Mint) {
|
2550
2480
|
return {
|
2551
|
-
fee:
|
2552
|
-
minFee:
|
2553
|
-
maxFee:
|
2554
|
-
feeFromGasUsed:
|
2481
|
+
fee: bn10(0),
|
2482
|
+
minFee: bn10(0),
|
2483
|
+
maxFee: bn10(0),
|
2484
|
+
feeFromGasUsed: bn10(0)
|
2555
2485
|
};
|
2556
2486
|
}
|
2557
2487
|
const { type, witnesses, inputs, policies } = transaction;
|
2558
|
-
let metadataGas =
|
2559
|
-
let gasLimit =
|
2488
|
+
let metadataGas = bn10(0);
|
2489
|
+
let gasLimit = bn10(0);
|
2560
2490
|
if (type === TransactionType6.Create) {
|
2561
2491
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2562
|
-
const contractBytesSize =
|
2492
|
+
const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2563
2493
|
metadataGas = calculateMetadataGasForTxCreate({
|
2564
2494
|
contractBytesSize,
|
2565
2495
|
gasCosts,
|
@@ -2578,12 +2508,12 @@ var calculateTransactionFee = (params) => {
|
|
2578
2508
|
}
|
2579
2509
|
const minGas = getMinGas({
|
2580
2510
|
gasCosts,
|
2581
|
-
gasPerByte:
|
2511
|
+
gasPerByte: bn10(gasPerByte),
|
2582
2512
|
inputs,
|
2583
2513
|
metadataGas,
|
2584
2514
|
txBytesSize: transactionBytes.length
|
2585
2515
|
});
|
2586
|
-
const gasPrice =
|
2516
|
+
const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2587
2517
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2588
2518
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2589
2519
|
const maxGas = getMaxGas({
|
@@ -2607,13 +2537,13 @@ var calculateTransactionFee = (params) => {
|
|
2607
2537
|
|
2608
2538
|
// src/providers/transaction-summary/operations.ts
|
2609
2539
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2610
|
-
import { ErrorCode as
|
2611
|
-
import { bn as
|
2612
|
-
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";
|
2613
2543
|
|
2614
2544
|
// src/providers/transaction-summary/call.ts
|
2615
2545
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2616
|
-
import { bn as
|
2546
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2617
2547
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2618
2548
|
const abiInterface = new Interface2(abi);
|
2619
2549
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2622,7 +2552,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2622
2552
|
let encodedArgs;
|
2623
2553
|
if (functionFragment.isInputDataPointer) {
|
2624
2554
|
if (rawPayload) {
|
2625
|
-
const argsOffset =
|
2555
|
+
const argsOffset = bn11(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2626
2556
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2627
2557
|
}
|
2628
2558
|
} else {
|
@@ -2656,7 +2586,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2656
2586
|
};
|
2657
2587
|
|
2658
2588
|
// src/providers/transaction-summary/input.ts
|
2659
|
-
import { ErrorCode as
|
2589
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2660
2590
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2661
2591
|
function getInputsByTypes(inputs, types) {
|
2662
2592
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2694,8 +2624,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2694
2624
|
return void 0;
|
2695
2625
|
}
|
2696
2626
|
if (contractInput.type !== InputType5.Contract) {
|
2697
|
-
throw new
|
2698
|
-
|
2627
|
+
throw new FuelError8(
|
2628
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2699
2629
|
`Contract input should be of type 'contract'.`
|
2700
2630
|
);
|
2701
2631
|
}
|
@@ -2742,8 +2672,8 @@ function getTransactionTypeName(transactionType) {
|
|
2742
2672
|
case TransactionType7.Script:
|
2743
2673
|
return "Script" /* Script */;
|
2744
2674
|
default:
|
2745
|
-
throw new
|
2746
|
-
|
2675
|
+
throw new FuelError9(
|
2676
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2747
2677
|
`Invalid transaction type: ${transactionType}.`
|
2748
2678
|
);
|
2749
2679
|
}
|
@@ -2762,10 +2692,10 @@ function isTypeScript(transactionType) {
|
|
2762
2692
|
return isType(transactionType, "Script" /* Script */);
|
2763
2693
|
}
|
2764
2694
|
function getReceiptsCall(receipts) {
|
2765
|
-
return getReceiptsByType(receipts,
|
2695
|
+
return getReceiptsByType(receipts, ReceiptType3.Call);
|
2766
2696
|
}
|
2767
2697
|
function getReceiptsMessageOut(receipts) {
|
2768
|
-
return getReceiptsByType(receipts,
|
2698
|
+
return getReceiptsByType(receipts, ReceiptType3.MessageOut);
|
2769
2699
|
}
|
2770
2700
|
var mergeAssets = (op1, op2) => {
|
2771
2701
|
const assets1 = op1.assetsSent || [];
|
@@ -2778,7 +2708,7 @@ var mergeAssets = (op1, op2) => {
|
|
2778
2708
|
if (!matchingAsset) {
|
2779
2709
|
return asset1;
|
2780
2710
|
}
|
2781
|
-
const mergedAmount =
|
2711
|
+
const mergedAmount = bn12(asset1.amount).add(matchingAsset.amount);
|
2782
2712
|
return { ...asset1, amount: mergedAmount };
|
2783
2713
|
});
|
2784
2714
|
return mergedAssets.concat(filteredAssets);
|
@@ -2961,11 +2891,11 @@ function getTransferOperations({
|
|
2961
2891
|
});
|
2962
2892
|
const transferReceipts = getReceiptsByType(
|
2963
2893
|
receipts,
|
2964
|
-
|
2894
|
+
ReceiptType3.Transfer
|
2965
2895
|
);
|
2966
2896
|
const transferOutReceipts = getReceiptsByType(
|
2967
2897
|
receipts,
|
2968
|
-
|
2898
|
+
ReceiptType3.TransferOut
|
2969
2899
|
);
|
2970
2900
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2971
2901
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3050,17 +2980,17 @@ function getOperations({
|
|
3050
2980
|
}
|
3051
2981
|
|
3052
2982
|
// src/providers/transaction-summary/receipt.ts
|
3053
|
-
import { ReceiptType as
|
2983
|
+
import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
|
3054
2984
|
var processGqlReceipt = (gqlReceipt) => {
|
3055
2985
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3056
2986
|
switch (receipt.type) {
|
3057
|
-
case
|
2987
|
+
case ReceiptType4.ReturnData: {
|
3058
2988
|
return {
|
3059
2989
|
...receipt,
|
3060
2990
|
data: gqlReceipt.data || "0x"
|
3061
2991
|
};
|
3062
2992
|
}
|
3063
|
-
case
|
2993
|
+
case ReceiptType4.LogData: {
|
3064
2994
|
return {
|
3065
2995
|
...receipt,
|
3066
2996
|
data: gqlReceipt.data || "0x"
|
@@ -3073,7 +3003,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3073
3003
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3074
3004
|
const mintedAssets = [];
|
3075
3005
|
receipts.forEach((receipt) => {
|
3076
|
-
if (receipt.type ===
|
3006
|
+
if (receipt.type === ReceiptType4.Mint) {
|
3077
3007
|
mintedAssets.push({
|
3078
3008
|
subId: receipt.subId,
|
3079
3009
|
contractId: receipt.contractId,
|
@@ -3087,7 +3017,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3087
3017
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3088
3018
|
const burnedAssets = [];
|
3089
3019
|
receipts.forEach((receipt) => {
|
3090
|
-
if (receipt.type ===
|
3020
|
+
if (receipt.type === ReceiptType4.Burn) {
|
3091
3021
|
burnedAssets.push({
|
3092
3022
|
subId: receipt.subId,
|
3093
3023
|
contractId: receipt.contractId,
|
@@ -3100,7 +3030,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3100
3030
|
};
|
3101
3031
|
|
3102
3032
|
// src/providers/transaction-summary/status.ts
|
3103
|
-
import { ErrorCode as
|
3033
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3104
3034
|
var getTransactionStatusName = (gqlStatus) => {
|
3105
3035
|
switch (gqlStatus) {
|
3106
3036
|
case "FailureStatus":
|
@@ -3112,8 +3042,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3112
3042
|
case "SqueezedOutStatus":
|
3113
3043
|
return "squeezedout" /* squeezedout */;
|
3114
3044
|
default:
|
3115
|
-
throw new
|
3116
|
-
|
3045
|
+
throw new FuelError10(
|
3046
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3117
3047
|
`Invalid transaction status: ${gqlStatus}.`
|
3118
3048
|
);
|
3119
3049
|
}
|
@@ -3226,12 +3156,12 @@ function assembleTransactionSummary(params) {
|
|
3226
3156
|
|
3227
3157
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3228
3158
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3229
|
-
import { ReceiptType as
|
3159
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3230
3160
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3231
3161
|
return receipts.reduce((logs, receipt) => {
|
3232
|
-
if (receipt.type ===
|
3162
|
+
if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
|
3233
3163
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3234
|
-
const data = receipt.type ===
|
3164
|
+
const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3235
3165
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3236
3166
|
logs.push(decodedLog);
|
3237
3167
|
}
|
@@ -3246,7 +3176,7 @@ var TransactionResponse = class {
|
|
3246
3176
|
/** Current provider */
|
3247
3177
|
provider;
|
3248
3178
|
/** Gas used on the transaction */
|
3249
|
-
gasUsed =
|
3179
|
+
gasUsed = bn13(0);
|
3250
3180
|
/** The graphql Transaction with receipts object. */
|
3251
3181
|
gqlTransaction;
|
3252
3182
|
abis;
|
@@ -3351,8 +3281,8 @@ var TransactionResponse = class {
|
|
3351
3281
|
});
|
3352
3282
|
for await (const { statusChange } of subscription) {
|
3353
3283
|
if (statusChange.type === "SqueezedOutStatus") {
|
3354
|
-
throw new
|
3355
|
-
|
3284
|
+
throw new FuelError11(
|
3285
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3356
3286
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3357
3287
|
);
|
3358
3288
|
}
|
@@ -3374,26 +3304,14 @@ var TransactionResponse = class {
|
|
3374
3304
|
gqlTransaction: this.gqlTransaction,
|
3375
3305
|
...transactionSummary
|
3376
3306
|
};
|
3377
|
-
let logs = [];
|
3378
3307
|
if (this.abis) {
|
3379
|
-
logs = getDecodedLogs(
|
3308
|
+
const logs = getDecodedLogs(
|
3380
3309
|
transactionSummary.receipts,
|
3381
3310
|
this.abis.main,
|
3382
3311
|
this.abis.otherContractsAbis
|
3383
3312
|
);
|
3384
3313
|
transactionResult.logs = logs;
|
3385
3314
|
}
|
3386
|
-
if (transactionResult.isStatusFailure) {
|
3387
|
-
const {
|
3388
|
-
receipts,
|
3389
|
-
gqlTransaction: { status }
|
3390
|
-
} = transactionResult;
|
3391
|
-
throw extractTxError({
|
3392
|
-
receipts,
|
3393
|
-
status,
|
3394
|
-
logs
|
3395
|
-
});
|
3396
|
-
}
|
3397
3315
|
return transactionResult;
|
3398
3316
|
}
|
3399
3317
|
/**
|
@@ -3402,7 +3320,14 @@ var TransactionResponse = class {
|
|
3402
3320
|
* @param contractsAbiMap - The contracts ABI map.
|
3403
3321
|
*/
|
3404
3322
|
async wait(contractsAbiMap) {
|
3405
|
-
|
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;
|
3406
3331
|
}
|
3407
3332
|
};
|
3408
3333
|
|
@@ -3464,29 +3389,29 @@ var processGqlChain = (chain) => {
|
|
3464
3389
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3465
3390
|
return {
|
3466
3391
|
name,
|
3467
|
-
baseChainHeight:
|
3392
|
+
baseChainHeight: bn14(daHeight),
|
3468
3393
|
consensusParameters: {
|
3469
|
-
contractMaxSize:
|
3470
|
-
maxInputs:
|
3471
|
-
maxOutputs:
|
3472
|
-
maxWitnesses:
|
3473
|
-
maxGasPerTx:
|
3474
|
-
maxScriptLength:
|
3475
|
-
maxScriptDataLength:
|
3476
|
-
maxStorageSlots:
|
3477
|
-
maxPredicateLength:
|
3478
|
-
maxPredicateDataLength:
|
3479
|
-
maxGasPerPredicate:
|
3480
|
-
gasPriceFactor:
|
3481
|
-
gasPerByte:
|
3482
|
-
maxMessageDataLength:
|
3483
|
-
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),
|
3484
3409
|
gasCosts
|
3485
3410
|
},
|
3486
3411
|
gasCosts,
|
3487
3412
|
latestBlock: {
|
3488
3413
|
id: latestBlock.id,
|
3489
|
-
height:
|
3414
|
+
height: bn14(latestBlock.header.height),
|
3490
3415
|
time: latestBlock.header.time,
|
3491
3416
|
transactions: latestBlock.transactions.map((i) => ({
|
3492
3417
|
id: i.id
|
@@ -3556,8 +3481,8 @@ var _Provider = class {
|
|
3556
3481
|
getChain() {
|
3557
3482
|
const chain = _Provider.chainInfoCache[this.url];
|
3558
3483
|
if (!chain) {
|
3559
|
-
throw new
|
3560
|
-
|
3484
|
+
throw new FuelError12(
|
3485
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3561
3486
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3562
3487
|
);
|
3563
3488
|
}
|
@@ -3569,8 +3494,8 @@ var _Provider = class {
|
|
3569
3494
|
getNode() {
|
3570
3495
|
const node = _Provider.nodeInfoCache[this.url];
|
3571
3496
|
if (!node) {
|
3572
|
-
throw new
|
3573
|
-
|
3497
|
+
throw new FuelError12(
|
3498
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3574
3499
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3575
3500
|
);
|
3576
3501
|
}
|
@@ -3617,8 +3542,8 @@ var _Provider = class {
|
|
3617
3542
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3618
3543
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3619
3544
|
if (!isMajorSupported || !isMinorSupported) {
|
3620
|
-
throw new
|
3621
|
-
|
3545
|
+
throw new FuelError12(
|
3546
|
+
FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3622
3547
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3623
3548
|
);
|
3624
3549
|
}
|
@@ -3681,7 +3606,7 @@ var _Provider = class {
|
|
3681
3606
|
*/
|
3682
3607
|
async getBlockNumber() {
|
3683
3608
|
const { chain } = await this.operations.getChain();
|
3684
|
-
return
|
3609
|
+
return bn14(chain.latestBlock.header.height, 10);
|
3685
3610
|
}
|
3686
3611
|
/**
|
3687
3612
|
* Returns the chain information.
|
@@ -3691,9 +3616,9 @@ var _Provider = class {
|
|
3691
3616
|
async fetchNode() {
|
3692
3617
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3693
3618
|
const processedNodeInfo = {
|
3694
|
-
maxDepth:
|
3695
|
-
maxTx:
|
3696
|
-
minGasPrice:
|
3619
|
+
maxDepth: bn14(nodeInfo.maxDepth),
|
3620
|
+
maxTx: bn14(nodeInfo.maxTx),
|
3621
|
+
minGasPrice: bn14(nodeInfo.minGasPrice),
|
3697
3622
|
nodeVersion: nodeInfo.nodeVersion,
|
3698
3623
|
utxoValidation: nodeInfo.utxoValidation,
|
3699
3624
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3748,8 +3673,8 @@ var _Provider = class {
|
|
3748
3673
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3749
3674
|
for await (const { submitAndAwait } of subscription) {
|
3750
3675
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3751
|
-
throw new
|
3752
|
-
|
3676
|
+
throw new FuelError12(
|
3677
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3753
3678
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3754
3679
|
);
|
3755
3680
|
}
|
@@ -3816,7 +3741,7 @@ var _Provider = class {
|
|
3816
3741
|
} = response;
|
3817
3742
|
if (inputs) {
|
3818
3743
|
inputs.forEach((input, index) => {
|
3819
|
-
if ("predicateGasUsed" in input &&
|
3744
|
+
if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
|
3820
3745
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3821
3746
|
}
|
3822
3747
|
});
|
@@ -3929,7 +3854,7 @@ var _Provider = class {
|
|
3929
3854
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3930
3855
|
if (estimatePredicates) {
|
3931
3856
|
if (isScriptTransaction) {
|
3932
|
-
txRequestClone.gasLimit =
|
3857
|
+
txRequestClone.gasLimit = bn14(0);
|
3933
3858
|
}
|
3934
3859
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3935
3860
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3945,8 +3870,8 @@ var _Provider = class {
|
|
3945
3870
|
let missingContractIds = [];
|
3946
3871
|
let outputVariables = 0;
|
3947
3872
|
if (isScriptTransaction && estimateTxDependencies) {
|
3948
|
-
txRequestClone.gasPrice =
|
3949
|
-
txRequestClone.gasLimit =
|
3873
|
+
txRequestClone.gasPrice = bn14(0);
|
3874
|
+
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3950
3875
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3951
3876
|
receipts = result.receipts;
|
3952
3877
|
outputVariables = result.outputVariables;
|
@@ -4008,11 +3933,11 @@ var _Provider = class {
|
|
4008
3933
|
return coins.map((coin) => ({
|
4009
3934
|
id: coin.utxoId,
|
4010
3935
|
assetId: coin.assetId,
|
4011
|
-
amount:
|
3936
|
+
amount: bn14(coin.amount),
|
4012
3937
|
owner: Address2.fromAddressOrString(coin.owner),
|
4013
|
-
maturity:
|
4014
|
-
blockCreated:
|
4015
|
-
txCreatedIdx:
|
3938
|
+
maturity: bn14(coin.maturity).toNumber(),
|
3939
|
+
blockCreated: bn14(coin.blockCreated),
|
3940
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4016
3941
|
}));
|
4017
3942
|
}
|
4018
3943
|
/**
|
@@ -4049,9 +3974,9 @@ var _Provider = class {
|
|
4049
3974
|
switch (coin.__typename) {
|
4050
3975
|
case "MessageCoin":
|
4051
3976
|
return {
|
4052
|
-
amount:
|
3977
|
+
amount: bn14(coin.amount),
|
4053
3978
|
assetId: coin.assetId,
|
4054
|
-
daHeight:
|
3979
|
+
daHeight: bn14(coin.daHeight),
|
4055
3980
|
sender: Address2.fromAddressOrString(coin.sender),
|
4056
3981
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4057
3982
|
nonce: coin.nonce
|
@@ -4059,12 +3984,12 @@ var _Provider = class {
|
|
4059
3984
|
case "Coin":
|
4060
3985
|
return {
|
4061
3986
|
id: coin.utxoId,
|
4062
|
-
amount:
|
3987
|
+
amount: bn14(coin.amount),
|
4063
3988
|
assetId: coin.assetId,
|
4064
3989
|
owner: Address2.fromAddressOrString(coin.owner),
|
4065
|
-
maturity:
|
4066
|
-
blockCreated:
|
4067
|
-
txCreatedIdx:
|
3990
|
+
maturity: bn14(coin.maturity).toNumber(),
|
3991
|
+
blockCreated: bn14(coin.blockCreated),
|
3992
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4068
3993
|
};
|
4069
3994
|
default:
|
4070
3995
|
return null;
|
@@ -4081,13 +4006,13 @@ var _Provider = class {
|
|
4081
4006
|
async getBlock(idOrHeight) {
|
4082
4007
|
let variables;
|
4083
4008
|
if (typeof idOrHeight === "number") {
|
4084
|
-
variables = { height:
|
4009
|
+
variables = { height: bn14(idOrHeight).toString(10) };
|
4085
4010
|
} else if (idOrHeight === "latest") {
|
4086
4011
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4087
4012
|
} else if (idOrHeight.length === 66) {
|
4088
4013
|
variables = { blockId: idOrHeight };
|
4089
4014
|
} else {
|
4090
|
-
variables = { blockId:
|
4015
|
+
variables = { blockId: bn14(idOrHeight).toString(10) };
|
4091
4016
|
}
|
4092
4017
|
const { block } = await this.operations.getBlock(variables);
|
4093
4018
|
if (!block) {
|
@@ -4095,7 +4020,7 @@ var _Provider = class {
|
|
4095
4020
|
}
|
4096
4021
|
return {
|
4097
4022
|
id: block.id,
|
4098
|
-
height:
|
4023
|
+
height: bn14(block.header.height),
|
4099
4024
|
time: block.header.time,
|
4100
4025
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4101
4026
|
};
|
@@ -4110,7 +4035,7 @@ var _Provider = class {
|
|
4110
4035
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4111
4036
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4112
4037
|
id: block.id,
|
4113
|
-
height:
|
4038
|
+
height: bn14(block.header.height),
|
4114
4039
|
time: block.header.time,
|
4115
4040
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4116
4041
|
}));
|
@@ -4125,7 +4050,7 @@ var _Provider = class {
|
|
4125
4050
|
async getBlockWithTransactions(idOrHeight) {
|
4126
4051
|
let variables;
|
4127
4052
|
if (typeof idOrHeight === "number") {
|
4128
|
-
variables = { blockHeight:
|
4053
|
+
variables = { blockHeight: bn14(idOrHeight).toString(10) };
|
4129
4054
|
} else if (idOrHeight === "latest") {
|
4130
4055
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4131
4056
|
} else {
|
@@ -4137,7 +4062,7 @@ var _Provider = class {
|
|
4137
4062
|
}
|
4138
4063
|
return {
|
4139
4064
|
id: block.id,
|
4140
|
-
height:
|
4065
|
+
height: bn14(block.header.height, 10),
|
4141
4066
|
time: block.header.time,
|
4142
4067
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4143
4068
|
transactions: block.transactions.map(
|
@@ -4186,7 +4111,7 @@ var _Provider = class {
|
|
4186
4111
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4187
4112
|
asset: hexlify12(assetId)
|
4188
4113
|
});
|
4189
|
-
return
|
4114
|
+
return bn14(contractBalance.amount, 10);
|
4190
4115
|
}
|
4191
4116
|
/**
|
4192
4117
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4200,7 +4125,7 @@ var _Provider = class {
|
|
4200
4125
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4201
4126
|
assetId: hexlify12(assetId)
|
4202
4127
|
});
|
4203
|
-
return
|
4128
|
+
return bn14(balance.amount, 10);
|
4204
4129
|
}
|
4205
4130
|
/**
|
4206
4131
|
* Returns balances for the given owner.
|
@@ -4218,7 +4143,7 @@ var _Provider = class {
|
|
4218
4143
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4219
4144
|
return balances.map((balance) => ({
|
4220
4145
|
assetId: balance.assetId,
|
4221
|
-
amount:
|
4146
|
+
amount: bn14(balance.amount)
|
4222
4147
|
}));
|
4223
4148
|
}
|
4224
4149
|
/**
|
@@ -4240,15 +4165,15 @@ var _Provider = class {
|
|
4240
4165
|
sender: message.sender,
|
4241
4166
|
recipient: message.recipient,
|
4242
4167
|
nonce: message.nonce,
|
4243
|
-
amount:
|
4168
|
+
amount: bn14(message.amount),
|
4244
4169
|
data: message.data
|
4245
4170
|
}),
|
4246
4171
|
sender: Address2.fromAddressOrString(message.sender),
|
4247
4172
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4248
4173
|
nonce: message.nonce,
|
4249
|
-
amount:
|
4174
|
+
amount: bn14(message.amount),
|
4250
4175
|
data: InputMessageCoder.decodeData(message.data),
|
4251
|
-
daHeight:
|
4176
|
+
daHeight: bn14(message.daHeight)
|
4252
4177
|
}));
|
4253
4178
|
}
|
4254
4179
|
/**
|
@@ -4266,8 +4191,8 @@ var _Provider = class {
|
|
4266
4191
|
nonce
|
4267
4192
|
};
|
4268
4193
|
if (commitBlockId && commitBlockHeight) {
|
4269
|
-
throw new
|
4270
|
-
|
4194
|
+
throw new FuelError12(
|
4195
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4271
4196
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4272
4197
|
);
|
4273
4198
|
}
|
@@ -4301,41 +4226,41 @@ var _Provider = class {
|
|
4301
4226
|
} = result.messageProof;
|
4302
4227
|
return {
|
4303
4228
|
messageProof: {
|
4304
|
-
proofIndex:
|
4229
|
+
proofIndex: bn14(messageProof.proofIndex),
|
4305
4230
|
proofSet: messageProof.proofSet
|
4306
4231
|
},
|
4307
4232
|
blockProof: {
|
4308
|
-
proofIndex:
|
4233
|
+
proofIndex: bn14(blockProof.proofIndex),
|
4309
4234
|
proofSet: blockProof.proofSet
|
4310
4235
|
},
|
4311
4236
|
messageBlockHeader: {
|
4312
4237
|
id: messageBlockHeader.id,
|
4313
|
-
daHeight:
|
4314
|
-
transactionsCount:
|
4238
|
+
daHeight: bn14(messageBlockHeader.daHeight),
|
4239
|
+
transactionsCount: bn14(messageBlockHeader.transactionsCount),
|
4315
4240
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4316
|
-
height:
|
4241
|
+
height: bn14(messageBlockHeader.height),
|
4317
4242
|
prevRoot: messageBlockHeader.prevRoot,
|
4318
4243
|
time: messageBlockHeader.time,
|
4319
4244
|
applicationHash: messageBlockHeader.applicationHash,
|
4320
4245
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4321
|
-
messageReceiptCount:
|
4246
|
+
messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
|
4322
4247
|
},
|
4323
4248
|
commitBlockHeader: {
|
4324
4249
|
id: commitBlockHeader.id,
|
4325
|
-
daHeight:
|
4326
|
-
transactionsCount:
|
4250
|
+
daHeight: bn14(commitBlockHeader.daHeight),
|
4251
|
+
transactionsCount: bn14(commitBlockHeader.transactionsCount),
|
4327
4252
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4328
|
-
height:
|
4253
|
+
height: bn14(commitBlockHeader.height),
|
4329
4254
|
prevRoot: commitBlockHeader.prevRoot,
|
4330
4255
|
time: commitBlockHeader.time,
|
4331
4256
|
applicationHash: commitBlockHeader.applicationHash,
|
4332
4257
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4333
|
-
messageReceiptCount:
|
4258
|
+
messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
|
4334
4259
|
},
|
4335
4260
|
sender: Address2.fromAddressOrString(sender),
|
4336
4261
|
recipient: Address2.fromAddressOrString(recipient),
|
4337
4262
|
nonce,
|
4338
|
-
amount:
|
4263
|
+
amount: bn14(amount),
|
4339
4264
|
data
|
4340
4265
|
};
|
4341
4266
|
}
|
@@ -4358,10 +4283,10 @@ var _Provider = class {
|
|
4358
4283
|
*/
|
4359
4284
|
async produceBlocks(amount, startTime) {
|
4360
4285
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4361
|
-
blocksToProduce:
|
4286
|
+
blocksToProduce: bn14(amount).toString(10),
|
4362
4287
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4363
4288
|
});
|
4364
|
-
return
|
4289
|
+
return bn14(latestBlockHeight);
|
4365
4290
|
}
|
4366
4291
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4367
4292
|
async getTransactionResponse(transactionId) {
|
@@ -4384,8 +4309,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4384
4309
|
__publicField(Provider, "nodeInfoCache", {});
|
4385
4310
|
|
4386
4311
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4387
|
-
import { ErrorCode as
|
4388
|
-
import { bn as
|
4312
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4313
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
4389
4314
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4390
4315
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4391
4316
|
|
@@ -4502,7 +4427,7 @@ var Account = class extends AbstractAccount {
|
|
4502
4427
|
*/
|
4503
4428
|
get provider() {
|
4504
4429
|
if (!this._provider) {
|
4505
|
-
throw new
|
4430
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4506
4431
|
}
|
4507
4432
|
return this._provider;
|
4508
4433
|
}
|
@@ -4554,8 +4479,8 @@ var Account = class extends AbstractAccount {
|
|
4554
4479
|
if (!hasNextPage) {
|
4555
4480
|
break;
|
4556
4481
|
}
|
4557
|
-
throw new
|
4558
|
-
|
4482
|
+
throw new FuelError14(
|
4483
|
+
ErrorCode14.NOT_SUPPORTED,
|
4559
4484
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4560
4485
|
);
|
4561
4486
|
}
|
@@ -4580,8 +4505,8 @@ var Account = class extends AbstractAccount {
|
|
4580
4505
|
if (!hasNextPage) {
|
4581
4506
|
break;
|
4582
4507
|
}
|
4583
|
-
throw new
|
4584
|
-
|
4508
|
+
throw new FuelError14(
|
4509
|
+
ErrorCode14.NOT_SUPPORTED,
|
4585
4510
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4586
4511
|
);
|
4587
4512
|
}
|
@@ -4616,8 +4541,8 @@ var Account = class extends AbstractAccount {
|
|
4616
4541
|
if (!hasNextPage) {
|
4617
4542
|
break;
|
4618
4543
|
}
|
4619
|
-
throw new
|
4620
|
-
|
4544
|
+
throw new FuelError14(
|
4545
|
+
ErrorCode14.NOT_SUPPORTED,
|
4621
4546
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4622
4547
|
);
|
4623
4548
|
}
|
@@ -4633,7 +4558,7 @@ var Account = class extends AbstractAccount {
|
|
4633
4558
|
*/
|
4634
4559
|
async fund(request, coinQuantities, fee) {
|
4635
4560
|
const updatedQuantities = addAmountToAsset({
|
4636
|
-
amount:
|
4561
|
+
amount: bn16(fee),
|
4637
4562
|
assetId: BaseAssetId3,
|
4638
4563
|
coinQuantities
|
4639
4564
|
});
|
@@ -4641,7 +4566,7 @@ var Account = class extends AbstractAccount {
|
|
4641
4566
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4642
4567
|
quantitiesDict[assetId] = {
|
4643
4568
|
required: amount,
|
4644
|
-
owned:
|
4569
|
+
owned: bn16(0)
|
4645
4570
|
};
|
4646
4571
|
});
|
4647
4572
|
const cachedUtxos = [];
|
@@ -4654,7 +4579,7 @@ var Account = class extends AbstractAccount {
|
|
4654
4579
|
if (isCoin2) {
|
4655
4580
|
const assetId = String(input.assetId);
|
4656
4581
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4657
|
-
const amount =
|
4582
|
+
const amount = bn16(input.amount);
|
4658
4583
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4659
4584
|
cachedUtxos.push(input.id);
|
4660
4585
|
}
|
@@ -4700,8 +4625,8 @@ var Account = class extends AbstractAccount {
|
|
4700
4625
|
estimateTxDependencies: true,
|
4701
4626
|
resourcesOwner: this
|
4702
4627
|
});
|
4703
|
-
request.gasPrice =
|
4704
|
-
request.gasLimit =
|
4628
|
+
request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
|
4629
|
+
request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
|
4705
4630
|
this.validateGas({
|
4706
4631
|
gasUsed,
|
4707
4632
|
gasPrice: request.gasPrice,
|
@@ -4722,9 +4647,9 @@ var Account = class extends AbstractAccount {
|
|
4722
4647
|
* @returns A promise that resolves to the transaction response.
|
4723
4648
|
*/
|
4724
4649
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4725
|
-
if (
|
4726
|
-
throw new
|
4727
|
-
|
4650
|
+
if (bn16(amount).lte(0)) {
|
4651
|
+
throw new FuelError14(
|
4652
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4728
4653
|
"Transfer amount must be a positive number."
|
4729
4654
|
);
|
4730
4655
|
}
|
@@ -4741,9 +4666,9 @@ var Account = class extends AbstractAccount {
|
|
4741
4666
|
* @returns A promise that resolves to the transaction response.
|
4742
4667
|
*/
|
4743
4668
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4744
|
-
if (
|
4745
|
-
throw new
|
4746
|
-
|
4669
|
+
if (bn16(amount).lte(0)) {
|
4670
|
+
throw new FuelError14(
|
4671
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4747
4672
|
"Transfer amount must be a positive number."
|
4748
4673
|
);
|
4749
4674
|
}
|
@@ -4752,7 +4677,7 @@ var Account = class extends AbstractAccount {
|
|
4752
4677
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4753
4678
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4754
4679
|
hexlifiedContractId: contractAddress.toB256(),
|
4755
|
-
amountToTransfer:
|
4680
|
+
amountToTransfer: bn16(amount),
|
4756
4681
|
assetId
|
4757
4682
|
});
|
4758
4683
|
const request = new ScriptTransactionRequest({
|
@@ -4763,9 +4688,9 @@ var Account = class extends AbstractAccount {
|
|
4763
4688
|
request.addContractInputAndOutput(contractAddress);
|
4764
4689
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4765
4690
|
request,
|
4766
|
-
[{ amount:
|
4691
|
+
[{ amount: bn16(amount), assetId: String(assetId) }]
|
4767
4692
|
);
|
4768
|
-
request.gasLimit =
|
4693
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
4769
4694
|
this.validateGas({
|
4770
4695
|
gasUsed,
|
4771
4696
|
gasPrice: request.gasPrice,
|
@@ -4790,7 +4715,7 @@ var Account = class extends AbstractAccount {
|
|
4790
4715
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4791
4716
|
);
|
4792
4717
|
const amountDataArray = arrayify14(
|
4793
|
-
"0x".concat(
|
4718
|
+
"0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
|
4794
4719
|
);
|
4795
4720
|
const script = new Uint8Array([
|
4796
4721
|
...arrayify14(withdrawScript.bytes),
|
@@ -4799,12 +4724,12 @@ var Account = class extends AbstractAccount {
|
|
4799
4724
|
]);
|
4800
4725
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4801
4726
|
const request = new ScriptTransactionRequest(params);
|
4802
|
-
const forwardingQuantities = [{ amount:
|
4727
|
+
const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
|
4803
4728
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4804
4729
|
request,
|
4805
4730
|
forwardingQuantities
|
4806
4731
|
);
|
4807
|
-
request.gasLimit =
|
4732
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
4808
4733
|
this.validateGas({
|
4809
4734
|
gasUsed,
|
4810
4735
|
gasPrice: request.gasPrice,
|
@@ -4816,7 +4741,7 @@ var Account = class extends AbstractAccount {
|
|
4816
4741
|
}
|
4817
4742
|
async signMessage(message) {
|
4818
4743
|
if (!this._connector) {
|
4819
|
-
throw new
|
4744
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4820
4745
|
}
|
4821
4746
|
return this._connector.signMessage(this.address.toString(), message);
|
4822
4747
|
}
|
@@ -4828,8 +4753,8 @@ var Account = class extends AbstractAccount {
|
|
4828
4753
|
*/
|
4829
4754
|
async signTransaction(transactionRequestLike) {
|
4830
4755
|
if (!this._connector) {
|
4831
|
-
throw new
|
4832
|
-
|
4756
|
+
throw new FuelError14(
|
4757
|
+
ErrorCode14.MISSING_CONNECTOR,
|
4833
4758
|
"A connector is required to sign transactions."
|
4834
4759
|
);
|
4835
4760
|
}
|
@@ -4876,14 +4801,14 @@ var Account = class extends AbstractAccount {
|
|
4876
4801
|
minGasPrice
|
4877
4802
|
}) {
|
4878
4803
|
if (minGasPrice.gt(gasPrice)) {
|
4879
|
-
throw new
|
4880
|
-
|
4804
|
+
throw new FuelError14(
|
4805
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
4881
4806
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4882
4807
|
);
|
4883
4808
|
}
|
4884
4809
|
if (gasUsed.gt(gasLimit)) {
|
4885
|
-
throw new
|
4886
|
-
|
4810
|
+
throw new FuelError14(
|
4811
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
4887
4812
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4888
4813
|
);
|
4889
4814
|
}
|
@@ -5010,7 +4935,7 @@ import {
|
|
5010
4935
|
decryptJsonWalletData,
|
5011
4936
|
encryptJsonWalletData
|
5012
4937
|
} from "@fuel-ts/crypto";
|
5013
|
-
import { ErrorCode as
|
4938
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5014
4939
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5015
4940
|
import { v4 as uuidv4 } from "uuid";
|
5016
4941
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5088,8 +5013,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5088
5013
|
const macHashUint8Array = keccak256(data);
|
5089
5014
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5090
5015
|
if (mac !== macHash) {
|
5091
|
-
throw new
|
5092
|
-
|
5016
|
+
throw new FuelError15(
|
5017
|
+
ErrorCode15.INVALID_PASSWORD,
|
5093
5018
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5094
5019
|
);
|
5095
5020
|
}
|
@@ -5211,15 +5136,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5211
5136
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5212
5137
|
|
5213
5138
|
// src/hdwallet/hdwallet.ts
|
5214
|
-
import { ErrorCode as
|
5139
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5215
5140
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5216
|
-
import { bn as
|
5141
|
+
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5217
5142
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5218
5143
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5219
5144
|
|
5220
5145
|
// src/mnemonic/mnemonic.ts
|
5221
5146
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5222
|
-
import { ErrorCode as
|
5147
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5223
5148
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5224
5149
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5225
5150
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7277,7 +7202,7 @@ var english = [
|
|
7277
7202
|
];
|
7278
7203
|
|
7279
7204
|
// src/mnemonic/utils.ts
|
7280
|
-
import { ErrorCode as
|
7205
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7281
7206
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7282
7207
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7283
7208
|
function toUtf8Bytes(stri) {
|
@@ -7294,8 +7219,8 @@ function toUtf8Bytes(stri) {
|
|
7294
7219
|
i += 1;
|
7295
7220
|
const c2 = str.charCodeAt(i);
|
7296
7221
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7297
|
-
throw new
|
7298
|
-
|
7222
|
+
throw new FuelError16(
|
7223
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7299
7224
|
"Invalid UTF-8 in the input string."
|
7300
7225
|
);
|
7301
7226
|
}
|
@@ -7358,8 +7283,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7358
7283
|
for (let i = 0; i < words.length; i += 1) {
|
7359
7284
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7360
7285
|
if (index === -1) {
|
7361
|
-
throw new
|
7362
|
-
|
7286
|
+
throw new FuelError16(
|
7287
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7363
7288
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7364
7289
|
);
|
7365
7290
|
}
|
@@ -7375,8 +7300,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7375
7300
|
const checksumMask = getUpperMask(checksumBits);
|
7376
7301
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7377
7302
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7378
|
-
throw new
|
7379
|
-
|
7303
|
+
throw new FuelError16(
|
7304
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7380
7305
|
"Checksum validation failed for the provided mnemonic."
|
7381
7306
|
);
|
7382
7307
|
}
|
@@ -7390,16 +7315,16 @@ var TestnetPRV = "0x04358394";
|
|
7390
7315
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7391
7316
|
function assertWordList(wordlist) {
|
7392
7317
|
if (wordlist.length !== 2048) {
|
7393
|
-
throw new
|
7394
|
-
|
7318
|
+
throw new FuelError17(
|
7319
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7395
7320
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7396
7321
|
);
|
7397
7322
|
}
|
7398
7323
|
}
|
7399
7324
|
function assertEntropy(entropy) {
|
7400
7325
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7401
|
-
throw new
|
7402
|
-
|
7326
|
+
throw new FuelError17(
|
7327
|
+
ErrorCode17.INVALID_ENTROPY,
|
7403
7328
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7404
7329
|
);
|
7405
7330
|
}
|
@@ -7409,7 +7334,7 @@ function assertMnemonic(words) {
|
|
7409
7334
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7410
7335
|
", "
|
7411
7336
|
)}] words, but got ${words.length}.`;
|
7412
|
-
throw new
|
7337
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7413
7338
|
}
|
7414
7339
|
}
|
7415
7340
|
var Mnemonic = class {
|
@@ -7527,8 +7452,8 @@ var Mnemonic = class {
|
|
7527
7452
|
static masterKeysFromSeed(seed) {
|
7528
7453
|
const seedArray = arrayify17(seed);
|
7529
7454
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7530
|
-
throw new
|
7531
|
-
|
7455
|
+
throw new FuelError17(
|
7456
|
+
ErrorCode17.INVALID_SEED,
|
7532
7457
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7533
7458
|
);
|
7534
7459
|
}
|
@@ -7605,7 +7530,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7605
7530
|
function parsePath(path2, depth = 0) {
|
7606
7531
|
const components = path2.split("/");
|
7607
7532
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7608
|
-
throw new
|
7533
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7609
7534
|
}
|
7610
7535
|
if (components[0] === "m") {
|
7611
7536
|
components.shift();
|
@@ -7634,8 +7559,8 @@ var HDWallet = class {
|
|
7634
7559
|
this.privateKey = hexlify17(config.privateKey);
|
7635
7560
|
} else {
|
7636
7561
|
if (!config.publicKey) {
|
7637
|
-
throw new
|
7638
|
-
|
7562
|
+
throw new FuelError18(
|
7563
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7639
7564
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7640
7565
|
);
|
7641
7566
|
}
|
@@ -7664,8 +7589,8 @@ var HDWallet = class {
|
|
7664
7589
|
const data = new Uint8Array(37);
|
7665
7590
|
if (index & HARDENED_INDEX) {
|
7666
7591
|
if (!privateKey) {
|
7667
|
-
throw new
|
7668
|
-
|
7592
|
+
throw new FuelError18(
|
7593
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7669
7594
|
"Cannot derive a hardened index without a private Key."
|
7670
7595
|
);
|
7671
7596
|
}
|
@@ -7679,7 +7604,7 @@ var HDWallet = class {
|
|
7679
7604
|
const IR = bytes.slice(32);
|
7680
7605
|
if (privateKey) {
|
7681
7606
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7682
|
-
const ki =
|
7607
|
+
const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
|
7683
7608
|
return new HDWallet({
|
7684
7609
|
privateKey: ki,
|
7685
7610
|
chainCode: IR,
|
@@ -7717,8 +7642,8 @@ var HDWallet = class {
|
|
7717
7642
|
*/
|
7718
7643
|
toExtendedKey(isPublic = false, testnet = false) {
|
7719
7644
|
if (this.depth >= 256) {
|
7720
|
-
throw new
|
7721
|
-
|
7645
|
+
throw new FuelError18(
|
7646
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7722
7647
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7723
7648
|
);
|
7724
7649
|
}
|
@@ -7749,10 +7674,10 @@ var HDWallet = class {
|
|
7749
7674
|
const bytes = arrayify18(decoded);
|
7750
7675
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7751
7676
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7752
|
-
throw new
|
7677
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7753
7678
|
}
|
7754
7679
|
if (!validChecksum) {
|
7755
|
-
throw new
|
7680
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7756
7681
|
}
|
7757
7682
|
const depth = bytes[4];
|
7758
7683
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7760,14 +7685,14 @@ var HDWallet = class {
|
|
7760
7685
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7761
7686
|
const key = bytes.slice(45, 78);
|
7762
7687
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7763
|
-
throw new
|
7764
|
-
|
7688
|
+
throw new FuelError18(
|
7689
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7765
7690
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7766
7691
|
);
|
7767
7692
|
}
|
7768
7693
|
if (isPublicExtendedKey(bytes)) {
|
7769
7694
|
if (key[0] !== 3) {
|
7770
|
-
throw new
|
7695
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7771
7696
|
}
|
7772
7697
|
return new HDWallet({
|
7773
7698
|
publicKey: key,
|
@@ -7778,7 +7703,7 @@ var HDWallet = class {
|
|
7778
7703
|
});
|
7779
7704
|
}
|
7780
7705
|
if (key[0] !== 0) {
|
7781
|
-
throw new
|
7706
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7782
7707
|
}
|
7783
7708
|
return new HDWallet({
|
7784
7709
|
privateKey: key.slice(1),
|