@fuel-ts/account 0.0.0-rc-1936-20240328132546 → 0.0.0-rc-1895-20240328133917
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 +160 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +572 -483
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -256
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +3 -0
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +5 -0
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +5 -2
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +30 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +160 -15
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +532 -438
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +320 -218
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
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 ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
30
|
+
import { bn as bn17 } 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 ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
+
import { BN, bn as bn15, 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 bn7 } from "@fuel-ts/math";
|
1156
1156
|
import {
|
1157
1157
|
PolicyType,
|
1158
1158
|
TransactionCoder,
|
@@ -1495,6 +1495,76 @@ 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
|
+
|
1498
1568
|
// src/providers/transaction-request/errors.ts
|
1499
1569
|
var NoWitnessAtIndexError = class extends Error {
|
1500
1570
|
constructor(index) {
|
@@ -1545,10 +1615,10 @@ var BaseTransactionRequest = class {
|
|
1545
1615
|
outputs,
|
1546
1616
|
witnesses
|
1547
1617
|
} = {}) {
|
1548
|
-
this.gasPrice =
|
1618
|
+
this.gasPrice = bn7(gasPrice);
|
1549
1619
|
this.maturity = maturity ?? 0;
|
1550
|
-
this.witnessLimit = witnessLimit ?
|
1551
|
-
this.maxFee = maxFee ?
|
1620
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1621
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1552
1622
|
this.inputs = inputs ?? [];
|
1553
1623
|
this.outputs = outputs ?? [];
|
1554
1624
|
this.witnesses = witnesses ?? [];
|
@@ -1978,13 +2048,13 @@ var BaseTransactionRequest = class {
|
|
1978
2048
|
assetId,
|
1979
2049
|
owner: resourcesOwner || Address.fromRandom(),
|
1980
2050
|
maturity: 0,
|
1981
|
-
blockCreated:
|
1982
|
-
txCreatedIdx:
|
2051
|
+
blockCreated: bn7(1),
|
2052
|
+
txCreatedIdx: bn7(1)
|
1983
2053
|
}
|
1984
2054
|
]);
|
1985
2055
|
}
|
1986
2056
|
};
|
1987
|
-
updateAssetInput(BaseAssetId2,
|
2057
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
1988
2058
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
1989
2059
|
}
|
1990
2060
|
/**
|
@@ -1995,7 +2065,7 @@ var BaseTransactionRequest = class {
|
|
1995
2065
|
*/
|
1996
2066
|
getCoinOutputsQuantities() {
|
1997
2067
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
1998
|
-
amount:
|
2068
|
+
amount: bn7(amount),
|
1999
2069
|
assetId: assetId.toString()
|
2000
2070
|
}));
|
2001
2071
|
return coinsQuantities;
|
@@ -2024,7 +2094,7 @@ var BaseTransactionRequest = class {
|
|
2024
2094
|
default:
|
2025
2095
|
return;
|
2026
2096
|
}
|
2027
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2097
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2028
2098
|
i.predicate = correspondingInput.predicate;
|
2029
2099
|
i.predicateData = correspondingInput.predicateData;
|
2030
2100
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2035,14 +2105,14 @@ var BaseTransactionRequest = class {
|
|
2035
2105
|
|
2036
2106
|
// src/providers/transaction-request/create-transaction-request.ts
|
2037
2107
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2038
|
-
import { bn as
|
2108
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2039
2109
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2040
2110
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2041
2111
|
|
2042
2112
|
// src/providers/transaction-request/hash-transaction.ts
|
2043
2113
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2044
2114
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2045
|
-
import { bn as
|
2115
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2046
2116
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2047
2117
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2048
2118
|
import { clone as clone2 } from "ramda";
|
@@ -2059,11 +2129,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2059
2129
|
blockHeight: 0,
|
2060
2130
|
txIndex: 0
|
2061
2131
|
};
|
2062
|
-
inputClone.predicateGasUsed =
|
2132
|
+
inputClone.predicateGasUsed = bn8(0);
|
2063
2133
|
return inputClone;
|
2064
2134
|
}
|
2065
2135
|
case InputType3.Message: {
|
2066
|
-
inputClone.predicateGasUsed =
|
2136
|
+
inputClone.predicateGasUsed = bn8(0);
|
2067
2137
|
return inputClone;
|
2068
2138
|
}
|
2069
2139
|
case InputType3.Contract: {
|
@@ -2090,12 +2160,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2090
2160
|
return outputClone;
|
2091
2161
|
}
|
2092
2162
|
case OutputType3.Change: {
|
2093
|
-
outputClone.amount =
|
2163
|
+
outputClone.amount = bn8(0);
|
2094
2164
|
return outputClone;
|
2095
2165
|
}
|
2096
2166
|
case OutputType3.Variable: {
|
2097
2167
|
outputClone.to = ZeroBytes325;
|
2098
|
-
outputClone.amount =
|
2168
|
+
outputClone.amount = bn8(0);
|
2099
2169
|
outputClone.assetId = ZeroBytes325;
|
2100
2170
|
return outputClone;
|
2101
2171
|
}
|
@@ -2219,7 +2289,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2219
2289
|
}
|
2220
2290
|
metadataGas(gasCosts) {
|
2221
2291
|
return calculateMetadataGasForTxCreate({
|
2222
|
-
contractBytesSize:
|
2292
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2223
2293
|
gasCosts,
|
2224
2294
|
stateRootSize: this.storageSlots.length,
|
2225
2295
|
txBytesSize: this.byteSize()
|
@@ -2231,7 +2301,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2231
2301
|
import { Interface } from "@fuel-ts/abi-coder";
|
2232
2302
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2233
2303
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2234
|
-
import { bn as
|
2304
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2235
2305
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2236
2306
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2237
2307
|
|
@@ -2277,6 +2347,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2277
2347
|
script;
|
2278
2348
|
/** Script input data (parameters) */
|
2279
2349
|
scriptData;
|
2350
|
+
abis;
|
2280
2351
|
/**
|
2281
2352
|
* Constructor for `ScriptTransactionRequest`.
|
2282
2353
|
*
|
@@ -2284,9 +2355,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2284
2355
|
*/
|
2285
2356
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2286
2357
|
super(rest);
|
2287
|
-
this.gasLimit =
|
2358
|
+
this.gasLimit = bn10(gasLimit);
|
2288
2359
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2289
2360
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2361
|
+
this.abis = rest.abis;
|
2290
2362
|
}
|
2291
2363
|
/**
|
2292
2364
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2431,7 +2503,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2431
2503
|
};
|
2432
2504
|
|
2433
2505
|
// src/providers/transaction-request/utils.ts
|
2434
|
-
import { ErrorCode as
|
2506
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2435
2507
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2436
2508
|
var transactionRequestify = (obj) => {
|
2437
2509
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2446,14 +2518,14 @@ var transactionRequestify = (obj) => {
|
|
2446
2518
|
return CreateTransactionRequest.from(obj);
|
2447
2519
|
}
|
2448
2520
|
default: {
|
2449
|
-
throw new
|
2521
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2450
2522
|
}
|
2451
2523
|
}
|
2452
2524
|
};
|
2453
2525
|
|
2454
2526
|
// src/providers/transaction-response/transaction-response.ts
|
2455
|
-
import { ErrorCode as
|
2456
|
-
import { bn as
|
2527
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2528
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2457
2529
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2458
2530
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2459
2531
|
|
@@ -2461,7 +2533,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2461
2533
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2462
2534
|
|
2463
2535
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2464
|
-
import { bn as
|
2536
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2465
2537
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2466
2538
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2467
2539
|
var calculateTransactionFee = (params) => {
|
@@ -2470,24 +2542,24 @@ var calculateTransactionFee = (params) => {
|
|
2470
2542
|
rawPayload,
|
2471
2543
|
consensusParameters: { gasCosts, feeParams }
|
2472
2544
|
} = params;
|
2473
|
-
const gasPerByte =
|
2474
|
-
const gasPriceFactor =
|
2545
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2546
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2475
2547
|
const transactionBytes = arrayify9(rawPayload);
|
2476
2548
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2477
2549
|
if (transaction.type === TransactionType6.Mint) {
|
2478
2550
|
return {
|
2479
|
-
fee:
|
2480
|
-
minFee:
|
2481
|
-
maxFee:
|
2482
|
-
feeFromGasUsed:
|
2551
|
+
fee: bn11(0),
|
2552
|
+
minFee: bn11(0),
|
2553
|
+
maxFee: bn11(0),
|
2554
|
+
feeFromGasUsed: bn11(0)
|
2483
2555
|
};
|
2484
2556
|
}
|
2485
2557
|
const { type, witnesses, inputs, policies } = transaction;
|
2486
|
-
let metadataGas =
|
2487
|
-
let gasLimit =
|
2558
|
+
let metadataGas = bn11(0);
|
2559
|
+
let gasLimit = bn11(0);
|
2488
2560
|
if (type === TransactionType6.Create) {
|
2489
2561
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2490
|
-
const contractBytesSize =
|
2562
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2491
2563
|
metadataGas = calculateMetadataGasForTxCreate({
|
2492
2564
|
contractBytesSize,
|
2493
2565
|
gasCosts,
|
@@ -2506,12 +2578,12 @@ var calculateTransactionFee = (params) => {
|
|
2506
2578
|
}
|
2507
2579
|
const minGas = getMinGas({
|
2508
2580
|
gasCosts,
|
2509
|
-
gasPerByte:
|
2581
|
+
gasPerByte: bn11(gasPerByte),
|
2510
2582
|
inputs,
|
2511
2583
|
metadataGas,
|
2512
2584
|
txBytesSize: transactionBytes.length
|
2513
2585
|
});
|
2514
|
-
const gasPrice =
|
2586
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2515
2587
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2516
2588
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2517
2589
|
const maxGas = getMaxGas({
|
@@ -2535,13 +2607,13 @@ var calculateTransactionFee = (params) => {
|
|
2535
2607
|
|
2536
2608
|
// src/providers/transaction-summary/operations.ts
|
2537
2609
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2538
|
-
import { ErrorCode as
|
2539
|
-
import { bn as
|
2540
|
-
import { ReceiptType as
|
2610
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2611
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2612
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2541
2613
|
|
2542
2614
|
// src/providers/transaction-summary/call.ts
|
2543
2615
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2544
|
-
import { bn as
|
2616
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2545
2617
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2546
2618
|
const abiInterface = new Interface2(abi);
|
2547
2619
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2550,7 +2622,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2550
2622
|
let encodedArgs;
|
2551
2623
|
if (functionFragment.isInputDataPointer) {
|
2552
2624
|
if (rawPayload) {
|
2553
|
-
const argsOffset =
|
2625
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2554
2626
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2555
2627
|
}
|
2556
2628
|
} else {
|
@@ -2584,7 +2656,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2584
2656
|
};
|
2585
2657
|
|
2586
2658
|
// src/providers/transaction-summary/input.ts
|
2587
|
-
import { ErrorCode as
|
2659
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2588
2660
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2589
2661
|
function getInputsByTypes(inputs, types) {
|
2590
2662
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2622,8 +2694,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2622
2694
|
return void 0;
|
2623
2695
|
}
|
2624
2696
|
if (contractInput.type !== InputType5.Contract) {
|
2625
|
-
throw new
|
2626
|
-
|
2697
|
+
throw new FuelError9(
|
2698
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2627
2699
|
`Contract input should be of type 'contract'.`
|
2628
2700
|
);
|
2629
2701
|
}
|
@@ -2670,8 +2742,8 @@ function getTransactionTypeName(transactionType) {
|
|
2670
2742
|
case TransactionType7.Script:
|
2671
2743
|
return "Script" /* Script */;
|
2672
2744
|
default:
|
2673
|
-
throw new
|
2674
|
-
|
2745
|
+
throw new FuelError10(
|
2746
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2675
2747
|
`Invalid transaction type: ${transactionType}.`
|
2676
2748
|
);
|
2677
2749
|
}
|
@@ -2690,10 +2762,10 @@ function isTypeScript(transactionType) {
|
|
2690
2762
|
return isType(transactionType, "Script" /* Script */);
|
2691
2763
|
}
|
2692
2764
|
function getReceiptsCall(receipts) {
|
2693
|
-
return getReceiptsByType(receipts,
|
2765
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2694
2766
|
}
|
2695
2767
|
function getReceiptsMessageOut(receipts) {
|
2696
|
-
return getReceiptsByType(receipts,
|
2768
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2697
2769
|
}
|
2698
2770
|
var mergeAssets = (op1, op2) => {
|
2699
2771
|
const assets1 = op1.assetsSent || [];
|
@@ -2706,7 +2778,7 @@ var mergeAssets = (op1, op2) => {
|
|
2706
2778
|
if (!matchingAsset) {
|
2707
2779
|
return asset1;
|
2708
2780
|
}
|
2709
|
-
const mergedAmount =
|
2781
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2710
2782
|
return { ...asset1, amount: mergedAmount };
|
2711
2783
|
});
|
2712
2784
|
return mergedAssets.concat(filteredAssets);
|
@@ -2889,11 +2961,11 @@ function getTransferOperations({
|
|
2889
2961
|
});
|
2890
2962
|
const transferReceipts = getReceiptsByType(
|
2891
2963
|
receipts,
|
2892
|
-
|
2964
|
+
ReceiptType4.Transfer
|
2893
2965
|
);
|
2894
2966
|
const transferOutReceipts = getReceiptsByType(
|
2895
2967
|
receipts,
|
2896
|
-
|
2968
|
+
ReceiptType4.TransferOut
|
2897
2969
|
);
|
2898
2970
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2899
2971
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -2978,17 +3050,17 @@ function getOperations({
|
|
2978
3050
|
}
|
2979
3051
|
|
2980
3052
|
// src/providers/transaction-summary/receipt.ts
|
2981
|
-
import { ReceiptType as
|
3053
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
2982
3054
|
var processGqlReceipt = (gqlReceipt) => {
|
2983
3055
|
const receipt = assembleReceiptByType(gqlReceipt);
|
2984
3056
|
switch (receipt.type) {
|
2985
|
-
case
|
3057
|
+
case ReceiptType5.ReturnData: {
|
2986
3058
|
return {
|
2987
3059
|
...receipt,
|
2988
3060
|
data: gqlReceipt.data || "0x"
|
2989
3061
|
};
|
2990
3062
|
}
|
2991
|
-
case
|
3063
|
+
case ReceiptType5.LogData: {
|
2992
3064
|
return {
|
2993
3065
|
...receipt,
|
2994
3066
|
data: gqlReceipt.data || "0x"
|
@@ -3001,7 +3073,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3001
3073
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3002
3074
|
const mintedAssets = [];
|
3003
3075
|
receipts.forEach((receipt) => {
|
3004
|
-
if (receipt.type ===
|
3076
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3005
3077
|
mintedAssets.push({
|
3006
3078
|
subId: receipt.subId,
|
3007
3079
|
contractId: receipt.contractId,
|
@@ -3015,7 +3087,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3015
3087
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3016
3088
|
const burnedAssets = [];
|
3017
3089
|
receipts.forEach((receipt) => {
|
3018
|
-
if (receipt.type ===
|
3090
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3019
3091
|
burnedAssets.push({
|
3020
3092
|
subId: receipt.subId,
|
3021
3093
|
contractId: receipt.contractId,
|
@@ -3028,7 +3100,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3028
3100
|
};
|
3029
3101
|
|
3030
3102
|
// src/providers/transaction-summary/status.ts
|
3031
|
-
import { ErrorCode as
|
3103
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3032
3104
|
var getTransactionStatusName = (gqlStatus) => {
|
3033
3105
|
switch (gqlStatus) {
|
3034
3106
|
case "FailureStatus":
|
@@ -3040,8 +3112,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3040
3112
|
case "SqueezedOutStatus":
|
3041
3113
|
return "squeezedout" /* squeezedout */;
|
3042
3114
|
default:
|
3043
|
-
throw new
|
3044
|
-
|
3115
|
+
throw new FuelError11(
|
3116
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3045
3117
|
`Invalid transaction status: ${gqlStatus}.`
|
3046
3118
|
);
|
3047
3119
|
}
|
@@ -3152,6 +3224,21 @@ function assembleTransactionSummary(params) {
|
|
3152
3224
|
return transactionSummary;
|
3153
3225
|
}
|
3154
3226
|
|
3227
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
3228
|
+
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3229
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3230
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3231
|
+
return receipts.reduce((logs, receipt) => {
|
3232
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3233
|
+
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3234
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3235
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3236
|
+
logs.push(decodedLog);
|
3237
|
+
}
|
3238
|
+
return logs;
|
3239
|
+
}, []);
|
3240
|
+
}
|
3241
|
+
|
3155
3242
|
// src/providers/transaction-response/transaction-response.ts
|
3156
3243
|
var TransactionResponse = class {
|
3157
3244
|
/** Transaction ID */
|
@@ -3159,18 +3246,20 @@ var TransactionResponse = class {
|
|
3159
3246
|
/** Current provider */
|
3160
3247
|
provider;
|
3161
3248
|
/** Gas used on the transaction */
|
3162
|
-
gasUsed =
|
3249
|
+
gasUsed = bn14(0);
|
3163
3250
|
/** The graphql Transaction with receipts object. */
|
3164
3251
|
gqlTransaction;
|
3252
|
+
abis;
|
3165
3253
|
/**
|
3166
3254
|
* Constructor for `TransactionResponse`.
|
3167
3255
|
*
|
3168
3256
|
* @param id - The transaction ID.
|
3169
3257
|
* @param provider - The provider.
|
3170
3258
|
*/
|
3171
|
-
constructor(id, provider) {
|
3259
|
+
constructor(id, provider, abis) {
|
3172
3260
|
this.id = id;
|
3173
3261
|
this.provider = provider;
|
3262
|
+
this.abis = abis;
|
3174
3263
|
}
|
3175
3264
|
/**
|
3176
3265
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -3180,8 +3269,8 @@ var TransactionResponse = class {
|
|
3180
3269
|
* @param id - The transaction ID.
|
3181
3270
|
* @param provider - The provider.
|
3182
3271
|
*/
|
3183
|
-
static async create(id, provider) {
|
3184
|
-
const response = new TransactionResponse(id, provider);
|
3272
|
+
static async create(id, provider, abis) {
|
3273
|
+
const response = new TransactionResponse(id, provider, abis);
|
3185
3274
|
await response.fetch();
|
3186
3275
|
return response;
|
3187
3276
|
}
|
@@ -3262,8 +3351,8 @@ var TransactionResponse = class {
|
|
3262
3351
|
});
|
3263
3352
|
for await (const { statusChange } of subscription) {
|
3264
3353
|
if (statusChange.type === "SqueezedOutStatus") {
|
3265
|
-
throw new
|
3266
|
-
|
3354
|
+
throw new FuelError12(
|
3355
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3267
3356
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3268
3357
|
);
|
3269
3358
|
}
|
@@ -3285,6 +3374,26 @@ var TransactionResponse = class {
|
|
3285
3374
|
gqlTransaction: this.gqlTransaction,
|
3286
3375
|
...transactionSummary
|
3287
3376
|
};
|
3377
|
+
let logs = [];
|
3378
|
+
if (this.abis) {
|
3379
|
+
logs = getDecodedLogs(
|
3380
|
+
transactionSummary.receipts,
|
3381
|
+
this.abis.main,
|
3382
|
+
this.abis.otherContractsAbis
|
3383
|
+
);
|
3384
|
+
transactionResult.logs = logs;
|
3385
|
+
}
|
3386
|
+
if (transactionResult.isStatusFailure) {
|
3387
|
+
const {
|
3388
|
+
receipts,
|
3389
|
+
gqlTransaction: { status }
|
3390
|
+
} = transactionResult;
|
3391
|
+
throw extractTxError({
|
3392
|
+
receipts,
|
3393
|
+
status,
|
3394
|
+
logs
|
3395
|
+
});
|
3396
|
+
}
|
3288
3397
|
return transactionResult;
|
3289
3398
|
}
|
3290
3399
|
/**
|
@@ -3293,21 +3402,10 @@ var TransactionResponse = class {
|
|
3293
3402
|
* @param contractsAbiMap - The contracts ABI map.
|
3294
3403
|
*/
|
3295
3404
|
async wait(contractsAbiMap) {
|
3296
|
-
|
3297
|
-
if (result.isStatusFailure) {
|
3298
|
-
throw new FuelError11(
|
3299
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3300
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3301
|
-
);
|
3302
|
-
}
|
3303
|
-
return result;
|
3405
|
+
return this.waitForResult(contractsAbiMap);
|
3304
3406
|
}
|
3305
3407
|
};
|
3306
3408
|
|
3307
|
-
// src/providers/transaction-response/getDecodedLogs.ts
|
3308
|
-
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3309
|
-
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3310
|
-
|
3311
3409
|
// src/providers/utils/auto-retry-fetch.ts
|
3312
3410
|
function getWaitDelay(options, retryAttemptNum) {
|
3313
3411
|
const duration = options.baseDelay ?? 150;
|
@@ -3366,29 +3464,29 @@ var processGqlChain = (chain) => {
|
|
3366
3464
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3367
3465
|
return {
|
3368
3466
|
name,
|
3369
|
-
baseChainHeight:
|
3467
|
+
baseChainHeight: bn15(daHeight),
|
3370
3468
|
consensusParameters: {
|
3371
|
-
contractMaxSize:
|
3372
|
-
maxInputs:
|
3373
|
-
maxOutputs:
|
3374
|
-
maxWitnesses:
|
3375
|
-
maxGasPerTx:
|
3376
|
-
maxScriptLength:
|
3377
|
-
maxScriptDataLength:
|
3378
|
-
maxStorageSlots:
|
3379
|
-
maxPredicateLength:
|
3380
|
-
maxPredicateDataLength:
|
3381
|
-
maxGasPerPredicate:
|
3382
|
-
gasPriceFactor:
|
3383
|
-
gasPerByte:
|
3384
|
-
maxMessageDataLength:
|
3385
|
-
chainId:
|
3469
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3470
|
+
maxInputs: bn15(txParams.maxInputs),
|
3471
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3472
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3473
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3474
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3475
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3476
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3477
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3478
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3479
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3480
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3481
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3482
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3483
|
+
chainId: bn15(consensusParameters.chainId),
|
3386
3484
|
gasCosts
|
3387
3485
|
},
|
3388
3486
|
gasCosts,
|
3389
3487
|
latestBlock: {
|
3390
3488
|
id: latestBlock.id,
|
3391
|
-
height:
|
3489
|
+
height: bn15(latestBlock.header.height),
|
3392
3490
|
time: latestBlock.header.time,
|
3393
3491
|
transactions: latestBlock.transactions.map((i) => ({
|
3394
3492
|
id: i.id
|
@@ -3458,8 +3556,8 @@ var _Provider = class {
|
|
3458
3556
|
getChain() {
|
3459
3557
|
const chain = _Provider.chainInfoCache[this.url];
|
3460
3558
|
if (!chain) {
|
3461
|
-
throw new
|
3462
|
-
|
3559
|
+
throw new FuelError13(
|
3560
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3463
3561
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3464
3562
|
);
|
3465
3563
|
}
|
@@ -3471,8 +3569,8 @@ var _Provider = class {
|
|
3471
3569
|
getNode() {
|
3472
3570
|
const node = _Provider.nodeInfoCache[this.url];
|
3473
3571
|
if (!node) {
|
3474
|
-
throw new
|
3475
|
-
|
3572
|
+
throw new FuelError13(
|
3573
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3476
3574
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3477
3575
|
);
|
3478
3576
|
}
|
@@ -3519,8 +3617,8 @@ var _Provider = class {
|
|
3519
3617
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3520
3618
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3521
3619
|
if (!isMajorSupported || !isMinorSupported) {
|
3522
|
-
throw new
|
3523
|
-
|
3620
|
+
throw new FuelError13(
|
3621
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3524
3622
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3525
3623
|
);
|
3526
3624
|
}
|
@@ -3583,7 +3681,7 @@ var _Provider = class {
|
|
3583
3681
|
*/
|
3584
3682
|
async getBlockNumber() {
|
3585
3683
|
const { chain } = await this.operations.getChain();
|
3586
|
-
return
|
3684
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3587
3685
|
}
|
3588
3686
|
/**
|
3589
3687
|
* Returns the chain information.
|
@@ -3593,9 +3691,9 @@ var _Provider = class {
|
|
3593
3691
|
async fetchNode() {
|
3594
3692
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3595
3693
|
const processedNodeInfo = {
|
3596
|
-
maxDepth:
|
3597
|
-
maxTx:
|
3598
|
-
minGasPrice:
|
3694
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3695
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3696
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3599
3697
|
nodeVersion: nodeInfo.nodeVersion,
|
3600
3698
|
utxoValidation: nodeInfo.utxoValidation,
|
3601
3699
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3642,12 +3740,16 @@ var _Provider = class {
|
|
3642
3740
|
await this.estimateTxDependencies(transactionRequest);
|
3643
3741
|
}
|
3644
3742
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3743
|
+
let abis;
|
3744
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3745
|
+
abis = transactionRequest.abis;
|
3746
|
+
}
|
3645
3747
|
if (awaitExecution) {
|
3646
3748
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3647
3749
|
for await (const { submitAndAwait } of subscription) {
|
3648
3750
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3649
|
-
throw new
|
3650
|
-
|
3751
|
+
throw new FuelError13(
|
3752
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3651
3753
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3652
3754
|
);
|
3653
3755
|
}
|
@@ -3656,14 +3758,14 @@ var _Provider = class {
|
|
3656
3758
|
}
|
3657
3759
|
}
|
3658
3760
|
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
3659
|
-
const response = new TransactionResponse(transactionId2, this);
|
3761
|
+
const response = new TransactionResponse(transactionId2, this, abis);
|
3660
3762
|
await response.fetch();
|
3661
3763
|
return response;
|
3662
3764
|
}
|
3663
3765
|
const {
|
3664
3766
|
submit: { id: transactionId }
|
3665
3767
|
} = await this.operations.submit({ encodedTransaction });
|
3666
|
-
return new TransactionResponse(transactionId, this);
|
3768
|
+
return new TransactionResponse(transactionId, this, abis);
|
3667
3769
|
}
|
3668
3770
|
/**
|
3669
3771
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -3714,7 +3816,7 @@ var _Provider = class {
|
|
3714
3816
|
} = response;
|
3715
3817
|
if (inputs) {
|
3716
3818
|
inputs.forEach((input, index) => {
|
3717
|
-
if ("predicateGasUsed" in input &&
|
3819
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3718
3820
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3719
3821
|
}
|
3720
3822
|
});
|
@@ -3827,7 +3929,7 @@ var _Provider = class {
|
|
3827
3929
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3828
3930
|
if (estimatePredicates) {
|
3829
3931
|
if (isScriptTransaction) {
|
3830
|
-
txRequestClone.gasLimit =
|
3932
|
+
txRequestClone.gasLimit = bn15(0);
|
3831
3933
|
}
|
3832
3934
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3833
3935
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3843,8 +3945,8 @@ var _Provider = class {
|
|
3843
3945
|
let missingContractIds = [];
|
3844
3946
|
let outputVariables = 0;
|
3845
3947
|
if (isScriptTransaction && estimateTxDependencies) {
|
3846
|
-
txRequestClone.gasPrice =
|
3847
|
-
txRequestClone.gasLimit =
|
3948
|
+
txRequestClone.gasPrice = bn15(0);
|
3949
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3848
3950
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3849
3951
|
receipts = result.receipts;
|
3850
3952
|
outputVariables = result.outputVariables;
|
@@ -3906,11 +4008,11 @@ var _Provider = class {
|
|
3906
4008
|
return coins.map((coin) => ({
|
3907
4009
|
id: coin.utxoId,
|
3908
4010
|
assetId: coin.assetId,
|
3909
|
-
amount:
|
4011
|
+
amount: bn15(coin.amount),
|
3910
4012
|
owner: Address2.fromAddressOrString(coin.owner),
|
3911
|
-
maturity:
|
3912
|
-
blockCreated:
|
3913
|
-
txCreatedIdx:
|
4013
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4014
|
+
blockCreated: bn15(coin.blockCreated),
|
4015
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3914
4016
|
}));
|
3915
4017
|
}
|
3916
4018
|
/**
|
@@ -3947,9 +4049,9 @@ var _Provider = class {
|
|
3947
4049
|
switch (coin.__typename) {
|
3948
4050
|
case "MessageCoin":
|
3949
4051
|
return {
|
3950
|
-
amount:
|
4052
|
+
amount: bn15(coin.amount),
|
3951
4053
|
assetId: coin.assetId,
|
3952
|
-
daHeight:
|
4054
|
+
daHeight: bn15(coin.daHeight),
|
3953
4055
|
sender: Address2.fromAddressOrString(coin.sender),
|
3954
4056
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
3955
4057
|
nonce: coin.nonce
|
@@ -3957,12 +4059,12 @@ var _Provider = class {
|
|
3957
4059
|
case "Coin":
|
3958
4060
|
return {
|
3959
4061
|
id: coin.utxoId,
|
3960
|
-
amount:
|
4062
|
+
amount: bn15(coin.amount),
|
3961
4063
|
assetId: coin.assetId,
|
3962
4064
|
owner: Address2.fromAddressOrString(coin.owner),
|
3963
|
-
maturity:
|
3964
|
-
blockCreated:
|
3965
|
-
txCreatedIdx:
|
4065
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4066
|
+
blockCreated: bn15(coin.blockCreated),
|
4067
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3966
4068
|
};
|
3967
4069
|
default:
|
3968
4070
|
return null;
|
@@ -3979,13 +4081,13 @@ var _Provider = class {
|
|
3979
4081
|
async getBlock(idOrHeight) {
|
3980
4082
|
let variables;
|
3981
4083
|
if (typeof idOrHeight === "number") {
|
3982
|
-
variables = { height:
|
4084
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
3983
4085
|
} else if (idOrHeight === "latest") {
|
3984
4086
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
3985
4087
|
} else if (idOrHeight.length === 66) {
|
3986
4088
|
variables = { blockId: idOrHeight };
|
3987
4089
|
} else {
|
3988
|
-
variables = { blockId:
|
4090
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
3989
4091
|
}
|
3990
4092
|
const { block } = await this.operations.getBlock(variables);
|
3991
4093
|
if (!block) {
|
@@ -3993,7 +4095,7 @@ var _Provider = class {
|
|
3993
4095
|
}
|
3994
4096
|
return {
|
3995
4097
|
id: block.id,
|
3996
|
-
height:
|
4098
|
+
height: bn15(block.header.height),
|
3997
4099
|
time: block.header.time,
|
3998
4100
|
transactionIds: block.transactions.map((tx) => tx.id)
|
3999
4101
|
};
|
@@ -4008,7 +4110,7 @@ var _Provider = class {
|
|
4008
4110
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4009
4111
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4010
4112
|
id: block.id,
|
4011
|
-
height:
|
4113
|
+
height: bn15(block.header.height),
|
4012
4114
|
time: block.header.time,
|
4013
4115
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4014
4116
|
}));
|
@@ -4023,7 +4125,7 @@ var _Provider = class {
|
|
4023
4125
|
async getBlockWithTransactions(idOrHeight) {
|
4024
4126
|
let variables;
|
4025
4127
|
if (typeof idOrHeight === "number") {
|
4026
|
-
variables = { blockHeight:
|
4128
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4027
4129
|
} else if (idOrHeight === "latest") {
|
4028
4130
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4029
4131
|
} else {
|
@@ -4035,7 +4137,7 @@ var _Provider = class {
|
|
4035
4137
|
}
|
4036
4138
|
return {
|
4037
4139
|
id: block.id,
|
4038
|
-
height:
|
4140
|
+
height: bn15(block.header.height, 10),
|
4039
4141
|
time: block.header.time,
|
4040
4142
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4041
4143
|
transactions: block.transactions.map(
|
@@ -4084,7 +4186,7 @@ var _Provider = class {
|
|
4084
4186
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4085
4187
|
asset: hexlify12(assetId)
|
4086
4188
|
});
|
4087
|
-
return
|
4189
|
+
return bn15(contractBalance.amount, 10);
|
4088
4190
|
}
|
4089
4191
|
/**
|
4090
4192
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4098,7 +4200,7 @@ var _Provider = class {
|
|
4098
4200
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4099
4201
|
assetId: hexlify12(assetId)
|
4100
4202
|
});
|
4101
|
-
return
|
4203
|
+
return bn15(balance.amount, 10);
|
4102
4204
|
}
|
4103
4205
|
/**
|
4104
4206
|
* Returns balances for the given owner.
|
@@ -4116,7 +4218,7 @@ var _Provider = class {
|
|
4116
4218
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4117
4219
|
return balances.map((balance) => ({
|
4118
4220
|
assetId: balance.assetId,
|
4119
|
-
amount:
|
4221
|
+
amount: bn15(balance.amount)
|
4120
4222
|
}));
|
4121
4223
|
}
|
4122
4224
|
/**
|
@@ -4138,15 +4240,15 @@ var _Provider = class {
|
|
4138
4240
|
sender: message.sender,
|
4139
4241
|
recipient: message.recipient,
|
4140
4242
|
nonce: message.nonce,
|
4141
|
-
amount:
|
4243
|
+
amount: bn15(message.amount),
|
4142
4244
|
data: message.data
|
4143
4245
|
}),
|
4144
4246
|
sender: Address2.fromAddressOrString(message.sender),
|
4145
4247
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4146
4248
|
nonce: message.nonce,
|
4147
|
-
amount:
|
4249
|
+
amount: bn15(message.amount),
|
4148
4250
|
data: InputMessageCoder.decodeData(message.data),
|
4149
|
-
daHeight:
|
4251
|
+
daHeight: bn15(message.daHeight)
|
4150
4252
|
}));
|
4151
4253
|
}
|
4152
4254
|
/**
|
@@ -4164,8 +4266,8 @@ var _Provider = class {
|
|
4164
4266
|
nonce
|
4165
4267
|
};
|
4166
4268
|
if (commitBlockId && commitBlockHeight) {
|
4167
|
-
throw new
|
4168
|
-
|
4269
|
+
throw new FuelError13(
|
4270
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4169
4271
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4170
4272
|
);
|
4171
4273
|
}
|
@@ -4199,41 +4301,41 @@ var _Provider = class {
|
|
4199
4301
|
} = result.messageProof;
|
4200
4302
|
return {
|
4201
4303
|
messageProof: {
|
4202
|
-
proofIndex:
|
4304
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4203
4305
|
proofSet: messageProof.proofSet
|
4204
4306
|
},
|
4205
4307
|
blockProof: {
|
4206
|
-
proofIndex:
|
4308
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4207
4309
|
proofSet: blockProof.proofSet
|
4208
4310
|
},
|
4209
4311
|
messageBlockHeader: {
|
4210
4312
|
id: messageBlockHeader.id,
|
4211
|
-
daHeight:
|
4212
|
-
transactionsCount:
|
4313
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4314
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4213
4315
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4214
|
-
height:
|
4316
|
+
height: bn15(messageBlockHeader.height),
|
4215
4317
|
prevRoot: messageBlockHeader.prevRoot,
|
4216
4318
|
time: messageBlockHeader.time,
|
4217
4319
|
applicationHash: messageBlockHeader.applicationHash,
|
4218
4320
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4219
|
-
messageReceiptCount:
|
4321
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4220
4322
|
},
|
4221
4323
|
commitBlockHeader: {
|
4222
4324
|
id: commitBlockHeader.id,
|
4223
|
-
daHeight:
|
4224
|
-
transactionsCount:
|
4325
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4326
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4225
4327
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4226
|
-
height:
|
4328
|
+
height: bn15(commitBlockHeader.height),
|
4227
4329
|
prevRoot: commitBlockHeader.prevRoot,
|
4228
4330
|
time: commitBlockHeader.time,
|
4229
4331
|
applicationHash: commitBlockHeader.applicationHash,
|
4230
4332
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4231
|
-
messageReceiptCount:
|
4333
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4232
4334
|
},
|
4233
4335
|
sender: Address2.fromAddressOrString(sender),
|
4234
4336
|
recipient: Address2.fromAddressOrString(recipient),
|
4235
4337
|
nonce,
|
4236
|
-
amount:
|
4338
|
+
amount: bn15(amount),
|
4237
4339
|
data
|
4238
4340
|
};
|
4239
4341
|
}
|
@@ -4256,10 +4358,10 @@ var _Provider = class {
|
|
4256
4358
|
*/
|
4257
4359
|
async produceBlocks(amount, startTime) {
|
4258
4360
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4259
|
-
blocksToProduce:
|
4361
|
+
blocksToProduce: bn15(amount).toString(10),
|
4260
4362
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4261
4363
|
});
|
4262
|
-
return
|
4364
|
+
return bn15(latestBlockHeight);
|
4263
4365
|
}
|
4264
4366
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4265
4367
|
async getTransactionResponse(transactionId) {
|
@@ -4282,8 +4384,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4282
4384
|
__publicField(Provider, "nodeInfoCache", {});
|
4283
4385
|
|
4284
4386
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4285
|
-
import { ErrorCode as
|
4286
|
-
import { bn as
|
4387
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4388
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4287
4389
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4288
4390
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4289
4391
|
|
@@ -4400,7 +4502,7 @@ var Account = class extends AbstractAccount {
|
|
4400
4502
|
*/
|
4401
4503
|
get provider() {
|
4402
4504
|
if (!this._provider) {
|
4403
|
-
throw new
|
4505
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4404
4506
|
}
|
4405
4507
|
return this._provider;
|
4406
4508
|
}
|
@@ -4452,8 +4554,8 @@ var Account = class extends AbstractAccount {
|
|
4452
4554
|
if (!hasNextPage) {
|
4453
4555
|
break;
|
4454
4556
|
}
|
4455
|
-
throw new
|
4456
|
-
|
4557
|
+
throw new FuelError15(
|
4558
|
+
ErrorCode15.NOT_SUPPORTED,
|
4457
4559
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4458
4560
|
);
|
4459
4561
|
}
|
@@ -4478,8 +4580,8 @@ var Account = class extends AbstractAccount {
|
|
4478
4580
|
if (!hasNextPage) {
|
4479
4581
|
break;
|
4480
4582
|
}
|
4481
|
-
throw new
|
4482
|
-
|
4583
|
+
throw new FuelError15(
|
4584
|
+
ErrorCode15.NOT_SUPPORTED,
|
4483
4585
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4484
4586
|
);
|
4485
4587
|
}
|
@@ -4514,8 +4616,8 @@ var Account = class extends AbstractAccount {
|
|
4514
4616
|
if (!hasNextPage) {
|
4515
4617
|
break;
|
4516
4618
|
}
|
4517
|
-
throw new
|
4518
|
-
|
4619
|
+
throw new FuelError15(
|
4620
|
+
ErrorCode15.NOT_SUPPORTED,
|
4519
4621
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4520
4622
|
);
|
4521
4623
|
}
|
@@ -4531,7 +4633,7 @@ var Account = class extends AbstractAccount {
|
|
4531
4633
|
*/
|
4532
4634
|
async fund(request, coinQuantities, fee) {
|
4533
4635
|
const updatedQuantities = addAmountToAsset({
|
4534
|
-
amount:
|
4636
|
+
amount: bn17(fee),
|
4535
4637
|
assetId: BaseAssetId3,
|
4536
4638
|
coinQuantities
|
4537
4639
|
});
|
@@ -4539,7 +4641,7 @@ var Account = class extends AbstractAccount {
|
|
4539
4641
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4540
4642
|
quantitiesDict[assetId] = {
|
4541
4643
|
required: amount,
|
4542
|
-
owned:
|
4644
|
+
owned: bn17(0)
|
4543
4645
|
};
|
4544
4646
|
});
|
4545
4647
|
const cachedUtxos = [];
|
@@ -4552,7 +4654,7 @@ var Account = class extends AbstractAccount {
|
|
4552
4654
|
if (isCoin2) {
|
4553
4655
|
const assetId = String(input.assetId);
|
4554
4656
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4555
|
-
const amount =
|
4657
|
+
const amount = bn17(input.amount);
|
4556
4658
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4557
4659
|
cachedUtxos.push(input.id);
|
4558
4660
|
}
|
@@ -4598,8 +4700,8 @@ var Account = class extends AbstractAccount {
|
|
4598
4700
|
estimateTxDependencies: true,
|
4599
4701
|
resourcesOwner: this
|
4600
4702
|
});
|
4601
|
-
request.gasPrice =
|
4602
|
-
request.gasLimit =
|
4703
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4704
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4603
4705
|
this.validateGas({
|
4604
4706
|
gasUsed,
|
4605
4707
|
gasPrice: request.gasPrice,
|
@@ -4620,9 +4722,9 @@ var Account = class extends AbstractAccount {
|
|
4620
4722
|
* @returns A promise that resolves to the transaction response.
|
4621
4723
|
*/
|
4622
4724
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4623
|
-
if (
|
4624
|
-
throw new
|
4625
|
-
|
4725
|
+
if (bn17(amount).lte(0)) {
|
4726
|
+
throw new FuelError15(
|
4727
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4626
4728
|
"Transfer amount must be a positive number."
|
4627
4729
|
);
|
4628
4730
|
}
|
@@ -4639,9 +4741,9 @@ var Account = class extends AbstractAccount {
|
|
4639
4741
|
* @returns A promise that resolves to the transaction response.
|
4640
4742
|
*/
|
4641
4743
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4642
|
-
if (
|
4643
|
-
throw new
|
4644
|
-
|
4744
|
+
if (bn17(amount).lte(0)) {
|
4745
|
+
throw new FuelError15(
|
4746
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4645
4747
|
"Transfer amount must be a positive number."
|
4646
4748
|
);
|
4647
4749
|
}
|
@@ -4650,7 +4752,7 @@ var Account = class extends AbstractAccount {
|
|
4650
4752
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4651
4753
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4652
4754
|
hexlifiedContractId: contractAddress.toB256(),
|
4653
|
-
amountToTransfer:
|
4755
|
+
amountToTransfer: bn17(amount),
|
4654
4756
|
assetId
|
4655
4757
|
});
|
4656
4758
|
const request = new ScriptTransactionRequest({
|
@@ -4661,9 +4763,9 @@ var Account = class extends AbstractAccount {
|
|
4661
4763
|
request.addContractInputAndOutput(contractAddress);
|
4662
4764
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4663
4765
|
request,
|
4664
|
-
[{ amount:
|
4766
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4665
4767
|
);
|
4666
|
-
request.gasLimit =
|
4768
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4667
4769
|
this.validateGas({
|
4668
4770
|
gasUsed,
|
4669
4771
|
gasPrice: request.gasPrice,
|
@@ -4688,7 +4790,7 @@ var Account = class extends AbstractAccount {
|
|
4688
4790
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4689
4791
|
);
|
4690
4792
|
const amountDataArray = arrayify14(
|
4691
|
-
"0x".concat(
|
4793
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
4692
4794
|
);
|
4693
4795
|
const script = new Uint8Array([
|
4694
4796
|
...arrayify14(withdrawScript.bytes),
|
@@ -4697,12 +4799,12 @@ var Account = class extends AbstractAccount {
|
|
4697
4799
|
]);
|
4698
4800
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4699
4801
|
const request = new ScriptTransactionRequest(params);
|
4700
|
-
const forwardingQuantities = [{ amount:
|
4802
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4701
4803
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4702
4804
|
request,
|
4703
4805
|
forwardingQuantities
|
4704
4806
|
);
|
4705
|
-
request.gasLimit =
|
4807
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4706
4808
|
this.validateGas({
|
4707
4809
|
gasUsed,
|
4708
4810
|
gasPrice: request.gasPrice,
|
@@ -4714,7 +4816,7 @@ var Account = class extends AbstractAccount {
|
|
4714
4816
|
}
|
4715
4817
|
async signMessage(message) {
|
4716
4818
|
if (!this._connector) {
|
4717
|
-
throw new
|
4819
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4718
4820
|
}
|
4719
4821
|
return this._connector.signMessage(this.address.toString(), message);
|
4720
4822
|
}
|
@@ -4726,8 +4828,8 @@ var Account = class extends AbstractAccount {
|
|
4726
4828
|
*/
|
4727
4829
|
async signTransaction(transactionRequestLike) {
|
4728
4830
|
if (!this._connector) {
|
4729
|
-
throw new
|
4730
|
-
|
4831
|
+
throw new FuelError15(
|
4832
|
+
ErrorCode15.MISSING_CONNECTOR,
|
4731
4833
|
"A connector is required to sign transactions."
|
4732
4834
|
);
|
4733
4835
|
}
|
@@ -4774,14 +4876,14 @@ var Account = class extends AbstractAccount {
|
|
4774
4876
|
minGasPrice
|
4775
4877
|
}) {
|
4776
4878
|
if (minGasPrice.gt(gasPrice)) {
|
4777
|
-
throw new
|
4778
|
-
|
4879
|
+
throw new FuelError15(
|
4880
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4779
4881
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4780
4882
|
);
|
4781
4883
|
}
|
4782
4884
|
if (gasUsed.gt(gasLimit)) {
|
4783
|
-
throw new
|
4784
|
-
|
4885
|
+
throw new FuelError15(
|
4886
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
4785
4887
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4786
4888
|
);
|
4787
4889
|
}
|
@@ -4908,7 +5010,7 @@ import {
|
|
4908
5010
|
decryptJsonWalletData,
|
4909
5011
|
encryptJsonWalletData
|
4910
5012
|
} from "@fuel-ts/crypto";
|
4911
|
-
import { ErrorCode as
|
5013
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4912
5014
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4913
5015
|
import { v4 as uuidv4 } from "uuid";
|
4914
5016
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -4986,8 +5088,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4986
5088
|
const macHashUint8Array = keccak256(data);
|
4987
5089
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
4988
5090
|
if (mac !== macHash) {
|
4989
|
-
throw new
|
4990
|
-
|
5091
|
+
throw new FuelError16(
|
5092
|
+
ErrorCode16.INVALID_PASSWORD,
|
4991
5093
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
4992
5094
|
);
|
4993
5095
|
}
|
@@ -5109,15 +5211,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5109
5211
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5110
5212
|
|
5111
5213
|
// src/hdwallet/hdwallet.ts
|
5112
|
-
import { ErrorCode as
|
5214
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5113
5215
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5114
|
-
import { bn as
|
5216
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5115
5217
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5116
5218
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5117
5219
|
|
5118
5220
|
// src/mnemonic/mnemonic.ts
|
5119
5221
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5120
|
-
import { ErrorCode as
|
5222
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5121
5223
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5122
5224
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5123
5225
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7175,7 +7277,7 @@ var english = [
|
|
7175
7277
|
];
|
7176
7278
|
|
7177
7279
|
// src/mnemonic/utils.ts
|
7178
|
-
import { ErrorCode as
|
7280
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7179
7281
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7180
7282
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7181
7283
|
function toUtf8Bytes(stri) {
|
@@ -7192,8 +7294,8 @@ function toUtf8Bytes(stri) {
|
|
7192
7294
|
i += 1;
|
7193
7295
|
const c2 = str.charCodeAt(i);
|
7194
7296
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7195
|
-
throw new
|
7196
|
-
|
7297
|
+
throw new FuelError17(
|
7298
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7197
7299
|
"Invalid UTF-8 in the input string."
|
7198
7300
|
);
|
7199
7301
|
}
|
@@ -7256,8 +7358,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7256
7358
|
for (let i = 0; i < words.length; i += 1) {
|
7257
7359
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7258
7360
|
if (index === -1) {
|
7259
|
-
throw new
|
7260
|
-
|
7361
|
+
throw new FuelError17(
|
7362
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7261
7363
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7262
7364
|
);
|
7263
7365
|
}
|
@@ -7273,8 +7375,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7273
7375
|
const checksumMask = getUpperMask(checksumBits);
|
7274
7376
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7275
7377
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7276
|
-
throw new
|
7277
|
-
|
7378
|
+
throw new FuelError17(
|
7379
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7278
7380
|
"Checksum validation failed for the provided mnemonic."
|
7279
7381
|
);
|
7280
7382
|
}
|
@@ -7288,16 +7390,16 @@ var TestnetPRV = "0x04358394";
|
|
7288
7390
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7289
7391
|
function assertWordList(wordlist) {
|
7290
7392
|
if (wordlist.length !== 2048) {
|
7291
|
-
throw new
|
7292
|
-
|
7393
|
+
throw new FuelError18(
|
7394
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7293
7395
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7294
7396
|
);
|
7295
7397
|
}
|
7296
7398
|
}
|
7297
7399
|
function assertEntropy(entropy) {
|
7298
7400
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7299
|
-
throw new
|
7300
|
-
|
7401
|
+
throw new FuelError18(
|
7402
|
+
ErrorCode18.INVALID_ENTROPY,
|
7301
7403
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7302
7404
|
);
|
7303
7405
|
}
|
@@ -7307,7 +7409,7 @@ function assertMnemonic(words) {
|
|
7307
7409
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7308
7410
|
", "
|
7309
7411
|
)}] words, but got ${words.length}.`;
|
7310
|
-
throw new
|
7412
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7311
7413
|
}
|
7312
7414
|
}
|
7313
7415
|
var Mnemonic = class {
|
@@ -7425,8 +7527,8 @@ var Mnemonic = class {
|
|
7425
7527
|
static masterKeysFromSeed(seed) {
|
7426
7528
|
const seedArray = arrayify17(seed);
|
7427
7529
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7428
|
-
throw new
|
7429
|
-
|
7530
|
+
throw new FuelError18(
|
7531
|
+
ErrorCode18.INVALID_SEED,
|
7430
7532
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7431
7533
|
);
|
7432
7534
|
}
|
@@ -7503,7 +7605,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7503
7605
|
function parsePath(path2, depth = 0) {
|
7504
7606
|
const components = path2.split("/");
|
7505
7607
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7506
|
-
throw new
|
7608
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7507
7609
|
}
|
7508
7610
|
if (components[0] === "m") {
|
7509
7611
|
components.shift();
|
@@ -7532,8 +7634,8 @@ var HDWallet = class {
|
|
7532
7634
|
this.privateKey = hexlify17(config.privateKey);
|
7533
7635
|
} else {
|
7534
7636
|
if (!config.publicKey) {
|
7535
|
-
throw new
|
7536
|
-
|
7637
|
+
throw new FuelError19(
|
7638
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7537
7639
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7538
7640
|
);
|
7539
7641
|
}
|
@@ -7562,8 +7664,8 @@ var HDWallet = class {
|
|
7562
7664
|
const data = new Uint8Array(37);
|
7563
7665
|
if (index & HARDENED_INDEX) {
|
7564
7666
|
if (!privateKey) {
|
7565
|
-
throw new
|
7566
|
-
|
7667
|
+
throw new FuelError19(
|
7668
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7567
7669
|
"Cannot derive a hardened index without a private Key."
|
7568
7670
|
);
|
7569
7671
|
}
|
@@ -7577,7 +7679,7 @@ var HDWallet = class {
|
|
7577
7679
|
const IR = bytes.slice(32);
|
7578
7680
|
if (privateKey) {
|
7579
7681
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7580
|
-
const ki =
|
7682
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7581
7683
|
return new HDWallet({
|
7582
7684
|
privateKey: ki,
|
7583
7685
|
chainCode: IR,
|
@@ -7615,8 +7717,8 @@ var HDWallet = class {
|
|
7615
7717
|
*/
|
7616
7718
|
toExtendedKey(isPublic = false, testnet = false) {
|
7617
7719
|
if (this.depth >= 256) {
|
7618
|
-
throw new
|
7619
|
-
|
7720
|
+
throw new FuelError19(
|
7721
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7620
7722
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7621
7723
|
);
|
7622
7724
|
}
|
@@ -7647,10 +7749,10 @@ var HDWallet = class {
|
|
7647
7749
|
const bytes = arrayify18(decoded);
|
7648
7750
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7649
7751
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7650
|
-
throw new
|
7752
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7651
7753
|
}
|
7652
7754
|
if (!validChecksum) {
|
7653
|
-
throw new
|
7755
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7654
7756
|
}
|
7655
7757
|
const depth = bytes[4];
|
7656
7758
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7658,14 +7760,14 @@ var HDWallet = class {
|
|
7658
7760
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7659
7761
|
const key = bytes.slice(45, 78);
|
7660
7762
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7661
|
-
throw new
|
7662
|
-
|
7763
|
+
throw new FuelError19(
|
7764
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7663
7765
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7664
7766
|
);
|
7665
7767
|
}
|
7666
7768
|
if (isPublicExtendedKey(bytes)) {
|
7667
7769
|
if (key[0] !== 3) {
|
7668
|
-
throw new
|
7770
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
7669
7771
|
}
|
7670
7772
|
return new HDWallet({
|
7671
7773
|
publicKey: key,
|
@@ -7676,7 +7778,7 @@ var HDWallet = class {
|
|
7676
7778
|
});
|
7677
7779
|
}
|
7678
7780
|
if (key[0] !== 0) {
|
7679
|
-
throw new
|
7781
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
7680
7782
|
}
|
7681
7783
|
return new HDWallet({
|
7682
7784
|
privateKey: key.slice(1),
|