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