@fuel-ts/account 0.0.0-rc-1976-20240415100843 → 0.0.0-rc-2040-20240415161332
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 +75 -119
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +150 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -122
- 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 +2 -20
- 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 +78 -125
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +147 -194
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +80 -127
- 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,8 +1051,7 @@ var MemoryCache = class {
|
|
1049
1051
|
};
|
1050
1052
|
|
1051
1053
|
// src/providers/transaction-request/input.ts
|
1052
|
-
var
|
1053
|
-
var import_configs = require("@fuel-ts/address/configs");
|
1054
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1054
1055
|
var import_errors3 = require("@fuel-ts/errors");
|
1055
1056
|
var import_math2 = require("@fuel-ts/math");
|
1056
1057
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1063,8 +1064,8 @@ var inputify = (value) => {
|
|
1063
1064
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1064
1065
|
return {
|
1065
1066
|
type: import_transactions.InputType.Coin,
|
1066
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1067
|
-
outputIndex: (0,
|
1067
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1068
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1068
1069
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1069
1070
|
amount: (0, import_math2.bn)(value.amount),
|
1070
1071
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1084,10 +1085,10 @@ var inputify = (value) => {
|
|
1084
1085
|
case import_transactions.InputType.Contract: {
|
1085
1086
|
return {
|
1086
1087
|
type: import_transactions.InputType.Contract,
|
1087
|
-
txID:
|
1088
|
+
txID: import_configs2.ZeroBytes32,
|
1088
1089
|
outputIndex: 0,
|
1089
|
-
balanceRoot:
|
1090
|
-
stateRoot:
|
1090
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1091
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1091
1092
|
txPointer: {
|
1092
1093
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1093
1094
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1125,7 +1126,7 @@ var inputify = (value) => {
|
|
1125
1126
|
};
|
1126
1127
|
|
1127
1128
|
// src/providers/transaction-request/output.ts
|
1128
|
-
var
|
1129
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1129
1130
|
var import_errors4 = require("@fuel-ts/errors");
|
1130
1131
|
var import_math3 = require("@fuel-ts/math");
|
1131
1132
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1145,8 +1146,8 @@ var outputify = (value) => {
|
|
1145
1146
|
return {
|
1146
1147
|
type: import_transactions2.OutputType.Contract,
|
1147
1148
|
inputIndex: value.inputIndex,
|
1148
|
-
balanceRoot:
|
1149
|
-
stateRoot:
|
1149
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1150
|
+
stateRoot: import_configs3.ZeroBytes32
|
1150
1151
|
};
|
1151
1152
|
}
|
1152
1153
|
case import_transactions2.OutputType.Change: {
|
@@ -1160,9 +1161,9 @@ var outputify = (value) => {
|
|
1160
1161
|
case import_transactions2.OutputType.Variable: {
|
1161
1162
|
return {
|
1162
1163
|
type: import_transactions2.OutputType.Variable,
|
1163
|
-
to:
|
1164
|
+
to: import_configs3.ZeroBytes32,
|
1164
1165
|
amount: (0, import_math3.bn)(0),
|
1165
|
-
assetId:
|
1166
|
+
assetId: import_configs3.ZeroBytes32
|
1166
1167
|
};
|
1167
1168
|
}
|
1168
1169
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1182,10 +1183,8 @@ var outputify = (value) => {
|
|
1182
1183
|
};
|
1183
1184
|
|
1184
1185
|
// src/providers/transaction-request/transaction-request.ts
|
1185
|
-
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1186
1186
|
var import_address = require("@fuel-ts/address");
|
1187
|
-
var
|
1188
|
-
var import_crypto = require("@fuel-ts/crypto");
|
1187
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1189
1188
|
var import_math7 = require("@fuel-ts/math");
|
1190
1189
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1191
1190
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1194,13 +1193,13 @@ var import_utils9 = require("@fuel-ts/utils");
|
|
1194
1193
|
var isCoin = (resource) => "id" in resource;
|
1195
1194
|
|
1196
1195
|
// src/providers/utils/receipts.ts
|
1197
|
-
var
|
1196
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1198
1197
|
var import_errors5 = require("@fuel-ts/errors");
|
1199
1198
|
var import_math4 = require("@fuel-ts/math");
|
1200
1199
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1201
|
-
var
|
1200
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1202
1201
|
var import_utils5 = require("@fuel-ts/utils");
|
1203
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1202
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1204
1203
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1205
1204
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1206
1205
|
(memo, receipt) => {
|
@@ -1217,7 +1216,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1217
1216
|
missingOutputContractIds: []
|
1218
1217
|
}
|
1219
1218
|
);
|
1220
|
-
var hexOrZero = (hex) => hex ||
|
1219
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1221
1220
|
function assembleReceiptByType(receipt) {
|
1222
1221
|
const { receiptType } = receipt;
|
1223
1222
|
switch (receiptType) {
|
@@ -1522,16 +1521,16 @@ function sleep(time) {
|
|
1522
1521
|
var import_errors7 = require("@fuel-ts/errors");
|
1523
1522
|
var import_math6 = require("@fuel-ts/math");
|
1524
1523
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1525
|
-
var
|
1524
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1526
1525
|
var assemblePanicError = (status) => {
|
1527
1526
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1528
1527
|
const reason = status.reason;
|
1529
|
-
if (
|
1528
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1530
1529
|
errorMessage = `${errorMessage}
|
1531
1530
|
|
1532
1531
|
You can read more about this error at:
|
1533
1532
|
|
1534
|
-
${
|
1533
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1535
1534
|
}
|
1536
1535
|
return { errorMessage, reason };
|
1537
1536
|
};
|
@@ -1543,28 +1542,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1543
1542
|
if (revertReceipt) {
|
1544
1543
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1545
1544
|
switch (reasonHex) {
|
1546
|
-
case
|
1545
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1547
1546
|
reason = "require";
|
1548
1547
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1549
1548
|
break;
|
1550
1549
|
}
|
1551
|
-
case
|
1550
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1552
1551
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1553
1552
|
reason = "assert_eq";
|
1554
1553
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1555
1554
|
break;
|
1556
1555
|
}
|
1557
|
-
case
|
1556
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1558
1557
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1559
1558
|
reason = "assert_ne";
|
1560
1559
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1561
1560
|
break;
|
1562
1561
|
}
|
1563
|
-
case
|
1562
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1564
1563
|
reason = "assert";
|
1565
1564
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1566
1565
|
break;
|
1567
|
-
case
|
1566
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1568
1567
|
reason = "MissingOutputChange";
|
1569
1568
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1570
1569
|
break;
|
@@ -1626,8 +1625,6 @@ var BaseTransactionRequest = class {
|
|
1626
1625
|
outputs = [];
|
1627
1626
|
/** List of witnesses */
|
1628
1627
|
witnesses = [];
|
1629
|
-
/** Base asset ID - should be fetched from the chain */
|
1630
|
-
baseAssetId;
|
1631
1628
|
/**
|
1632
1629
|
* Constructor for initializing a base transaction request.
|
1633
1630
|
*
|
@@ -1640,9 +1637,8 @@ var BaseTransactionRequest = class {
|
|
1640
1637
|
witnessLimit,
|
1641
1638
|
inputs,
|
1642
1639
|
outputs,
|
1643
|
-
witnesses
|
1644
|
-
|
1645
|
-
}) {
|
1640
|
+
witnesses
|
1641
|
+
} = {}) {
|
1646
1642
|
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1647
1643
|
this.maturity = maturity ?? 0;
|
1648
1644
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
@@ -1650,7 +1646,6 @@ var BaseTransactionRequest = class {
|
|
1650
1646
|
this.inputs = inputs ?? [];
|
1651
1647
|
this.outputs = outputs ?? [];
|
1652
1648
|
this.witnesses = witnesses ?? [];
|
1653
|
-
this.baseAssetId = baseAssetId;
|
1654
1649
|
}
|
1655
1650
|
static getPolicyMeta(req) {
|
1656
1651
|
let policyTypes = 0;
|
@@ -1743,7 +1738,7 @@ var BaseTransactionRequest = class {
|
|
1743
1738
|
* @returns The index of the created witness.
|
1744
1739
|
*/
|
1745
1740
|
addEmptyWitness() {
|
1746
|
-
this.addWitness((0, import_utils9.concat)([
|
1741
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1747
1742
|
return this.witnesses.length - 1;
|
1748
1743
|
}
|
1749
1744
|
/**
|
@@ -1874,9 +1869,11 @@ var BaseTransactionRequest = class {
|
|
1874
1869
|
*
|
1875
1870
|
* @param message - Message resource.
|
1876
1871
|
* @param predicate - Predicate bytes.
|
1872
|
+
* @param predicateData - Predicate data bytes.
|
1877
1873
|
*/
|
1878
1874
|
addMessageInput(message, predicate) {
|
1879
1875
|
const { recipient, sender, amount } = message;
|
1876
|
+
const assetId = import_configs7.BaseAssetId;
|
1880
1877
|
let witnessIndex;
|
1881
1878
|
if (predicate) {
|
1882
1879
|
witnessIndex = 0;
|
@@ -1896,7 +1893,7 @@ var BaseTransactionRequest = class {
|
|
1896
1893
|
predicate: predicate?.bytes
|
1897
1894
|
};
|
1898
1895
|
this.pushInput(input);
|
1899
|
-
this.addChangeOutput(recipient,
|
1896
|
+
this.addChangeOutput(recipient, assetId);
|
1900
1897
|
}
|
1901
1898
|
/**
|
1902
1899
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1957,12 +1954,12 @@ var BaseTransactionRequest = class {
|
|
1957
1954
|
* @param amount - Amount of coin.
|
1958
1955
|
* @param assetId - Asset ID of coin.
|
1959
1956
|
*/
|
1960
|
-
addCoinOutput(to, amount, assetId) {
|
1957
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1961
1958
|
this.pushOutput({
|
1962
1959
|
type: import_transactions6.OutputType.Coin,
|
1963
1960
|
to: (0, import_address.addressify)(to).toB256(),
|
1964
1961
|
amount,
|
1965
|
-
assetId
|
1962
|
+
assetId
|
1966
1963
|
});
|
1967
1964
|
return this;
|
1968
1965
|
}
|
@@ -1989,7 +1986,7 @@ var BaseTransactionRequest = class {
|
|
1989
1986
|
* @param to - Address of the owner.
|
1990
1987
|
* @param assetId - Asset ID of coin.
|
1991
1988
|
*/
|
1992
|
-
addChangeOutput(to, assetId) {
|
1989
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1993
1990
|
const changeOutput = this.getChangeOutputs().find(
|
1994
1991
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1995
1992
|
);
|
@@ -1997,7 +1994,7 @@ var BaseTransactionRequest = class {
|
|
1997
1994
|
this.pushOutput({
|
1998
1995
|
type: import_transactions6.OutputType.Change,
|
1999
1996
|
to: (0, import_address.addressify)(to).toB256(),
|
2000
|
-
assetId
|
1997
|
+
assetId
|
2001
1998
|
});
|
2002
1999
|
}
|
2003
2000
|
}
|
@@ -2048,6 +2045,12 @@ var BaseTransactionRequest = class {
|
|
2048
2045
|
* @param quantities - CoinQuantity Array.
|
2049
2046
|
*/
|
2050
2047
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2048
|
+
let idCounter = 0;
|
2049
|
+
const generateId = () => {
|
2050
|
+
const counterString = String(idCounter++);
|
2051
|
+
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2052
|
+
return id;
|
2053
|
+
};
|
2051
2054
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2052
2055
|
if ("assetId" in input) {
|
2053
2056
|
return input.assetId === assetId;
|
@@ -2057,12 +2060,12 @@ var BaseTransactionRequest = class {
|
|
2057
2060
|
const updateAssetInput = (assetId, quantity) => {
|
2058
2061
|
const assetInput = findAssetInput(assetId);
|
2059
2062
|
if (assetInput && "assetId" in assetInput) {
|
2060
|
-
assetInput.id = (
|
2063
|
+
assetInput.id = generateId();
|
2061
2064
|
assetInput.amount = quantity;
|
2062
2065
|
} else {
|
2063
2066
|
this.addResources([
|
2064
2067
|
{
|
2065
|
-
id: (
|
2068
|
+
id: generateId(),
|
2066
2069
|
amount: quantity,
|
2067
2070
|
assetId,
|
2068
2071
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2073,7 +2076,7 @@ var BaseTransactionRequest = class {
|
|
2073
2076
|
]);
|
2074
2077
|
}
|
2075
2078
|
};
|
2076
|
-
updateAssetInput(
|
2079
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2077
2080
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2078
2081
|
}
|
2079
2082
|
/**
|
@@ -2123,13 +2126,13 @@ var BaseTransactionRequest = class {
|
|
2123
2126
|
};
|
2124
2127
|
|
2125
2128
|
// src/providers/transaction-request/create-transaction-request.ts
|
2126
|
-
var
|
2129
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2127
2130
|
var import_math9 = require("@fuel-ts/math");
|
2128
2131
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2129
2132
|
var import_utils13 = require("@fuel-ts/utils");
|
2130
2133
|
|
2131
2134
|
// src/providers/transaction-request/hash-transaction.ts
|
2132
|
-
var
|
2135
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2133
2136
|
var import_hasher = require("@fuel-ts/hasher");
|
2134
2137
|
var import_math8 = require("@fuel-ts/math");
|
2135
2138
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2138,7 +2141,7 @@ var import_ramda2 = require("ramda");
|
|
2138
2141
|
function hashTransaction(transactionRequest, chainId) {
|
2139
2142
|
const transaction = transactionRequest.toTransaction();
|
2140
2143
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2141
|
-
transaction.receiptsRoot =
|
2144
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2142
2145
|
}
|
2143
2146
|
transaction.inputs = transaction.inputs.map((input) => {
|
2144
2147
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2160,10 +2163,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2160
2163
|
blockHeight: 0,
|
2161
2164
|
txIndex: 0
|
2162
2165
|
};
|
2163
|
-
inputClone.txID =
|
2166
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2164
2167
|
inputClone.outputIndex = 0;
|
2165
|
-
inputClone.balanceRoot =
|
2166
|
-
inputClone.stateRoot =
|
2168
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2169
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2167
2170
|
return inputClone;
|
2168
2171
|
}
|
2169
2172
|
default:
|
@@ -2174,8 +2177,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2174
2177
|
const outputClone = (0, import_ramda2.clone)(output);
|
2175
2178
|
switch (outputClone.type) {
|
2176
2179
|
case import_transactions7.OutputType.Contract: {
|
2177
|
-
outputClone.balanceRoot =
|
2178
|
-
outputClone.stateRoot =
|
2180
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2181
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2179
2182
|
return outputClone;
|
2180
2183
|
}
|
2181
2184
|
case import_transactions7.OutputType.Change: {
|
@@ -2183,9 +2186,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2183
2186
|
return outputClone;
|
2184
2187
|
}
|
2185
2188
|
case import_transactions7.OutputType.Variable: {
|
2186
|
-
outputClone.to =
|
2189
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2187
2190
|
outputClone.amount = (0, import_math8.bn)(0);
|
2188
|
-
outputClone.assetId =
|
2191
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2189
2192
|
return outputClone;
|
2190
2193
|
}
|
2191
2194
|
default:
|
@@ -2243,10 +2246,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2243
2246
|
*
|
2244
2247
|
* @param createTransactionRequestLike - The initial values for the instance
|
2245
2248
|
*/
|
2246
|
-
constructor({
|
2249
|
+
constructor({
|
2250
|
+
bytecodeWitnessIndex,
|
2251
|
+
salt,
|
2252
|
+
storageSlots,
|
2253
|
+
...rest
|
2254
|
+
} = {}) {
|
2247
2255
|
super(rest);
|
2248
2256
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2249
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2257
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2250
2258
|
this.storageSlots = [...storageSlots ?? []];
|
2251
2259
|
}
|
2252
2260
|
/**
|
@@ -2264,7 +2272,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2264
2272
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2265
2273
|
bytecodeWitnessIndex,
|
2266
2274
|
storageSlotsCount: storageSlots.length,
|
2267
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2275
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2268
2276
|
storageSlots
|
2269
2277
|
};
|
2270
2278
|
}
|
@@ -2312,9 +2320,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2312
2320
|
};
|
2313
2321
|
|
2314
2322
|
// src/providers/transaction-request/script-transaction-request.ts
|
2315
|
-
var
|
2323
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2316
2324
|
var import_address2 = require("@fuel-ts/address");
|
2317
|
-
var
|
2325
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2318
2326
|
var import_math10 = require("@fuel-ts/math");
|
2319
2327
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2320
2328
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2367,7 +2375,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2367
2375
|
*
|
2368
2376
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2369
2377
|
*/
|
2370
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2378
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2371
2379
|
super(rest);
|
2372
2380
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2373
2381
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2388,7 +2396,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2388
2396
|
...super.getBaseTransaction(),
|
2389
2397
|
scriptLength: script.length,
|
2390
2398
|
scriptDataLength: scriptData.length,
|
2391
|
-
receiptsRoot:
|
2399
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2392
2400
|
script: (0, import_utils15.hexlify)(script),
|
2393
2401
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2394
2402
|
};
|
@@ -2504,7 +2512,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2512
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2505
2513
|
*/
|
2506
2514
|
setData(abi, args) {
|
2507
|
-
const abiInterface = new
|
2515
|
+
const abiInterface = new import_abi_coder.Interface(abi);
|
2508
2516
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2509
2517
|
return this;
|
2510
2518
|
}
|
@@ -2620,23 +2628,23 @@ var calculateTransactionFee = (params) => {
|
|
2620
2628
|
};
|
2621
2629
|
|
2622
2630
|
// src/providers/transaction-summary/operations.ts
|
2623
|
-
var
|
2631
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2624
2632
|
var import_errors11 = require("@fuel-ts/errors");
|
2625
2633
|
var import_math13 = require("@fuel-ts/math");
|
2626
2634
|
var import_transactions14 = require("@fuel-ts/transactions");
|
2627
2635
|
|
2628
2636
|
// src/providers/transaction-summary/call.ts
|
2629
|
-
var
|
2637
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2630
2638
|
var import_math12 = require("@fuel-ts/math");
|
2631
2639
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2632
|
-
const abiInterface = new
|
2640
|
+
const abiInterface = new import_abi_coder2.Interface(abi);
|
2633
2641
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2634
2642
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2635
2643
|
const inputs = functionFragment.jsonFn.inputs;
|
2636
2644
|
let encodedArgs;
|
2637
2645
|
if (functionFragment.isInputDataPointer) {
|
2638
2646
|
if (rawPayload) {
|
2639
|
-
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0,
|
2647
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2640
2648
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2641
2649
|
}
|
2642
2650
|
} else {
|
@@ -2918,7 +2926,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2918
2926
|
const { to: toAddress, assetId, amount } = receipt;
|
2919
2927
|
let { from: fromAddress } = receipt;
|
2920
2928
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2921
|
-
if (
|
2929
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2922
2930
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2923
2931
|
fromAddress = change?.to || fromAddress;
|
2924
2932
|
}
|
@@ -3239,13 +3247,13 @@ function assembleTransactionSummary(params) {
|
|
3239
3247
|
}
|
3240
3248
|
|
3241
3249
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3242
|
-
var
|
3250
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3243
3251
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3244
3252
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3245
3253
|
return receipts.reduce((logs, receipt) => {
|
3246
3254
|
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3247
|
-
const interfaceToUse = new
|
3248
|
-
const data = receipt.type === import_transactions16.ReceiptType.Log ? new
|
3255
|
+
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3256
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3249
3257
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3250
3258
|
logs.push(decodedLog);
|
3251
3259
|
}
|
@@ -3495,7 +3503,6 @@ var processGqlChain = (chain) => {
|
|
3495
3503
|
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3496
3504
|
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3497
3505
|
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3498
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3499
3506
|
gasCosts
|
3500
3507
|
},
|
3501
3508
|
gasCosts,
|
@@ -3738,17 +3745,6 @@ var _Provider = class {
|
|
3738
3745
|
} = this.getChain();
|
3739
3746
|
return chainId.toNumber();
|
3740
3747
|
}
|
3741
|
-
/**
|
3742
|
-
* Returns the base asset ID
|
3743
|
-
*
|
3744
|
-
* @returns A promise that resolves to the base asset ID
|
3745
|
-
*/
|
3746
|
-
getBaseAssetId() {
|
3747
|
-
const {
|
3748
|
-
consensusParameters: { baseAssetId }
|
3749
|
-
} = this.getChain();
|
3750
|
-
return baseAssetId;
|
3751
|
-
}
|
3752
3748
|
/**
|
3753
3749
|
* Submits a transaction to the chain to be executed.
|
3754
3750
|
*
|
@@ -3899,36 +3895,6 @@ var _Provider = class {
|
|
3899
3895
|
missingContractIds
|
3900
3896
|
};
|
3901
3897
|
}
|
3902
|
-
/**
|
3903
|
-
* Estimates the transaction gas and fee based on the provided transaction request.
|
3904
|
-
* @param transactionRequest - The transaction request object.
|
3905
|
-
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3906
|
-
*/
|
3907
|
-
estimateTxGasAndFee(params) {
|
3908
|
-
const { transactionRequest } = params;
|
3909
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3910
|
-
const chainInfo = this.getChain();
|
3911
|
-
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3912
|
-
transactionRequest.gasPrice = gasPrice;
|
3913
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3914
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3915
|
-
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3916
|
-
if (transactionRequest.gasLimit.eq(0)) {
|
3917
|
-
transactionRequest.gasLimit = minGas;
|
3918
|
-
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3919
|
-
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3920
|
-
);
|
3921
|
-
}
|
3922
|
-
}
|
3923
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3924
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3925
|
-
return {
|
3926
|
-
minGas,
|
3927
|
-
minFee,
|
3928
|
-
maxGas,
|
3929
|
-
maxFee
|
3930
|
-
};
|
3931
|
-
}
|
3932
3898
|
/**
|
3933
3899
|
* Executes a signed transaction without applying the states changes
|
3934
3900
|
* on the chain.
|
@@ -3976,16 +3942,17 @@ var _Provider = class {
|
|
3976
3942
|
signatureCallback
|
3977
3943
|
} = {}) {
|
3978
3944
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3979
|
-
const
|
3980
|
-
const
|
3945
|
+
const chainInfo = this.getChain();
|
3946
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3947
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3981
3948
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3982
3949
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3983
3950
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3984
3951
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3985
|
-
if (isScriptTransaction) {
|
3986
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3987
|
-
}
|
3988
3952
|
if (estimatePredicates) {
|
3953
|
+
if (isScriptTransaction) {
|
3954
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3955
|
+
}
|
3989
3956
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3990
3957
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3991
3958
|
}
|
@@ -3994,34 +3961,36 @@ var _Provider = class {
|
|
3994
3961
|
if (signatureCallback && isScriptTransaction) {
|
3995
3962
|
await signatureCallback(txRequestClone);
|
3996
3963
|
}
|
3997
|
-
|
3998
|
-
|
3999
|
-
});
|
3964
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3965
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4000
3966
|
let receipts = [];
|
4001
3967
|
let missingContractIds = [];
|
4002
3968
|
let outputVariables = 0;
|
4003
|
-
let gasUsed = (0, import_math15.bn)(0);
|
4004
3969
|
if (isScriptTransaction && estimateTxDependencies) {
|
4005
3970
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3971
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4006
3972
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4007
3973
|
receipts = result.receipts;
|
4008
3974
|
outputVariables = result.outputVariables;
|
4009
3975
|
missingContractIds = result.missingContractIds;
|
4010
|
-
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4011
|
-
txRequestClone.gasLimit = gasUsed;
|
4012
|
-
txRequestClone.gasPrice = setGasPrice;
|
4013
|
-
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4014
|
-
transactionRequest: txRequestClone
|
4015
|
-
}));
|
4016
3976
|
}
|
3977
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3978
|
+
const usedFee = calculatePriceWithFactor(
|
3979
|
+
gasUsed,
|
3980
|
+
gasPrice,
|
3981
|
+
gasPriceFactor
|
3982
|
+
).normalizeZeroToOne();
|
3983
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3984
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4017
3985
|
return {
|
4018
3986
|
requiredQuantities: allQuantities,
|
4019
3987
|
receipts,
|
4020
3988
|
gasUsed,
|
4021
3989
|
minGasPrice,
|
4022
|
-
gasPrice
|
3990
|
+
gasPrice,
|
4023
3991
|
minGas,
|
4024
3992
|
maxGas,
|
3993
|
+
usedFee,
|
4025
3994
|
minFee,
|
4026
3995
|
maxFee,
|
4027
3996
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4488,13 +4457,13 @@ var assets = [
|
|
4488
4457
|
];
|
4489
4458
|
|
4490
4459
|
// src/utils/formatTransferToContractScriptData.ts
|
4491
|
-
var
|
4460
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4492
4461
|
var import_math17 = require("@fuel-ts/math");
|
4493
4462
|
var import_utils27 = require("@fuel-ts/utils");
|
4494
4463
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4495
4464
|
var formatTransferToContractScriptData = (params) => {
|
4496
4465
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4497
|
-
const numberCoder = new
|
4466
|
+
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4498
4467
|
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4499
4468
|
const scriptData = Uint8Array.from([
|
4500
4469
|
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
@@ -4646,9 +4615,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4646
4615
|
* @param assetId - The asset ID to check the balance for.
|
4647
4616
|
* @returns A promise that resolves to the balance amount.
|
4648
4617
|
*/
|
4649
|
-
async getBalance(assetId) {
|
4650
|
-
const
|
4651
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4618
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4619
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4652
4620
|
return amount;
|
4653
4621
|
}
|
4654
4622
|
/**
|
@@ -4686,10 +4654,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4686
4654
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4687
4655
|
*/
|
4688
4656
|
async fund(request, coinQuantities, fee) {
|
4689
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4690
4657
|
const updatedQuantities = addAmountToAsset({
|
4691
4658
|
amount: (0, import_math18.bn)(fee),
|
4692
|
-
assetId:
|
4659
|
+
assetId: import_configs12.BaseAssetId,
|
4693
4660
|
coinQuantities
|
4694
4661
|
});
|
4695
4662
|
const quantitiesDict = {};
|
@@ -4713,8 +4680,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4713
4680
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4714
4681
|
cachedUtxos.push(input.id);
|
4715
4682
|
}
|
4716
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4717
|
-
quantitiesDict[
|
4683
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4684
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4718
4685
|
cachedMessages.push(input.nonce);
|
4719
4686
|
}
|
4720
4687
|
}
|
@@ -4746,13 +4713,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4746
4713
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4747
4714
|
* @returns A promise that resolves to the prepared transaction request.
|
4748
4715
|
*/
|
4749
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4716
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4750
4717
|
const { minGasPrice } = this.provider.getGasConfig();
|
4751
|
-
const
|
4752
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4753
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4718
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4754
4719
|
const request = new ScriptTransactionRequest(params);
|
4755
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
4720
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4756
4721
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4757
4722
|
estimateTxDependencies: true,
|
4758
4723
|
resourcesOwner: this
|
@@ -4778,15 +4743,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4778
4743
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4779
4744
|
* @returns A promise that resolves to the transaction response.
|
4780
4745
|
*/
|
4781
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4746
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4782
4747
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4783
4748
|
throw new import_errors16.FuelError(
|
4784
4749
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4785
4750
|
"Transfer amount must be a positive number."
|
4786
4751
|
);
|
4787
4752
|
}
|
4788
|
-
const
|
4789
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4753
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4790
4754
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4791
4755
|
}
|
4792
4756
|
/**
|
@@ -4798,7 +4762,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4798
4762
|
* @param txParams - The optional transaction parameters.
|
4799
4763
|
* @returns A promise that resolves to the transaction response.
|
4800
4764
|
*/
|
4801
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4765
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4802
4766
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4803
4767
|
throw new import_errors16.FuelError(
|
4804
4768
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -4807,13 +4771,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4807
4771
|
}
|
4808
4772
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4809
4773
|
const { minGasPrice } = this.provider.getGasConfig();
|
4810
|
-
const
|
4811
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4812
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4774
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4813
4775
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4814
4776
|
hexlifiedContractId: contractAddress.toB256(),
|
4815
4777
|
amountToTransfer: (0, import_math18.bn)(amount),
|
4816
|
-
assetId
|
4778
|
+
assetId
|
4817
4779
|
});
|
4818
4780
|
const request = new ScriptTransactionRequest({
|
4819
4781
|
...params,
|
@@ -4823,7 +4785,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4823
4785
|
request.addContractInputAndOutput(contractAddress);
|
4824
4786
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4825
4787
|
request,
|
4826
|
-
[{ amount: (0, import_math18.bn)(amount), assetId: String(
|
4788
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4827
4789
|
);
|
4828
4790
|
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4829
4791
|
this.validateGas({
|
@@ -4845,7 +4807,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4845
4807
|
*/
|
4846
4808
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4847
4809
|
const { minGasPrice } = this.provider.getGasConfig();
|
4848
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4849
4810
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4850
4811
|
const recipientDataArray = (0, import_utils28.arrayify)(
|
4851
4812
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4858,14 +4819,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4858
4819
|
...recipientDataArray,
|
4859
4820
|
...amountDataArray
|
4860
4821
|
]);
|
4861
|
-
const params = {
|
4862
|
-
script,
|
4863
|
-
gasPrice: minGasPrice,
|
4864
|
-
baseAssetId,
|
4865
|
-
...txParams
|
4866
|
-
};
|
4822
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4867
4823
|
const request = new ScriptTransactionRequest(params);
|
4868
|
-
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId:
|
4824
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4869
4825
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4870
4826
|
request,
|
4871
4827
|
forwardingQuantities
|
@@ -4958,7 +4914,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4958
4914
|
|
4959
4915
|
// src/signer/signer.ts
|
4960
4916
|
var import_address5 = require("@fuel-ts/address");
|
4961
|
-
var
|
4917
|
+
var import_crypto = require("@fuel-ts/crypto");
|
4962
4918
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4963
4919
|
var import_math19 = require("@fuel-ts/math");
|
4964
4920
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5051,7 +5007,7 @@ var Signer = class {
|
|
5051
5007
|
* @returns random 32-byte hashed
|
5052
5008
|
*/
|
5053
5009
|
static generatePrivateKey(entropy) {
|
5054
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5010
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5055
5011
|
}
|
5056
5012
|
/**
|
5057
5013
|
* Extended publicKey from a compact publicKey
|
@@ -5067,7 +5023,7 @@ var Signer = class {
|
|
5067
5023
|
|
5068
5024
|
// src/wallet/keystore-wallet.ts
|
5069
5025
|
var import_address6 = require("@fuel-ts/address");
|
5070
|
-
var
|
5026
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
5071
5027
|
var import_errors17 = require("@fuel-ts/errors");
|
5072
5028
|
var import_utils30 = require("@fuel-ts/utils");
|
5073
5029
|
var import_uuid = require("uuid");
|
@@ -5083,22 +5039,22 @@ var removeHexPrefix = (hexString) => {
|
|
5083
5039
|
return hexString;
|
5084
5040
|
};
|
5085
5041
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5086
|
-
const privateKeyBuffer = (0,
|
5042
|
+
const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5087
5043
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5088
|
-
const salt = (0,
|
5089
|
-
const key = (0,
|
5090
|
-
password: (0,
|
5044
|
+
const salt = (0, import_crypto2.randomBytes)(DEFAULT_KEY_SIZE);
|
5045
|
+
const key = (0, import_crypto2.scrypt)({
|
5046
|
+
password: (0, import_crypto2.bufferFromString)(password),
|
5091
5047
|
salt,
|
5092
5048
|
dklen: DEFAULT_KEY_SIZE,
|
5093
5049
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5094
5050
|
r: DEFAULT_KDF_PARAMS_R,
|
5095
5051
|
p: DEFAULT_KDF_PARAMS_P
|
5096
5052
|
});
|
5097
|
-
const iv = (0,
|
5098
|
-
const ciphertext = await (0,
|
5053
|
+
const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
|
5054
|
+
const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5099
5055
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5100
|
-
const macHashUint8Array = (0,
|
5101
|
-
const mac = (0,
|
5056
|
+
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5057
|
+
const mac = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5102
5058
|
const keystore = {
|
5103
5059
|
id: (0, import_uuid.v4)(),
|
5104
5060
|
version: 3,
|
@@ -5106,15 +5062,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5106
5062
|
crypto: {
|
5107
5063
|
cipher: "aes-128-ctr",
|
5108
5064
|
mac,
|
5109
|
-
cipherparams: { iv: (0,
|
5110
|
-
ciphertext: (0,
|
5065
|
+
cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
|
5066
|
+
ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
|
5111
5067
|
kdf: "scrypt",
|
5112
5068
|
kdfparams: {
|
5113
5069
|
dklen: DEFAULT_KEY_SIZE,
|
5114
5070
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5115
5071
|
p: DEFAULT_KDF_PARAMS_P,
|
5116
5072
|
r: DEFAULT_KDF_PARAMS_R,
|
5117
|
-
salt: (0,
|
5073
|
+
salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
|
5118
5074
|
}
|
5119
5075
|
}
|
5120
5076
|
};
|
@@ -5130,11 +5086,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5130
5086
|
kdfparams: { dklen, n, r, p, salt }
|
5131
5087
|
}
|
5132
5088
|
} = keystoreWallet;
|
5133
|
-
const ciphertextBuffer = (0,
|
5134
|
-
const ivBuffer = (0,
|
5135
|
-
const saltBuffer = (0,
|
5136
|
-
const passwordBuffer = (0,
|
5137
|
-
const key = (0,
|
5089
|
+
const ciphertextBuffer = (0, import_crypto2.bufferFromString)(ciphertext, "hex");
|
5090
|
+
const ivBuffer = (0, import_crypto2.bufferFromString)(iv, "hex");
|
5091
|
+
const saltBuffer = (0, import_crypto2.bufferFromString)(salt, "hex");
|
5092
|
+
const passwordBuffer = (0, import_crypto2.bufferFromString)(password);
|
5093
|
+
const key = (0, import_crypto2.scrypt)({
|
5138
5094
|
password: passwordBuffer,
|
5139
5095
|
salt: saltBuffer,
|
5140
5096
|
n,
|
@@ -5143,15 +5099,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5143
5099
|
dklen
|
5144
5100
|
});
|
5145
5101
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5146
|
-
const macHashUint8Array = (0,
|
5147
|
-
const macHash = (0,
|
5102
|
+
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5103
|
+
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5148
5104
|
if (mac !== macHash) {
|
5149
5105
|
throw new import_errors17.FuelError(
|
5150
5106
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5151
5107
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5152
5108
|
);
|
5153
5109
|
}
|
5154
|
-
const buffer = await (0,
|
5110
|
+
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5155
5111
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5156
5112
|
return privateKey;
|
5157
5113
|
}
|
@@ -5276,7 +5232,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5276
5232
|
var import_ethers3 = require("ethers");
|
5277
5233
|
|
5278
5234
|
// src/mnemonic/mnemonic.ts
|
5279
|
-
var
|
5235
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5280
5236
|
var import_errors19 = require("@fuel-ts/errors");
|
5281
5237
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5282
5238
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -7631,7 +7587,7 @@ var Mnemonic = class {
|
|
7631
7587
|
* @returns A randomly generated mnemonic
|
7632
7588
|
*/
|
7633
7589
|
static generate(size = 32, extraEntropy = "") {
|
7634
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
7590
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7635
7591
|
return Mnemonic.entropyToMnemonic(entropy);
|
7636
7592
|
}
|
7637
7593
|
};
|
@@ -8002,17 +7958,15 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8002
7958
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8003
7959
|
|
8004
7960
|
// src/test-utils/seedTestWallet.ts
|
8005
|
-
var
|
7961
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
8006
7962
|
var seedTestWallet = async (wallet, quantities) => {
|
8007
7963
|
const genesisWallet = new WalletUnlocked(
|
8008
|
-
process.env.GENESIS_SECRET || (0,
|
7964
|
+
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
8009
7965
|
wallet.provider
|
8010
7966
|
);
|
8011
7967
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
8012
7968
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8013
|
-
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
8014
7969
|
const request = new ScriptTransactionRequest({
|
8015
|
-
baseAssetId,
|
8016
7970
|
gasLimit: 1e4,
|
8017
7971
|
gasPrice: minGasPrice
|
8018
7972
|
});
|
@@ -8031,12 +7985,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8031
7985
|
};
|
8032
7986
|
|
8033
7987
|
// src/test-utils/launchNode.ts
|
8034
|
-
var
|
7988
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8035
7989
|
var import_math21 = require("@fuel-ts/math");
|
8036
7990
|
var import_utils36 = require("@fuel-ts/utils");
|
8037
7991
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8038
7992
|
var import_child_process = require("child_process");
|
8039
|
-
var
|
7993
|
+
var import_crypto5 = require("crypto");
|
8040
7994
|
var import_fs = require("fs");
|
8041
7995
|
var import_os = __toESM(require("os"));
|
8042
7996
|
var import_path = __toESM(require("path"));
|
@@ -8108,7 +8062,7 @@ var launchNode = async ({
|
|
8108
8062
|
})).toString();
|
8109
8063
|
let chainConfigPathToUse;
|
8110
8064
|
const prefix = basePath || import_os.default.tmpdir();
|
8111
|
-
const suffix = basePath ? "" : (0,
|
8065
|
+
const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
|
8112
8066
|
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8113
8067
|
if (chainConfigPath) {
|
8114
8068
|
chainConfigPathToUse = chainConfigPath;
|
@@ -8131,7 +8085,7 @@ var launchNode = async ({
|
|
8131
8085
|
{
|
8132
8086
|
owner: signer.address.toHexString(),
|
8133
8087
|
amount: (0, import_math21.toHex)(1e9),
|
8134
|
-
asset_id:
|
8088
|
+
asset_id: import_configs13.BaseAssetId
|
8135
8089
|
}
|
8136
8090
|
]
|
8137
8091
|
}
|
@@ -8197,10 +8151,9 @@ var launchNode = async ({
|
|
8197
8151
|
})
|
8198
8152
|
);
|
8199
8153
|
var generateWallets = async (count, provider) => {
|
8200
|
-
const baseAssetId = provider.getBaseAssetId();
|
8201
8154
|
const wallets = [];
|
8202
8155
|
for (let i = 0; i < count; i += 1) {
|
8203
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8156
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8204
8157
|
wallets.push(wallet);
|
8205
8158
|
}
|
8206
8159
|
return wallets;
|