@fuel-ts/account 0.0.0-rc-1976-20240410143455 → 0.0.0-rc-2034-20240410172045
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 +95 -96
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +157 -155
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -97
- 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 +13 -9
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.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/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +98 -102
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +158 -159
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +101 -102
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -62,12 +62,14 @@ 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 import_configs12 = require("@fuel-ts/address/configs");
|
65
66
|
var import_errors16 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
68
|
var import_math18 = require("@fuel-ts/math");
|
68
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);
|
@@ -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");
|
@@ -1063,7 +1065,7 @@ var inputify = (value) => {
|
|
1063
1065
|
return {
|
1064
1066
|
type: import_transactions.InputType.Coin,
|
1065
1067
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1066
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1068
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 33)),
|
1067
1069
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1068
1070
|
amount: (0, import_math2.bn)(value.amount),
|
1069
1071
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -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,7 +1184,8 @@ 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
|
1187
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1188
|
+
var import_crypto = require("@fuel-ts/crypto");
|
1186
1189
|
var import_math7 = require("@fuel-ts/math");
|
1187
1190
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1191
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1191,13 +1194,13 @@ var import_utils9 = require("@fuel-ts/utils");
|
|
1191
1194
|
var isCoin = (resource) => "id" in resource;
|
1192
1195
|
|
1193
1196
|
// src/providers/utils/receipts.ts
|
1194
|
-
var
|
1197
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1195
1198
|
var import_errors5 = require("@fuel-ts/errors");
|
1196
1199
|
var import_math4 = require("@fuel-ts/math");
|
1197
1200
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1198
|
-
var
|
1201
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1199
1202
|
var import_utils5 = require("@fuel-ts/utils");
|
1200
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1203
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1201
1204
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1202
1205
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1203
1206
|
(memo, receipt) => {
|
@@ -1214,7 +1217,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1214
1217
|
missingOutputContractIds: []
|
1215
1218
|
}
|
1216
1219
|
);
|
1217
|
-
var hexOrZero = (hex) => hex ||
|
1220
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1218
1221
|
function assembleReceiptByType(receipt) {
|
1219
1222
|
const { receiptType } = receipt;
|
1220
1223
|
switch (receiptType) {
|
@@ -1519,16 +1522,16 @@ function sleep(time) {
|
|
1519
1522
|
var import_errors7 = require("@fuel-ts/errors");
|
1520
1523
|
var import_math6 = require("@fuel-ts/math");
|
1521
1524
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1522
|
-
var
|
1525
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1523
1526
|
var assemblePanicError = (status) => {
|
1524
1527
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1525
1528
|
const reason = status.reason;
|
1526
|
-
if (
|
1529
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1527
1530
|
errorMessage = `${errorMessage}
|
1528
1531
|
|
1529
1532
|
You can read more about this error at:
|
1530
1533
|
|
1531
|
-
${
|
1534
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1532
1535
|
}
|
1533
1536
|
return { errorMessage, reason };
|
1534
1537
|
};
|
@@ -1540,28 +1543,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1540
1543
|
if (revertReceipt) {
|
1541
1544
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1542
1545
|
switch (reasonHex) {
|
1543
|
-
case
|
1546
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1544
1547
|
reason = "require";
|
1545
1548
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1546
1549
|
break;
|
1547
1550
|
}
|
1548
|
-
case
|
1551
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1549
1552
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1550
1553
|
reason = "assert_eq";
|
1551
1554
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1552
1555
|
break;
|
1553
1556
|
}
|
1554
|
-
case
|
1557
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1555
1558
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1556
1559
|
reason = "assert_ne";
|
1557
1560
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1558
1561
|
break;
|
1559
1562
|
}
|
1560
|
-
case
|
1563
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1561
1564
|
reason = "assert";
|
1562
1565
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1563
1566
|
break;
|
1564
|
-
case
|
1567
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1565
1568
|
reason = "MissingOutputChange";
|
1566
1569
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1567
1570
|
break;
|
@@ -1623,8 +1626,6 @@ var BaseTransactionRequest = class {
|
|
1623
1626
|
outputs = [];
|
1624
1627
|
/** List of witnesses */
|
1625
1628
|
witnesses = [];
|
1626
|
-
/** Base asset ID - should be fetched from the chain */
|
1627
|
-
baseAssetId;
|
1628
1629
|
/**
|
1629
1630
|
* Constructor for initializing a base transaction request.
|
1630
1631
|
*
|
@@ -1637,9 +1638,8 @@ var BaseTransactionRequest = class {
|
|
1637
1638
|
witnessLimit,
|
1638
1639
|
inputs,
|
1639
1640
|
outputs,
|
1640
|
-
witnesses
|
1641
|
-
|
1642
|
-
}) {
|
1641
|
+
witnesses
|
1642
|
+
} = {}) {
|
1643
1643
|
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1644
1644
|
this.maturity = maturity ?? 0;
|
1645
1645
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
@@ -1647,7 +1647,6 @@ var BaseTransactionRequest = class {
|
|
1647
1647
|
this.inputs = inputs ?? [];
|
1648
1648
|
this.outputs = outputs ?? [];
|
1649
1649
|
this.witnesses = witnesses ?? [];
|
1650
|
-
this.baseAssetId = baseAssetId;
|
1651
1650
|
}
|
1652
1651
|
static getPolicyMeta(req) {
|
1653
1652
|
let policyTypes = 0;
|
@@ -1740,7 +1739,7 @@ var BaseTransactionRequest = class {
|
|
1740
1739
|
* @returns The index of the created witness.
|
1741
1740
|
*/
|
1742
1741
|
addEmptyWitness() {
|
1743
|
-
this.addWitness((0, import_utils9.concat)([
|
1742
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1744
1743
|
return this.witnesses.length - 1;
|
1745
1744
|
}
|
1746
1745
|
/**
|
@@ -1871,9 +1870,11 @@ var BaseTransactionRequest = class {
|
|
1871
1870
|
*
|
1872
1871
|
* @param message - Message resource.
|
1873
1872
|
* @param predicate - Predicate bytes.
|
1873
|
+
* @param predicateData - Predicate data bytes.
|
1874
1874
|
*/
|
1875
1875
|
addMessageInput(message, predicate) {
|
1876
1876
|
const { recipient, sender, amount } = message;
|
1877
|
+
const assetId = import_configs7.BaseAssetId;
|
1877
1878
|
let witnessIndex;
|
1878
1879
|
if (predicate) {
|
1879
1880
|
witnessIndex = 0;
|
@@ -1893,7 +1894,7 @@ var BaseTransactionRequest = class {
|
|
1893
1894
|
predicate: predicate?.bytes
|
1894
1895
|
};
|
1895
1896
|
this.pushInput(input);
|
1896
|
-
this.addChangeOutput(recipient,
|
1897
|
+
this.addChangeOutput(recipient, assetId);
|
1897
1898
|
}
|
1898
1899
|
/**
|
1899
1900
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1954,12 +1955,12 @@ var BaseTransactionRequest = class {
|
|
1954
1955
|
* @param amount - Amount of coin.
|
1955
1956
|
* @param assetId - Asset ID of coin.
|
1956
1957
|
*/
|
1957
|
-
addCoinOutput(to, amount, assetId) {
|
1958
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1958
1959
|
this.pushOutput({
|
1959
1960
|
type: import_transactions6.OutputType.Coin,
|
1960
1961
|
to: (0, import_address.addressify)(to).toB256(),
|
1961
1962
|
amount,
|
1962
|
-
assetId
|
1963
|
+
assetId
|
1963
1964
|
});
|
1964
1965
|
return this;
|
1965
1966
|
}
|
@@ -1986,7 +1987,7 @@ var BaseTransactionRequest = class {
|
|
1986
1987
|
* @param to - Address of the owner.
|
1987
1988
|
* @param assetId - Asset ID of coin.
|
1988
1989
|
*/
|
1989
|
-
addChangeOutput(to, assetId) {
|
1990
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1990
1991
|
const changeOutput = this.getChangeOutputs().find(
|
1991
1992
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1992
1993
|
);
|
@@ -1994,7 +1995,7 @@ var BaseTransactionRequest = class {
|
|
1994
1995
|
this.pushOutput({
|
1995
1996
|
type: import_transactions6.OutputType.Change,
|
1996
1997
|
to: (0, import_address.addressify)(to).toB256(),
|
1997
|
-
assetId
|
1998
|
+
assetId
|
1998
1999
|
});
|
1999
2000
|
}
|
2000
2001
|
}
|
@@ -2045,12 +2046,6 @@ var BaseTransactionRequest = class {
|
|
2045
2046
|
* @param quantities - CoinQuantity Array.
|
2046
2047
|
*/
|
2047
2048
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2048
|
-
let idCounter = 0;
|
2049
|
-
const generateId = () => {
|
2050
|
-
const counterString = String(idCounter++);
|
2051
|
-
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2052
|
-
return id;
|
2053
|
-
};
|
2054
2049
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2055
2050
|
if ("assetId" in input) {
|
2056
2051
|
return input.assetId === assetId;
|
@@ -2060,12 +2055,12 @@ var BaseTransactionRequest = class {
|
|
2060
2055
|
const updateAssetInput = (assetId, quantity) => {
|
2061
2056
|
const assetInput = findAssetInput(assetId);
|
2062
2057
|
if (assetInput && "assetId" in assetInput) {
|
2063
|
-
assetInput.id =
|
2058
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(33));
|
2064
2059
|
assetInput.amount = quantity;
|
2065
2060
|
} else {
|
2066
2061
|
this.addResources([
|
2067
2062
|
{
|
2068
|
-
id:
|
2063
|
+
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(33)),
|
2069
2064
|
amount: quantity,
|
2070
2065
|
assetId,
|
2071
2066
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2076,7 +2071,7 @@ var BaseTransactionRequest = class {
|
|
2076
2071
|
]);
|
2077
2072
|
}
|
2078
2073
|
};
|
2079
|
-
updateAssetInput(
|
2074
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2080
2075
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2081
2076
|
}
|
2082
2077
|
/**
|
@@ -2126,13 +2121,13 @@ var BaseTransactionRequest = class {
|
|
2126
2121
|
};
|
2127
2122
|
|
2128
2123
|
// src/providers/transaction-request/create-transaction-request.ts
|
2129
|
-
var
|
2124
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2130
2125
|
var import_math9 = require("@fuel-ts/math");
|
2131
2126
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2132
2127
|
var import_utils13 = require("@fuel-ts/utils");
|
2133
2128
|
|
2134
2129
|
// src/providers/transaction-request/hash-transaction.ts
|
2135
|
-
var
|
2130
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2136
2131
|
var import_hasher = require("@fuel-ts/hasher");
|
2137
2132
|
var import_math8 = require("@fuel-ts/math");
|
2138
2133
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2141,7 +2136,7 @@ var import_ramda2 = require("ramda");
|
|
2141
2136
|
function hashTransaction(transactionRequest, chainId) {
|
2142
2137
|
const transaction = transactionRequest.toTransaction();
|
2143
2138
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2144
|
-
transaction.receiptsRoot =
|
2139
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2145
2140
|
}
|
2146
2141
|
transaction.inputs = transaction.inputs.map((input) => {
|
2147
2142
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2163,10 +2158,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2163
2158
|
blockHeight: 0,
|
2164
2159
|
txIndex: 0
|
2165
2160
|
};
|
2166
|
-
inputClone.txID =
|
2161
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2167
2162
|
inputClone.outputIndex = 0;
|
2168
|
-
inputClone.balanceRoot =
|
2169
|
-
inputClone.stateRoot =
|
2163
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2164
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2170
2165
|
return inputClone;
|
2171
2166
|
}
|
2172
2167
|
default:
|
@@ -2177,8 +2172,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2177
2172
|
const outputClone = (0, import_ramda2.clone)(output);
|
2178
2173
|
switch (outputClone.type) {
|
2179
2174
|
case import_transactions7.OutputType.Contract: {
|
2180
|
-
outputClone.balanceRoot =
|
2181
|
-
outputClone.stateRoot =
|
2175
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2176
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2182
2177
|
return outputClone;
|
2183
2178
|
}
|
2184
2179
|
case import_transactions7.OutputType.Change: {
|
@@ -2186,9 +2181,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2186
2181
|
return outputClone;
|
2187
2182
|
}
|
2188
2183
|
case import_transactions7.OutputType.Variable: {
|
2189
|
-
outputClone.to =
|
2184
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2190
2185
|
outputClone.amount = (0, import_math8.bn)(0);
|
2191
|
-
outputClone.assetId =
|
2186
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2192
2187
|
return outputClone;
|
2193
2188
|
}
|
2194
2189
|
default:
|
@@ -2246,10 +2241,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2246
2241
|
*
|
2247
2242
|
* @param createTransactionRequestLike - The initial values for the instance
|
2248
2243
|
*/
|
2249
|
-
constructor({
|
2244
|
+
constructor({
|
2245
|
+
bytecodeWitnessIndex,
|
2246
|
+
salt,
|
2247
|
+
storageSlots,
|
2248
|
+
...rest
|
2249
|
+
} = {}) {
|
2250
2250
|
super(rest);
|
2251
2251
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2252
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2252
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2253
2253
|
this.storageSlots = [...storageSlots ?? []];
|
2254
2254
|
}
|
2255
2255
|
/**
|
@@ -2267,7 +2267,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2267
2267
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2268
2268
|
bytecodeWitnessIndex,
|
2269
2269
|
storageSlotsCount: storageSlots.length,
|
2270
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2270
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2271
2271
|
storageSlots
|
2272
2272
|
};
|
2273
2273
|
}
|
@@ -2317,7 +2317,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2317
2317
|
// src/providers/transaction-request/script-transaction-request.ts
|
2318
2318
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2319
2319
|
var import_address2 = require("@fuel-ts/address");
|
2320
|
-
var
|
2320
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2321
2321
|
var import_math10 = require("@fuel-ts/math");
|
2322
2322
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2323
2323
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2370,7 +2370,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2370
2370
|
*
|
2371
2371
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2372
2372
|
*/
|
2373
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2373
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2374
2374
|
super(rest);
|
2375
2375
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2376
2376
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2391,7 +2391,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2391
|
...super.getBaseTransaction(),
|
2392
2392
|
scriptLength: script.length,
|
2393
2393
|
scriptDataLength: scriptData.length,
|
2394
|
-
receiptsRoot:
|
2394
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2395
2395
|
script: (0, import_utils15.hexlify)(script),
|
2396
2396
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2397
2397
|
};
|
@@ -2623,7 +2623,7 @@ var calculateTransactionFee = (params) => {
|
|
2623
2623
|
};
|
2624
2624
|
|
2625
2625
|
// src/providers/transaction-summary/operations.ts
|
2626
|
-
var
|
2626
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2627
2627
|
var import_errors11 = require("@fuel-ts/errors");
|
2628
2628
|
var import_math13 = require("@fuel-ts/math");
|
2629
2629
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -2921,7 +2921,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2921
2921
|
const { to: toAddress, assetId, amount } = receipt;
|
2922
2922
|
let { from: fromAddress } = receipt;
|
2923
2923
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2924
|
-
if (
|
2924
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2925
2925
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2926
2926
|
fromAddress = change?.to || fromAddress;
|
2927
2927
|
}
|
@@ -3498,7 +3498,6 @@ var processGqlChain = (chain) => {
|
|
3498
3498
|
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3499
3499
|
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3500
3500
|
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3501
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3502
3501
|
gasCosts
|
3503
3502
|
},
|
3504
3503
|
gasCosts,
|
@@ -3741,17 +3740,6 @@ var _Provider = class {
|
|
3741
3740
|
} = this.getChain();
|
3742
3741
|
return chainId.toNumber();
|
3743
3742
|
}
|
3744
|
-
/**
|
3745
|
-
* Returns the base asset ID
|
3746
|
-
*
|
3747
|
-
* @returns A promise that resolves to the base asset ID
|
3748
|
-
*/
|
3749
|
-
getBaseAssetId() {
|
3750
|
-
const {
|
3751
|
-
consensusParameters: { baseAssetId }
|
3752
|
-
} = this.getChain();
|
3753
|
-
return baseAssetId;
|
3754
|
-
}
|
3755
3743
|
/**
|
3756
3744
|
* Submits a transaction to the chain to be executed.
|
3757
3745
|
*
|
@@ -3902,6 +3890,36 @@ var _Provider = class {
|
|
3902
3890
|
missingContractIds
|
3903
3891
|
};
|
3904
3892
|
}
|
3893
|
+
/**
|
3894
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3895
|
+
* @param transactionRequest - The transaction request object.
|
3896
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3897
|
+
*/
|
3898
|
+
estimateTxGasAndFee(params) {
|
3899
|
+
const { transactionRequest } = params;
|
3900
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3901
|
+
const chainInfo = this.getChain();
|
3902
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3903
|
+
transactionRequest.gasPrice = gasPrice;
|
3904
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3905
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3906
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3907
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3908
|
+
transactionRequest.gasLimit = minGas;
|
3909
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3910
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3911
|
+
);
|
3912
|
+
}
|
3913
|
+
}
|
3914
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3915
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3916
|
+
return {
|
3917
|
+
minGas,
|
3918
|
+
minFee,
|
3919
|
+
maxGas,
|
3920
|
+
maxFee
|
3921
|
+
};
|
3922
|
+
}
|
3905
3923
|
/**
|
3906
3924
|
* Executes a signed transaction without applying the states changes
|
3907
3925
|
* on the chain.
|
@@ -3949,17 +3967,16 @@ var _Provider = class {
|
|
3949
3967
|
signatureCallback
|
3950
3968
|
} = {}) {
|
3951
3969
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3952
|
-
const
|
3953
|
-
const
|
3954
|
-
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3970
|
+
const { minGasPrice } = this.getGasConfig();
|
3971
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3955
3972
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3956
3973
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3957
3974
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3958
3975
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3976
|
+
if (isScriptTransaction) {
|
3977
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3978
|
+
}
|
3959
3979
|
if (estimatePredicates) {
|
3960
|
-
if (isScriptTransaction) {
|
3961
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3962
|
-
}
|
3963
3980
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3964
3981
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3965
3982
|
}
|
@@ -3968,36 +3985,34 @@ var _Provider = class {
|
|
3968
3985
|
if (signatureCallback && isScriptTransaction) {
|
3969
3986
|
await signatureCallback(txRequestClone);
|
3970
3987
|
}
|
3971
|
-
|
3972
|
-
|
3988
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3989
|
+
transactionRequest: txRequestClone
|
3990
|
+
});
|
3973
3991
|
let receipts = [];
|
3974
3992
|
let missingContractIds = [];
|
3975
3993
|
let outputVariables = 0;
|
3994
|
+
let gasUsed = (0, import_math15.bn)(0);
|
3976
3995
|
if (isScriptTransaction && estimateTxDependencies) {
|
3977
3996
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3978
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3979
3997
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3980
3998
|
receipts = result.receipts;
|
3981
3999
|
outputVariables = result.outputVariables;
|
3982
4000
|
missingContractIds = result.missingContractIds;
|
4001
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4002
|
+
txRequestClone.gasLimit = gasUsed;
|
4003
|
+
txRequestClone.gasPrice = setGasPrice;
|
4004
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4005
|
+
transactionRequest: txRequestClone
|
4006
|
+
}));
|
3983
4007
|
}
|
3984
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3985
|
-
const usedFee = calculatePriceWithFactor(
|
3986
|
-
gasUsed,
|
3987
|
-
gasPrice,
|
3988
|
-
gasPriceFactor
|
3989
|
-
).normalizeZeroToOne();
|
3990
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3991
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3992
4008
|
return {
|
3993
4009
|
requiredQuantities: allQuantities,
|
3994
4010
|
receipts,
|
3995
4011
|
gasUsed,
|
3996
4012
|
minGasPrice,
|
3997
|
-
gasPrice,
|
4013
|
+
gasPrice: setGasPrice,
|
3998
4014
|
minGas,
|
3999
4015
|
maxGas,
|
4000
|
-
usedFee,
|
4001
4016
|
minFee,
|
4002
4017
|
maxFee,
|
4003
4018
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4622,9 +4637,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4622
4637
|
* @param assetId - The asset ID to check the balance for.
|
4623
4638
|
* @returns A promise that resolves to the balance amount.
|
4624
4639
|
*/
|
4625
|
-
async getBalance(assetId) {
|
4626
|
-
const
|
4627
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4640
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4641
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4628
4642
|
return amount;
|
4629
4643
|
}
|
4630
4644
|
/**
|
@@ -4662,10 +4676,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4662
4676
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4663
4677
|
*/
|
4664
4678
|
async fund(request, coinQuantities, fee) {
|
4665
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4666
4679
|
const updatedQuantities = addAmountToAsset({
|
4667
4680
|
amount: (0, import_math18.bn)(fee),
|
4668
|
-
assetId:
|
4681
|
+
assetId: import_configs12.BaseAssetId,
|
4669
4682
|
coinQuantities
|
4670
4683
|
});
|
4671
4684
|
const quantitiesDict = {};
|
@@ -4689,8 +4702,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4689
4702
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
4703
|
cachedUtxos.push(input.id);
|
4691
4704
|
}
|
4692
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4693
|
-
quantitiesDict[
|
4705
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4706
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4694
4707
|
cachedMessages.push(input.nonce);
|
4695
4708
|
}
|
4696
4709
|
}
|
@@ -4722,13 +4735,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4722
4735
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4723
4736
|
* @returns A promise that resolves to the prepared transaction request.
|
4724
4737
|
*/
|
4725
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4738
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4726
4739
|
const { minGasPrice } = this.provider.getGasConfig();
|
4727
|
-
const
|
4728
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4729
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4740
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4730
4741
|
const request = new ScriptTransactionRequest(params);
|
4731
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
4742
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4732
4743
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4733
4744
|
estimateTxDependencies: true,
|
4734
4745
|
resourcesOwner: this
|
@@ -4754,15 +4765,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4754
4765
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4755
4766
|
* @returns A promise that resolves to the transaction response.
|
4756
4767
|
*/
|
4757
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4768
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4758
4769
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4759
4770
|
throw new import_errors16.FuelError(
|
4760
4771
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4761
4772
|
"Transfer amount must be a positive number."
|
4762
4773
|
);
|
4763
4774
|
}
|
4764
|
-
const
|
4765
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4775
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4766
4776
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4767
4777
|
}
|
4768
4778
|
/**
|
@@ -4774,7 +4784,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4774
4784
|
* @param txParams - The optional transaction parameters.
|
4775
4785
|
* @returns A promise that resolves to the transaction response.
|
4776
4786
|
*/
|
4777
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4787
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4778
4788
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4779
4789
|
throw new import_errors16.FuelError(
|
4780
4790
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -4783,13 +4793,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4783
4793
|
}
|
4784
4794
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4785
4795
|
const { minGasPrice } = this.provider.getGasConfig();
|
4786
|
-
const
|
4787
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4788
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4796
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4789
4797
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4790
4798
|
hexlifiedContractId: contractAddress.toB256(),
|
4791
4799
|
amountToTransfer: (0, import_math18.bn)(amount),
|
4792
|
-
assetId
|
4800
|
+
assetId
|
4793
4801
|
});
|
4794
4802
|
const request = new ScriptTransactionRequest({
|
4795
4803
|
...params,
|
@@ -4799,7 +4807,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4799
4807
|
request.addContractInputAndOutput(contractAddress);
|
4800
4808
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4801
4809
|
request,
|
4802
|
-
[{ amount: (0, import_math18.bn)(amount), assetId: String(
|
4810
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4803
4811
|
);
|
4804
4812
|
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4805
4813
|
this.validateGas({
|
@@ -4821,7 +4829,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4821
4829
|
*/
|
4822
4830
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4823
4831
|
const { minGasPrice } = this.provider.getGasConfig();
|
4824
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4825
4832
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4826
4833
|
const recipientDataArray = (0, import_utils28.arrayify)(
|
4827
4834
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4834,14 +4841,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4834
4841
|
...recipientDataArray,
|
4835
4842
|
...amountDataArray
|
4836
4843
|
]);
|
4837
|
-
const params = {
|
4838
|
-
script,
|
4839
|
-
gasPrice: minGasPrice,
|
4840
|
-
baseAssetId,
|
4841
|
-
...txParams
|
4842
|
-
};
|
4844
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4843
4845
|
const request = new ScriptTransactionRequest(params);
|
4844
|
-
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId:
|
4846
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4845
4847
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4846
4848
|
request,
|
4847
4849
|
forwardingQuantities
|
@@ -4934,7 +4936,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4934
4936
|
|
4935
4937
|
// src/signer/signer.ts
|
4936
4938
|
var import_address5 = require("@fuel-ts/address");
|
4937
|
-
var
|
4939
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
4938
4940
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4939
4941
|
var import_math19 = require("@fuel-ts/math");
|
4940
4942
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5027,7 +5029,7 @@ var Signer = class {
|
|
5027
5029
|
* @returns random 32-byte hashed
|
5028
5030
|
*/
|
5029
5031
|
static generatePrivateKey(entropy) {
|
5030
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5032
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5031
5033
|
}
|
5032
5034
|
/**
|
5033
5035
|
* Extended publicKey from a compact publicKey
|
@@ -5043,7 +5045,7 @@ var Signer = class {
|
|
5043
5045
|
|
5044
5046
|
// src/wallet/keystore-wallet.ts
|
5045
5047
|
var import_address6 = require("@fuel-ts/address");
|
5046
|
-
var
|
5048
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5047
5049
|
var import_errors17 = require("@fuel-ts/errors");
|
5048
5050
|
var import_utils30 = require("@fuel-ts/utils");
|
5049
5051
|
var import_uuid = require("uuid");
|
@@ -5059,22 +5061,22 @@ var removeHexPrefix = (hexString) => {
|
|
5059
5061
|
return hexString;
|
5060
5062
|
};
|
5061
5063
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5062
|
-
const privateKeyBuffer = (0,
|
5064
|
+
const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5063
5065
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5064
|
-
const salt = (0,
|
5065
|
-
const key = (0,
|
5066
|
-
password: (0,
|
5066
|
+
const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
|
5067
|
+
const key = (0, import_crypto3.scrypt)({
|
5068
|
+
password: (0, import_crypto3.bufferFromString)(password),
|
5067
5069
|
salt,
|
5068
5070
|
dklen: DEFAULT_KEY_SIZE,
|
5069
5071
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5070
5072
|
r: DEFAULT_KDF_PARAMS_R,
|
5071
5073
|
p: DEFAULT_KDF_PARAMS_P
|
5072
5074
|
});
|
5073
|
-
const iv = (0,
|
5074
|
-
const ciphertext = await (0,
|
5075
|
+
const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
|
5076
|
+
const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5075
5077
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5076
|
-
const macHashUint8Array = (0,
|
5077
|
-
const mac = (0,
|
5078
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5079
|
+
const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5078
5080
|
const keystore = {
|
5079
5081
|
id: (0, import_uuid.v4)(),
|
5080
5082
|
version: 3,
|
@@ -5082,15 +5084,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5082
5084
|
crypto: {
|
5083
5085
|
cipher: "aes-128-ctr",
|
5084
5086
|
mac,
|
5085
|
-
cipherparams: { iv: (0,
|
5086
|
-
ciphertext: (0,
|
5087
|
+
cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
|
5088
|
+
ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
|
5087
5089
|
kdf: "scrypt",
|
5088
5090
|
kdfparams: {
|
5089
5091
|
dklen: DEFAULT_KEY_SIZE,
|
5090
5092
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5091
5093
|
p: DEFAULT_KDF_PARAMS_P,
|
5092
5094
|
r: DEFAULT_KDF_PARAMS_R,
|
5093
|
-
salt: (0,
|
5095
|
+
salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
|
5094
5096
|
}
|
5095
5097
|
}
|
5096
5098
|
};
|
@@ -5106,11 +5108,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5106
5108
|
kdfparams: { dklen, n, r, p, salt }
|
5107
5109
|
}
|
5108
5110
|
} = keystoreWallet;
|
5109
|
-
const ciphertextBuffer = (0,
|
5110
|
-
const ivBuffer = (0,
|
5111
|
-
const saltBuffer = (0,
|
5112
|
-
const passwordBuffer = (0,
|
5113
|
-
const key = (0,
|
5111
|
+
const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
|
5112
|
+
const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
|
5113
|
+
const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
|
5114
|
+
const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
|
5115
|
+
const key = (0, import_crypto3.scrypt)({
|
5114
5116
|
password: passwordBuffer,
|
5115
5117
|
salt: saltBuffer,
|
5116
5118
|
n,
|
@@ -5119,15 +5121,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5119
5121
|
dklen
|
5120
5122
|
});
|
5121
5123
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5122
|
-
const macHashUint8Array = (0,
|
5123
|
-
const macHash = (0,
|
5124
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5125
|
+
const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5124
5126
|
if (mac !== macHash) {
|
5125
5127
|
throw new import_errors17.FuelError(
|
5126
5128
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5127
5129
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5128
5130
|
);
|
5129
5131
|
}
|
5130
|
-
const buffer = await (0,
|
5132
|
+
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5131
5133
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5132
5134
|
return privateKey;
|
5133
5135
|
}
|
@@ -5252,7 +5254,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5252
5254
|
var import_ethers3 = require("ethers");
|
5253
5255
|
|
5254
5256
|
// src/mnemonic/mnemonic.ts
|
5255
|
-
var
|
5257
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5256
5258
|
var import_errors19 = require("@fuel-ts/errors");
|
5257
5259
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5258
5260
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -7607,7 +7609,7 @@ var Mnemonic = class {
|
|
7607
7609
|
* @returns A randomly generated mnemonic
|
7608
7610
|
*/
|
7609
7611
|
static generate(size = 32, extraEntropy = "") {
|
7610
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
7612
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7611
7613
|
return Mnemonic.entropyToMnemonic(entropy);
|
7612
7614
|
}
|
7613
7615
|
};
|
@@ -7978,17 +7980,15 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7978
7980
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7979
7981
|
|
7980
7982
|
// src/test-utils/seedTestWallet.ts
|
7981
|
-
var
|
7983
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
7982
7984
|
var seedTestWallet = async (wallet, quantities) => {
|
7983
7985
|
const genesisWallet = new WalletUnlocked(
|
7984
|
-
process.env.GENESIS_SECRET || (0,
|
7986
|
+
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7985
7987
|
wallet.provider
|
7986
7988
|
);
|
7987
7989
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7988
7990
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7989
|
-
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7990
7991
|
const request = new ScriptTransactionRequest({
|
7991
|
-
baseAssetId,
|
7992
7992
|
gasLimit: 1e4,
|
7993
7993
|
gasPrice: minGasPrice
|
7994
7994
|
});
|
@@ -8007,12 +8007,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8007
8007
|
};
|
8008
8008
|
|
8009
8009
|
// src/test-utils/launchNode.ts
|
8010
|
-
var
|
8010
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8011
8011
|
var import_math21 = require("@fuel-ts/math");
|
8012
8012
|
var import_utils36 = require("@fuel-ts/utils");
|
8013
8013
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8014
8014
|
var import_child_process = require("child_process");
|
8015
|
-
var
|
8015
|
+
var import_crypto6 = require("crypto");
|
8016
8016
|
var import_fs = require("fs");
|
8017
8017
|
var import_os = __toESM(require("os"));
|
8018
8018
|
var import_path = __toESM(require("path"));
|
@@ -8084,7 +8084,7 @@ var launchNode = async ({
|
|
8084
8084
|
})).toString();
|
8085
8085
|
let chainConfigPathToUse;
|
8086
8086
|
const prefix = basePath || import_os.default.tmpdir();
|
8087
|
-
const suffix = basePath ? "" : (0,
|
8087
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8088
8088
|
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8089
8089
|
if (chainConfigPath) {
|
8090
8090
|
chainConfigPathToUse = chainConfigPath;
|
@@ -8107,7 +8107,7 @@ var launchNode = async ({
|
|
8107
8107
|
{
|
8108
8108
|
owner: signer.address.toHexString(),
|
8109
8109
|
amount: (0, import_math21.toHex)(1e9),
|
8110
|
-
asset_id:
|
8110
|
+
asset_id: import_configs13.BaseAssetId
|
8111
8111
|
}
|
8112
8112
|
]
|
8113
8113
|
}
|
@@ -8173,10 +8173,9 @@ var launchNode = async ({
|
|
8173
8173
|
})
|
8174
8174
|
);
|
8175
8175
|
var generateWallets = async (count, provider) => {
|
8176
|
-
const baseAssetId = provider.getBaseAssetId();
|
8177
8176
|
const wallets = [];
|
8178
8177
|
for (let i = 0; i < count; i += 1) {
|
8179
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8178
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8180
8179
|
wallets.push(wallet);
|
8181
8180
|
}
|
8182
8181
|
return wallets;
|