@fuel-ts/account 0.74.0 → 0.75.0
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 +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +2 -1
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +1 -2
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +0 -8
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +2 -36
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/connectors/types/index.d.ts +0 -2
- package/dist/connectors/types/index.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +1358 -1074
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +569 -426
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +486 -362
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +4 -0
- package/dist/providers/assets/index.d.ts.map +1 -0
- package/dist/providers/assets/types.d.ts +36 -0
- package/dist/providers/assets/types.d.ts.map +1 -0
- package/dist/providers/assets/utils/index.d.ts +4 -0
- package/dist/providers/assets/utils/index.d.ts.map +1 -0
- package/dist/providers/assets/utils/network.d.ts +33 -0
- package/dist/providers/assets/utils/network.d.ts.map +1 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +14 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts.map +1 -0
- package/dist/providers/assets/utils/url.d.ts +2 -0
- package/dist/providers/assets/utils/url.d.ts.map +1 -0
- package/dist/providers/chains.d.ts +11 -0
- package/dist/providers/chains.d.ts.map +1 -0
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/memory-cache.d.ts +1 -1
- package/dist/providers/memory-cache.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -2
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +17 -7
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +1 -1
- package/dist/providers/resource.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/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/output.d.ts +1 -1
- package/dist/providers/transaction-request/output.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -2
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -10
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/witness.d.ts +1 -1
- package/dist/providers/transaction-request/witness.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +0 -2
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/output.d.ts +2 -2
- package/dist/providers/transaction-summary/output.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +0 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/signer/signer.d.ts +1 -1
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +4010 -3792
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +462 -402
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +384 -336
- package/dist/test-utils.mjs.map +1 -1
- package/dist/utils/formatTransferToContractScriptData.d.ts +1 -2
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +4 -4
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/dist/wallet/wallet.d.ts +1 -2
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallets.d.ts +1 -1
- package/dist/wallet/wallets.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/connectors/types/asset.d.ts +0 -2
- package/dist/connectors/types/asset.d.ts.map +0 -1
- package/dist/connectors/types/constants.d.ts +0 -7
- package/dist/connectors/types/constants.d.ts.map +0 -1
- package/dist/connectors/types/message.d.ts +0 -15
- package/dist/connectors/types/message.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -20,6 +20,7 @@ var __privateMethod = (obj, member, method) => {
|
|
20
20
|
|
21
21
|
// src/wallet/base-wallet-unlocked.ts
|
22
22
|
import { hashMessage } from "@fuel-ts/hasher";
|
23
|
+
import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
23
24
|
|
24
25
|
// src/account.ts
|
25
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
@@ -27,12 +28,12 @@ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
|
27
28
|
import { ErrorCode as ErrorCode13, FuelError as FuelError14 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
30
|
import { bn as bn16 } from "@fuel-ts/math";
|
30
|
-
import {
|
31
|
+
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
31
32
|
|
32
33
|
// src/providers/coin-quantity.ts
|
33
34
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
34
35
|
import { bn } from "@fuel-ts/math";
|
35
|
-
import { hexlify } from "
|
36
|
+
import { hexlify } from "@fuel-ts/utils";
|
36
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
37
38
|
let assetId;
|
38
39
|
let amount;
|
@@ -68,15 +69,17 @@ var addAmountToAsset = (params) => {
|
|
68
69
|
// src/providers/provider.ts
|
69
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
70
71
|
import { ErrorCode as ErrorCode11, FuelError as FuelError12 } from "@fuel-ts/errors";
|
71
|
-
import { bn as bn14, max } from "@fuel-ts/math";
|
72
|
+
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
72
73
|
import {
|
73
74
|
InputType as InputType6,
|
74
75
|
TransactionType as TransactionType8,
|
75
76
|
InputMessageCoder,
|
76
77
|
TransactionCoder as TransactionCoder5
|
77
78
|
} from "@fuel-ts/transactions";
|
79
|
+
import { arrayify as arrayify11, hexlify as hexlify12 } from "@fuel-ts/utils";
|
78
80
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
79
|
-
import {
|
81
|
+
import { equalBytes } from "@noble/curves/abstract/utils";
|
82
|
+
import { Network } from "ethers";
|
80
83
|
import { GraphQLClient } from "graphql-request";
|
81
84
|
import { clone as clone3 } from "ramda";
|
82
85
|
|
@@ -885,71 +888,67 @@ function getSdk(requester) {
|
|
885
888
|
// src/providers/fuel-graphql-subscriber.ts
|
886
889
|
import { FuelError } from "@fuel-ts/errors";
|
887
890
|
import { print } from "graphql";
|
888
|
-
var
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
this.readableStreamController.enqueue(
|
905
|
-
new FuelError(
|
906
|
-
FuelError.CODES.INVALID_REQUEST,
|
907
|
-
errors.map((err) => err.message).join("\n\n")
|
908
|
-
)
|
909
|
-
);
|
910
|
-
} else {
|
911
|
-
this.readableStreamController.enqueue(data);
|
912
|
-
}
|
913
|
-
}
|
891
|
+
var _FuelGraphqlSubscriber = class {
|
892
|
+
constructor(options) {
|
893
|
+
this.options = options;
|
894
|
+
}
|
895
|
+
stream;
|
896
|
+
async setStream() {
|
897
|
+
const { url, query, variables, fetchFn } = this.options;
|
898
|
+
const response = await fetchFn(`${url}-sub`, {
|
899
|
+
method: "POST",
|
900
|
+
body: JSON.stringify({
|
901
|
+
query: print(query),
|
902
|
+
variables
|
903
|
+
}),
|
904
|
+
headers: {
|
905
|
+
"Content-Type": "application/json",
|
906
|
+
Accept: "text/event-stream"
|
914
907
|
}
|
915
908
|
});
|
909
|
+
this.stream = response.body.getReader();
|
916
910
|
}
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
async function* fuelGraphQLSubscriber({
|
921
|
-
url,
|
922
|
-
variables,
|
923
|
-
query,
|
924
|
-
fetchFn
|
925
|
-
}) {
|
926
|
-
const response = await fetchFn(`${url}-sub`, {
|
927
|
-
method: "POST",
|
928
|
-
body: JSON.stringify({
|
929
|
-
query: print(query),
|
930
|
-
variables
|
931
|
-
}),
|
932
|
-
headers: {
|
933
|
-
"Content-Type": "application/json",
|
934
|
-
Accept: "text/event-stream"
|
911
|
+
async next() {
|
912
|
+
if (!this.stream) {
|
913
|
+
await this.setStream();
|
935
914
|
}
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
915
|
+
while (true) {
|
916
|
+
const { value, done } = await this.stream.read();
|
917
|
+
if (done) {
|
918
|
+
return { value, done };
|
919
|
+
}
|
920
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
921
|
+
if (!text.startsWith("data:")) {
|
922
|
+
continue;
|
923
|
+
}
|
924
|
+
const { data, errors } = JSON.parse(text.split("data:")[1]);
|
925
|
+
if (Array.isArray(errors)) {
|
926
|
+
throw new FuelError(
|
927
|
+
FuelError.CODES.INVALID_REQUEST,
|
928
|
+
errors.map((err) => err.message).join("\n\n")
|
929
|
+
);
|
930
|
+
}
|
931
|
+
return { value: data, done: false };
|
946
932
|
}
|
947
933
|
}
|
948
|
-
|
934
|
+
/**
|
935
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
936
|
+
*/
|
937
|
+
async return() {
|
938
|
+
await this.stream.cancel();
|
939
|
+
this.stream.releaseLock();
|
940
|
+
return { done: true, value: void 0 };
|
941
|
+
}
|
942
|
+
[Symbol.asyncIterator]() {
|
943
|
+
return this;
|
944
|
+
}
|
945
|
+
};
|
946
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
947
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
949
948
|
|
950
949
|
// src/providers/memory-cache.ts
|
951
950
|
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
952
|
-
import { hexlify as hexlify2 } from "
|
951
|
+
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
953
952
|
var cache = {};
|
954
953
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
955
954
|
var MemoryCache = class {
|
@@ -1011,23 +1010,23 @@ import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
|
1011
1010
|
import { ErrorCode as ErrorCode2, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1012
1011
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1013
1012
|
import { InputType } from "@fuel-ts/transactions";
|
1014
|
-
import {
|
1013
|
+
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
1015
1014
|
var inputify = (value) => {
|
1016
1015
|
const { type } = value;
|
1017
1016
|
switch (value.type) {
|
1018
1017
|
case InputType.Coin: {
|
1019
|
-
const predicate =
|
1020
|
-
const predicateData =
|
1018
|
+
const predicate = arrayify(value.predicate ?? "0x");
|
1019
|
+
const predicateData = arrayify(value.predicateData ?? "0x");
|
1021
1020
|
return {
|
1022
1021
|
type: InputType.Coin,
|
1023
|
-
txID: hexlify3(
|
1024
|
-
outputIndex:
|
1022
|
+
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1023
|
+
outputIndex: arrayify(value.id)[32],
|
1025
1024
|
owner: hexlify3(value.owner),
|
1026
1025
|
amount: bn2(value.amount),
|
1027
1026
|
assetId: hexlify3(value.assetId),
|
1028
1027
|
txPointer: {
|
1029
|
-
blockHeight: toNumber(
|
1030
|
-
txIndex: toNumber(
|
1028
|
+
blockHeight: toNumber(arrayify(value.txPointer).slice(0, 8)),
|
1029
|
+
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1031
1030
|
},
|
1032
1031
|
witnessIndex: value.witnessIndex,
|
1033
1032
|
maturity: value.maturity ?? 0,
|
@@ -1046,16 +1045,16 @@ var inputify = (value) => {
|
|
1046
1045
|
balanceRoot: ZeroBytes32,
|
1047
1046
|
stateRoot: ZeroBytes32,
|
1048
1047
|
txPointer: {
|
1049
|
-
blockHeight: toNumber(
|
1050
|
-
txIndex: toNumber(
|
1048
|
+
blockHeight: toNumber(arrayify(value.txPointer).slice(0, 8)),
|
1049
|
+
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1051
1050
|
},
|
1052
1051
|
contractID: hexlify3(value.contractId)
|
1053
1052
|
};
|
1054
1053
|
}
|
1055
1054
|
case InputType.Message: {
|
1056
|
-
const predicate =
|
1057
|
-
const predicateData =
|
1058
|
-
const data =
|
1055
|
+
const predicate = arrayify(value.predicate ?? "0x");
|
1056
|
+
const predicateData = arrayify(value.predicateData ?? "0x");
|
1057
|
+
const data = arrayify(value.data ?? "0x");
|
1059
1058
|
return {
|
1060
1059
|
type: InputType.Message,
|
1061
1060
|
sender: hexlify3(value.sender),
|
@@ -1086,7 +1085,7 @@ import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
|
1086
1085
|
import { ErrorCode as ErrorCode3, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1087
1086
|
import { bn as bn3 } from "@fuel-ts/math";
|
1088
1087
|
import { OutputType } from "@fuel-ts/transactions";
|
1089
|
-
import { hexlify as hexlify4 } from "
|
1088
|
+
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
1090
1089
|
var outputify = (value) => {
|
1091
1090
|
const { type } = value;
|
1092
1091
|
switch (type) {
|
@@ -1149,7 +1148,7 @@ import {
|
|
1149
1148
|
OutputType as OutputType2,
|
1150
1149
|
TransactionType
|
1151
1150
|
} from "@fuel-ts/transactions";
|
1152
|
-
import { concat,
|
1151
|
+
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1153
1152
|
|
1154
1153
|
// src/providers/resource.ts
|
1155
1154
|
var isCoin = (resource) => "id" in resource;
|
@@ -1165,7 +1164,7 @@ import {
|
|
1165
1164
|
ReceiptType
|
1166
1165
|
} from "@fuel-ts/transactions";
|
1167
1166
|
import { FAILED_TRANSFER_TO_ADDRESS_SIGNAL } from "@fuel-ts/transactions/configs";
|
1168
|
-
import {
|
1167
|
+
import { arrayify as arrayify2 } from "@fuel-ts/utils";
|
1169
1168
|
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1170
1169
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1171
1170
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
@@ -1309,7 +1308,7 @@ function assembleReceiptByType(receipt) {
|
|
1309
1308
|
const recipient = hexOrZero(receipt.recipient);
|
1310
1309
|
const nonce = hexOrZero(receipt.nonce);
|
1311
1310
|
const amount = bn4(receipt.amount);
|
1312
|
-
const data = receipt.data ?
|
1311
|
+
const data = receipt.data ? arrayify2(receipt.data) : Uint8Array.from([]);
|
1313
1312
|
const digest = hexOrZero(receipt.digest);
|
1314
1313
|
const messageId = ReceiptMessageOutCoder.getMessageId({
|
1315
1314
|
sender,
|
@@ -1371,7 +1370,7 @@ import { ErrorCode as ErrorCode5, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1371
1370
|
// src/providers/utils/gas.ts
|
1372
1371
|
import { bn as bn5 } from "@fuel-ts/math";
|
1373
1372
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1374
|
-
import {
|
1373
|
+
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1375
1374
|
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1376
1375
|
var getGasUsedFromReceipts = (receipts) => {
|
1377
1376
|
const scriptResult = receipts.filter(
|
@@ -1396,9 +1395,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
1396
1395
|
const totalGas = inputs.reduce((total, input) => {
|
1397
1396
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1398
1397
|
return total.add(
|
1399
|
-
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(
|
1400
|
-
resolveGasDependentCosts(getBytesCopy3(input.predicate).length, gasCosts.contractRoot)
|
1401
|
-
).add(bn5(input.predicateGasUsed))
|
1398
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1402
1399
|
);
|
1403
1400
|
}
|
1404
1401
|
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
@@ -1447,7 +1444,7 @@ function calculateMetadataGasForTxScript({
|
|
1447
1444
|
}
|
1448
1445
|
|
1449
1446
|
// src/providers/utils/json.ts
|
1450
|
-
import { hexlify as hexlify5 } from "
|
1447
|
+
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
1451
1448
|
import { clone } from "ramda";
|
1452
1449
|
function normalize(object) {
|
1453
1450
|
Object.keys(object).forEach((key) => {
|
@@ -1500,9 +1497,9 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1500
1497
|
};
|
1501
1498
|
|
1502
1499
|
// src/providers/transaction-request/witness.ts
|
1503
|
-
import {
|
1500
|
+
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
1504
1501
|
var witnessify = (value) => {
|
1505
|
-
const data =
|
1502
|
+
const data = arrayify4(value);
|
1506
1503
|
return {
|
1507
1504
|
data: hexlify6(data),
|
1508
1505
|
dataLength: data.length
|
@@ -1974,19 +1971,27 @@ var BaseTransactionRequest = class {
|
|
1974
1971
|
toJSON() {
|
1975
1972
|
return normalizeJSON(this);
|
1976
1973
|
}
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1974
|
+
updatePredicateInputs(inputs) {
|
1975
|
+
this.inputs.forEach((i) => {
|
1976
|
+
let correspondingInput;
|
1977
|
+
switch (i.type) {
|
1978
|
+
case InputType2.Coin:
|
1979
|
+
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
1980
|
+
break;
|
1981
|
+
case InputType2.Message:
|
1982
|
+
correspondingInput = inputs.find(
|
1983
|
+
(x) => x.type === InputType2.Message && x.sender === i.sender
|
1984
|
+
);
|
1985
|
+
break;
|
1986
|
+
default:
|
1987
|
+
return;
|
1988
|
+
}
|
1989
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
1990
|
+
i.predicate = correspondingInput.predicate;
|
1991
|
+
i.predicateData = correspondingInput.predicateData;
|
1992
|
+
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
1993
|
+
}
|
1994
|
+
});
|
1990
1995
|
}
|
1991
1996
|
};
|
1992
1997
|
|
@@ -1994,14 +1999,15 @@ var BaseTransactionRequest = class {
|
|
1994
1999
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
1995
2000
|
import { bn as bn8 } from "@fuel-ts/math";
|
1996
2001
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
1997
|
-
import {
|
2002
|
+
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
1998
2003
|
|
1999
2004
|
// src/providers/transaction-request/hash-transaction.ts
|
2000
2005
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2001
2006
|
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2002
2007
|
import { bn as bn7 } from "@fuel-ts/math";
|
2003
2008
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2004
|
-
import { concat as concat2
|
2009
|
+
import { concat as concat2 } from "@fuel-ts/utils";
|
2010
|
+
import { sha256 } from "ethers";
|
2005
2011
|
import { clone as clone2 } from "ramda";
|
2006
2012
|
function hashTransaction(transactionRequest, chainId) {
|
2007
2013
|
const transaction = transactionRequest.toTransaction();
|
@@ -2068,10 +2074,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2068
2074
|
}
|
2069
2075
|
|
2070
2076
|
// src/providers/transaction-request/storage-slot.ts
|
2071
|
-
import {
|
2077
|
+
import { arrayify as arrayify5, hexlify as hexlify8 } from "@fuel-ts/utils";
|
2072
2078
|
var getStorageValue = (value) => {
|
2073
2079
|
const v = new Uint8Array(32);
|
2074
|
-
v.set(
|
2080
|
+
v.set(arrayify5(value));
|
2075
2081
|
return v;
|
2076
2082
|
};
|
2077
2083
|
var storageSlotify = (storageSlot) => {
|
@@ -2176,7 +2182,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2176
2182
|
}
|
2177
2183
|
metadataGas(gasCosts) {
|
2178
2184
|
return calculateMetadataGasForTxCreate({
|
2179
|
-
contractBytesSize: bn8(
|
2185
|
+
contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2180
2186
|
gasCosts,
|
2181
2187
|
stateRootSize: this.storageSlots.length,
|
2182
2188
|
txBytesSize: this.byteSize()
|
@@ -2190,17 +2196,17 @@ import { addressify as addressify2 } from "@fuel-ts/address";
|
|
2190
2196
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2191
2197
|
import { bn as bn9 } from "@fuel-ts/math";
|
2192
2198
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2193
|
-
import {
|
2199
|
+
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2194
2200
|
|
2195
2201
|
// src/providers/transaction-request/scripts.ts
|
2196
|
-
import {
|
2202
|
+
import { arrayify as arrayify7 } from "@fuel-ts/utils";
|
2197
2203
|
var returnZeroScript = {
|
2198
2204
|
/*
|
2199
2205
|
Opcode::RET(REG_ZERO)
|
2200
2206
|
Opcode::NOOP
|
2201
2207
|
*/
|
2202
2208
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2203
|
-
bytes:
|
2209
|
+
bytes: arrayify7("0x24000000"),
|
2204
2210
|
encodeScriptData: () => new Uint8Array(0)
|
2205
2211
|
};
|
2206
2212
|
var withdrawScript = {
|
@@ -2214,7 +2220,7 @@ var withdrawScript = {
|
|
2214
2220
|
00000000 00000000 [amount value]
|
2215
2221
|
*/
|
2216
2222
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2217
|
-
bytes:
|
2223
|
+
bytes: arrayify7("0x5040C0105D44C0064C40001124000000"),
|
2218
2224
|
encodeScriptData: () => new Uint8Array(0)
|
2219
2225
|
};
|
2220
2226
|
|
@@ -2242,8 +2248,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2242
2248
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2243
2249
|
super(rest);
|
2244
2250
|
this.gasLimit = bn9(gasLimit);
|
2245
|
-
this.script =
|
2246
|
-
this.scriptData =
|
2251
|
+
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2252
|
+
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2247
2253
|
}
|
2248
2254
|
/**
|
2249
2255
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2251,8 +2257,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2251
2257
|
* @returns The transaction script object.
|
2252
2258
|
*/
|
2253
2259
|
toTransaction() {
|
2254
|
-
const script =
|
2255
|
-
const scriptData =
|
2260
|
+
const script = arrayify8(this.script ?? "0x");
|
2261
|
+
const scriptData = arrayify8(this.scriptData ?? "0x");
|
2256
2262
|
return {
|
2257
2263
|
type: TransactionType4.Script,
|
2258
2264
|
scriptGasLimit: this.gasLimit,
|
@@ -2412,15 +2418,15 @@ var transactionRequestify = (obj) => {
|
|
2412
2418
|
import { ErrorCode as ErrorCode10, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2413
2419
|
import { bn as bn13 } from "@fuel-ts/math";
|
2414
2420
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2415
|
-
import {
|
2421
|
+
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2416
2422
|
|
2417
2423
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2418
|
-
import { hexlify as hexlify11 } from "
|
2424
|
+
import { hexlify as hexlify11 } from "@fuel-ts/utils";
|
2419
2425
|
|
2420
2426
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2421
2427
|
import { bn as bn10 } from "@fuel-ts/math";
|
2422
2428
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2423
|
-
import {
|
2429
|
+
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2424
2430
|
var calculateTransactionFee = (params) => {
|
2425
2431
|
const {
|
2426
2432
|
gasUsed,
|
@@ -2429,7 +2435,7 @@ var calculateTransactionFee = (params) => {
|
|
2429
2435
|
} = params;
|
2430
2436
|
const gasPerByte = bn10(feeParams.gasPerByte);
|
2431
2437
|
const gasPriceFactor = bn10(feeParams.gasPriceFactor);
|
2432
|
-
const transactionBytes =
|
2438
|
+
const transactionBytes = arrayify9(rawPayload);
|
2433
2439
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2434
2440
|
if (transaction.type === TransactionType6.Mint) {
|
2435
2441
|
return {
|
@@ -2444,7 +2450,7 @@ var calculateTransactionFee = (params) => {
|
|
2444
2450
|
let gasLimit = bn10(0);
|
2445
2451
|
if (type === TransactionType6.Create) {
|
2446
2452
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2447
|
-
const contractBytesSize = bn10(
|
2453
|
+
const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2448
2454
|
metadataGas = calculateMetadataGasForTxCreate({
|
2449
2455
|
contractBytesSize,
|
2450
2456
|
gasCosts,
|
@@ -2498,6 +2504,7 @@ var fromTai64ToDate = (tai64Timestamp) => {
|
|
2498
2504
|
};
|
2499
2505
|
|
2500
2506
|
// src/providers/transaction-summary/operations.ts
|
2507
|
+
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2501
2508
|
import { ErrorCode as ErrorCode8, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2502
2509
|
import { bn as bn12 } from "@fuel-ts/math";
|
2503
2510
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
@@ -2694,36 +2701,6 @@ function addOperation(operations, toAdd) {
|
|
2694
2701
|
}
|
2695
2702
|
return allOperations;
|
2696
2703
|
}
|
2697
|
-
function getReceiptsTransferOut(receipts) {
|
2698
|
-
return getReceiptsByType(receipts, ReceiptType3.TransferOut);
|
2699
|
-
}
|
2700
|
-
function getContractTransferOperations({ receipts }) {
|
2701
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
2702
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
2703
|
-
(prevContractTransferOps, receipt) => {
|
2704
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
2705
|
-
name: "Contract transfer" /* contractTransfer */,
|
2706
|
-
from: {
|
2707
|
-
type: 0 /* contract */,
|
2708
|
-
address: receipt.from
|
2709
|
-
},
|
2710
|
-
to: {
|
2711
|
-
type: 1 /* account */,
|
2712
|
-
address: receipt.to
|
2713
|
-
},
|
2714
|
-
assetsSent: [
|
2715
|
-
{
|
2716
|
-
amount: receipt.amount,
|
2717
|
-
assetId: receipt.assetId
|
2718
|
-
}
|
2719
|
-
]
|
2720
|
-
});
|
2721
|
-
return newContractTransferOps;
|
2722
|
-
},
|
2723
|
-
[]
|
2724
|
-
);
|
2725
|
-
return contractTransferOperations;
|
2726
|
-
}
|
2727
2704
|
function getWithdrawFromFuelOperations({
|
2728
2705
|
inputs,
|
2729
2706
|
receipts
|
@@ -2821,70 +2798,77 @@ function getContractCallOperations({
|
|
2821
2798
|
}, []);
|
2822
2799
|
return contractCallOperations;
|
2823
2800
|
}
|
2801
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
2802
|
+
const { to: toAddress, assetId, amount } = receipt;
|
2803
|
+
let { from: fromAddress } = receipt;
|
2804
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2805
|
+
if (ZeroBytes328 === fromAddress) {
|
2806
|
+
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2807
|
+
fromAddress = change?.to || fromAddress;
|
2808
|
+
}
|
2809
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
2810
|
+
return {
|
2811
|
+
name: "Transfer asset" /* transfer */,
|
2812
|
+
from: {
|
2813
|
+
type: fromType,
|
2814
|
+
address: fromAddress
|
2815
|
+
},
|
2816
|
+
to: {
|
2817
|
+
type: toType,
|
2818
|
+
address: toAddress
|
2819
|
+
},
|
2820
|
+
assetsSent: [
|
2821
|
+
{
|
2822
|
+
assetId: assetId.toString(),
|
2823
|
+
amount
|
2824
|
+
}
|
2825
|
+
]
|
2826
|
+
};
|
2827
|
+
}
|
2824
2828
|
function getTransferOperations({
|
2825
2829
|
inputs,
|
2826
2830
|
outputs,
|
2827
2831
|
receipts
|
2828
2832
|
}) {
|
2833
|
+
let operations = [];
|
2829
2834
|
const coinOutputs = getOutputsCoin(outputs);
|
2830
|
-
const
|
2835
|
+
const contractInputs = getInputsContract(inputs);
|
2836
|
+
const changeOutputs = getOutputsChange(outputs);
|
2837
|
+
coinOutputs.forEach((output) => {
|
2838
|
+
const { amount, assetId, to } = output;
|
2839
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
2840
|
+
if (changeOutput) {
|
2841
|
+
operations = addOperation(operations, {
|
2842
|
+
name: "Transfer asset" /* transfer */,
|
2843
|
+
from: {
|
2844
|
+
type: 1 /* account */,
|
2845
|
+
address: changeOutput.to
|
2846
|
+
},
|
2847
|
+
to: {
|
2848
|
+
type: 1 /* account */,
|
2849
|
+
address: to
|
2850
|
+
},
|
2851
|
+
assetsSent: [
|
2852
|
+
{
|
2853
|
+
assetId,
|
2854
|
+
amount
|
2855
|
+
}
|
2856
|
+
]
|
2857
|
+
});
|
2858
|
+
}
|
2859
|
+
});
|
2860
|
+
const transferReceipts = getReceiptsByType(
|
2831
2861
|
receipts,
|
2832
2862
|
ReceiptType3.Transfer
|
2833
2863
|
);
|
2834
|
-
|
2835
|
-
|
2836
|
-
|
2837
|
-
|
2838
|
-
|
2839
|
-
|
2840
|
-
|
2841
|
-
|
2842
|
-
const inputAddress = getInputAccountAddress(utxo);
|
2843
|
-
operations = addOperation(operations, {
|
2844
|
-
name: "Transfer asset" /* transfer */,
|
2845
|
-
from: {
|
2846
|
-
type: 1 /* account */,
|
2847
|
-
address: inputAddress
|
2848
|
-
},
|
2849
|
-
to: {
|
2850
|
-
type: 0 /* contract */,
|
2851
|
-
address: contractInput.contractID
|
2852
|
-
},
|
2853
|
-
assetsSent: [
|
2854
|
-
{
|
2855
|
-
assetId: assetId.toString(),
|
2856
|
-
amount: transferReceipt.amount
|
2857
|
-
}
|
2858
|
-
]
|
2859
|
-
});
|
2860
|
-
}
|
2861
|
-
});
|
2862
|
-
} else {
|
2863
|
-
coinOutputs.forEach((output) => {
|
2864
|
-
const input = getInputFromAssetId(inputs, output.assetId);
|
2865
|
-
if (input) {
|
2866
|
-
const inputAddress = getInputAccountAddress(input);
|
2867
|
-
const operationToAdd = {
|
2868
|
-
name: "Transfer asset" /* transfer */,
|
2869
|
-
from: {
|
2870
|
-
type: 1 /* account */,
|
2871
|
-
address: inputAddress
|
2872
|
-
},
|
2873
|
-
to: {
|
2874
|
-
type: 1 /* account */,
|
2875
|
-
address: output.to.toString()
|
2876
|
-
},
|
2877
|
-
assetsSent: [
|
2878
|
-
{
|
2879
|
-
assetId: output.assetId.toString(),
|
2880
|
-
amount: output.amount
|
2881
|
-
}
|
2882
|
-
]
|
2883
|
-
};
|
2884
|
-
operations = addOperation(operations, operationToAdd);
|
2885
|
-
}
|
2886
|
-
});
|
2887
|
-
}
|
2864
|
+
const transferOutReceipts = getReceiptsByType(
|
2865
|
+
receipts,
|
2866
|
+
ReceiptType3.TransferOut
|
2867
|
+
);
|
2868
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2869
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
2870
|
+
operations = addOperation(operations, operation);
|
2871
|
+
});
|
2888
2872
|
return operations;
|
2889
2873
|
}
|
2890
2874
|
function getPayProducerOperations(outputs) {
|
@@ -2957,7 +2941,6 @@ function getOperations({
|
|
2957
2941
|
rawPayload,
|
2958
2942
|
maxInputs
|
2959
2943
|
}),
|
2960
|
-
...getContractTransferOperations({ receipts }),
|
2961
2944
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
2962
2945
|
];
|
2963
2946
|
}
|
@@ -3203,7 +3186,7 @@ var TransactionResponse = class {
|
|
3203
3186
|
*/
|
3204
3187
|
decodeTransaction(transactionWithReceipts) {
|
3205
3188
|
return new TransactionCoder4().decode(
|
3206
|
-
|
3189
|
+
arrayify10(transactionWithReceipts.rawPayload),
|
3207
3190
|
0
|
3208
3191
|
)?.[0];
|
3209
3192
|
}
|
@@ -3229,7 +3212,7 @@ var TransactionResponse = class {
|
|
3229
3212
|
id: this.id,
|
3230
3213
|
receipts,
|
3231
3214
|
transaction: decodedTransaction,
|
3232
|
-
transactionBytes:
|
3215
|
+
transactionBytes: arrayify10(transaction.rawPayload),
|
3233
3216
|
gqlTransactionStatus: transaction.status,
|
3234
3217
|
gasPerByte,
|
3235
3218
|
gasPriceFactor,
|
@@ -3519,7 +3502,7 @@ var _Provider = class {
|
|
3519
3502
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
3520
3503
|
const isSubscription = opDefinition?.operation === "subscription";
|
3521
3504
|
if (isSubscription) {
|
3522
|
-
return
|
3505
|
+
return new FuelGraphqlSubscriber({
|
3523
3506
|
url: this.url,
|
3524
3507
|
query,
|
3525
3508
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -3652,7 +3635,7 @@ var _Provider = class {
|
|
3652
3635
|
async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
3653
3636
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3654
3637
|
if (estimateTxDependencies) {
|
3655
|
-
|
3638
|
+
return this.estimateTxDependencies(transactionRequest);
|
3656
3639
|
}
|
3657
3640
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3658
3641
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
@@ -3671,6 +3654,14 @@ var _Provider = class {
|
|
3671
3654
|
* @returns A promise that resolves to the estimated transaction request object.
|
3672
3655
|
*/
|
3673
3656
|
async estimatePredicates(transactionRequest) {
|
3657
|
+
const shouldEstimatePredicates = Boolean(
|
3658
|
+
transactionRequest.inputs.find(
|
3659
|
+
(input) => "predicate" in input && input.predicate && !equalBytes(arrayify11(input.predicate), arrayify11("0x")) && new BN(input.predicateGasUsed).isZero()
|
3660
|
+
)
|
3661
|
+
);
|
3662
|
+
if (!shouldEstimatePredicates) {
|
3663
|
+
return transactionRequest;
|
3664
|
+
}
|
3674
3665
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3675
3666
|
const response = await this.operations.estimatePredicates({
|
3676
3667
|
encodedTransaction
|
@@ -3701,34 +3692,41 @@ var _Provider = class {
|
|
3701
3692
|
* @returns A promise.
|
3702
3693
|
*/
|
3703
3694
|
async estimateTxDependencies(transactionRequest) {
|
3704
|
-
let missingOutputVariableCount = 0;
|
3705
|
-
let missingOutputContractIdsCount = 0;
|
3706
|
-
let tries = 0;
|
3707
3695
|
if (transactionRequest.type === TransactionType8.Create) {
|
3708
|
-
return
|
3709
|
-
|
3710
|
-
|
3711
|
-
|
3712
|
-
|
3696
|
+
return {
|
3697
|
+
receipts: [],
|
3698
|
+
outputVariables: 0,
|
3699
|
+
missingContractIds: []
|
3700
|
+
};
|
3713
3701
|
}
|
3714
|
-
|
3702
|
+
await this.estimatePredicates(transactionRequest);
|
3703
|
+
let receipts = [];
|
3704
|
+
const missingContractIds = [];
|
3705
|
+
let outputVariables = 0;
|
3706
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3715
3707
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3716
|
-
encodedTransaction: hexlify12(
|
3708
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3717
3709
|
utxoValidation: false
|
3718
3710
|
});
|
3719
|
-
|
3711
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3720
3712
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3721
|
-
|
3722
|
-
|
3723
|
-
|
3724
|
-
|
3713
|
+
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3714
|
+
if (hasMissingOutputs) {
|
3715
|
+
outputVariables += missingOutputVariables.length;
|
3716
|
+
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3717
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
3718
|
+
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3719
|
+
missingContractIds.push(contractId);
|
3720
|
+
});
|
3721
|
+
} else {
|
3722
|
+
break;
|
3725
3723
|
}
|
3726
|
-
txRequest.addVariableOutputs(missingOutputVariableCount);
|
3727
|
-
missingOutputContractIds.forEach(
|
3728
|
-
({ contractId }) => txRequest.addContractInputAndOutput(Address2.fromString(contractId))
|
3729
|
-
);
|
3730
|
-
tries += 1;
|
3731
3724
|
}
|
3725
|
+
return {
|
3726
|
+
receipts,
|
3727
|
+
outputVariables,
|
3728
|
+
missingContractIds
|
3729
|
+
};
|
3732
3730
|
}
|
3733
3731
|
/**
|
3734
3732
|
* Executes a signed transaction without applying the states changes
|
@@ -3743,7 +3741,7 @@ var _Provider = class {
|
|
3743
3741
|
async simulate(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
3744
3742
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3745
3743
|
if (estimateTxDependencies) {
|
3746
|
-
|
3744
|
+
return this.estimateTxDependencies(transactionRequest);
|
3747
3745
|
}
|
3748
3746
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3749
3747
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
@@ -3775,35 +3773,37 @@ var _Provider = class {
|
|
3775
3773
|
estimatePredicates = true,
|
3776
3774
|
resourcesOwner
|
3777
3775
|
} = {}) {
|
3778
|
-
const
|
3776
|
+
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3779
3777
|
const chainInfo = this.getChain();
|
3780
3778
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3781
|
-
const gasPrice = max(
|
3782
|
-
const isScriptTransaction =
|
3783
|
-
|
3779
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3780
|
+
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3781
|
+
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3782
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3783
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3784
|
+
if (estimatePredicates) {
|
3784
3785
|
if (isScriptTransaction) {
|
3785
|
-
|
3786
|
+
txRequestClone.gasLimit = bn14(0);
|
3787
|
+
}
|
3788
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3789
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3786
3790
|
}
|
3787
|
-
await this.estimatePredicates(
|
3791
|
+
await this.estimatePredicates(txRequestClone);
|
3788
3792
|
}
|
3789
|
-
const minGas =
|
3790
|
-
const maxGas =
|
3791
|
-
const coinOutputsQuantities = transactionRequest.getCoinOutputsQuantities();
|
3792
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3793
|
-
transactionRequest.fundWithFakeUtxos(allQuantities, resourcesOwner);
|
3794
|
-
let gasUsed = minGas;
|
3793
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3794
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3795
3795
|
let receipts = [];
|
3796
|
-
|
3797
|
-
|
3798
|
-
|
3799
|
-
|
3800
|
-
|
3801
|
-
|
3796
|
+
let missingContractIds = [];
|
3797
|
+
let outputVariables = 0;
|
3798
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3799
|
+
txRequestClone.gasPrice = bn14(0);
|
3800
|
+
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3801
|
+
const result = await this.estimateTxDependencies(txRequestClone);
|
3802
3802
|
receipts = result.receipts;
|
3803
|
-
|
3804
|
-
|
3805
|
-
gasUsed = minGas;
|
3803
|
+
outputVariables = result.outputVariables;
|
3804
|
+
missingContractIds = result.missingContractIds;
|
3806
3805
|
}
|
3806
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3807
3807
|
const usedFee = calculatePriceWithFactor(
|
3808
3808
|
gasUsed,
|
3809
3809
|
gasPrice,
|
@@ -3821,7 +3821,10 @@ var _Provider = class {
|
|
3821
3821
|
maxGas,
|
3822
3822
|
usedFee,
|
3823
3823
|
minFee,
|
3824
|
-
maxFee
|
3824
|
+
maxFee,
|
3825
|
+
estimatedInputs: txRequestClone.inputs,
|
3826
|
+
outputVariables,
|
3827
|
+
missingContractIds
|
3825
3828
|
};
|
3826
3829
|
}
|
3827
3830
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -3989,7 +3992,7 @@ var _Provider = class {
|
|
3989
3992
|
time: block.header.time,
|
3990
3993
|
transactionIds: block.transactions.map((tx) => tx.id),
|
3991
3994
|
transactions: block.transactions.map(
|
3992
|
-
(tx) => new TransactionCoder5().decode(
|
3995
|
+
(tx) => new TransactionCoder5().decode(arrayify11(tx.rawPayload), 0)?.[0]
|
3993
3996
|
)
|
3994
3997
|
};
|
3995
3998
|
}
|
@@ -4005,7 +4008,7 @@ var _Provider = class {
|
|
4005
4008
|
return null;
|
4006
4009
|
}
|
4007
4010
|
return new TransactionCoder5().decode(
|
4008
|
-
|
4011
|
+
arrayify11(transaction.rawPayload),
|
4009
4012
|
0
|
4010
4013
|
)?.[0];
|
4011
4014
|
}
|
@@ -4235,21 +4238,66 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4235
4238
|
import { ErrorCode as ErrorCode12, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4236
4239
|
import { bn as bn15 } from "@fuel-ts/math";
|
4237
4240
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4238
|
-
import {
|
4241
|
+
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4242
|
+
|
4243
|
+
// src/providers/chains.ts
|
4244
|
+
var CHAIN_IDS = {
|
4245
|
+
eth: {
|
4246
|
+
sepolia: 11155111,
|
4247
|
+
foundry: 31337
|
4248
|
+
},
|
4249
|
+
fuel: {
|
4250
|
+
beta5: 0,
|
4251
|
+
devnet: 10
|
4252
|
+
}
|
4253
|
+
};
|
4254
|
+
|
4255
|
+
// src/providers/assets/index.ts
|
4256
|
+
var assets = [
|
4257
|
+
{
|
4258
|
+
name: "Ethereum",
|
4259
|
+
symbol: "ETH",
|
4260
|
+
icon: "eth.svg",
|
4261
|
+
networks: [
|
4262
|
+
{
|
4263
|
+
type: "ethereum",
|
4264
|
+
chainId: CHAIN_IDS.eth.sepolia,
|
4265
|
+
decimals: 18
|
4266
|
+
},
|
4267
|
+
{
|
4268
|
+
type: "ethereum",
|
4269
|
+
chainId: CHAIN_IDS.eth.foundry,
|
4270
|
+
decimals: 18
|
4271
|
+
},
|
4272
|
+
{
|
4273
|
+
type: "fuel",
|
4274
|
+
chainId: CHAIN_IDS.fuel.beta5,
|
4275
|
+
decimals: 9,
|
4276
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4277
|
+
},
|
4278
|
+
{
|
4279
|
+
type: "fuel",
|
4280
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4281
|
+
decimals: 9,
|
4282
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4283
|
+
}
|
4284
|
+
]
|
4285
|
+
}
|
4286
|
+
];
|
4239
4287
|
|
4240
4288
|
// src/utils/formatTransferToContractScriptData.ts
|
4241
4289
|
import { U64Coder as U64Coder2 } from "@fuel-ts/abi-coder";
|
4242
|
-
import { BN } from "@fuel-ts/math";
|
4290
|
+
import { BN as BN2 } from "@fuel-ts/math";
|
4291
|
+
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
4243
4292
|
import * as asm from "@fuels/vm-asm";
|
4244
|
-
import { getBytesCopy as getBytesCopy14 } from "ethers";
|
4245
4293
|
var formatTransferToContractScriptData = (params) => {
|
4246
4294
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4247
4295
|
const numberCoder = new U64Coder2();
|
4248
|
-
const encoded = numberCoder.encode(new
|
4296
|
+
const encoded = numberCoder.encode(new BN2(amountToTransfer).toNumber());
|
4249
4297
|
const scriptData = Uint8Array.from([
|
4250
|
-
...
|
4298
|
+
...arrayify13(hexlifiedContractId),
|
4251
4299
|
...encoded,
|
4252
|
-
...
|
4300
|
+
...arrayify13(assetId)
|
4253
4301
|
]);
|
4254
4302
|
return scriptData;
|
4255
4303
|
};
|
@@ -4499,7 +4547,10 @@ var Account = class extends AbstractAccount {
|
|
4499
4547
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4500
4548
|
const request = new ScriptTransactionRequest(params);
|
4501
4549
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4502
|
-
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(request
|
4550
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4551
|
+
estimateTxDependencies: true,
|
4552
|
+
resourcesOwner: this
|
4553
|
+
});
|
4503
4554
|
request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
|
4504
4555
|
request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
|
4505
4556
|
this.validateGas({
|
@@ -4509,6 +4560,7 @@ var Account = class extends AbstractAccount {
|
|
4509
4560
|
minGasPrice
|
4510
4561
|
});
|
4511
4562
|
await this.fund(request, requiredQuantities, maxFee);
|
4563
|
+
request.updatePredicateInputs(estimatedInputs);
|
4512
4564
|
return request;
|
4513
4565
|
}
|
4514
4566
|
/**
|
@@ -4522,7 +4574,7 @@ var Account = class extends AbstractAccount {
|
|
4522
4574
|
*/
|
4523
4575
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4524
4576
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4525
|
-
return this.sendTransaction(request);
|
4577
|
+
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4526
4578
|
}
|
4527
4579
|
/**
|
4528
4580
|
* Transfers coins to a contract address.
|
@@ -4573,14 +4625,14 @@ var Account = class extends AbstractAccount {
|
|
4573
4625
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4574
4626
|
const { minGasPrice } = this.provider.getGasConfig();
|
4575
4627
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4576
|
-
const recipientDataArray =
|
4628
|
+
const recipientDataArray = arrayify14(
|
4577
4629
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4578
4630
|
);
|
4579
|
-
const amountDataArray =
|
4631
|
+
const amountDataArray = arrayify14(
|
4580
4632
|
"0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
|
4581
4633
|
);
|
4582
4634
|
const script = new Uint8Array([
|
4583
|
-
...
|
4635
|
+
...arrayify14(withdrawScript.bytes),
|
4584
4636
|
...recipientDataArray,
|
4585
4637
|
...amountDataArray
|
4586
4638
|
]);
|
@@ -4613,16 +4665,18 @@ var Account = class extends AbstractAccount {
|
|
4613
4665
|
* @param transactionRequestLike - The transaction request to be sent.
|
4614
4666
|
* @returns A promise that resolves to the transaction response.
|
4615
4667
|
*/
|
4616
|
-
async sendTransaction(transactionRequestLike,
|
4668
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4617
4669
|
if (this._connector) {
|
4618
4670
|
return this.provider.getTransactionResponse(
|
4619
4671
|
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
|
4620
4672
|
);
|
4621
4673
|
}
|
4622
4674
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4623
|
-
|
4675
|
+
if (estimateTxDependencies) {
|
4676
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4677
|
+
}
|
4624
4678
|
return this.provider.sendTransaction(transactionRequest, {
|
4625
|
-
|
4679
|
+
awaitExecution,
|
4626
4680
|
estimateTxDependencies: false
|
4627
4681
|
});
|
4628
4682
|
}
|
@@ -4632,9 +4686,11 @@ var Account = class extends AbstractAccount {
|
|
4632
4686
|
* @param transactionRequestLike - The transaction request to be simulated.
|
4633
4687
|
* @returns A promise that resolves to the call result.
|
4634
4688
|
*/
|
4635
|
-
async simulateTransaction(transactionRequestLike) {
|
4689
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4636
4690
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4637
|
-
|
4691
|
+
if (estimateTxDependencies) {
|
4692
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4693
|
+
}
|
4638
4694
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4639
4695
|
}
|
4640
4696
|
validateGas({
|
@@ -4663,8 +4719,8 @@ import { Address as Address4 } from "@fuel-ts/address";
|
|
4663
4719
|
import { randomBytes } from "@fuel-ts/crypto";
|
4664
4720
|
import { hash } from "@fuel-ts/hasher";
|
4665
4721
|
import { toBytes } from "@fuel-ts/math";
|
4722
|
+
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
4666
4723
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
4667
|
-
import { hexlify as hexlify13, concat as concat3, getBytesCopy as getBytesCopy16 } from "ethers";
|
4668
4724
|
var Signer = class {
|
4669
4725
|
address;
|
4670
4726
|
publicKey;
|
@@ -4699,11 +4755,11 @@ var Signer = class {
|
|
4699
4755
|
* @returns hashed signature
|
4700
4756
|
*/
|
4701
4757
|
sign(data) {
|
4702
|
-
const signature = secp256k1.sign(
|
4758
|
+
const signature = secp256k1.sign(arrayify15(data), arrayify15(this.privateKey));
|
4703
4759
|
const r = toBytes(`0x${signature.r.toString(16)}`, 32);
|
4704
4760
|
const s = toBytes(`0x${signature.s.toString(16)}`, 32);
|
4705
4761
|
s[0] |= (signature.recovery || 0) << 7;
|
4706
|
-
return concat3([r, s]);
|
4762
|
+
return hexlify13(concat3([r, s]));
|
4707
4763
|
}
|
4708
4764
|
/**
|
4709
4765
|
* Add point on the current elliptic curve
|
@@ -4712,8 +4768,8 @@ var Signer = class {
|
|
4712
4768
|
* @returns compressed point on the curve
|
4713
4769
|
*/
|
4714
4770
|
addPoint(point) {
|
4715
|
-
const p0 = secp256k1.ProjectivePoint.fromHex(
|
4716
|
-
const p1 = secp256k1.ProjectivePoint.fromHex(
|
4771
|
+
const p0 = secp256k1.ProjectivePoint.fromHex(arrayify15(this.compressedPublicKey));
|
4772
|
+
const p1 = secp256k1.ProjectivePoint.fromHex(arrayify15(point));
|
4717
4773
|
const result = p0.add(p1);
|
4718
4774
|
return `0x${result.toHex(true)}`;
|
4719
4775
|
}
|
@@ -4725,7 +4781,7 @@ var Signer = class {
|
|
4725
4781
|
* @returns public key from signature from the
|
4726
4782
|
*/
|
4727
4783
|
static recoverPublicKey(data, signature) {
|
4728
|
-
const signedMessageBytes =
|
4784
|
+
const signedMessageBytes = arrayify15(signature);
|
4729
4785
|
const r = signedMessageBytes.slice(0, 32);
|
4730
4786
|
const s = signedMessageBytes.slice(32, 64);
|
4731
4787
|
const recoveryParam = (s[0] & 128) >> 7;
|
@@ -4733,7 +4789,7 @@ var Signer = class {
|
|
4733
4789
|
const sig = new secp256k1.Signature(BigInt(hexlify13(r)), BigInt(hexlify13(s))).addRecoveryBit(
|
4734
4790
|
recoveryParam
|
4735
4791
|
);
|
4736
|
-
const publicKey = sig.recoverPublicKey(
|
4792
|
+
const publicKey = sig.recoverPublicKey(arrayify15(data)).toRawBytes(false).slice(1);
|
4737
4793
|
return hexlify13(publicKey);
|
4738
4794
|
}
|
4739
4795
|
/**
|
@@ -4753,7 +4809,7 @@ var Signer = class {
|
|
4753
4809
|
* @returns random 32-byte hashed
|
4754
4810
|
*/
|
4755
4811
|
static generatePrivateKey(entropy) {
|
4756
|
-
return entropy ? hash(concat3([randomBytes(32),
|
4812
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
4757
4813
|
}
|
4758
4814
|
/**
|
4759
4815
|
* Extended publicKey from a compact publicKey
|
@@ -4762,7 +4818,7 @@ var Signer = class {
|
|
4762
4818
|
* @returns extended publicKey
|
4763
4819
|
*/
|
4764
4820
|
static extendPublicKey(publicKey) {
|
4765
|
-
const point = secp256k1.ProjectivePoint.fromHex(
|
4821
|
+
const point = secp256k1.ProjectivePoint.fromHex(arrayify15(publicKey));
|
4766
4822
|
return hexlify13(point.toRawBytes(false).slice(1));
|
4767
4823
|
}
|
4768
4824
|
};
|
@@ -4779,7 +4835,7 @@ import {
|
|
4779
4835
|
encryptJsonWalletData
|
4780
4836
|
} from "@fuel-ts/crypto";
|
4781
4837
|
import { ErrorCode as ErrorCode14, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4782
|
-
import { hexlify as hexlify14 } from "
|
4838
|
+
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4783
4839
|
import { v4 as uuidv4 } from "uuid";
|
4784
4840
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4785
4841
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -4907,7 +4963,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4907
4963
|
*/
|
4908
4964
|
async signMessage(message) {
|
4909
4965
|
const signedMessage = await this.signer().sign(hashMessage(message));
|
4910
|
-
return signedMessage;
|
4966
|
+
return hexlify15(signedMessage);
|
4911
4967
|
}
|
4912
4968
|
/**
|
4913
4969
|
* Signs a transaction with the wallet's private key.
|
@@ -4920,7 +4976,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4920
4976
|
const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
|
4921
4977
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
4922
4978
|
const signature = await this.signer().sign(hashedTransaction);
|
4923
|
-
return signature;
|
4979
|
+
return hexlify15(signature);
|
4924
4980
|
}
|
4925
4981
|
/**
|
4926
4982
|
* Populates a transaction with the witnesses signature.
|
@@ -4940,12 +4996,14 @@ var BaseWalletUnlocked = class extends Account {
|
|
4940
4996
|
* @param transactionRequestLike - The transaction request to send.
|
4941
4997
|
* @returns A promise that resolves to the TransactionResponse object.
|
4942
4998
|
*/
|
4943
|
-
async sendTransaction(transactionRequestLike,
|
4999
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4944
5000
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4945
|
-
|
5001
|
+
if (estimateTxDependencies) {
|
5002
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5003
|
+
}
|
4946
5004
|
return this.provider.sendTransaction(
|
4947
5005
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4948
|
-
{
|
5006
|
+
{ awaitExecution, estimateTxDependencies: false }
|
4949
5007
|
);
|
4950
5008
|
}
|
4951
5009
|
/**
|
@@ -4954,9 +5012,11 @@ var BaseWalletUnlocked = class extends Account {
|
|
4954
5012
|
* @param transactionRequestLike - The transaction request to simulate.
|
4955
5013
|
* @returns A promise that resolves to the CallResult object.
|
4956
5014
|
*/
|
4957
|
-
async simulateTransaction(transactionRequestLike) {
|
5015
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4958
5016
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4959
|
-
|
5017
|
+
if (estimateTxDependencies) {
|
5018
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5019
|
+
}
|
4960
5020
|
return this.provider.call(
|
4961
5021
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4962
5022
|
{
|
@@ -4977,32 +5037,22 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
4977
5037
|
// src/hdwallet/hdwallet.ts
|
4978
5038
|
import { ErrorCode as ErrorCode17, FuelError as FuelError18 } from "@fuel-ts/errors";
|
4979
5039
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5040
|
+
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
4980
5041
|
import {
|
4981
5042
|
toBeHex,
|
4982
5043
|
dataSlice as dataSlice2,
|
4983
|
-
hexlify as hexlify16,
|
4984
5044
|
encodeBase58 as encodeBase582,
|
4985
5045
|
decodeBase58,
|
4986
5046
|
sha256 as sha2564,
|
4987
5047
|
computeHmac as computeHmac2,
|
4988
|
-
ripemd160
|
4989
|
-
getBytesCopy as getBytesCopy19,
|
4990
|
-
concat as concat5
|
5048
|
+
ripemd160
|
4991
5049
|
} from "ethers";
|
4992
5050
|
|
4993
5051
|
// src/mnemonic/mnemonic.ts
|
4994
5052
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
4995
5053
|
import { ErrorCode as ErrorCode16, FuelError as FuelError17 } from "@fuel-ts/errors";
|
4996
|
-
import {
|
4997
|
-
|
4998
|
-
hexlify as hexlify15,
|
4999
|
-
dataSlice,
|
5000
|
-
pbkdf2,
|
5001
|
-
sha256 as sha2563,
|
5002
|
-
computeHmac,
|
5003
|
-
encodeBase58,
|
5004
|
-
getBytesCopy as getBytesCopy18
|
5005
|
-
} from "ethers";
|
5054
|
+
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5055
|
+
import { dataSlice, pbkdf2, sha256 as sha2563, computeHmac, encodeBase58 } from "ethers";
|
5006
5056
|
|
5007
5057
|
// src/wordlists/words/english.ts
|
5008
5058
|
var english = [
|
@@ -7058,7 +7108,8 @@ var english = [
|
|
7058
7108
|
|
7059
7109
|
// src/mnemonic/utils.ts
|
7060
7110
|
import { ErrorCode as ErrorCode15, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7061
|
-
import {
|
7111
|
+
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7112
|
+
import { sha256 as sha2562 } from "ethers";
|
7062
7113
|
function toUtf8Bytes(stri) {
|
7063
7114
|
const str = stri.normalize("NFKD");
|
7064
7115
|
const result = [];
|
@@ -7125,14 +7176,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7125
7176
|
}
|
7126
7177
|
}
|
7127
7178
|
const checksumBits = entropy.length / 4;
|
7128
|
-
const checksum =
|
7179
|
+
const checksum = arrayify16(sha2562(entropy))[0] & getUpperMask(checksumBits);
|
7129
7180
|
indices[indices.length - 1] <<= checksumBits;
|
7130
7181
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7131
7182
|
return indices;
|
7132
7183
|
}
|
7133
7184
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7134
7185
|
const size = Math.ceil(11 * words.length / 8);
|
7135
|
-
const entropy =
|
7186
|
+
const entropy = arrayify16(new Uint8Array(size));
|
7136
7187
|
let offset = 0;
|
7137
7188
|
for (let i = 0; i < words.length; i += 1) {
|
7138
7189
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7152,7 +7203,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7152
7203
|
const entropyBits = 32 * words.length / 3;
|
7153
7204
|
const checksumBits = words.length / 3;
|
7154
7205
|
const checksumMask = getUpperMask(checksumBits);
|
7155
|
-
const checksum =
|
7206
|
+
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7156
7207
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7157
7208
|
throw new FuelError16(
|
7158
7209
|
ErrorCode15.INVALID_CHECKSUM,
|
@@ -7227,7 +7278,7 @@ var Mnemonic = class {
|
|
7227
7278
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7228
7279
|
const words = getWords(phrase);
|
7229
7280
|
assertMnemonic(words);
|
7230
|
-
return
|
7281
|
+
return hexlify16(mnemonicWordsToEntropy(words, wordlist));
|
7231
7282
|
}
|
7232
7283
|
/**
|
7233
7284
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7235,7 +7286,7 @@ var Mnemonic = class {
|
|
7235
7286
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7236
7287
|
*/
|
7237
7288
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7238
|
-
const entropyBytes =
|
7289
|
+
const entropyBytes = arrayify17(entropy);
|
7239
7290
|
assertWordList(wordlist);
|
7240
7291
|
assertEntropy(entropyBytes);
|
7241
7292
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7304,14 +7355,14 @@ var Mnemonic = class {
|
|
7304
7355
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7305
7356
|
*/
|
7306
7357
|
static masterKeysFromSeed(seed) {
|
7307
|
-
const seedArray =
|
7358
|
+
const seedArray = arrayify17(seed);
|
7308
7359
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7309
7360
|
throw new FuelError17(
|
7310
7361
|
ErrorCode16.INVALID_SEED,
|
7311
7362
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7312
7363
|
);
|
7313
7364
|
}
|
7314
|
-
return
|
7365
|
+
return arrayify17(computeHmac("sha512", MasterSecret, seedArray));
|
7315
7366
|
}
|
7316
7367
|
/**
|
7317
7368
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7322,7 +7373,7 @@ var Mnemonic = class {
|
|
7322
7373
|
*/
|
7323
7374
|
static seedToExtendedKey(seed, testnet = false) {
|
7324
7375
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7325
|
-
const prefix =
|
7376
|
+
const prefix = arrayify17(testnet ? TestnetPRV : MainnetPRV);
|
7326
7377
|
const depth = "0x00";
|
7327
7378
|
const fingerprint = "0x00000000";
|
7328
7379
|
const index = "0x00000000";
|
@@ -7352,7 +7403,7 @@ var Mnemonic = class {
|
|
7352
7403
|
* @returns A randomly generated mnemonic
|
7353
7404
|
*/
|
7354
7405
|
static generate(size = 32, extraEntropy = "") {
|
7355
|
-
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size),
|
7406
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7356
7407
|
return Mnemonic.entropyToMnemonic(entropy);
|
7357
7408
|
}
|
7358
7409
|
};
|
@@ -7360,10 +7411,10 @@ var mnemonic_default = Mnemonic;
|
|
7360
7411
|
|
7361
7412
|
// src/hdwallet/hdwallet.ts
|
7362
7413
|
var HARDENED_INDEX = 2147483648;
|
7363
|
-
var MainnetPRV2 =
|
7364
|
-
var MainnetPUB =
|
7365
|
-
var TestnetPRV2 =
|
7366
|
-
var TestnetPUB =
|
7414
|
+
var MainnetPRV2 = hexlify17("0x0488ade4");
|
7415
|
+
var MainnetPUB = hexlify17("0x0488b21e");
|
7416
|
+
var TestnetPRV2 = hexlify17("0x04358394");
|
7417
|
+
var TestnetPUB = hexlify17("0x043587cf");
|
7367
7418
|
function base58check(data) {
|
7368
7419
|
return encodeBase582(concat5([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
7369
7420
|
}
|
@@ -7374,11 +7425,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7374
7425
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7375
7426
|
}
|
7376
7427
|
function isPublicExtendedKey(extendedKey) {
|
7377
|
-
return [MainnetPUB, TestnetPUB].includes(
|
7428
|
+
return [MainnetPUB, TestnetPUB].includes(hexlify17(extendedKey.slice(0, 4)));
|
7378
7429
|
}
|
7379
7430
|
function isValidExtendedKey(extendedKey) {
|
7380
7431
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7381
|
-
|
7432
|
+
hexlify17(extendedKey.slice(0, 4))
|
7382
7433
|
);
|
7383
7434
|
}
|
7384
7435
|
function parsePath(path2, depth = 0) {
|
@@ -7396,8 +7447,8 @@ function parsePath(path2, depth = 0) {
|
|
7396
7447
|
var HDWallet = class {
|
7397
7448
|
depth = 0;
|
7398
7449
|
index = 0;
|
7399
|
-
fingerprint =
|
7400
|
-
parentFingerprint =
|
7450
|
+
fingerprint = hexlify17("0x00000000");
|
7451
|
+
parentFingerprint = hexlify17("0x00000000");
|
7401
7452
|
privateKey;
|
7402
7453
|
publicKey;
|
7403
7454
|
chainCode;
|
@@ -7409,8 +7460,8 @@ var HDWallet = class {
|
|
7409
7460
|
constructor(config) {
|
7410
7461
|
if (config.privateKey) {
|
7411
7462
|
const signer = new Signer(config.privateKey);
|
7412
|
-
this.publicKey =
|
7413
|
-
this.privateKey =
|
7463
|
+
this.publicKey = hexlify17(signer.compressedPublicKey);
|
7464
|
+
this.privateKey = hexlify17(config.privateKey);
|
7414
7465
|
} else {
|
7415
7466
|
if (!config.publicKey) {
|
7416
7467
|
throw new FuelError18(
|
@@ -7418,7 +7469,7 @@ var HDWallet = class {
|
|
7418
7469
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7419
7470
|
);
|
7420
7471
|
}
|
7421
|
-
this.publicKey =
|
7472
|
+
this.publicKey = hexlify17(config.publicKey);
|
7422
7473
|
}
|
7423
7474
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7424
7475
|
this.fingerprint = dataSlice2(ripemd160(sha2564(this.publicKey)), 0, 4);
|
@@ -7437,9 +7488,9 @@ var HDWallet = class {
|
|
7437
7488
|
* @returns A new instance of HDWallet on the derived index
|
7438
7489
|
*/
|
7439
7490
|
deriveIndex(index) {
|
7440
|
-
const privateKey = this.privateKey &&
|
7441
|
-
const publicKey =
|
7442
|
-
const chainCode =
|
7491
|
+
const privateKey = this.privateKey && arrayify18(this.privateKey);
|
7492
|
+
const publicKey = arrayify18(this.publicKey);
|
7493
|
+
const chainCode = arrayify18(this.chainCode);
|
7443
7494
|
const data = new Uint8Array(37);
|
7444
7495
|
if (index & HARDENED_INDEX) {
|
7445
7496
|
if (!privateKey) {
|
@@ -7450,10 +7501,10 @@ var HDWallet = class {
|
|
7450
7501
|
}
|
7451
7502
|
data.set(privateKey, 1);
|
7452
7503
|
} else {
|
7453
|
-
data.set(
|
7504
|
+
data.set(arrayify18(this.publicKey));
|
7454
7505
|
}
|
7455
7506
|
data.set(toBytes2(index, 4), 33);
|
7456
|
-
const bytes =
|
7507
|
+
const bytes = arrayify18(computeHmac2("sha512", chainCode, data));
|
7457
7508
|
const IL = bytes.slice(0, 32);
|
7458
7509
|
const IR = bytes.slice(32);
|
7459
7510
|
if (privateKey) {
|
@@ -7467,7 +7518,7 @@ var HDWallet = class {
|
|
7467
7518
|
parentFingerprint: this.fingerprint
|
7468
7519
|
});
|
7469
7520
|
}
|
7470
|
-
const signer = new Signer(
|
7521
|
+
const signer = new Signer(hexlify17(IL));
|
7471
7522
|
const Ki = signer.addPoint(publicKey);
|
7472
7523
|
return new HDWallet({
|
7473
7524
|
publicKey: Ki,
|
@@ -7502,14 +7553,12 @@ var HDWallet = class {
|
|
7502
7553
|
);
|
7503
7554
|
}
|
7504
7555
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7505
|
-
const depth =
|
7556
|
+
const depth = hexlify17(Uint8Array.from([this.depth]));
|
7506
7557
|
const parentFingerprint = this.parentFingerprint;
|
7507
7558
|
const index = toHex(this.index, 4);
|
7508
7559
|
const chainCode = this.chainCode;
|
7509
7560
|
const key = this.privateKey != null && !isPublic ? concat5(["0x00", this.privateKey]) : this.publicKey;
|
7510
|
-
const extendedKey =
|
7511
|
-
concat5([prefix, depth, parentFingerprint, index, chainCode, key])
|
7512
|
-
);
|
7561
|
+
const extendedKey = arrayify18(concat5([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7513
7562
|
return base58check(extendedKey);
|
7514
7563
|
}
|
7515
7564
|
/**
|
@@ -7521,13 +7570,13 @@ var HDWallet = class {
|
|
7521
7570
|
static fromSeed(seed) {
|
7522
7571
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7523
7572
|
return new HDWallet({
|
7524
|
-
chainCode:
|
7525
|
-
privateKey:
|
7573
|
+
chainCode: arrayify18(masterKey.slice(32)),
|
7574
|
+
privateKey: arrayify18(masterKey.slice(0, 32))
|
7526
7575
|
});
|
7527
7576
|
}
|
7528
7577
|
static fromExtendedKey(extendedKey) {
|
7529
7578
|
const decoded = toBeHex(decodeBase58(extendedKey));
|
7530
|
-
const bytes =
|
7579
|
+
const bytes = arrayify18(decoded);
|
7531
7580
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7532
7581
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7533
7582
|
throw new FuelError18(ErrorCode17.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7536,9 +7585,9 @@ var HDWallet = class {
|
|
7536
7585
|
throw new FuelError18(ErrorCode17.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7537
7586
|
}
|
7538
7587
|
const depth = bytes[4];
|
7539
|
-
const parentFingerprint =
|
7540
|
-
const index = parseInt(
|
7541
|
-
const chainCode =
|
7588
|
+
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
7589
|
+
const index = parseInt(hexlify17(bytes.slice(9, 13)).substring(2), 16);
|
7590
|
+
const chainCode = hexlify17(bytes.slice(13, 45));
|
7542
7591
|
const key = bytes.slice(45, 78);
|
7543
7592
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7544
7593
|
throw new FuelError18(
|
@@ -7754,11 +7803,10 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7754
7803
|
// src/test-utils/launchNode.ts
|
7755
7804
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
7756
7805
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
7757
|
-
import { defaultChainConfig, defaultConsensusKey } from "@fuel-ts/utils";
|
7806
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
7758
7807
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
7759
7808
|
import { spawn } from "child_process";
|
7760
7809
|
import { randomUUID } from "crypto";
|
7761
|
-
import { hexlify as hexlify17 } from "ethers";
|
7762
7810
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
7763
7811
|
import os from "os";
|
7764
7812
|
import path from "path";
|
@@ -7843,7 +7891,7 @@ var launchNode = async ({
|
|
7843
7891
|
if (!process.env.GENESIS_SECRET) {
|
7844
7892
|
const pk = Signer.generatePrivateKey();
|
7845
7893
|
const signer = new Signer(pk);
|
7846
|
-
process.env.GENESIS_SECRET =
|
7894
|
+
process.env.GENESIS_SECRET = hexlify18(pk);
|
7847
7895
|
chainConfig = {
|
7848
7896
|
...defaultChainConfig,
|
7849
7897
|
initial_state: {
|