@fuel-ts/account 0.0.0-rc-1976-20240403225009 → 0.0.0-rc-1895-20240404023124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +171 -63
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +578 -513
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +356 -286
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +0 -7
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +172 -65
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +537 -479
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +326 -260
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -58,16 +58,18 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
-
var
|
65
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
66
|
+
var import_errors16 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
|
-
var
|
68
|
-
var
|
68
|
+
var import_math18 = require("@fuel-ts/math");
|
69
|
+
var import_utils28 = require("@fuel-ts/utils");
|
69
70
|
|
70
71
|
// src/providers/coin-quantity.ts
|
72
|
+
var import_configs = require("@fuel-ts/address/configs");
|
71
73
|
var import_math = require("@fuel-ts/math");
|
72
74
|
var import_utils = require("@fuel-ts/utils");
|
73
75
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -76,11 +78,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
76
78
|
let max2;
|
77
79
|
if (Array.isArray(coinQuantityLike)) {
|
78
80
|
amount = coinQuantityLike[0];
|
79
|
-
assetId = coinQuantityLike[1];
|
80
|
-
max2 = coinQuantityLike[2];
|
81
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
82
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
81
83
|
} else {
|
82
84
|
amount = coinQuantityLike.amount;
|
83
|
-
assetId = coinQuantityLike.assetId;
|
85
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
84
86
|
max2 = coinQuantityLike.max ?? void 0;
|
85
87
|
}
|
86
88
|
const bnAmount = (0, import_math.bn)(amount);
|
@@ -104,12 +106,12 @@ var addAmountToAsset = (params) => {
|
|
104
106
|
|
105
107
|
// src/providers/provider.ts
|
106
108
|
var import_address3 = require("@fuel-ts/address");
|
107
|
-
var
|
108
|
-
var
|
109
|
-
var
|
110
|
-
var
|
109
|
+
var import_errors14 = require("@fuel-ts/errors");
|
110
|
+
var import_math15 = require("@fuel-ts/math");
|
111
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
112
|
+
var import_utils23 = require("@fuel-ts/utils");
|
111
113
|
var import_versions = require("@fuel-ts/versions");
|
112
|
-
var
|
114
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
113
115
|
var import_ethers = require("ethers");
|
114
116
|
var import_graphql_request = require("graphql-request");
|
115
117
|
var import_ramda3 = require("ramda");
|
@@ -1049,7 +1051,7 @@ var MemoryCache = class {
|
|
1049
1051
|
};
|
1050
1052
|
|
1051
1053
|
// src/providers/transaction-request/input.ts
|
1052
|
-
var
|
1054
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1053
1055
|
var import_errors3 = require("@fuel-ts/errors");
|
1054
1056
|
var import_math2 = require("@fuel-ts/math");
|
1055
1057
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1083,10 +1085,10 @@ var inputify = (value) => {
|
|
1083
1085
|
case import_transactions.InputType.Contract: {
|
1084
1086
|
return {
|
1085
1087
|
type: import_transactions.InputType.Contract,
|
1086
|
-
txID:
|
1088
|
+
txID: import_configs2.ZeroBytes32,
|
1087
1089
|
outputIndex: 0,
|
1088
|
-
balanceRoot:
|
1089
|
-
stateRoot:
|
1090
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1091
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1090
1092
|
txPointer: {
|
1091
1093
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1092
1094
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1124,7 +1126,7 @@ var inputify = (value) => {
|
|
1124
1126
|
};
|
1125
1127
|
|
1126
1128
|
// src/providers/transaction-request/output.ts
|
1127
|
-
var
|
1129
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1128
1130
|
var import_errors4 = require("@fuel-ts/errors");
|
1129
1131
|
var import_math3 = require("@fuel-ts/math");
|
1130
1132
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1144,8 +1146,8 @@ var outputify = (value) => {
|
|
1144
1146
|
return {
|
1145
1147
|
type: import_transactions2.OutputType.Contract,
|
1146
1148
|
inputIndex: value.inputIndex,
|
1147
|
-
balanceRoot:
|
1148
|
-
stateRoot:
|
1149
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1150
|
+
stateRoot: import_configs3.ZeroBytes32
|
1149
1151
|
};
|
1150
1152
|
}
|
1151
1153
|
case import_transactions2.OutputType.Change: {
|
@@ -1159,9 +1161,9 @@ var outputify = (value) => {
|
|
1159
1161
|
case import_transactions2.OutputType.Variable: {
|
1160
1162
|
return {
|
1161
1163
|
type: import_transactions2.OutputType.Variable,
|
1162
|
-
to:
|
1164
|
+
to: import_configs3.ZeroBytes32,
|
1163
1165
|
amount: (0, import_math3.bn)(0),
|
1164
|
-
assetId:
|
1166
|
+
assetId: import_configs3.ZeroBytes32
|
1165
1167
|
};
|
1166
1168
|
}
|
1167
1169
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1182,22 +1184,22 @@ var outputify = (value) => {
|
|
1182
1184
|
|
1183
1185
|
// src/providers/transaction-request/transaction-request.ts
|
1184
1186
|
var import_address = require("@fuel-ts/address");
|
1185
|
-
var
|
1186
|
-
var
|
1187
|
-
var
|
1187
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1188
|
+
var import_math7 = require("@fuel-ts/math");
|
1189
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1190
|
var import_utils9 = require("@fuel-ts/utils");
|
1189
1191
|
|
1190
1192
|
// src/providers/resource.ts
|
1191
1193
|
var isCoin = (resource) => "id" in resource;
|
1192
1194
|
|
1193
1195
|
// src/providers/utils/receipts.ts
|
1194
|
-
var
|
1196
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1195
1197
|
var import_errors5 = require("@fuel-ts/errors");
|
1196
1198
|
var import_math4 = require("@fuel-ts/math");
|
1197
1199
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1198
|
-
var
|
1200
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1199
1201
|
var import_utils5 = require("@fuel-ts/utils");
|
1200
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1202
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1201
1203
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1202
1204
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1203
1205
|
(memo, receipt) => {
|
@@ -1214,7 +1216,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1214
1216
|
missingOutputContractIds: []
|
1215
1217
|
}
|
1216
1218
|
);
|
1217
|
-
var hexOrZero = (hex) => hex ||
|
1219
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1218
1220
|
function assembleReceiptByType(receipt) {
|
1219
1221
|
const { receiptType } = receipt;
|
1220
1222
|
switch (receiptType) {
|
@@ -1515,6 +1517,78 @@ function sleep(time) {
|
|
1515
1517
|
});
|
1516
1518
|
}
|
1517
1519
|
|
1520
|
+
// src/providers/utils/extract-tx-error.ts
|
1521
|
+
var import_errors7 = require("@fuel-ts/errors");
|
1522
|
+
var import_math6 = require("@fuel-ts/math");
|
1523
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1524
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1525
|
+
var assemblePanicError = (status) => {
|
1526
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1527
|
+
const reason = status.reason;
|
1528
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1529
|
+
errorMessage = `${errorMessage}
|
1530
|
+
|
1531
|
+
You can read more about this error at:
|
1532
|
+
|
1533
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1534
|
+
}
|
1535
|
+
return { errorMessage, reason };
|
1536
|
+
};
|
1537
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1538
|
+
var assembleRevertError = (receipts, logs) => {
|
1539
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1540
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1541
|
+
let reason = "";
|
1542
|
+
if (revertReceipt) {
|
1543
|
+
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1544
|
+
switch (reasonHex) {
|
1545
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1546
|
+
reason = "require";
|
1547
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1548
|
+
break;
|
1549
|
+
}
|
1550
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1551
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1552
|
+
reason = "assert_eq";
|
1553
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1554
|
+
break;
|
1555
|
+
}
|
1556
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1557
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1558
|
+
reason = "assert_ne";
|
1559
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1560
|
+
break;
|
1561
|
+
}
|
1562
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1563
|
+
reason = "assert";
|
1564
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1565
|
+
break;
|
1566
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1567
|
+
reason = "MissingOutputChange";
|
1568
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1569
|
+
break;
|
1570
|
+
default:
|
1571
|
+
reason = "unknown";
|
1572
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
return { errorMessage, reason };
|
1576
|
+
};
|
1577
|
+
var extractTxError = (params) => {
|
1578
|
+
const { receipts, status, logs } = params;
|
1579
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1580
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1581
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1582
|
+
const metadata = {
|
1583
|
+
logs,
|
1584
|
+
receipts,
|
1585
|
+
panic: isPanic,
|
1586
|
+
revert: isRevert,
|
1587
|
+
reason
|
1588
|
+
};
|
1589
|
+
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1590
|
+
};
|
1591
|
+
|
1518
1592
|
// src/providers/transaction-request/errors.ts
|
1519
1593
|
var NoWitnessAtIndexError = class extends Error {
|
1520
1594
|
constructor(index) {
|
@@ -1551,8 +1625,6 @@ var BaseTransactionRequest = class {
|
|
1551
1625
|
outputs = [];
|
1552
1626
|
/** List of witnesses */
|
1553
1627
|
witnesses = [];
|
1554
|
-
/** Base asset ID - should be fetched from the chain */
|
1555
|
-
baseAssetId = import_configs5.ZeroBytes32;
|
1556
1628
|
/**
|
1557
1629
|
* Constructor for initializing a base transaction request.
|
1558
1630
|
*
|
@@ -1565,36 +1637,34 @@ var BaseTransactionRequest = class {
|
|
1565
1637
|
witnessLimit,
|
1566
1638
|
inputs,
|
1567
1639
|
outputs,
|
1568
|
-
witnesses
|
1569
|
-
baseAssetId
|
1640
|
+
witnesses
|
1570
1641
|
} = {}) {
|
1571
|
-
this.gasPrice = (0,
|
1642
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1572
1643
|
this.maturity = maturity ?? 0;
|
1573
|
-
this.witnessLimit = witnessLimit ? (0,
|
1574
|
-
this.maxFee = maxFee ? (0,
|
1644
|
+
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1645
|
+
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1575
1646
|
this.inputs = inputs ?? [];
|
1576
1647
|
this.outputs = outputs ?? [];
|
1577
1648
|
this.witnesses = witnesses ?? [];
|
1578
|
-
this.baseAssetId = baseAssetId ?? import_configs5.ZeroBytes32;
|
1579
1649
|
}
|
1580
1650
|
static getPolicyMeta(req) {
|
1581
1651
|
let policyTypes = 0;
|
1582
1652
|
const policies = [];
|
1583
1653
|
if (req.gasPrice) {
|
1584
|
-
policyTypes +=
|
1585
|
-
policies.push({ data: req.gasPrice, type:
|
1654
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1655
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1586
1656
|
}
|
1587
1657
|
if (req.witnessLimit) {
|
1588
|
-
policyTypes +=
|
1589
|
-
policies.push({ data: req.witnessLimit, type:
|
1658
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1659
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1590
1660
|
}
|
1591
1661
|
if (req.maturity > 0) {
|
1592
|
-
policyTypes +=
|
1593
|
-
policies.push({ data: req.maturity, type:
|
1662
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1663
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1594
1664
|
}
|
1595
1665
|
if (req.maxFee) {
|
1596
|
-
policyTypes +=
|
1597
|
-
policies.push({ data: req.maxFee, type:
|
1666
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1667
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1598
1668
|
}
|
1599
1669
|
return {
|
1600
1670
|
policyTypes,
|
@@ -1628,7 +1698,7 @@ var BaseTransactionRequest = class {
|
|
1628
1698
|
* @returns The transaction bytes.
|
1629
1699
|
*/
|
1630
1700
|
toTransactionBytes() {
|
1631
|
-
return new
|
1701
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1632
1702
|
}
|
1633
1703
|
/**
|
1634
1704
|
* @hidden
|
@@ -1668,7 +1738,7 @@ var BaseTransactionRequest = class {
|
|
1668
1738
|
* @returns The index of the created witness.
|
1669
1739
|
*/
|
1670
1740
|
addEmptyWitness() {
|
1671
|
-
this.addWitness((0, import_utils9.concat)([
|
1741
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1672
1742
|
return this.witnesses.length - 1;
|
1673
1743
|
}
|
1674
1744
|
/**
|
@@ -1719,7 +1789,7 @@ var BaseTransactionRequest = class {
|
|
1719
1789
|
*/
|
1720
1790
|
getCoinInputs() {
|
1721
1791
|
return this.inputs.filter(
|
1722
|
-
(input) => input.type ===
|
1792
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1723
1793
|
);
|
1724
1794
|
}
|
1725
1795
|
/**
|
@@ -1729,7 +1799,7 @@ var BaseTransactionRequest = class {
|
|
1729
1799
|
*/
|
1730
1800
|
getCoinOutputs() {
|
1731
1801
|
return this.outputs.filter(
|
1732
|
-
(output) => output.type ===
|
1802
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1733
1803
|
);
|
1734
1804
|
}
|
1735
1805
|
/**
|
@@ -1739,7 +1809,7 @@ var BaseTransactionRequest = class {
|
|
1739
1809
|
*/
|
1740
1810
|
getChangeOutputs() {
|
1741
1811
|
return this.outputs.filter(
|
1742
|
-
(output) => output.type ===
|
1812
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1743
1813
|
);
|
1744
1814
|
}
|
1745
1815
|
/**
|
@@ -1751,9 +1821,9 @@ var BaseTransactionRequest = class {
|
|
1751
1821
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1752
1822
|
const found = this.inputs.find((input) => {
|
1753
1823
|
switch (input.type) {
|
1754
|
-
case
|
1824
|
+
case import_transactions6.InputType.Coin:
|
1755
1825
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1756
|
-
case
|
1826
|
+
case import_transactions6.InputType.Message:
|
1757
1827
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1758
1828
|
default:
|
1759
1829
|
return false;
|
@@ -1782,7 +1852,7 @@ var BaseTransactionRequest = class {
|
|
1782
1852
|
}
|
1783
1853
|
const input = {
|
1784
1854
|
...coin,
|
1785
|
-
type:
|
1855
|
+
type: import_transactions6.InputType.Coin,
|
1786
1856
|
owner: owner.toB256(),
|
1787
1857
|
amount,
|
1788
1858
|
assetId,
|
@@ -1800,9 +1870,11 @@ var BaseTransactionRequest = class {
|
|
1800
1870
|
*
|
1801
1871
|
* @param message - Message resource.
|
1802
1872
|
* @param predicate - Predicate bytes.
|
1873
|
+
* @param predicateData - Predicate data bytes.
|
1803
1874
|
*/
|
1804
1875
|
addMessageInput(message, predicate) {
|
1805
1876
|
const { recipient, sender, amount } = message;
|
1877
|
+
const assetId = import_configs7.BaseAssetId;
|
1806
1878
|
let witnessIndex;
|
1807
1879
|
if (predicate) {
|
1808
1880
|
witnessIndex = 0;
|
@@ -1814,7 +1886,7 @@ var BaseTransactionRequest = class {
|
|
1814
1886
|
}
|
1815
1887
|
const input = {
|
1816
1888
|
...message,
|
1817
|
-
type:
|
1889
|
+
type: import_transactions6.InputType.Message,
|
1818
1890
|
sender: sender.toB256(),
|
1819
1891
|
recipient: recipient.toB256(),
|
1820
1892
|
amount,
|
@@ -1823,7 +1895,7 @@ var BaseTransactionRequest = class {
|
|
1823
1895
|
predicateData: predicate?.predicateDataBytes
|
1824
1896
|
};
|
1825
1897
|
this.pushInput(input);
|
1826
|
-
this.addChangeOutput(recipient,
|
1898
|
+
this.addChangeOutput(recipient, assetId);
|
1827
1899
|
}
|
1828
1900
|
/**
|
1829
1901
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1884,12 +1956,12 @@ var BaseTransactionRequest = class {
|
|
1884
1956
|
* @param amount - Amount of coin.
|
1885
1957
|
* @param assetId - Asset ID of coin.
|
1886
1958
|
*/
|
1887
|
-
addCoinOutput(to, amount, assetId) {
|
1959
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1888
1960
|
this.pushOutput({
|
1889
|
-
type:
|
1961
|
+
type: import_transactions6.OutputType.Coin,
|
1890
1962
|
to: (0, import_address.addressify)(to).toB256(),
|
1891
1963
|
amount,
|
1892
|
-
assetId
|
1964
|
+
assetId
|
1893
1965
|
});
|
1894
1966
|
return this;
|
1895
1967
|
}
|
@@ -1902,7 +1974,7 @@ var BaseTransactionRequest = class {
|
|
1902
1974
|
addCoinOutputs(to, quantities) {
|
1903
1975
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
1904
1976
|
this.pushOutput({
|
1905
|
-
type:
|
1977
|
+
type: import_transactions6.OutputType.Coin,
|
1906
1978
|
to: (0, import_address.addressify)(to).toB256(),
|
1907
1979
|
amount: quantity.amount,
|
1908
1980
|
assetId: quantity.assetId
|
@@ -1916,15 +1988,15 @@ var BaseTransactionRequest = class {
|
|
1916
1988
|
* @param to - Address of the owner.
|
1917
1989
|
* @param assetId - Asset ID of coin.
|
1918
1990
|
*/
|
1919
|
-
addChangeOutput(to, assetId) {
|
1991
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1920
1992
|
const changeOutput = this.getChangeOutputs().find(
|
1921
1993
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1922
1994
|
);
|
1923
1995
|
if (!changeOutput) {
|
1924
1996
|
this.pushOutput({
|
1925
|
-
type:
|
1997
|
+
type: import_transactions6.OutputType.Change,
|
1926
1998
|
to: (0, import_address.addressify)(to).toB256(),
|
1927
|
-
assetId
|
1999
|
+
assetId
|
1928
2000
|
});
|
1929
2001
|
}
|
1930
2002
|
}
|
@@ -1978,7 +2050,7 @@ var BaseTransactionRequest = class {
|
|
1978
2050
|
let idCounter = 0;
|
1979
2051
|
const generateId = () => {
|
1980
2052
|
const counterString = String(idCounter++);
|
1981
|
-
const id =
|
2053
|
+
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
1982
2054
|
return id;
|
1983
2055
|
};
|
1984
2056
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2000,13 +2072,13 @@ var BaseTransactionRequest = class {
|
|
2000
2072
|
assetId,
|
2001
2073
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2002
2074
|
maturity: 0,
|
2003
|
-
blockCreated: (0,
|
2004
|
-
txCreatedIdx: (0,
|
2075
|
+
blockCreated: (0, import_math7.bn)(1),
|
2076
|
+
txCreatedIdx: (0, import_math7.bn)(1)
|
2005
2077
|
}
|
2006
2078
|
]);
|
2007
2079
|
}
|
2008
2080
|
};
|
2009
|
-
updateAssetInput(
|
2081
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2010
2082
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2011
2083
|
}
|
2012
2084
|
/**
|
@@ -2017,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
2017
2089
|
*/
|
2018
2090
|
getCoinOutputsQuantities() {
|
2019
2091
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2020
|
-
amount: (0,
|
2092
|
+
amount: (0, import_math7.bn)(amount),
|
2021
2093
|
assetId: assetId.toString()
|
2022
2094
|
}));
|
2023
2095
|
return coinsQuantities;
|
@@ -2035,18 +2107,18 @@ var BaseTransactionRequest = class {
|
|
2035
2107
|
this.inputs.forEach((i) => {
|
2036
2108
|
let correspondingInput;
|
2037
2109
|
switch (i.type) {
|
2038
|
-
case
|
2039
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2110
|
+
case import_transactions6.InputType.Coin:
|
2111
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2040
2112
|
break;
|
2041
|
-
case
|
2113
|
+
case import_transactions6.InputType.Message:
|
2042
2114
|
correspondingInput = inputs.find(
|
2043
|
-
(x) => x.type ===
|
2115
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2044
2116
|
);
|
2045
2117
|
break;
|
2046
2118
|
default:
|
2047
2119
|
return;
|
2048
2120
|
}
|
2049
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2121
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2050
2122
|
i.predicate = correspondingInput.predicate;
|
2051
2123
|
i.predicateData = correspondingInput.predicateData;
|
2052
2124
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2056,47 +2128,47 @@ var BaseTransactionRequest = class {
|
|
2056
2128
|
};
|
2057
2129
|
|
2058
2130
|
// src/providers/transaction-request/create-transaction-request.ts
|
2059
|
-
var
|
2060
|
-
var
|
2061
|
-
var
|
2131
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2132
|
+
var import_math9 = require("@fuel-ts/math");
|
2133
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2062
2134
|
var import_utils13 = require("@fuel-ts/utils");
|
2063
2135
|
|
2064
2136
|
// src/providers/transaction-request/hash-transaction.ts
|
2065
|
-
var
|
2137
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2066
2138
|
var import_hasher = require("@fuel-ts/hasher");
|
2067
|
-
var
|
2068
|
-
var
|
2139
|
+
var import_math8 = require("@fuel-ts/math");
|
2140
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2069
2141
|
var import_utils11 = require("@fuel-ts/utils");
|
2070
2142
|
var import_ramda2 = require("ramda");
|
2071
2143
|
function hashTransaction(transactionRequest, chainId) {
|
2072
2144
|
const transaction = transactionRequest.toTransaction();
|
2073
|
-
if (transaction.type ===
|
2074
|
-
transaction.receiptsRoot =
|
2145
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2146
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2075
2147
|
}
|
2076
2148
|
transaction.inputs = transaction.inputs.map((input) => {
|
2077
2149
|
const inputClone = (0, import_ramda2.clone)(input);
|
2078
2150
|
switch (inputClone.type) {
|
2079
|
-
case
|
2151
|
+
case import_transactions7.InputType.Coin: {
|
2080
2152
|
inputClone.txPointer = {
|
2081
2153
|
blockHeight: 0,
|
2082
2154
|
txIndex: 0
|
2083
2155
|
};
|
2084
|
-
inputClone.predicateGasUsed = (0,
|
2156
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2085
2157
|
return inputClone;
|
2086
2158
|
}
|
2087
|
-
case
|
2088
|
-
inputClone.predicateGasUsed = (0,
|
2159
|
+
case import_transactions7.InputType.Message: {
|
2160
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2089
2161
|
return inputClone;
|
2090
2162
|
}
|
2091
|
-
case
|
2163
|
+
case import_transactions7.InputType.Contract: {
|
2092
2164
|
inputClone.txPointer = {
|
2093
2165
|
blockHeight: 0,
|
2094
2166
|
txIndex: 0
|
2095
2167
|
};
|
2096
|
-
inputClone.txID =
|
2168
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2097
2169
|
inputClone.outputIndex = 0;
|
2098
|
-
inputClone.balanceRoot =
|
2099
|
-
inputClone.stateRoot =
|
2170
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2171
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2100
2172
|
return inputClone;
|
2101
2173
|
}
|
2102
2174
|
default:
|
@@ -2106,19 +2178,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2106
2178
|
transaction.outputs = transaction.outputs.map((output) => {
|
2107
2179
|
const outputClone = (0, import_ramda2.clone)(output);
|
2108
2180
|
switch (outputClone.type) {
|
2109
|
-
case
|
2110
|
-
outputClone.balanceRoot =
|
2111
|
-
outputClone.stateRoot =
|
2181
|
+
case import_transactions7.OutputType.Contract: {
|
2182
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2183
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2112
2184
|
return outputClone;
|
2113
2185
|
}
|
2114
|
-
case
|
2115
|
-
outputClone.amount = (0,
|
2186
|
+
case import_transactions7.OutputType.Change: {
|
2187
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2116
2188
|
return outputClone;
|
2117
2189
|
}
|
2118
|
-
case
|
2119
|
-
outputClone.to =
|
2120
|
-
outputClone.amount = (0,
|
2121
|
-
outputClone.assetId =
|
2190
|
+
case import_transactions7.OutputType.Variable: {
|
2191
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2192
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2193
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2122
2194
|
return outputClone;
|
2123
2195
|
}
|
2124
2196
|
default:
|
@@ -2128,7 +2200,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2128
2200
|
transaction.witnessesCount = 0;
|
2129
2201
|
transaction.witnesses = [];
|
2130
2202
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2131
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2203
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2132
2204
|
return (0, import_hasher.sha256)(concatenatedData);
|
2133
2205
|
}
|
2134
2206
|
|
@@ -2164,7 +2236,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2164
2236
|
return new this(obj);
|
2165
2237
|
}
|
2166
2238
|
/** Type of the transaction */
|
2167
|
-
type =
|
2239
|
+
type = import_transactions8.TransactionType.Create;
|
2168
2240
|
/** Witness index of contract bytecode to create */
|
2169
2241
|
bytecodeWitnessIndex;
|
2170
2242
|
/** Salt */
|
@@ -2184,7 +2256,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2184
2256
|
} = {}) {
|
2185
2257
|
super(rest);
|
2186
2258
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2187
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2259
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2188
2260
|
this.storageSlots = [...storageSlots ?? []];
|
2189
2261
|
}
|
2190
2262
|
/**
|
@@ -2197,12 +2269,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2197
2269
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2198
2270
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2199
2271
|
return {
|
2200
|
-
type:
|
2272
|
+
type: import_transactions8.TransactionType.Create,
|
2201
2273
|
...baseTransaction,
|
2202
2274
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2203
2275
|
bytecodeWitnessIndex,
|
2204
2276
|
storageSlotsCount: storageSlots.length,
|
2205
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2277
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2206
2278
|
storageSlots
|
2207
2279
|
};
|
2208
2280
|
}
|
@@ -2213,7 +2285,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2213
2285
|
*/
|
2214
2286
|
getContractCreatedOutputs() {
|
2215
2287
|
return this.outputs.filter(
|
2216
|
-
(output) => output.type ===
|
2288
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2217
2289
|
);
|
2218
2290
|
}
|
2219
2291
|
/**
|
@@ -2234,14 +2306,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2234
2306
|
*/
|
2235
2307
|
addContractCreatedOutput(contractId, stateRoot) {
|
2236
2308
|
this.pushOutput({
|
2237
|
-
type:
|
2309
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2238
2310
|
contractId,
|
2239
2311
|
stateRoot
|
2240
2312
|
});
|
2241
2313
|
}
|
2242
2314
|
metadataGas(gasCosts) {
|
2243
2315
|
return calculateMetadataGasForTxCreate({
|
2244
|
-
contractBytesSize: (0,
|
2316
|
+
contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2245
2317
|
gasCosts,
|
2246
2318
|
stateRootSize: this.storageSlots.length,
|
2247
2319
|
txBytesSize: this.byteSize()
|
@@ -2252,9 +2324,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2252
2324
|
// src/providers/transaction-request/script-transaction-request.ts
|
2253
2325
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2254
2326
|
var import_address2 = require("@fuel-ts/address");
|
2255
|
-
var
|
2256
|
-
var
|
2257
|
-
var
|
2327
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2328
|
+
var import_math10 = require("@fuel-ts/math");
|
2329
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2258
2330
|
var import_utils15 = require("@fuel-ts/utils");
|
2259
2331
|
|
2260
2332
|
// src/providers/transaction-request/scripts.ts
|
@@ -2292,7 +2364,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2292
2364
|
return new this(obj);
|
2293
2365
|
}
|
2294
2366
|
/** Type of the transaction */
|
2295
|
-
type =
|
2367
|
+
type = import_transactions9.TransactionType.Script;
|
2296
2368
|
/** Gas limit for transaction */
|
2297
2369
|
gasLimit;
|
2298
2370
|
/** Script to execute */
|
@@ -2307,7 +2379,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2307
2379
|
*/
|
2308
2380
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2309
2381
|
super(rest);
|
2310
|
-
this.gasLimit = (0,
|
2382
|
+
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2311
2383
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2312
2384
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2313
2385
|
this.abis = rest.abis;
|
@@ -2321,12 +2393,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2321
2393
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2322
2394
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2323
2395
|
return {
|
2324
|
-
type:
|
2396
|
+
type: import_transactions9.TransactionType.Script,
|
2325
2397
|
scriptGasLimit: this.gasLimit,
|
2326
2398
|
...super.getBaseTransaction(),
|
2327
2399
|
scriptLength: script.length,
|
2328
2400
|
scriptDataLength: scriptData.length,
|
2329
|
-
receiptsRoot:
|
2401
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2330
2402
|
script: (0, import_utils15.hexlify)(script),
|
2331
2403
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2332
2404
|
};
|
@@ -2338,7 +2410,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2338
2410
|
*/
|
2339
2411
|
getContractInputs() {
|
2340
2412
|
return this.inputs.filter(
|
2341
|
-
(input) => input.type ===
|
2413
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2342
2414
|
);
|
2343
2415
|
}
|
2344
2416
|
/**
|
@@ -2348,7 +2420,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2348
2420
|
*/
|
2349
2421
|
getContractOutputs() {
|
2350
2422
|
return this.outputs.filter(
|
2351
|
-
(output) => output.type ===
|
2423
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2352
2424
|
);
|
2353
2425
|
}
|
2354
2426
|
/**
|
@@ -2358,7 +2430,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2358
2430
|
*/
|
2359
2431
|
getVariableOutputs() {
|
2360
2432
|
return this.outputs.filter(
|
2361
|
-
(output) => output.type ===
|
2433
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2362
2434
|
);
|
2363
2435
|
}
|
2364
2436
|
/**
|
@@ -2381,7 +2453,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2453
|
let outputsNumber = numberOfVariables;
|
2382
2454
|
while (outputsNumber) {
|
2383
2455
|
this.pushOutput({
|
2384
|
-
type:
|
2456
|
+
type: import_transactions9.OutputType.Variable
|
2385
2457
|
});
|
2386
2458
|
outputsNumber -= 1;
|
2387
2459
|
}
|
@@ -2414,12 +2486,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2414
2486
|
return this;
|
2415
2487
|
}
|
2416
2488
|
const inputIndex = super.pushInput({
|
2417
|
-
type:
|
2489
|
+
type: import_transactions9.InputType.Contract,
|
2418
2490
|
contractId: contractAddress.toB256(),
|
2419
2491
|
txPointer: "0x00000000000000000000000000000000"
|
2420
2492
|
});
|
2421
2493
|
this.pushOutput({
|
2422
|
-
type:
|
2494
|
+
type: import_transactions9.OutputType.Contract,
|
2423
2495
|
inputIndex
|
2424
2496
|
});
|
2425
2497
|
return this;
|
@@ -2455,38 +2527,38 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2455
2527
|
};
|
2456
2528
|
|
2457
2529
|
// src/providers/transaction-request/utils.ts
|
2458
|
-
var
|
2459
|
-
var
|
2530
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2531
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2460
2532
|
var transactionRequestify = (obj) => {
|
2461
2533
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2462
2534
|
return obj;
|
2463
2535
|
}
|
2464
2536
|
const { type } = obj;
|
2465
2537
|
switch (obj.type) {
|
2466
|
-
case
|
2538
|
+
case import_transactions10.TransactionType.Script: {
|
2467
2539
|
return ScriptTransactionRequest.from(obj);
|
2468
2540
|
}
|
2469
|
-
case
|
2541
|
+
case import_transactions10.TransactionType.Create: {
|
2470
2542
|
return CreateTransactionRequest.from(obj);
|
2471
2543
|
}
|
2472
2544
|
default: {
|
2473
|
-
throw new
|
2545
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2474
2546
|
}
|
2475
2547
|
}
|
2476
2548
|
};
|
2477
2549
|
|
2478
2550
|
// src/providers/transaction-response/transaction-response.ts
|
2479
|
-
var
|
2480
|
-
var
|
2481
|
-
var
|
2551
|
+
var import_errors13 = require("@fuel-ts/errors");
|
2552
|
+
var import_math14 = require("@fuel-ts/math");
|
2553
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2482
2554
|
var import_utils21 = require("@fuel-ts/utils");
|
2483
2555
|
|
2484
2556
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2485
2557
|
var import_utils19 = require("@fuel-ts/utils");
|
2486
2558
|
|
2487
2559
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2488
|
-
var
|
2489
|
-
var
|
2560
|
+
var import_math11 = require("@fuel-ts/math");
|
2561
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2490
2562
|
var import_utils16 = require("@fuel-ts/utils");
|
2491
2563
|
var calculateTransactionFee = (params) => {
|
2492
2564
|
const {
|
@@ -2494,24 +2566,24 @@ var calculateTransactionFee = (params) => {
|
|
2494
2566
|
rawPayload,
|
2495
2567
|
consensusParameters: { gasCosts, feeParams }
|
2496
2568
|
} = params;
|
2497
|
-
const gasPerByte = (0,
|
2498
|
-
const gasPriceFactor = (0,
|
2569
|
+
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2570
|
+
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2499
2571
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2500
|
-
const [transaction] = new
|
2501
|
-
if (transaction.type ===
|
2572
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2573
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2502
2574
|
return {
|
2503
|
-
fee: (0,
|
2504
|
-
minFee: (0,
|
2505
|
-
maxFee: (0,
|
2506
|
-
feeFromGasUsed: (0,
|
2575
|
+
fee: (0, import_math11.bn)(0),
|
2576
|
+
minFee: (0, import_math11.bn)(0),
|
2577
|
+
maxFee: (0, import_math11.bn)(0),
|
2578
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2507
2579
|
};
|
2508
2580
|
}
|
2509
2581
|
const { type, witnesses, inputs, policies } = transaction;
|
2510
|
-
let metadataGas = (0,
|
2511
|
-
let gasLimit = (0,
|
2512
|
-
if (type ===
|
2582
|
+
let metadataGas = (0, import_math11.bn)(0);
|
2583
|
+
let gasLimit = (0, import_math11.bn)(0);
|
2584
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2513
2585
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2514
|
-
const contractBytesSize = (0,
|
2586
|
+
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2515
2587
|
metadataGas = calculateMetadataGasForTxCreate({
|
2516
2588
|
contractBytesSize,
|
2517
2589
|
gasCosts,
|
@@ -2530,13 +2602,13 @@ var calculateTransactionFee = (params) => {
|
|
2530
2602
|
}
|
2531
2603
|
const minGas = getMinGas({
|
2532
2604
|
gasCosts,
|
2533
|
-
gasPerByte: (0,
|
2605
|
+
gasPerByte: (0, import_math11.bn)(gasPerByte),
|
2534
2606
|
inputs,
|
2535
2607
|
metadataGas,
|
2536
2608
|
txBytesSize: transactionBytes.length
|
2537
2609
|
});
|
2538
|
-
const gasPrice = (0,
|
2539
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
2610
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2611
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2540
2612
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2541
2613
|
const maxGas = getMaxGas({
|
2542
2614
|
gasPerByte,
|
@@ -2558,14 +2630,14 @@ var calculateTransactionFee = (params) => {
|
|
2558
2630
|
};
|
2559
2631
|
|
2560
2632
|
// src/providers/transaction-summary/operations.ts
|
2561
|
-
var
|
2562
|
-
var
|
2563
|
-
var
|
2564
|
-
var
|
2633
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2634
|
+
var import_errors11 = require("@fuel-ts/errors");
|
2635
|
+
var import_math13 = require("@fuel-ts/math");
|
2636
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2565
2637
|
|
2566
2638
|
// src/providers/transaction-summary/call.ts
|
2567
2639
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2568
|
-
var
|
2640
|
+
var import_math12 = require("@fuel-ts/math");
|
2569
2641
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2570
2642
|
const abiInterface = new import_abi_coder2.Interface(abi);
|
2571
2643
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2574,7 +2646,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2574
2646
|
let encodedArgs;
|
2575
2647
|
if (functionFragment.isInputDataPointer) {
|
2576
2648
|
if (rawPayload) {
|
2577
|
-
const argsOffset = (0,
|
2649
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2578
2650
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2579
2651
|
}
|
2580
2652
|
} else {
|
@@ -2608,8 +2680,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2608
2680
|
};
|
2609
2681
|
|
2610
2682
|
// src/providers/transaction-summary/input.ts
|
2611
|
-
var
|
2612
|
-
var
|
2683
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2684
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2613
2685
|
function getInputsByTypes(inputs, types) {
|
2614
2686
|
return inputs.filter((i) => types.includes(i.type));
|
2615
2687
|
}
|
@@ -2617,16 +2689,16 @@ function getInputsByType(inputs, type) {
|
|
2617
2689
|
return inputs.filter((i) => i.type === type);
|
2618
2690
|
}
|
2619
2691
|
function getInputsCoin(inputs) {
|
2620
|
-
return getInputsByType(inputs,
|
2692
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2621
2693
|
}
|
2622
2694
|
function getInputsMessage(inputs) {
|
2623
|
-
return getInputsByType(inputs,
|
2695
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2624
2696
|
}
|
2625
2697
|
function getInputsCoinAndMessage(inputs) {
|
2626
|
-
return getInputsByTypes(inputs, [
|
2698
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2627
2699
|
}
|
2628
2700
|
function getInputsContract(inputs) {
|
2629
|
-
return getInputsByType(inputs,
|
2701
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2630
2702
|
}
|
2631
2703
|
function getInputFromAssetId(inputs, assetId) {
|
2632
2704
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2645,40 +2717,40 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2645
2717
|
if (!contractInput) {
|
2646
2718
|
return void 0;
|
2647
2719
|
}
|
2648
|
-
if (contractInput.type !==
|
2649
|
-
throw new
|
2650
|
-
|
2720
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2721
|
+
throw new import_errors10.FuelError(
|
2722
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2651
2723
|
`Contract input should be of type 'contract'.`
|
2652
2724
|
);
|
2653
2725
|
}
|
2654
2726
|
return contractInput;
|
2655
2727
|
}
|
2656
2728
|
function getInputAccountAddress(input) {
|
2657
|
-
if (input.type ===
|
2729
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2658
2730
|
return input.owner.toString();
|
2659
2731
|
}
|
2660
|
-
if (input.type ===
|
2732
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2661
2733
|
return input.recipient.toString();
|
2662
2734
|
}
|
2663
2735
|
return "";
|
2664
2736
|
}
|
2665
2737
|
|
2666
2738
|
// src/providers/transaction-summary/output.ts
|
2667
|
-
var
|
2739
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2668
2740
|
function getOutputsByType(outputs, type) {
|
2669
2741
|
return outputs.filter((o) => o.type === type);
|
2670
2742
|
}
|
2671
2743
|
function getOutputsContractCreated(outputs) {
|
2672
|
-
return getOutputsByType(outputs,
|
2744
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2673
2745
|
}
|
2674
2746
|
function getOutputsCoin(outputs) {
|
2675
|
-
return getOutputsByType(outputs,
|
2747
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2676
2748
|
}
|
2677
2749
|
function getOutputsChange(outputs) {
|
2678
|
-
return getOutputsByType(outputs,
|
2750
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2679
2751
|
}
|
2680
2752
|
function getOutputsContract(outputs) {
|
2681
|
-
return getOutputsByType(outputs,
|
2753
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2682
2754
|
}
|
2683
2755
|
|
2684
2756
|
// src/providers/transaction-summary/operations.ts
|
@@ -2687,15 +2759,15 @@ function getReceiptsByType(receipts, type) {
|
|
2687
2759
|
}
|
2688
2760
|
function getTransactionTypeName(transactionType) {
|
2689
2761
|
switch (transactionType) {
|
2690
|
-
case
|
2762
|
+
case import_transactions14.TransactionType.Mint:
|
2691
2763
|
return "Mint" /* Mint */;
|
2692
|
-
case
|
2764
|
+
case import_transactions14.TransactionType.Create:
|
2693
2765
|
return "Create" /* Create */;
|
2694
|
-
case
|
2766
|
+
case import_transactions14.TransactionType.Script:
|
2695
2767
|
return "Script" /* Script */;
|
2696
2768
|
default:
|
2697
|
-
throw new
|
2698
|
-
|
2769
|
+
throw new import_errors11.FuelError(
|
2770
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
|
2699
2771
|
`Invalid transaction type: ${transactionType}.`
|
2700
2772
|
);
|
2701
2773
|
}
|
@@ -2714,10 +2786,10 @@ function isTypeScript(transactionType) {
|
|
2714
2786
|
return isType(transactionType, "Script" /* Script */);
|
2715
2787
|
}
|
2716
2788
|
function getReceiptsCall(receipts) {
|
2717
|
-
return getReceiptsByType(receipts,
|
2789
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
2718
2790
|
}
|
2719
2791
|
function getReceiptsMessageOut(receipts) {
|
2720
|
-
return getReceiptsByType(receipts,
|
2792
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
2721
2793
|
}
|
2722
2794
|
var mergeAssets = (op1, op2) => {
|
2723
2795
|
const assets1 = op1.assetsSent || [];
|
@@ -2730,7 +2802,7 @@ var mergeAssets = (op1, op2) => {
|
|
2730
2802
|
if (!matchingAsset) {
|
2731
2803
|
return asset1;
|
2732
2804
|
}
|
2733
|
-
const mergedAmount = (0,
|
2805
|
+
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
2734
2806
|
return { ...asset1, amount: mergedAmount };
|
2735
2807
|
});
|
2736
2808
|
return mergedAssets.concat(filteredAssets);
|
@@ -2856,7 +2928,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2856
2928
|
const { to: toAddress, assetId, amount } = receipt;
|
2857
2929
|
let { from: fromAddress } = receipt;
|
2858
2930
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2859
|
-
if (
|
2931
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2860
2932
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2861
2933
|
fromAddress = change?.to || fromAddress;
|
2862
2934
|
}
|
@@ -2913,11 +2985,11 @@ function getTransferOperations({
|
|
2913
2985
|
});
|
2914
2986
|
const transferReceipts = getReceiptsByType(
|
2915
2987
|
receipts,
|
2916
|
-
|
2988
|
+
import_transactions14.ReceiptType.Transfer
|
2917
2989
|
);
|
2918
2990
|
const transferOutReceipts = getReceiptsByType(
|
2919
2991
|
receipts,
|
2920
|
-
|
2992
|
+
import_transactions14.ReceiptType.TransferOut
|
2921
2993
|
);
|
2922
2994
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2923
2995
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3002,17 +3074,17 @@ function getOperations({
|
|
3002
3074
|
}
|
3003
3075
|
|
3004
3076
|
// src/providers/transaction-summary/receipt.ts
|
3005
|
-
var
|
3077
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3006
3078
|
var processGqlReceipt = (gqlReceipt) => {
|
3007
3079
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3008
3080
|
switch (receipt.type) {
|
3009
|
-
case
|
3081
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3010
3082
|
return {
|
3011
3083
|
...receipt,
|
3012
3084
|
data: gqlReceipt.data || "0x"
|
3013
3085
|
};
|
3014
3086
|
}
|
3015
|
-
case
|
3087
|
+
case import_transactions15.ReceiptType.LogData: {
|
3016
3088
|
return {
|
3017
3089
|
...receipt,
|
3018
3090
|
data: gqlReceipt.data || "0x"
|
@@ -3025,7 +3097,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3025
3097
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3026
3098
|
const mintedAssets = [];
|
3027
3099
|
receipts.forEach((receipt) => {
|
3028
|
-
if (receipt.type ===
|
3100
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3029
3101
|
mintedAssets.push({
|
3030
3102
|
subId: receipt.subId,
|
3031
3103
|
contractId: receipt.contractId,
|
@@ -3039,7 +3111,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3039
3111
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3040
3112
|
const burnedAssets = [];
|
3041
3113
|
receipts.forEach((receipt) => {
|
3042
|
-
if (receipt.type ===
|
3114
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3043
3115
|
burnedAssets.push({
|
3044
3116
|
subId: receipt.subId,
|
3045
3117
|
contractId: receipt.contractId,
|
@@ -3052,7 +3124,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3052
3124
|
};
|
3053
3125
|
|
3054
3126
|
// src/providers/transaction-summary/status.ts
|
3055
|
-
var
|
3127
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3056
3128
|
var getTransactionStatusName = (gqlStatus) => {
|
3057
3129
|
switch (gqlStatus) {
|
3058
3130
|
case "FailureStatus":
|
@@ -3064,8 +3136,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3064
3136
|
case "SqueezedOutStatus":
|
3065
3137
|
return "squeezedout" /* squeezedout */;
|
3066
3138
|
default:
|
3067
|
-
throw new
|
3068
|
-
|
3139
|
+
throw new import_errors12.FuelError(
|
3140
|
+
import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3069
3141
|
`Invalid transaction status: ${gqlStatus}.`
|
3070
3142
|
);
|
3071
3143
|
}
|
@@ -3178,12 +3250,12 @@ function assembleTransactionSummary(params) {
|
|
3178
3250
|
|
3179
3251
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3180
3252
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3181
|
-
var
|
3253
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3182
3254
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3183
3255
|
return receipts.reduce((logs, receipt) => {
|
3184
|
-
if (receipt.type ===
|
3256
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3185
3257
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3186
|
-
const data = receipt.type ===
|
3258
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3187
3259
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3188
3260
|
logs.push(decodedLog);
|
3189
3261
|
}
|
@@ -3198,7 +3270,7 @@ var TransactionResponse = class {
|
|
3198
3270
|
/** Current provider */
|
3199
3271
|
provider;
|
3200
3272
|
/** Gas used on the transaction */
|
3201
|
-
gasUsed = (0,
|
3273
|
+
gasUsed = (0, import_math14.bn)(0);
|
3202
3274
|
/** The graphql Transaction with receipts object. */
|
3203
3275
|
gqlTransaction;
|
3204
3276
|
abis;
|
@@ -3256,7 +3328,7 @@ var TransactionResponse = class {
|
|
3256
3328
|
* @returns The decoded transaction.
|
3257
3329
|
*/
|
3258
3330
|
decodeTransaction(transactionWithReceipts) {
|
3259
|
-
return new
|
3331
|
+
return new import_transactions17.TransactionCoder().decode(
|
3260
3332
|
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3261
3333
|
0
|
3262
3334
|
)?.[0];
|
@@ -3303,8 +3375,8 @@ var TransactionResponse = class {
|
|
3303
3375
|
});
|
3304
3376
|
for await (const { statusChange } of subscription) {
|
3305
3377
|
if (statusChange.type === "SqueezedOutStatus") {
|
3306
|
-
throw new
|
3307
|
-
|
3378
|
+
throw new import_errors13.FuelError(
|
3379
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3308
3380
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3309
3381
|
);
|
3310
3382
|
}
|
@@ -3326,14 +3398,26 @@ var TransactionResponse = class {
|
|
3326
3398
|
gqlTransaction: this.gqlTransaction,
|
3327
3399
|
...transactionSummary
|
3328
3400
|
};
|
3401
|
+
let logs = [];
|
3329
3402
|
if (this.abis) {
|
3330
|
-
|
3403
|
+
logs = getDecodedLogs(
|
3331
3404
|
transactionSummary.receipts,
|
3332
3405
|
this.abis.main,
|
3333
3406
|
this.abis.otherContractsAbis
|
3334
3407
|
);
|
3335
3408
|
transactionResult.logs = logs;
|
3336
3409
|
}
|
3410
|
+
if (transactionResult.isStatusFailure) {
|
3411
|
+
const {
|
3412
|
+
receipts,
|
3413
|
+
gqlTransaction: { status }
|
3414
|
+
} = transactionResult;
|
3415
|
+
throw extractTxError({
|
3416
|
+
receipts,
|
3417
|
+
status,
|
3418
|
+
logs
|
3419
|
+
});
|
3420
|
+
}
|
3337
3421
|
return transactionResult;
|
3338
3422
|
}
|
3339
3423
|
/**
|
@@ -3342,14 +3426,7 @@ var TransactionResponse = class {
|
|
3342
3426
|
* @param contractsAbiMap - The contracts ABI map.
|
3343
3427
|
*/
|
3344
3428
|
async wait(contractsAbiMap) {
|
3345
|
-
|
3346
|
-
if (result.isStatusFailure) {
|
3347
|
-
throw new import_errors12.FuelError(
|
3348
|
-
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3349
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3350
|
-
);
|
3351
|
-
}
|
3352
|
-
return result;
|
3429
|
+
return this.waitForResult(contractsAbiMap);
|
3353
3430
|
}
|
3354
3431
|
};
|
3355
3432
|
|
@@ -3411,30 +3488,29 @@ var processGqlChain = (chain) => {
|
|
3411
3488
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3412
3489
|
return {
|
3413
3490
|
name,
|
3414
|
-
baseChainHeight: (0,
|
3491
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3415
3492
|
consensusParameters: {
|
3416
|
-
contractMaxSize: (0,
|
3417
|
-
maxInputs: (0,
|
3418
|
-
maxOutputs: (0,
|
3419
|
-
maxWitnesses: (0,
|
3420
|
-
maxGasPerTx: (0,
|
3421
|
-
maxScriptLength: (0,
|
3422
|
-
maxScriptDataLength: (0,
|
3423
|
-
maxStorageSlots: (0,
|
3424
|
-
maxPredicateLength: (0,
|
3425
|
-
maxPredicateDataLength: (0,
|
3426
|
-
maxGasPerPredicate: (0,
|
3427
|
-
gasPriceFactor: (0,
|
3428
|
-
gasPerByte: (0,
|
3429
|
-
maxMessageDataLength: (0,
|
3430
|
-
chainId: (0,
|
3431
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3493
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3494
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3495
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3496
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3497
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3498
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3499
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3500
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3501
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3502
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3503
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3504
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3505
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3506
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3507
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3432
3508
|
gasCosts
|
3433
3509
|
},
|
3434
3510
|
gasCosts,
|
3435
3511
|
latestBlock: {
|
3436
3512
|
id: latestBlock.id,
|
3437
|
-
height: (0,
|
3513
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3438
3514
|
time: latestBlock.header.time,
|
3439
3515
|
transactions: latestBlock.transactions.map((i) => ({
|
3440
3516
|
id: i.id
|
@@ -3504,8 +3580,8 @@ var _Provider = class {
|
|
3504
3580
|
getChain() {
|
3505
3581
|
const chain = _Provider.chainInfoCache[this.url];
|
3506
3582
|
if (!chain) {
|
3507
|
-
throw new
|
3508
|
-
|
3583
|
+
throw new import_errors14.FuelError(
|
3584
|
+
import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3509
3585
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3510
3586
|
);
|
3511
3587
|
}
|
@@ -3517,8 +3593,8 @@ var _Provider = class {
|
|
3517
3593
|
getNode() {
|
3518
3594
|
const node = _Provider.nodeInfoCache[this.url];
|
3519
3595
|
if (!node) {
|
3520
|
-
throw new
|
3521
|
-
|
3596
|
+
throw new import_errors14.FuelError(
|
3597
|
+
import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3522
3598
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3523
3599
|
);
|
3524
3600
|
}
|
@@ -3565,8 +3641,8 @@ var _Provider = class {
|
|
3565
3641
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3566
3642
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3567
3643
|
if (!isMajorSupported || !isMinorSupported) {
|
3568
|
-
throw new
|
3569
|
-
|
3644
|
+
throw new import_errors14.FuelError(
|
3645
|
+
import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3570
3646
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3571
3647
|
);
|
3572
3648
|
}
|
@@ -3629,7 +3705,7 @@ var _Provider = class {
|
|
3629
3705
|
*/
|
3630
3706
|
async getBlockNumber() {
|
3631
3707
|
const { chain } = await this.operations.getChain();
|
3632
|
-
return (0,
|
3708
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3633
3709
|
}
|
3634
3710
|
/**
|
3635
3711
|
* Returns the chain information.
|
@@ -3639,9 +3715,9 @@ var _Provider = class {
|
|
3639
3715
|
async fetchNode() {
|
3640
3716
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3641
3717
|
const processedNodeInfo = {
|
3642
|
-
maxDepth: (0,
|
3643
|
-
maxTx: (0,
|
3644
|
-
minGasPrice: (0,
|
3718
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3719
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3720
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3645
3721
|
nodeVersion: nodeInfo.nodeVersion,
|
3646
3722
|
utxoValidation: nodeInfo.utxoValidation,
|
3647
3723
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3671,17 +3747,6 @@ var _Provider = class {
|
|
3671
3747
|
} = this.getChain();
|
3672
3748
|
return chainId.toNumber();
|
3673
3749
|
}
|
3674
|
-
/**
|
3675
|
-
* Returns the base asset ID
|
3676
|
-
*
|
3677
|
-
* @returns A promise that resolves to the base asset ID
|
3678
|
-
*/
|
3679
|
-
getBaseAssetId() {
|
3680
|
-
const {
|
3681
|
-
consensusParameters: { baseAssetId }
|
3682
|
-
} = this.getChain();
|
3683
|
-
return baseAssetId;
|
3684
|
-
}
|
3685
3750
|
/**
|
3686
3751
|
* Submits a transaction to the chain to be executed.
|
3687
3752
|
*
|
@@ -3698,17 +3763,17 @@ var _Provider = class {
|
|
3698
3763
|
if (estimateTxDependencies) {
|
3699
3764
|
await this.estimateTxDependencies(transactionRequest);
|
3700
3765
|
}
|
3701
|
-
const encodedTransaction = (0,
|
3766
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3702
3767
|
let abis;
|
3703
|
-
if (transactionRequest.type ===
|
3768
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3704
3769
|
abis = transactionRequest.abis;
|
3705
3770
|
}
|
3706
3771
|
if (awaitExecution) {
|
3707
3772
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3708
3773
|
for await (const { submitAndAwait } of subscription) {
|
3709
3774
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3710
|
-
throw new
|
3711
|
-
|
3775
|
+
throw new import_errors14.FuelError(
|
3776
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3712
3777
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3713
3778
|
);
|
3714
3779
|
}
|
@@ -3741,7 +3806,7 @@ var _Provider = class {
|
|
3741
3806
|
if (estimateTxDependencies) {
|
3742
3807
|
return this.estimateTxDependencies(transactionRequest);
|
3743
3808
|
}
|
3744
|
-
const encodedTransaction = (0,
|
3809
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3745
3810
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3746
3811
|
encodedTransaction,
|
3747
3812
|
utxoValidation: utxoValidation || false
|
@@ -3760,13 +3825,13 @@ var _Provider = class {
|
|
3760
3825
|
async estimatePredicates(transactionRequest) {
|
3761
3826
|
const shouldEstimatePredicates = Boolean(
|
3762
3827
|
transactionRequest.inputs.find(
|
3763
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3828
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
3764
3829
|
)
|
3765
3830
|
);
|
3766
3831
|
if (!shouldEstimatePredicates) {
|
3767
3832
|
return transactionRequest;
|
3768
3833
|
}
|
3769
|
-
const encodedTransaction = (0,
|
3834
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3770
3835
|
const response = await this.operations.estimatePredicates({
|
3771
3836
|
encodedTransaction
|
3772
3837
|
});
|
@@ -3775,7 +3840,7 @@ var _Provider = class {
|
|
3775
3840
|
} = response;
|
3776
3841
|
if (inputs) {
|
3777
3842
|
inputs.forEach((input, index) => {
|
3778
|
-
if ("predicateGasUsed" in input && (0,
|
3843
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3779
3844
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3780
3845
|
}
|
3781
3846
|
});
|
@@ -3796,7 +3861,7 @@ var _Provider = class {
|
|
3796
3861
|
* @returns A promise.
|
3797
3862
|
*/
|
3798
3863
|
async estimateTxDependencies(transactionRequest) {
|
3799
|
-
if (transactionRequest.type ===
|
3864
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3800
3865
|
return {
|
3801
3866
|
receipts: [],
|
3802
3867
|
outputVariables: 0,
|
@@ -3809,7 +3874,7 @@ var _Provider = class {
|
|
3809
3874
|
let outputVariables = 0;
|
3810
3875
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3811
3876
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3812
|
-
encodedTransaction: (0,
|
3877
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3813
3878
|
utxoValidation: false
|
3814
3879
|
});
|
3815
3880
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3847,7 +3912,7 @@ var _Provider = class {
|
|
3847
3912
|
if (estimateTxDependencies) {
|
3848
3913
|
return this.estimateTxDependencies(transactionRequest);
|
3849
3914
|
}
|
3850
|
-
const encodedTransaction = (0,
|
3915
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3851
3916
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3852
3917
|
encodedTransaction,
|
3853
3918
|
utxoValidation: true
|
@@ -3881,14 +3946,14 @@ var _Provider = class {
|
|
3881
3946
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3882
3947
|
const chainInfo = this.getChain();
|
3883
3948
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3884
|
-
const gasPrice = (0,
|
3885
|
-
const isScriptTransaction = txRequestClone.type ===
|
3949
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3950
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3886
3951
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3887
3952
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3888
3953
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3889
3954
|
if (estimatePredicates) {
|
3890
3955
|
if (isScriptTransaction) {
|
3891
|
-
txRequestClone.gasLimit = (0,
|
3956
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3892
3957
|
}
|
3893
3958
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3894
3959
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3904,8 +3969,8 @@ var _Provider = class {
|
|
3904
3969
|
let missingContractIds = [];
|
3905
3970
|
let outputVariables = 0;
|
3906
3971
|
if (isScriptTransaction && estimateTxDependencies) {
|
3907
|
-
txRequestClone.gasPrice = (0,
|
3908
|
-
txRequestClone.gasLimit = (0,
|
3972
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3973
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3909
3974
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3910
3975
|
receipts = result.receipts;
|
3911
3976
|
outputVariables = result.outputVariables;
|
@@ -3961,17 +4026,17 @@ var _Provider = class {
|
|
3961
4026
|
const result = await this.operations.getCoins({
|
3962
4027
|
first: 10,
|
3963
4028
|
...paginationArgs,
|
3964
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4029
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
3965
4030
|
});
|
3966
4031
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3967
4032
|
return coins.map((coin) => ({
|
3968
4033
|
id: coin.utxoId,
|
3969
4034
|
assetId: coin.assetId,
|
3970
|
-
amount: (0,
|
4035
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3971
4036
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3972
|
-
maturity: (0,
|
3973
|
-
blockCreated: (0,
|
3974
|
-
txCreatedIdx: (0,
|
4037
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4038
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4039
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
3975
4040
|
}));
|
3976
4041
|
}
|
3977
4042
|
/**
|
@@ -3985,19 +4050,19 @@ var _Provider = class {
|
|
3985
4050
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3986
4051
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3987
4052
|
const excludeInput = {
|
3988
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3989
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4053
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4054
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
3990
4055
|
};
|
3991
4056
|
if (this.cache) {
|
3992
4057
|
const uniqueUtxos = new Set(
|
3993
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4058
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
3994
4059
|
);
|
3995
4060
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3996
4061
|
}
|
3997
4062
|
const coinsQuery = {
|
3998
4063
|
owner: ownerAddress.toB256(),
|
3999
4064
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4000
|
-
assetId: (0,
|
4065
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4001
4066
|
amount: amount.toString(10),
|
4002
4067
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4003
4068
|
})),
|
@@ -4008,9 +4073,9 @@ var _Provider = class {
|
|
4008
4073
|
switch (coin.__typename) {
|
4009
4074
|
case "MessageCoin":
|
4010
4075
|
return {
|
4011
|
-
amount: (0,
|
4076
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4012
4077
|
assetId: coin.assetId,
|
4013
|
-
daHeight: (0,
|
4078
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4014
4079
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4015
4080
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4016
4081
|
nonce: coin.nonce
|
@@ -4018,12 +4083,12 @@ var _Provider = class {
|
|
4018
4083
|
case "Coin":
|
4019
4084
|
return {
|
4020
4085
|
id: coin.utxoId,
|
4021
|
-
amount: (0,
|
4086
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4022
4087
|
assetId: coin.assetId,
|
4023
4088
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4024
|
-
maturity: (0,
|
4025
|
-
blockCreated: (0,
|
4026
|
-
txCreatedIdx: (0,
|
4089
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4090
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4091
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4027
4092
|
};
|
4028
4093
|
default:
|
4029
4094
|
return null;
|
@@ -4040,13 +4105,13 @@ var _Provider = class {
|
|
4040
4105
|
async getBlock(idOrHeight) {
|
4041
4106
|
let variables;
|
4042
4107
|
if (typeof idOrHeight === "number") {
|
4043
|
-
variables = { height: (0,
|
4108
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4044
4109
|
} else if (idOrHeight === "latest") {
|
4045
4110
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4046
4111
|
} else if (idOrHeight.length === 66) {
|
4047
4112
|
variables = { blockId: idOrHeight };
|
4048
4113
|
} else {
|
4049
|
-
variables = { blockId: (0,
|
4114
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4050
4115
|
}
|
4051
4116
|
const { block } = await this.operations.getBlock(variables);
|
4052
4117
|
if (!block) {
|
@@ -4054,7 +4119,7 @@ var _Provider = class {
|
|
4054
4119
|
}
|
4055
4120
|
return {
|
4056
4121
|
id: block.id,
|
4057
|
-
height: (0,
|
4122
|
+
height: (0, import_math15.bn)(block.header.height),
|
4058
4123
|
time: block.header.time,
|
4059
4124
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4060
4125
|
};
|
@@ -4069,7 +4134,7 @@ var _Provider = class {
|
|
4069
4134
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4070
4135
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4071
4136
|
id: block.id,
|
4072
|
-
height: (0,
|
4137
|
+
height: (0, import_math15.bn)(block.header.height),
|
4073
4138
|
time: block.header.time,
|
4074
4139
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4075
4140
|
}));
|
@@ -4084,7 +4149,7 @@ var _Provider = class {
|
|
4084
4149
|
async getBlockWithTransactions(idOrHeight) {
|
4085
4150
|
let variables;
|
4086
4151
|
if (typeof idOrHeight === "number") {
|
4087
|
-
variables = { blockHeight: (0,
|
4152
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4088
4153
|
} else if (idOrHeight === "latest") {
|
4089
4154
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4090
4155
|
} else {
|
@@ -4096,11 +4161,11 @@ var _Provider = class {
|
|
4096
4161
|
}
|
4097
4162
|
return {
|
4098
4163
|
id: block.id,
|
4099
|
-
height: (0,
|
4164
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4100
4165
|
time: block.header.time,
|
4101
4166
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4102
4167
|
transactions: block.transactions.map(
|
4103
|
-
(tx) => new
|
4168
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4104
4169
|
)
|
4105
4170
|
};
|
4106
4171
|
}
|
@@ -4115,8 +4180,8 @@ var _Provider = class {
|
|
4115
4180
|
if (!transaction) {
|
4116
4181
|
return null;
|
4117
4182
|
}
|
4118
|
-
return new
|
4119
|
-
(0,
|
4183
|
+
return new import_transactions18.TransactionCoder().decode(
|
4184
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4120
4185
|
0
|
4121
4186
|
)?.[0];
|
4122
4187
|
}
|
@@ -4143,9 +4208,9 @@ var _Provider = class {
|
|
4143
4208
|
async getContractBalance(contractId, assetId) {
|
4144
4209
|
const { contractBalance } = await this.operations.getContractBalance({
|
4145
4210
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4146
|
-
asset: (0,
|
4211
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4147
4212
|
});
|
4148
|
-
return (0,
|
4213
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4149
4214
|
}
|
4150
4215
|
/**
|
4151
4216
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4157,9 +4222,9 @@ var _Provider = class {
|
|
4157
4222
|
async getBalance(owner, assetId) {
|
4158
4223
|
const { balance } = await this.operations.getBalance({
|
4159
4224
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4160
|
-
assetId: (0,
|
4225
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4161
4226
|
});
|
4162
|
-
return (0,
|
4227
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4163
4228
|
}
|
4164
4229
|
/**
|
4165
4230
|
* Returns balances for the given owner.
|
@@ -4177,7 +4242,7 @@ var _Provider = class {
|
|
4177
4242
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4178
4243
|
return balances.map((balance) => ({
|
4179
4244
|
assetId: balance.assetId,
|
4180
|
-
amount: (0,
|
4245
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4181
4246
|
}));
|
4182
4247
|
}
|
4183
4248
|
/**
|
@@ -4195,19 +4260,19 @@ var _Provider = class {
|
|
4195
4260
|
});
|
4196
4261
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4197
4262
|
return messages.map((message) => ({
|
4198
|
-
messageId:
|
4263
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4199
4264
|
sender: message.sender,
|
4200
4265
|
recipient: message.recipient,
|
4201
4266
|
nonce: message.nonce,
|
4202
|
-
amount: (0,
|
4267
|
+
amount: (0, import_math15.bn)(message.amount),
|
4203
4268
|
data: message.data
|
4204
4269
|
}),
|
4205
4270
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4206
4271
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4207
4272
|
nonce: message.nonce,
|
4208
|
-
amount: (0,
|
4209
|
-
data:
|
4210
|
-
daHeight: (0,
|
4273
|
+
amount: (0, import_math15.bn)(message.amount),
|
4274
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4275
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4211
4276
|
}));
|
4212
4277
|
}
|
4213
4278
|
/**
|
@@ -4225,8 +4290,8 @@ var _Provider = class {
|
|
4225
4290
|
nonce
|
4226
4291
|
};
|
4227
4292
|
if (commitBlockId && commitBlockHeight) {
|
4228
|
-
throw new
|
4229
|
-
|
4293
|
+
throw new import_errors14.FuelError(
|
4294
|
+
import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4230
4295
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4231
4296
|
);
|
4232
4297
|
}
|
@@ -4260,41 +4325,41 @@ var _Provider = class {
|
|
4260
4325
|
} = result.messageProof;
|
4261
4326
|
return {
|
4262
4327
|
messageProof: {
|
4263
|
-
proofIndex: (0,
|
4328
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4264
4329
|
proofSet: messageProof.proofSet
|
4265
4330
|
},
|
4266
4331
|
blockProof: {
|
4267
|
-
proofIndex: (0,
|
4332
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4268
4333
|
proofSet: blockProof.proofSet
|
4269
4334
|
},
|
4270
4335
|
messageBlockHeader: {
|
4271
4336
|
id: messageBlockHeader.id,
|
4272
|
-
daHeight: (0,
|
4273
|
-
transactionsCount: (0,
|
4337
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4338
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4274
4339
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4275
|
-
height: (0,
|
4340
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4276
4341
|
prevRoot: messageBlockHeader.prevRoot,
|
4277
4342
|
time: messageBlockHeader.time,
|
4278
4343
|
applicationHash: messageBlockHeader.applicationHash,
|
4279
4344
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4280
|
-
messageReceiptCount: (0,
|
4345
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4281
4346
|
},
|
4282
4347
|
commitBlockHeader: {
|
4283
4348
|
id: commitBlockHeader.id,
|
4284
|
-
daHeight: (0,
|
4285
|
-
transactionsCount: (0,
|
4349
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4350
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4286
4351
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4287
|
-
height: (0,
|
4352
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4288
4353
|
prevRoot: commitBlockHeader.prevRoot,
|
4289
4354
|
time: commitBlockHeader.time,
|
4290
4355
|
applicationHash: commitBlockHeader.applicationHash,
|
4291
4356
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4292
|
-
messageReceiptCount: (0,
|
4357
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4293
4358
|
},
|
4294
4359
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4295
4360
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4296
4361
|
nonce,
|
4297
|
-
amount: (0,
|
4362
|
+
amount: (0, import_math15.bn)(amount),
|
4298
4363
|
data
|
4299
4364
|
};
|
4300
4365
|
}
|
@@ -4317,10 +4382,10 @@ var _Provider = class {
|
|
4317
4382
|
*/
|
4318
4383
|
async produceBlocks(amount, startTime) {
|
4319
4384
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4320
|
-
blocksToProduce: (0,
|
4321
|
-
startTimestamp: startTime ?
|
4385
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4386
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4322
4387
|
});
|
4323
|
-
return (0,
|
4388
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4324
4389
|
}
|
4325
4390
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4326
4391
|
async getTransactionResponse(transactionId) {
|
@@ -4334,7 +4399,7 @@ cacheInputs_fn = function(inputs) {
|
|
4334
4399
|
return;
|
4335
4400
|
}
|
4336
4401
|
inputs.forEach((input) => {
|
4337
|
-
if (input.type ===
|
4402
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4338
4403
|
this.cache?.set(input.id);
|
4339
4404
|
}
|
4340
4405
|
});
|
@@ -4343,10 +4408,10 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4343
4408
|
__publicField(Provider, "nodeInfoCache", {});
|
4344
4409
|
|
4345
4410
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4346
|
-
var
|
4347
|
-
var
|
4348
|
-
var
|
4349
|
-
var
|
4411
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4412
|
+
var import_math16 = require("@fuel-ts/math");
|
4413
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4414
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4350
4415
|
|
4351
4416
|
// src/providers/chains.ts
|
4352
4417
|
var CHAIN_IDS = {
|
@@ -4395,17 +4460,17 @@ var assets = [
|
|
4395
4460
|
|
4396
4461
|
// src/utils/formatTransferToContractScriptData.ts
|
4397
4462
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4398
|
-
var
|
4399
|
-
var
|
4463
|
+
var import_math17 = require("@fuel-ts/math");
|
4464
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4400
4465
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4401
4466
|
var formatTransferToContractScriptData = (params) => {
|
4402
4467
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4403
4468
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4404
|
-
const encoded = numberCoder.encode(new
|
4469
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4405
4470
|
const scriptData = Uint8Array.from([
|
4406
|
-
...(0,
|
4471
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4407
4472
|
...encoded,
|
4408
|
-
...(0,
|
4473
|
+
...(0, import_utils27.arrayify)(assetId)
|
4409
4474
|
]);
|
4410
4475
|
return scriptData;
|
4411
4476
|
};
|
@@ -4461,7 +4526,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4461
4526
|
*/
|
4462
4527
|
get provider() {
|
4463
4528
|
if (!this._provider) {
|
4464
|
-
throw new
|
4529
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4465
4530
|
}
|
4466
4531
|
return this._provider;
|
4467
4532
|
}
|
@@ -4513,8 +4578,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4513
4578
|
if (!hasNextPage) {
|
4514
4579
|
break;
|
4515
4580
|
}
|
4516
|
-
throw new
|
4517
|
-
|
4581
|
+
throw new import_errors16.FuelError(
|
4582
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4518
4583
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4519
4584
|
);
|
4520
4585
|
}
|
@@ -4539,8 +4604,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4539
4604
|
if (!hasNextPage) {
|
4540
4605
|
break;
|
4541
4606
|
}
|
4542
|
-
throw new
|
4543
|
-
|
4607
|
+
throw new import_errors16.FuelError(
|
4608
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4544
4609
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4545
4610
|
);
|
4546
4611
|
}
|
@@ -4552,9 +4617,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4552
4617
|
* @param assetId - The asset ID to check the balance for.
|
4553
4618
|
* @returns A promise that resolves to the balance amount.
|
4554
4619
|
*/
|
4555
|
-
async getBalance(assetId) {
|
4556
|
-
const
|
4557
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4620
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4621
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4558
4622
|
return amount;
|
4559
4623
|
}
|
4560
4624
|
/**
|
@@ -4576,8 +4640,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4576
4640
|
if (!hasNextPage) {
|
4577
4641
|
break;
|
4578
4642
|
}
|
4579
|
-
throw new
|
4580
|
-
|
4643
|
+
throw new import_errors16.FuelError(
|
4644
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4581
4645
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4582
4646
|
);
|
4583
4647
|
}
|
@@ -4592,17 +4656,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4592
4656
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4593
4657
|
*/
|
4594
4658
|
async fund(request, coinQuantities, fee) {
|
4595
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4596
4659
|
const updatedQuantities = addAmountToAsset({
|
4597
|
-
amount: (0,
|
4598
|
-
assetId:
|
4660
|
+
amount: (0, import_math18.bn)(fee),
|
4661
|
+
assetId: import_configs12.BaseAssetId,
|
4599
4662
|
coinQuantities
|
4600
4663
|
});
|
4601
4664
|
const quantitiesDict = {};
|
4602
4665
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4603
4666
|
quantitiesDict[assetId] = {
|
4604
4667
|
required: amount,
|
4605
|
-
owned: (0,
|
4668
|
+
owned: (0, import_math18.bn)(0)
|
4606
4669
|
};
|
4607
4670
|
});
|
4608
4671
|
const cachedUtxos = [];
|
@@ -4615,12 +4678,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4615
4678
|
if (isCoin2) {
|
4616
4679
|
const assetId = String(input.assetId);
|
4617
4680
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4618
|
-
const amount = (0,
|
4681
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4619
4682
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4620
4683
|
cachedUtxos.push(input.id);
|
4621
4684
|
}
|
4622
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4623
|
-
quantitiesDict[
|
4685
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4686
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4624
4687
|
cachedMessages.push(input.nonce);
|
4625
4688
|
}
|
4626
4689
|
}
|
@@ -4652,18 +4715,17 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4652
4715
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4653
4716
|
* @returns A promise that resolves to the prepared transaction request.
|
4654
4717
|
*/
|
4655
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4718
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4656
4719
|
const { minGasPrice } = this.provider.getGasConfig();
|
4657
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4658
4720
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4659
4721
|
const request = new ScriptTransactionRequest(params);
|
4660
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
4722
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4661
4723
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4662
4724
|
estimateTxDependencies: true,
|
4663
4725
|
resourcesOwner: this
|
4664
4726
|
});
|
4665
|
-
request.gasPrice = (0,
|
4666
|
-
request.gasLimit = (0,
|
4727
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4728
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4667
4729
|
this.validateGas({
|
4668
4730
|
gasUsed,
|
4669
4731
|
gasPrice: request.gasPrice,
|
@@ -4683,15 +4745,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4683
4745
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4684
4746
|
* @returns A promise that resolves to the transaction response.
|
4685
4747
|
*/
|
4686
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4687
|
-
if ((0,
|
4688
|
-
throw new
|
4689
|
-
|
4748
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4749
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4750
|
+
throw new import_errors16.FuelError(
|
4751
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4690
4752
|
"Transfer amount must be a positive number."
|
4691
4753
|
);
|
4692
4754
|
}
|
4693
|
-
const
|
4694
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4755
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4695
4756
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4696
4757
|
}
|
4697
4758
|
/**
|
@@ -4703,21 +4764,20 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4703
4764
|
* @param txParams - The optional transaction parameters.
|
4704
4765
|
* @returns A promise that resolves to the transaction response.
|
4705
4766
|
*/
|
4706
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4707
|
-
if ((0,
|
4708
|
-
throw new
|
4709
|
-
|
4767
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4768
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4769
|
+
throw new import_errors16.FuelError(
|
4770
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4710
4771
|
"Transfer amount must be a positive number."
|
4711
4772
|
);
|
4712
4773
|
}
|
4713
4774
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4714
4775
|
const { minGasPrice } = this.provider.getGasConfig();
|
4715
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4716
4776
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4717
4777
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4718
4778
|
hexlifiedContractId: contractAddress.toB256(),
|
4719
|
-
amountToTransfer: (0,
|
4720
|
-
assetId
|
4779
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4780
|
+
assetId
|
4721
4781
|
});
|
4722
4782
|
const request = new ScriptTransactionRequest({
|
4723
4783
|
...params,
|
@@ -4727,9 +4787,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4727
4787
|
request.addContractInputAndOutput(contractAddress);
|
4728
4788
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4729
4789
|
request,
|
4730
|
-
[{ amount: (0,
|
4790
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4731
4791
|
);
|
4732
|
-
request.gasLimit = (0,
|
4792
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4733
4793
|
this.validateGas({
|
4734
4794
|
gasUsed,
|
4735
4795
|
gasPrice: request.gasPrice,
|
@@ -4749,27 +4809,26 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4749
4809
|
*/
|
4750
4810
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4751
4811
|
const { minGasPrice } = this.provider.getGasConfig();
|
4752
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4753
4812
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4754
|
-
const recipientDataArray = (0,
|
4813
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
4755
4814
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4756
4815
|
);
|
4757
|
-
const amountDataArray = (0,
|
4758
|
-
"0x".concat((0,
|
4816
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4817
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4759
4818
|
);
|
4760
4819
|
const script = new Uint8Array([
|
4761
|
-
...(0,
|
4820
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
4762
4821
|
...recipientDataArray,
|
4763
4822
|
...amountDataArray
|
4764
4823
|
]);
|
4765
4824
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4766
4825
|
const request = new ScriptTransactionRequest(params);
|
4767
|
-
const forwardingQuantities = [{ amount: (0,
|
4826
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4768
4827
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4769
4828
|
request,
|
4770
4829
|
forwardingQuantities
|
4771
4830
|
);
|
4772
|
-
request.gasLimit = (0,
|
4831
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4773
4832
|
this.validateGas({
|
4774
4833
|
gasUsed,
|
4775
4834
|
gasPrice: request.gasPrice,
|
@@ -4781,7 +4840,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4781
4840
|
}
|
4782
4841
|
async signMessage(message) {
|
4783
4842
|
if (!this._connector) {
|
4784
|
-
throw new
|
4843
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4785
4844
|
}
|
4786
4845
|
return this._connector.signMessage(this.address.toString(), message);
|
4787
4846
|
}
|
@@ -4793,8 +4852,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4793
4852
|
*/
|
4794
4853
|
async signTransaction(transactionRequestLike) {
|
4795
4854
|
if (!this._connector) {
|
4796
|
-
throw new
|
4797
|
-
|
4855
|
+
throw new import_errors16.FuelError(
|
4856
|
+
import_errors16.ErrorCode.MISSING_CONNECTOR,
|
4798
4857
|
"A connector is required to sign transactions."
|
4799
4858
|
);
|
4800
4859
|
}
|
@@ -4841,14 +4900,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4841
4900
|
minGasPrice
|
4842
4901
|
}) {
|
4843
4902
|
if (minGasPrice.gt(gasPrice)) {
|
4844
|
-
throw new
|
4845
|
-
|
4903
|
+
throw new import_errors16.FuelError(
|
4904
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4846
4905
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4847
4906
|
);
|
4848
4907
|
}
|
4849
4908
|
if (gasUsed.gt(gasLimit)) {
|
4850
|
-
throw new
|
4851
|
-
|
4909
|
+
throw new import_errors16.FuelError(
|
4910
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4852
4911
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4853
4912
|
);
|
4854
4913
|
}
|
@@ -4859,8 +4918,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4859
4918
|
var import_address5 = require("@fuel-ts/address");
|
4860
4919
|
var import_crypto = require("@fuel-ts/crypto");
|
4861
4920
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4862
|
-
var
|
4863
|
-
var
|
4921
|
+
var import_math19 = require("@fuel-ts/math");
|
4922
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4864
4923
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4865
4924
|
var Signer = class {
|
4866
4925
|
address;
|
@@ -4879,10 +4938,10 @@ var Signer = class {
|
|
4879
4938
|
privateKey = `0x${privateKey}`;
|
4880
4939
|
}
|
4881
4940
|
}
|
4882
|
-
const privateKeyBytes = (0,
|
4883
|
-
this.privateKey = (0,
|
4884
|
-
this.publicKey = (0,
|
4885
|
-
this.compressedPublicKey = (0,
|
4941
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4942
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4943
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4944
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4886
4945
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4887
4946
|
}
|
4888
4947
|
/**
|
@@ -4896,11 +4955,11 @@ var Signer = class {
|
|
4896
4955
|
* @returns hashed signature
|
4897
4956
|
*/
|
4898
4957
|
sign(data) {
|
4899
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4900
|
-
const r = (0,
|
4901
|
-
const s = (0,
|
4958
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4959
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4960
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4902
4961
|
s[0] |= (signature.recovery || 0) << 7;
|
4903
|
-
return (0,
|
4962
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
4904
4963
|
}
|
4905
4964
|
/**
|
4906
4965
|
* Add point on the current elliptic curve
|
@@ -4909,8 +4968,8 @@ var Signer = class {
|
|
4909
4968
|
* @returns compressed point on the curve
|
4910
4969
|
*/
|
4911
4970
|
addPoint(point) {
|
4912
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4913
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4971
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4972
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
4914
4973
|
const result = p0.add(p1);
|
4915
4974
|
return `0x${result.toHex(true)}`;
|
4916
4975
|
}
|
@@ -4922,16 +4981,16 @@ var Signer = class {
|
|
4922
4981
|
* @returns public key from signature from the
|
4923
4982
|
*/
|
4924
4983
|
static recoverPublicKey(data, signature) {
|
4925
|
-
const signedMessageBytes = (0,
|
4984
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
4926
4985
|
const r = signedMessageBytes.slice(0, 32);
|
4927
4986
|
const s = signedMessageBytes.slice(32, 64);
|
4928
4987
|
const recoveryParam = (s[0] & 128) >> 7;
|
4929
4988
|
s[0] &= 127;
|
4930
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
4989
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
4931
4990
|
recoveryParam
|
4932
4991
|
);
|
4933
|
-
const publicKey = sig.recoverPublicKey((0,
|
4934
|
-
return (0,
|
4992
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
4993
|
+
return (0, import_utils29.hexlify)(publicKey);
|
4935
4994
|
}
|
4936
4995
|
/**
|
4937
4996
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4950,7 +5009,7 @@ var Signer = class {
|
|
4950
5009
|
* @returns random 32-byte hashed
|
4951
5010
|
*/
|
4952
5011
|
static generatePrivateKey(entropy) {
|
4953
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5012
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
4954
5013
|
}
|
4955
5014
|
/**
|
4956
5015
|
* Extended publicKey from a compact publicKey
|
@@ -4959,16 +5018,16 @@ var Signer = class {
|
|
4959
5018
|
* @returns extended publicKey
|
4960
5019
|
*/
|
4961
5020
|
static extendPublicKey(publicKey) {
|
4962
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4963
|
-
return (0,
|
5021
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5022
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
4964
5023
|
}
|
4965
5024
|
};
|
4966
5025
|
|
4967
5026
|
// src/wallet/keystore-wallet.ts
|
4968
5027
|
var import_address6 = require("@fuel-ts/address");
|
4969
5028
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4970
|
-
var
|
4971
|
-
var
|
5029
|
+
var import_errors17 = require("@fuel-ts/errors");
|
5030
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4972
5031
|
var import_uuid = require("uuid");
|
4973
5032
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4974
5033
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5045,13 +5104,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5045
5104
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5046
5105
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5047
5106
|
if (mac !== macHash) {
|
5048
|
-
throw new
|
5049
|
-
|
5107
|
+
throw new import_errors17.FuelError(
|
5108
|
+
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5050
5109
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5051
5110
|
);
|
5052
5111
|
}
|
5053
5112
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5054
|
-
const privateKey = (0,
|
5113
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5055
5114
|
return privateKey;
|
5056
5115
|
}
|
5057
5116
|
|
@@ -5096,7 +5155,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5096
5155
|
*/
|
5097
5156
|
async signMessage(message) {
|
5098
5157
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5099
|
-
return (0,
|
5158
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5100
5159
|
}
|
5101
5160
|
/**
|
5102
5161
|
* Signs a transaction with the wallet's private key.
|
@@ -5109,7 +5168,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5109
5168
|
const chainId = this.provider.getChainId();
|
5110
5169
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5111
5170
|
const signature = await this.signer().sign(hashedTransaction);
|
5112
|
-
return (0,
|
5171
|
+
return (0, import_utils31.hexlify)(signature);
|
5113
5172
|
}
|
5114
5173
|
/**
|
5115
5174
|
* Populates a transaction with the witnesses signature.
|
@@ -5168,17 +5227,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5168
5227
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5169
5228
|
|
5170
5229
|
// src/hdwallet/hdwallet.ts
|
5171
|
-
var
|
5230
|
+
var import_errors20 = require("@fuel-ts/errors");
|
5172
5231
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5173
|
-
var
|
5174
|
-
var
|
5232
|
+
var import_math20 = require("@fuel-ts/math");
|
5233
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5175
5234
|
var import_ethers3 = require("ethers");
|
5176
5235
|
|
5177
5236
|
// src/mnemonic/mnemonic.ts
|
5178
5237
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5179
|
-
var
|
5238
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5180
5239
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5181
|
-
var
|
5240
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5182
5241
|
var import_ethers2 = require("ethers");
|
5183
5242
|
|
5184
5243
|
// src/wordlists/words/english.ts
|
@@ -7234,9 +7293,9 @@ var english = [
|
|
7234
7293
|
];
|
7235
7294
|
|
7236
7295
|
// src/mnemonic/utils.ts
|
7237
|
-
var
|
7296
|
+
var import_errors18 = require("@fuel-ts/errors");
|
7238
7297
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7239
|
-
var
|
7298
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7240
7299
|
function toUtf8Bytes(stri) {
|
7241
7300
|
const str = stri.normalize("NFKD");
|
7242
7301
|
const result = [];
|
@@ -7251,8 +7310,8 @@ function toUtf8Bytes(stri) {
|
|
7251
7310
|
i += 1;
|
7252
7311
|
const c2 = str.charCodeAt(i);
|
7253
7312
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7254
|
-
throw new
|
7255
|
-
|
7313
|
+
throw new import_errors18.FuelError(
|
7314
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7256
7315
|
"Invalid UTF-8 in the input string."
|
7257
7316
|
);
|
7258
7317
|
}
|
@@ -7303,20 +7362,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7303
7362
|
}
|
7304
7363
|
}
|
7305
7364
|
const checksumBits = entropy.length / 4;
|
7306
|
-
const checksum = (0,
|
7365
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7307
7366
|
indices[indices.length - 1] <<= checksumBits;
|
7308
7367
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7309
7368
|
return indices;
|
7310
7369
|
}
|
7311
7370
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7312
7371
|
const size = Math.ceil(11 * words.length / 8);
|
7313
|
-
const entropy = (0,
|
7372
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7314
7373
|
let offset = 0;
|
7315
7374
|
for (let i = 0; i < words.length; i += 1) {
|
7316
7375
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7317
7376
|
if (index === -1) {
|
7318
|
-
throw new
|
7319
|
-
|
7377
|
+
throw new import_errors18.FuelError(
|
7378
|
+
import_errors18.ErrorCode.INVALID_MNEMONIC,
|
7320
7379
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7321
7380
|
);
|
7322
7381
|
}
|
@@ -7330,10 +7389,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7330
7389
|
const entropyBits = 32 * words.length / 3;
|
7331
7390
|
const checksumBits = words.length / 3;
|
7332
7391
|
const checksumMask = getUpperMask(checksumBits);
|
7333
|
-
const checksum = (0,
|
7392
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7334
7393
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7335
|
-
throw new
|
7336
|
-
|
7394
|
+
throw new import_errors18.FuelError(
|
7395
|
+
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
7337
7396
|
"Checksum validation failed for the provided mnemonic."
|
7338
7397
|
);
|
7339
7398
|
}
|
@@ -7347,16 +7406,16 @@ var TestnetPRV = "0x04358394";
|
|
7347
7406
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7348
7407
|
function assertWordList(wordlist) {
|
7349
7408
|
if (wordlist.length !== 2048) {
|
7350
|
-
throw new
|
7351
|
-
|
7409
|
+
throw new import_errors19.FuelError(
|
7410
|
+
import_errors19.ErrorCode.INVALID_WORD_LIST,
|
7352
7411
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7353
7412
|
);
|
7354
7413
|
}
|
7355
7414
|
}
|
7356
7415
|
function assertEntropy(entropy) {
|
7357
7416
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7358
|
-
throw new
|
7359
|
-
|
7417
|
+
throw new import_errors19.FuelError(
|
7418
|
+
import_errors19.ErrorCode.INVALID_ENTROPY,
|
7360
7419
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7361
7420
|
);
|
7362
7421
|
}
|
@@ -7366,7 +7425,7 @@ function assertMnemonic(words) {
|
|
7366
7425
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7367
7426
|
", "
|
7368
7427
|
)}] words, but got ${words.length}.`;
|
7369
|
-
throw new
|
7428
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7370
7429
|
}
|
7371
7430
|
}
|
7372
7431
|
var Mnemonic = class {
|
@@ -7405,7 +7464,7 @@ var Mnemonic = class {
|
|
7405
7464
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7406
7465
|
const words = getWords(phrase);
|
7407
7466
|
assertMnemonic(words);
|
7408
|
-
return (0,
|
7467
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7409
7468
|
}
|
7410
7469
|
/**
|
7411
7470
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7413,7 +7472,7 @@ var Mnemonic = class {
|
|
7413
7472
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7414
7473
|
*/
|
7415
7474
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7416
|
-
const entropyBytes = (0,
|
7475
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7417
7476
|
assertWordList(wordlist);
|
7418
7477
|
assertEntropy(entropyBytes);
|
7419
7478
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7482,14 +7541,14 @@ var Mnemonic = class {
|
|
7482
7541
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7483
7542
|
*/
|
7484
7543
|
static masterKeysFromSeed(seed) {
|
7485
|
-
const seedArray = (0,
|
7544
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7486
7545
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7487
|
-
throw new
|
7488
|
-
|
7546
|
+
throw new import_errors19.FuelError(
|
7547
|
+
import_errors19.ErrorCode.INVALID_SEED,
|
7489
7548
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7490
7549
|
);
|
7491
7550
|
}
|
7492
|
-
return (0,
|
7551
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7493
7552
|
}
|
7494
7553
|
/**
|
7495
7554
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7500,22 +7559,22 @@ var Mnemonic = class {
|
|
7500
7559
|
*/
|
7501
7560
|
static seedToExtendedKey(seed, testnet = false) {
|
7502
7561
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7503
|
-
const prefix = (0,
|
7562
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7504
7563
|
const depth = "0x00";
|
7505
7564
|
const fingerprint = "0x00000000";
|
7506
7565
|
const index = "0x00000000";
|
7507
7566
|
const chainCode = masterKey.slice(32);
|
7508
7567
|
const privateKey = masterKey.slice(0, 32);
|
7509
|
-
const extendedKey = (0,
|
7568
|
+
const extendedKey = (0, import_utils33.concat)([
|
7510
7569
|
prefix,
|
7511
7570
|
depth,
|
7512
7571
|
fingerprint,
|
7513
7572
|
index,
|
7514
7573
|
chainCode,
|
7515
|
-
(0,
|
7574
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7516
7575
|
]);
|
7517
7576
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7518
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7577
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7519
7578
|
}
|
7520
7579
|
/**
|
7521
7580
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7530,7 +7589,7 @@ var Mnemonic = class {
|
|
7530
7589
|
* @returns A randomly generated mnemonic
|
7531
7590
|
*/
|
7532
7591
|
static generate(size = 32, extraEntropy = "") {
|
7533
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7592
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7534
7593
|
return Mnemonic.entropyToMnemonic(entropy);
|
7535
7594
|
}
|
7536
7595
|
};
|
@@ -7538,12 +7597,12 @@ var mnemonic_default = Mnemonic;
|
|
7538
7597
|
|
7539
7598
|
// src/hdwallet/hdwallet.ts
|
7540
7599
|
var HARDENED_INDEX = 2147483648;
|
7541
|
-
var MainnetPRV2 = (0,
|
7542
|
-
var MainnetPUB = (0,
|
7543
|
-
var TestnetPRV2 = (0,
|
7544
|
-
var TestnetPUB = (0,
|
7600
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7601
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7602
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7603
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7545
7604
|
function base58check(data) {
|
7546
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7605
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7547
7606
|
}
|
7548
7607
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7549
7608
|
if (isPublic) {
|
@@ -7552,17 +7611,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7552
7611
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7553
7612
|
}
|
7554
7613
|
function isPublicExtendedKey(extendedKey) {
|
7555
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7614
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7556
7615
|
}
|
7557
7616
|
function isValidExtendedKey(extendedKey) {
|
7558
7617
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7559
|
-
(0,
|
7618
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7560
7619
|
);
|
7561
7620
|
}
|
7562
7621
|
function parsePath(path2, depth = 0) {
|
7563
7622
|
const components = path2.split("/");
|
7564
7623
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7565
|
-
throw new
|
7624
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7566
7625
|
}
|
7567
7626
|
if (components[0] === "m") {
|
7568
7627
|
components.shift();
|
@@ -7574,8 +7633,8 @@ function parsePath(path2, depth = 0) {
|
|
7574
7633
|
var HDWallet = class {
|
7575
7634
|
depth = 0;
|
7576
7635
|
index = 0;
|
7577
|
-
fingerprint = (0,
|
7578
|
-
parentFingerprint = (0,
|
7636
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7637
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7579
7638
|
privateKey;
|
7580
7639
|
publicKey;
|
7581
7640
|
chainCode;
|
@@ -7587,16 +7646,16 @@ var HDWallet = class {
|
|
7587
7646
|
constructor(config) {
|
7588
7647
|
if (config.privateKey) {
|
7589
7648
|
const signer = new Signer(config.privateKey);
|
7590
|
-
this.publicKey = (0,
|
7591
|
-
this.privateKey = (0,
|
7649
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7650
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7592
7651
|
} else {
|
7593
7652
|
if (!config.publicKey) {
|
7594
|
-
throw new
|
7595
|
-
|
7653
|
+
throw new import_errors20.FuelError(
|
7654
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7596
7655
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7597
7656
|
);
|
7598
7657
|
}
|
7599
|
-
this.publicKey = (0,
|
7658
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7600
7659
|
}
|
7601
7660
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7602
7661
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7615,28 +7674,28 @@ var HDWallet = class {
|
|
7615
7674
|
* @returns A new instance of HDWallet on the derived index
|
7616
7675
|
*/
|
7617
7676
|
deriveIndex(index) {
|
7618
|
-
const privateKey = this.privateKey && (0,
|
7619
|
-
const publicKey = (0,
|
7620
|
-
const chainCode = (0,
|
7677
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7678
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7679
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7621
7680
|
const data = new Uint8Array(37);
|
7622
7681
|
if (index & HARDENED_INDEX) {
|
7623
7682
|
if (!privateKey) {
|
7624
|
-
throw new
|
7625
|
-
|
7683
|
+
throw new import_errors20.FuelError(
|
7684
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7626
7685
|
"Cannot derive a hardened index without a private Key."
|
7627
7686
|
);
|
7628
7687
|
}
|
7629
7688
|
data.set(privateKey, 1);
|
7630
7689
|
} else {
|
7631
|
-
data.set((0,
|
7690
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7632
7691
|
}
|
7633
|
-
data.set((0,
|
7634
|
-
const bytes = (0,
|
7692
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7693
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7635
7694
|
const IL = bytes.slice(0, 32);
|
7636
7695
|
const IR = bytes.slice(32);
|
7637
7696
|
if (privateKey) {
|
7638
7697
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7639
|
-
const ki = (0,
|
7698
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7640
7699
|
return new HDWallet({
|
7641
7700
|
privateKey: ki,
|
7642
7701
|
chainCode: IR,
|
@@ -7645,7 +7704,7 @@ var HDWallet = class {
|
|
7645
7704
|
parentFingerprint: this.fingerprint
|
7646
7705
|
});
|
7647
7706
|
}
|
7648
|
-
const signer = new Signer((0,
|
7707
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7649
7708
|
const Ki = signer.addPoint(publicKey);
|
7650
7709
|
return new HDWallet({
|
7651
7710
|
publicKey: Ki,
|
@@ -7674,18 +7733,18 @@ var HDWallet = class {
|
|
7674
7733
|
*/
|
7675
7734
|
toExtendedKey(isPublic = false, testnet = false) {
|
7676
7735
|
if (this.depth >= 256) {
|
7677
|
-
throw new
|
7678
|
-
|
7736
|
+
throw new import_errors20.FuelError(
|
7737
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7679
7738
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7680
7739
|
);
|
7681
7740
|
}
|
7682
7741
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7683
|
-
const depth = (0,
|
7742
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7684
7743
|
const parentFingerprint = this.parentFingerprint;
|
7685
|
-
const index = (0,
|
7744
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7686
7745
|
const chainCode = this.chainCode;
|
7687
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7688
|
-
const extendedKey = (0,
|
7746
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7747
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7689
7748
|
return base58check(extendedKey);
|
7690
7749
|
}
|
7691
7750
|
/**
|
@@ -7697,34 +7756,34 @@ var HDWallet = class {
|
|
7697
7756
|
static fromSeed(seed) {
|
7698
7757
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7699
7758
|
return new HDWallet({
|
7700
|
-
chainCode: (0,
|
7701
|
-
privateKey: (0,
|
7759
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7760
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7702
7761
|
});
|
7703
7762
|
}
|
7704
7763
|
static fromExtendedKey(extendedKey) {
|
7705
7764
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7706
|
-
const bytes = (0,
|
7765
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7707
7766
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7708
7767
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7709
|
-
throw new
|
7768
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7710
7769
|
}
|
7711
7770
|
if (!validChecksum) {
|
7712
|
-
throw new
|
7771
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7713
7772
|
}
|
7714
7773
|
const depth = bytes[4];
|
7715
|
-
const parentFingerprint = (0,
|
7716
|
-
const index = parseInt((0,
|
7717
|
-
const chainCode = (0,
|
7774
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7775
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7776
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7718
7777
|
const key = bytes.slice(45, 78);
|
7719
7778
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7720
|
-
throw new
|
7721
|
-
|
7779
|
+
throw new import_errors20.FuelError(
|
7780
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7722
7781
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7723
7782
|
);
|
7724
7783
|
}
|
7725
7784
|
if (isPublicExtendedKey(bytes)) {
|
7726
7785
|
if (key[0] !== 3) {
|
7727
|
-
throw new
|
7786
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
7728
7787
|
}
|
7729
7788
|
return new HDWallet({
|
7730
7789
|
publicKey: key,
|
@@ -7735,7 +7794,7 @@ var HDWallet = class {
|
|
7735
7794
|
});
|
7736
7795
|
}
|
7737
7796
|
if (key[0] !== 0) {
|
7738
|
-
throw new
|
7797
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
7739
7798
|
}
|
7740
7799
|
return new HDWallet({
|
7741
7800
|
privateKey: key.slice(1),
|
@@ -7928,9 +7987,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7928
7987
|
};
|
7929
7988
|
|
7930
7989
|
// src/test-utils/launchNode.ts
|
7931
|
-
var
|
7932
|
-
var
|
7933
|
-
var
|
7990
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
7991
|
+
var import_math21 = require("@fuel-ts/math");
|
7992
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7934
7993
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7935
7994
|
var import_child_process = require("child_process");
|
7936
7995
|
var import_crypto5 = require("crypto");
|
@@ -7988,7 +8047,7 @@ var launchNode = async ({
|
|
7988
8047
|
"--poa-instant"
|
7989
8048
|
]);
|
7990
8049
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7991
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8050
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
7992
8051
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7993
8052
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7994
8053
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8014,21 +8073,21 @@ var launchNode = async ({
|
|
8014
8073
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8015
8074
|
}
|
8016
8075
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8017
|
-
let chainConfig =
|
8076
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8018
8077
|
if (!process.env.GENESIS_SECRET) {
|
8019
8078
|
const pk = Signer.generatePrivateKey();
|
8020
8079
|
const signer = new Signer(pk);
|
8021
|
-
process.env.GENESIS_SECRET = (0,
|
8080
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8022
8081
|
chainConfig = {
|
8023
|
-
...
|
8082
|
+
...import_utils36.defaultChainConfig,
|
8024
8083
|
initial_state: {
|
8025
|
-
...
|
8084
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8026
8085
|
coins: [
|
8027
|
-
...
|
8086
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8028
8087
|
{
|
8029
8088
|
owner: signer.address.toHexString(),
|
8030
|
-
amount: (0,
|
8031
|
-
asset_id:
|
8089
|
+
amount: (0, import_math21.toHex)(1e9),
|
8090
|
+
asset_id: import_configs13.BaseAssetId
|
8032
8091
|
}
|
8033
8092
|
]
|
8034
8093
|
}
|
@@ -8094,10 +8153,9 @@ var launchNode = async ({
|
|
8094
8153
|
})
|
8095
8154
|
);
|
8096
8155
|
var generateWallets = async (count, provider) => {
|
8097
|
-
const baseAssetId = provider.getBaseAssetId();
|
8098
8156
|
const wallets = [];
|
8099
8157
|
for (let i = 0; i < count; i += 1) {
|
8100
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8158
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8101
8159
|
wallets.push(wallet);
|
8102
8160
|
}
|
8103
8161
|
return wallets;
|