@fuel-ts/account 0.89.1 → 0.90.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 +8 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts +3 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +4 -2
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +10 -4
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +7 -3
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +3328 -3275
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +217 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -72
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +8 -0
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +58 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/chains.d.ts +1 -1
- package/dist/providers/provider.d.ts +12 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +8 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/launchNode.d.ts +8 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +29 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +55 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.d.ts +8 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/test-utils.global.js +2275 -1900
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +491 -210
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +398 -121
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +1 -1
- package/package.json +18 -17
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -45,27 +45,33 @@ var __privateMethod = (obj, member, method) => {
|
|
45
45
|
return method;
|
46
46
|
};
|
47
47
|
|
48
|
-
// src/test-utils
|
48
|
+
// src/test-utils.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
+
AssetId: () => AssetId,
|
52
|
+
TestMessage: () => TestMessage,
|
53
|
+
WalletsConfig: () => WalletsConfig,
|
51
54
|
generateTestWallet: () => generateTestWallet,
|
52
55
|
killNode: () => killNode,
|
53
56
|
launchNode: () => launchNode,
|
54
57
|
launchNodeAndGetWallets: () => launchNodeAndGetWallets,
|
55
|
-
seedTestWallet: () => seedTestWallet
|
58
|
+
seedTestWallet: () => seedTestWallet,
|
59
|
+
setupTestProviderAndWallets: () => setupTestProviderAndWallets
|
56
60
|
});
|
57
61
|
module.exports = __toCommonJS(test_utils_exports);
|
58
62
|
|
59
63
|
// src/wallet/base-wallet-unlocked.ts
|
60
64
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
65
|
+
var import_utils32 = require("@fuel-ts/utils");
|
62
66
|
|
63
67
|
// src/account.ts
|
68
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
64
69
|
var import_address4 = require("@fuel-ts/address");
|
70
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
65
71
|
var import_errors16 = require("@fuel-ts/errors");
|
66
72
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
73
|
var import_math20 = require("@fuel-ts/math");
|
68
|
-
var
|
74
|
+
var import_utils29 = require("@fuel-ts/utils");
|
69
75
|
var import_ramda4 = require("ramda");
|
70
76
|
|
71
77
|
// src/providers/coin-quantity.ts
|
@@ -108,9 +114,9 @@ var import_address3 = require("@fuel-ts/address");
|
|
108
114
|
var import_errors14 = require("@fuel-ts/errors");
|
109
115
|
var import_math17 = require("@fuel-ts/math");
|
110
116
|
var import_transactions20 = require("@fuel-ts/transactions");
|
111
|
-
var
|
117
|
+
var import_utils23 = require("@fuel-ts/utils");
|
112
118
|
var import_versions = require("@fuel-ts/versions");
|
113
|
-
var
|
119
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
114
120
|
var import_graphql_request = require("graphql-request");
|
115
121
|
var import_ramda3 = require("ramda");
|
116
122
|
|
@@ -335,6 +341,7 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
|
|
335
341
|
proofIndex
|
336
342
|
}
|
337
343
|
messageBlockHeader {
|
344
|
+
version
|
338
345
|
id
|
339
346
|
daHeight
|
340
347
|
consensusParametersVersion
|
@@ -350,6 +357,7 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
|
|
350
357
|
applicationHash
|
351
358
|
}
|
352
359
|
commitBlockHeader {
|
360
|
+
version
|
353
361
|
id
|
354
362
|
daHeight
|
355
363
|
consensusParametersVersion
|
@@ -536,6 +544,9 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
|
|
536
544
|
wqmm
|
537
545
|
xor
|
538
546
|
xori
|
547
|
+
alocDependentCost {
|
548
|
+
...DependentCostFragment
|
549
|
+
}
|
539
550
|
call {
|
540
551
|
...DependentCostFragment
|
541
552
|
}
|
@@ -720,9 +731,13 @@ var GetTransactionsDocument = import_graphql_tag.default`
|
|
720
731
|
...transactionFragment
|
721
732
|
}
|
722
733
|
}
|
734
|
+
pageInfo {
|
735
|
+
...pageInfoFragment
|
736
|
+
}
|
723
737
|
}
|
724
738
|
}
|
725
|
-
${TransactionFragmentDoc}
|
739
|
+
${TransactionFragmentDoc}
|
740
|
+
${PageInfoFragmentDoc}`;
|
726
741
|
var GetTransactionsByOwnerDocument = import_graphql_tag.default`
|
727
742
|
query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
728
743
|
transactionsByOwner(
|
@@ -914,8 +929,12 @@ var GetRelayedTransactionStatusDocument = import_graphql_tag.default`
|
|
914
929
|
}
|
915
930
|
${RelayedTransactionStatusFragmentDoc}`;
|
916
931
|
var DryRunDocument = import_graphql_tag.default`
|
917
|
-
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
918
|
-
dryRun(
|
932
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
933
|
+
dryRun(
|
934
|
+
txs: $encodedTransactions
|
935
|
+
utxoValidation: $utxoValidation
|
936
|
+
gasPrice: $gasPrice
|
937
|
+
) {
|
919
938
|
...dryRunTransactionExecutionStatusFragment
|
920
939
|
}
|
921
940
|
}
|
@@ -1669,15 +1688,6 @@ function normalizeJSON(root) {
|
|
1669
1688
|
return normalize((0, import_ramda.clone)(root));
|
1670
1689
|
}
|
1671
1690
|
|
1672
|
-
// src/providers/utils/sleep.ts
|
1673
|
-
function sleep(time) {
|
1674
|
-
return new Promise((resolve) => {
|
1675
|
-
setTimeout(() => {
|
1676
|
-
resolve(true);
|
1677
|
-
}, time);
|
1678
|
-
});
|
1679
|
-
}
|
1680
|
-
|
1681
1691
|
// src/providers/utils/extract-tx-error.ts
|
1682
1692
|
var import_errors7 = require("@fuel-ts/errors");
|
1683
1693
|
var import_math6 = require("@fuel-ts/math");
|
@@ -3624,6 +3634,7 @@ var TransactionResponse = class {
|
|
3624
3634
|
};
|
3625
3635
|
|
3626
3636
|
// src/providers/utils/auto-retry-fetch.ts
|
3637
|
+
var import_utils22 = require("@fuel-ts/utils");
|
3627
3638
|
function getWaitDelay(options, retryAttemptNum) {
|
3628
3639
|
const duration = options.baseDelay ?? 150;
|
3629
3640
|
switch (options.backoff) {
|
@@ -3653,7 +3664,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3653
3664
|
throw error;
|
3654
3665
|
}
|
3655
3666
|
const delay = getWaitDelay(options, retryNum);
|
3656
|
-
await sleep(delay);
|
3667
|
+
await (0, import_utils22.sleep)(delay);
|
3657
3668
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3658
3669
|
}
|
3659
3670
|
};
|
@@ -4012,7 +4023,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4012
4023
|
if (estimateTxDependencies) {
|
4013
4024
|
await this.estimateTxDependencies(transactionRequest);
|
4014
4025
|
}
|
4015
|
-
const encodedTransaction = (0,
|
4026
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4016
4027
|
let abis;
|
4017
4028
|
if (transactionRequest.type === import_transactions20.TransactionType.Script) {
|
4018
4029
|
abis = transactionRequest.abis;
|
@@ -4050,12 +4061,12 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4050
4061
|
* @param sendTransactionParams - The provider call parameters (optional).
|
4051
4062
|
* @returns A promise that resolves to the call result object.
|
4052
4063
|
*/
|
4053
|
-
async
|
4064
|
+
async dryRun(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4054
4065
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4055
4066
|
if (estimateTxDependencies) {
|
4056
4067
|
return this.estimateTxDependencies(transactionRequest);
|
4057
4068
|
}
|
4058
|
-
const encodedTransaction = (0,
|
4069
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4059
4070
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4060
4071
|
encodedTransactions: encodedTransaction,
|
4061
4072
|
utxoValidation: utxoValidation || false
|
@@ -4075,13 +4086,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4075
4086
|
async estimatePredicates(transactionRequest) {
|
4076
4087
|
const shouldEstimatePredicates = Boolean(
|
4077
4088
|
transactionRequest.inputs.find(
|
4078
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4089
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
|
4079
4090
|
)
|
4080
4091
|
);
|
4081
4092
|
if (!shouldEstimatePredicates) {
|
4082
4093
|
return transactionRequest;
|
4083
4094
|
}
|
4084
|
-
const encodedTransaction = (0,
|
4095
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4085
4096
|
const response = await this.operations.estimatePredicates({
|
4086
4097
|
encodedTransaction
|
4087
4098
|
});
|
@@ -4122,7 +4133,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4122
4133
|
const {
|
4123
4134
|
dryRun: [{ receipts: rawReceipts, status }]
|
4124
4135
|
} = await this.operations.dryRun({
|
4125
|
-
encodedTransactions: [(0,
|
4136
|
+
encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
|
4126
4137
|
utxoValidation: false
|
4127
4138
|
});
|
4128
4139
|
receipts = rawReceipts.map(processGqlReceipt);
|
@@ -4172,7 +4183,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4172
4183
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4173
4184
|
allRequests.forEach((req, index) => {
|
4174
4185
|
if (req.type === import_transactions20.TransactionType.Script) {
|
4175
|
-
serializedTransactionsMap.set(index, (0,
|
4186
|
+
serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
|
4176
4187
|
}
|
4177
4188
|
});
|
4178
4189
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4208,7 +4219,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4208
4219
|
transactionRequest: request
|
4209
4220
|
});
|
4210
4221
|
request.maxFee = maxFee;
|
4211
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
4222
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
|
4212
4223
|
nextRoundTransactions.push(requestIdx);
|
4213
4224
|
}
|
4214
4225
|
}
|
@@ -4229,7 +4240,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4229
4240
|
if (estimateTxDependencies) {
|
4230
4241
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4231
4242
|
}
|
4232
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
4243
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
|
4233
4244
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4234
4245
|
encodedTransactions,
|
4235
4246
|
utxoValidation: utxoValidation || false
|
@@ -4303,7 +4314,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4303
4314
|
if (estimateTxDependencies) {
|
4304
4315
|
return this.estimateTxDependencies(transactionRequest);
|
4305
4316
|
}
|
4306
|
-
const encodedTransactions = [(0,
|
4317
|
+
const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
|
4307
4318
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4308
4319
|
encodedTransactions,
|
4309
4320
|
utxoValidation: true
|
@@ -4432,7 +4443,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4432
4443
|
const result = await this.operations.getCoins({
|
4433
4444
|
first: 10,
|
4434
4445
|
...paginationArgs,
|
4435
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4446
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4436
4447
|
});
|
4437
4448
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4438
4449
|
return coins.map((coin) => ({
|
@@ -4455,19 +4466,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4455
4466
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4456
4467
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4457
4468
|
const excludeInput = {
|
4458
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4459
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4469
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4470
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4460
4471
|
};
|
4461
4472
|
if (this.cache) {
|
4462
4473
|
const uniqueUtxos = new Set(
|
4463
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4474
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4464
4475
|
);
|
4465
4476
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4466
4477
|
}
|
4467
4478
|
const coinsQuery = {
|
4468
4479
|
owner: ownerAddress.toB256(),
|
4469
4480
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4470
|
-
assetId: (0,
|
4481
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4471
4482
|
amount: amount.toString(10),
|
4472
4483
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4473
4484
|
})),
|
@@ -4569,7 +4580,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4569
4580
|
time: block.header.time,
|
4570
4581
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4571
4582
|
transactions: block.transactions.map(
|
4572
|
-
(tx) => new import_transactions20.TransactionCoder().decode((0,
|
4583
|
+
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4573
4584
|
)
|
4574
4585
|
};
|
4575
4586
|
}
|
@@ -4585,10 +4596,25 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4585
4596
|
return null;
|
4586
4597
|
}
|
4587
4598
|
return new import_transactions20.TransactionCoder().decode(
|
4588
|
-
(0,
|
4599
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4589
4600
|
0
|
4590
4601
|
)?.[0];
|
4591
4602
|
}
|
4603
|
+
/**
|
4604
|
+
* Retrieves transactions based on the provided pagination arguments.
|
4605
|
+
* @param paginationArgs - The pagination arguments for retrieving transactions.
|
4606
|
+
* @returns A promise that resolves to an object containing the retrieved transactions and pagination information.
|
4607
|
+
*/
|
4608
|
+
async getTransactions(paginationArgs) {
|
4609
|
+
const {
|
4610
|
+
transactions: { edges, pageInfo }
|
4611
|
+
} = await this.operations.getTransactions(paginationArgs);
|
4612
|
+
const coder = new import_transactions20.TransactionCoder();
|
4613
|
+
const transactions = edges.map(
|
4614
|
+
({ node: { rawPayload } }) => coder.decode((0, import_utils23.arrayify)(rawPayload), 0)[0]
|
4615
|
+
);
|
4616
|
+
return { transactions, pageInfo };
|
4617
|
+
}
|
4592
4618
|
/**
|
4593
4619
|
* Get deployed contract with the given ID.
|
4594
4620
|
*
|
@@ -4612,7 +4638,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4612
4638
|
async getContractBalance(contractId, assetId) {
|
4613
4639
|
const { contractBalance } = await this.operations.getContractBalance({
|
4614
4640
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4615
|
-
asset: (0,
|
4641
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4616
4642
|
});
|
4617
4643
|
return (0, import_math17.bn)(contractBalance.amount, 10);
|
4618
4644
|
}
|
@@ -4626,7 +4652,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4626
4652
|
async getBalance(owner, assetId) {
|
4627
4653
|
const { balance } = await this.operations.getBalance({
|
4628
4654
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4629
|
-
assetId: (0,
|
4655
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4630
4656
|
});
|
4631
4657
|
return (0, import_math17.bn)(balance.amount, 10);
|
4632
4658
|
}
|
@@ -4814,7 +4840,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4814
4840
|
async produceBlocks(amount, startTime) {
|
4815
4841
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4816
4842
|
blocksToProduce: (0, import_math17.bn)(amount).toString(10),
|
4817
|
-
startTimestamp: startTime ?
|
4843
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4818
4844
|
});
|
4819
4845
|
return (0, import_math17.bn)(latestBlockHeight);
|
4820
4846
|
}
|
@@ -4897,7 +4923,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4897
4923
|
var import_errors15 = require("@fuel-ts/errors");
|
4898
4924
|
var import_math18 = require("@fuel-ts/math");
|
4899
4925
|
var import_transactions21 = require("@fuel-ts/transactions");
|
4900
|
-
var
|
4926
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4901
4927
|
|
4902
4928
|
// src/providers/chains.ts
|
4903
4929
|
var CHAIN_IDS = {
|
@@ -4906,8 +4932,8 @@ var CHAIN_IDS = {
|
|
4906
4932
|
foundry: 31337
|
4907
4933
|
},
|
4908
4934
|
fuel: {
|
4909
|
-
|
4910
|
-
|
4935
|
+
devnet: 0,
|
4936
|
+
testnet: 0
|
4911
4937
|
}
|
4912
4938
|
};
|
4913
4939
|
|
@@ -4955,15 +4981,15 @@ var rawAssets = [
|
|
4955
4981
|
},
|
4956
4982
|
{
|
4957
4983
|
type: "fuel",
|
4958
|
-
chainId: CHAIN_IDS.fuel.
|
4984
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4959
4985
|
decimals: 9,
|
4960
|
-
assetId: "
|
4986
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4961
4987
|
},
|
4962
4988
|
{
|
4963
4989
|
type: "fuel",
|
4964
|
-
chainId: CHAIN_IDS.fuel.
|
4990
|
+
chainId: CHAIN_IDS.fuel.testnet,
|
4965
4991
|
decimals: 9,
|
4966
|
-
assetId: "
|
4992
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4967
4993
|
}
|
4968
4994
|
]
|
4969
4995
|
}
|
@@ -4973,16 +4999,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
|
|
4973
4999
|
// src/utils/formatTransferToContractScriptData.ts
|
4974
5000
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4975
5001
|
var import_math19 = require("@fuel-ts/math");
|
4976
|
-
var
|
5002
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4977
5003
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4978
5004
|
var formatTransferToContractScriptData = (params) => {
|
4979
5005
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4980
5006
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4981
5007
|
const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
|
4982
5008
|
const scriptData = Uint8Array.from([
|
4983
|
-
...(0,
|
5009
|
+
...(0, import_utils28.arrayify)(hexlifiedContractId),
|
4984
5010
|
...encoded,
|
4985
|
-
...(0,
|
5011
|
+
...(0, import_utils28.arrayify)(assetId)
|
4986
5012
|
]);
|
4987
5013
|
return scriptData;
|
4988
5014
|
};
|
@@ -5387,14 +5413,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5387
5413
|
*/
|
5388
5414
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5389
5415
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5390
|
-
const recipientDataArray = (0,
|
5416
|
+
const recipientDataArray = (0, import_utils29.arrayify)(
|
5391
5417
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5392
5418
|
);
|
5393
|
-
const amountDataArray = (0,
|
5419
|
+
const amountDataArray = (0, import_utils29.arrayify)(
|
5394
5420
|
"0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5395
5421
|
);
|
5396
5422
|
const script = new Uint8Array([
|
5397
|
-
...(0,
|
5423
|
+
...(0, import_utils29.arrayify)(withdrawScript.bytes),
|
5398
5424
|
...recipientDataArray,
|
5399
5425
|
...amountDataArray
|
5400
5426
|
]);
|
@@ -5477,6 +5503,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5477
5503
|
}
|
5478
5504
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5479
5505
|
}
|
5506
|
+
/**
|
5507
|
+
* Generates an array of fake resources based on the provided coins.
|
5508
|
+
*
|
5509
|
+
* @param coins - An array of `FakeResources` objects representing the coins.
|
5510
|
+
* @returns An array of `Resource` objects with generated properties.
|
5511
|
+
*/
|
5512
|
+
generateFakeResources(coins) {
|
5513
|
+
return coins.map((coin) => ({
|
5514
|
+
id: (0, import_utils29.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
5515
|
+
owner: this.address,
|
5516
|
+
blockCreated: (0, import_math20.bn)(1),
|
5517
|
+
txCreatedIdx: (0, import_math20.bn)(1),
|
5518
|
+
...coin
|
5519
|
+
}));
|
5520
|
+
}
|
5480
5521
|
/** @hidden * */
|
5481
5522
|
validateTransferAmount(amount) {
|
5482
5523
|
if ((0, import_math20.bn)(amount).lte(0)) {
|
@@ -5509,7 +5550,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5509
5550
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
5510
5551
|
}) {
|
5511
5552
|
const request = transactionRequestify(transactionRequest);
|
5512
|
-
if (!(0,
|
5553
|
+
if (!(0, import_utils29.isDefined)(setGasLimit)) {
|
5513
5554
|
request.gasLimit = gasUsed;
|
5514
5555
|
} else if (gasUsed.gt(setGasLimit)) {
|
5515
5556
|
throw new import_errors16.FuelError(
|
@@ -5517,7 +5558,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5517
5558
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5518
5559
|
);
|
5519
5560
|
}
|
5520
|
-
if (!(0,
|
5561
|
+
if (!(0, import_utils29.isDefined)(setMaxFee)) {
|
5521
5562
|
request.maxFee = maxFee;
|
5522
5563
|
} else if (maxFee.gt(setMaxFee)) {
|
5523
5564
|
throw new import_errors16.FuelError(
|
@@ -5531,10 +5572,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5531
5572
|
|
5532
5573
|
// src/signer/signer.ts
|
5533
5574
|
var import_address5 = require("@fuel-ts/address");
|
5534
|
-
var
|
5575
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5535
5576
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5536
5577
|
var import_math21 = require("@fuel-ts/math");
|
5537
|
-
var
|
5578
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5538
5579
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5539
5580
|
var Signer = class {
|
5540
5581
|
address;
|
@@ -5554,9 +5595,9 @@ var Signer = class {
|
|
5554
5595
|
}
|
5555
5596
|
}
|
5556
5597
|
const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
|
5557
|
-
this.privateKey = (0,
|
5558
|
-
this.publicKey = (0,
|
5559
|
-
this.compressedPublicKey = (0,
|
5598
|
+
this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
|
5599
|
+
this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5600
|
+
this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5560
5601
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5561
5602
|
}
|
5562
5603
|
/**
|
@@ -5570,11 +5611,11 @@ var Signer = class {
|
|
5570
5611
|
* @returns hashed signature
|
5571
5612
|
*/
|
5572
5613
|
sign(data) {
|
5573
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5614
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
|
5574
5615
|
const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5575
5616
|
const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5576
5617
|
s[0] |= (signature.recovery || 0) << 7;
|
5577
|
-
return (0,
|
5618
|
+
return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
|
5578
5619
|
}
|
5579
5620
|
/**
|
5580
5621
|
* Add point on the current elliptic curve
|
@@ -5583,8 +5624,8 @@ var Signer = class {
|
|
5583
5624
|
* @returns compressed point on the curve
|
5584
5625
|
*/
|
5585
5626
|
addPoint(point) {
|
5586
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5587
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5627
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
|
5628
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
|
5588
5629
|
const result = p0.add(p1);
|
5589
5630
|
return `0x${result.toHex(true)}`;
|
5590
5631
|
}
|
@@ -5596,16 +5637,16 @@ var Signer = class {
|
|
5596
5637
|
* @returns public key from signature from the
|
5597
5638
|
*/
|
5598
5639
|
static recoverPublicKey(data, signature) {
|
5599
|
-
const signedMessageBytes = (0,
|
5640
|
+
const signedMessageBytes = (0, import_utils30.arrayify)(signature);
|
5600
5641
|
const r = signedMessageBytes.slice(0, 32);
|
5601
5642
|
const s = signedMessageBytes.slice(32, 64);
|
5602
5643
|
const recoveryParam = (s[0] & 128) >> 7;
|
5603
5644
|
s[0] &= 127;
|
5604
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5645
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
|
5605
5646
|
recoveryParam
|
5606
5647
|
);
|
5607
|
-
const publicKey = sig.recoverPublicKey((0,
|
5608
|
-
return (0,
|
5648
|
+
const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
|
5649
|
+
return (0, import_utils30.hexlify)(publicKey);
|
5609
5650
|
}
|
5610
5651
|
/**
|
5611
5652
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5624,7 +5665,7 @@ var Signer = class {
|
|
5624
5665
|
* @returns random 32-byte hashed
|
5625
5666
|
*/
|
5626
5667
|
static generatePrivateKey(entropy) {
|
5627
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5668
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils30.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils30.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
|
5628
5669
|
}
|
5629
5670
|
/**
|
5630
5671
|
* Extended publicKey from a compact publicKey
|
@@ -5633,16 +5674,16 @@ var Signer = class {
|
|
5633
5674
|
* @returns extended publicKey
|
5634
5675
|
*/
|
5635
5676
|
static extendPublicKey(publicKey) {
|
5636
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5637
|
-
return (0,
|
5677
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
|
5678
|
+
return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
|
5638
5679
|
}
|
5639
5680
|
};
|
5640
5681
|
|
5641
5682
|
// src/wallet/keystore-wallet.ts
|
5642
5683
|
var import_address6 = require("@fuel-ts/address");
|
5643
|
-
var
|
5684
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5644
5685
|
var import_errors17 = require("@fuel-ts/errors");
|
5645
|
-
var
|
5686
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5646
5687
|
var import_uuid = require("uuid");
|
5647
5688
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5648
5689
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5656,22 +5697,22 @@ var removeHexPrefix = (hexString) => {
|
|
5656
5697
|
return hexString;
|
5657
5698
|
};
|
5658
5699
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5659
|
-
const privateKeyBuffer = (0,
|
5700
|
+
const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5660
5701
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5661
|
-
const salt = (0,
|
5662
|
-
const key = (0,
|
5663
|
-
password: (0,
|
5702
|
+
const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
|
5703
|
+
const key = (0, import_crypto4.scrypt)({
|
5704
|
+
password: (0, import_crypto4.bufferFromString)(password),
|
5664
5705
|
salt,
|
5665
5706
|
dklen: DEFAULT_KEY_SIZE,
|
5666
5707
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5667
5708
|
r: DEFAULT_KDF_PARAMS_R,
|
5668
5709
|
p: DEFAULT_KDF_PARAMS_P
|
5669
5710
|
});
|
5670
|
-
const iv = (0,
|
5671
|
-
const ciphertext = await (0,
|
5711
|
+
const iv = (0, import_crypto4.randomBytes)(DEFAULT_IV_SIZE);
|
5712
|
+
const ciphertext = await (0, import_crypto4.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5672
5713
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5673
|
-
const macHashUint8Array = (0,
|
5674
|
-
const mac = (0,
|
5714
|
+
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
5715
|
+
const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
5675
5716
|
const keystore = {
|
5676
5717
|
id: (0, import_uuid.v4)(),
|
5677
5718
|
version: 3,
|
@@ -5679,15 +5720,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5679
5720
|
crypto: {
|
5680
5721
|
cipher: "aes-128-ctr",
|
5681
5722
|
mac,
|
5682
|
-
cipherparams: { iv: (0,
|
5683
|
-
ciphertext: (0,
|
5723
|
+
cipherparams: { iv: (0, import_crypto4.stringFromBuffer)(iv, "hex") },
|
5724
|
+
ciphertext: (0, import_crypto4.stringFromBuffer)(ciphertext, "hex"),
|
5684
5725
|
kdf: "scrypt",
|
5685
5726
|
kdfparams: {
|
5686
5727
|
dklen: DEFAULT_KEY_SIZE,
|
5687
5728
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5688
5729
|
p: DEFAULT_KDF_PARAMS_P,
|
5689
5730
|
r: DEFAULT_KDF_PARAMS_R,
|
5690
|
-
salt: (0,
|
5731
|
+
salt: (0, import_crypto4.stringFromBuffer)(salt, "hex")
|
5691
5732
|
}
|
5692
5733
|
}
|
5693
5734
|
};
|
@@ -5703,11 +5744,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5703
5744
|
kdfparams: { dklen, n, r, p, salt }
|
5704
5745
|
}
|
5705
5746
|
} = keystoreWallet;
|
5706
|
-
const ciphertextBuffer = (0,
|
5707
|
-
const ivBuffer = (0,
|
5708
|
-
const saltBuffer = (0,
|
5709
|
-
const passwordBuffer = (0,
|
5710
|
-
const key = (0,
|
5747
|
+
const ciphertextBuffer = (0, import_crypto4.bufferFromString)(ciphertext, "hex");
|
5748
|
+
const ivBuffer = (0, import_crypto4.bufferFromString)(iv, "hex");
|
5749
|
+
const saltBuffer = (0, import_crypto4.bufferFromString)(salt, "hex");
|
5750
|
+
const passwordBuffer = (0, import_crypto4.bufferFromString)(password);
|
5751
|
+
const key = (0, import_crypto4.scrypt)({
|
5711
5752
|
password: passwordBuffer,
|
5712
5753
|
salt: saltBuffer,
|
5713
5754
|
n,
|
@@ -5716,16 +5757,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5716
5757
|
dklen
|
5717
5758
|
});
|
5718
5759
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5719
|
-
const macHashUint8Array = (0,
|
5720
|
-
const macHash = (0,
|
5760
|
+
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
5761
|
+
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
5721
5762
|
if (mac !== macHash) {
|
5722
5763
|
throw new import_errors17.FuelError(
|
5723
5764
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5724
5765
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5725
5766
|
);
|
5726
5767
|
}
|
5727
|
-
const buffer = await (0,
|
5728
|
-
const privateKey = (0,
|
5768
|
+
const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5769
|
+
const privateKey = (0, import_utils31.hexlify)(buffer);
|
5729
5770
|
return privateKey;
|
5730
5771
|
}
|
5731
5772
|
|
@@ -5770,7 +5811,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5770
5811
|
*/
|
5771
5812
|
async signMessage(message) {
|
5772
5813
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5773
|
-
return (0,
|
5814
|
+
return (0, import_utils32.hexlify)(signedMessage);
|
5774
5815
|
}
|
5775
5816
|
/**
|
5776
5817
|
* Signs a transaction with the wallet's private key.
|
@@ -5783,7 +5824,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5783
5824
|
const chainId = this.provider.getChainId();
|
5784
5825
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5785
5826
|
const signature = await this.signer().sign(hashedTransaction);
|
5786
|
-
return (0,
|
5827
|
+
return (0, import_utils32.hexlify)(signature);
|
5787
5828
|
}
|
5788
5829
|
/**
|
5789
5830
|
* Populates a transaction with the witnesses signature.
|
@@ -5816,7 +5857,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5816
5857
|
);
|
5817
5858
|
}
|
5818
5859
|
/**
|
5819
|
-
* Populates the witness signature for a transaction and sends a call to the network using `provider.
|
5860
|
+
* Populates the witness signature for a transaction and sends a call to the network using `provider.dryRun`.
|
5820
5861
|
*
|
5821
5862
|
* @param transactionRequestLike - The transaction request to simulate.
|
5822
5863
|
* @returns A promise that resolves to the CallResult object.
|
@@ -5826,7 +5867,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5826
5867
|
if (estimateTxDependencies) {
|
5827
5868
|
await this.provider.estimateTxDependencies(transactionRequest);
|
5828
5869
|
}
|
5829
|
-
return this.provider.
|
5870
|
+
return this.provider.dryRun(
|
5830
5871
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
5831
5872
|
{
|
5832
5873
|
utxoValidation: true,
|
@@ -5850,17 +5891,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5850
5891
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5851
5892
|
|
5852
5893
|
// src/hdwallet/hdwallet.ts
|
5853
|
-
var
|
5894
|
+
var import_crypto6 = require("@fuel-ts/crypto");
|
5854
5895
|
var import_errors20 = require("@fuel-ts/errors");
|
5855
5896
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5856
5897
|
var import_math22 = require("@fuel-ts/math");
|
5857
|
-
var
|
5898
|
+
var import_utils36 = require("@fuel-ts/utils");
|
5858
5899
|
|
5859
5900
|
// src/mnemonic/mnemonic.ts
|
5860
|
-
var
|
5901
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
5861
5902
|
var import_errors19 = require("@fuel-ts/errors");
|
5862
5903
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5863
|
-
var
|
5904
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5864
5905
|
|
5865
5906
|
// src/wordlists/words/english.ts
|
5866
5907
|
var english = [
|
@@ -7917,7 +7958,7 @@ var english = [
|
|
7917
7958
|
// src/mnemonic/utils.ts
|
7918
7959
|
var import_errors18 = require("@fuel-ts/errors");
|
7919
7960
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7920
|
-
var
|
7961
|
+
var import_utils33 = require("@fuel-ts/utils");
|
7921
7962
|
function getLowerMask(bits) {
|
7922
7963
|
return (1 << bits) - 1;
|
7923
7964
|
}
|
@@ -7952,14 +7993,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7952
7993
|
}
|
7953
7994
|
}
|
7954
7995
|
const checksumBits = entropy.length / 4;
|
7955
|
-
const checksum = (0,
|
7996
|
+
const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7956
7997
|
indices[indices.length - 1] <<= checksumBits;
|
7957
7998
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7958
7999
|
return indices;
|
7959
8000
|
}
|
7960
8001
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7961
8002
|
const size = Math.ceil(11 * words.length / 8);
|
7962
|
-
const entropy = (0,
|
8003
|
+
const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
|
7963
8004
|
let offset = 0;
|
7964
8005
|
for (let i = 0; i < words.length; i += 1) {
|
7965
8006
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7979,7 +8020,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7979
8020
|
const entropyBits = 32 * words.length / 3;
|
7980
8021
|
const checksumBits = words.length / 3;
|
7981
8022
|
const checksumMask = getUpperMask(checksumBits);
|
7982
|
-
const checksum = (0,
|
8023
|
+
const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7983
8024
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7984
8025
|
throw new import_errors18.FuelError(
|
7985
8026
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7990,7 +8031,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7990
8031
|
}
|
7991
8032
|
|
7992
8033
|
// src/mnemonic/mnemonic.ts
|
7993
|
-
var MasterSecret = (0,
|
8034
|
+
var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
|
7994
8035
|
var MainnetPRV = "0x0488ade4";
|
7995
8036
|
var TestnetPRV = "0x04358394";
|
7996
8037
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
@@ -8054,7 +8095,7 @@ var Mnemonic = class {
|
|
8054
8095
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8055
8096
|
const words = getWords(phrase);
|
8056
8097
|
assertMnemonic(words);
|
8057
|
-
return (0,
|
8098
|
+
return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8058
8099
|
}
|
8059
8100
|
/**
|
8060
8101
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8062,7 +8103,7 @@ var Mnemonic = class {
|
|
8062
8103
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8063
8104
|
*/
|
8064
8105
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8065
|
-
const entropyBytes = (0,
|
8106
|
+
const entropyBytes = (0, import_utils34.arrayify)(entropy);
|
8066
8107
|
assertWordList(wordlist);
|
8067
8108
|
assertEntropy(entropyBytes);
|
8068
8109
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8074,9 +8115,9 @@ var Mnemonic = class {
|
|
8074
8115
|
*/
|
8075
8116
|
static mnemonicToSeed(phrase, passphrase = "") {
|
8076
8117
|
assertMnemonic(getWords(phrase));
|
8077
|
-
const phraseBytes = (0,
|
8078
|
-
const salt = (0,
|
8079
|
-
return (0,
|
8118
|
+
const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
|
8119
|
+
const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
|
8120
|
+
return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
8080
8121
|
}
|
8081
8122
|
/**
|
8082
8123
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -8131,14 +8172,14 @@ var Mnemonic = class {
|
|
8131
8172
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8132
8173
|
*/
|
8133
8174
|
static masterKeysFromSeed(seed) {
|
8134
|
-
const seedArray = (0,
|
8175
|
+
const seedArray = (0, import_utils34.arrayify)(seed);
|
8135
8176
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8136
8177
|
throw new import_errors19.FuelError(
|
8137
8178
|
import_errors19.ErrorCode.INVALID_SEED,
|
8138
8179
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8139
8180
|
);
|
8140
8181
|
}
|
8141
|
-
return (0,
|
8182
|
+
return (0, import_utils34.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
|
8142
8183
|
}
|
8143
8184
|
/**
|
8144
8185
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8149,22 +8190,22 @@ var Mnemonic = class {
|
|
8149
8190
|
*/
|
8150
8191
|
static seedToExtendedKey(seed, testnet = false) {
|
8151
8192
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8152
|
-
const prefix = (0,
|
8193
|
+
const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8153
8194
|
const depth = "0x00";
|
8154
8195
|
const fingerprint = "0x00000000";
|
8155
8196
|
const index = "0x00000000";
|
8156
8197
|
const chainCode = masterKey.slice(32);
|
8157
8198
|
const privateKey = masterKey.slice(0, 32);
|
8158
|
-
const extendedKey = (0,
|
8199
|
+
const extendedKey = (0, import_utils34.concat)([
|
8159
8200
|
prefix,
|
8160
8201
|
depth,
|
8161
8202
|
fingerprint,
|
8162
8203
|
index,
|
8163
8204
|
chainCode,
|
8164
|
-
(0,
|
8205
|
+
(0, import_utils34.concat)(["0x00", privateKey])
|
8165
8206
|
]);
|
8166
|
-
const checksum = (0,
|
8167
|
-
return (0,
|
8207
|
+
const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8208
|
+
return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
|
8168
8209
|
}
|
8169
8210
|
/**
|
8170
8211
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8179,7 +8220,7 @@ var Mnemonic = class {
|
|
8179
8220
|
* @returns A randomly generated mnemonic
|
8180
8221
|
*/
|
8181
8222
|
static generate(size = 32, extraEntropy = "") {
|
8182
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8223
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils34.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils34.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
|
8183
8224
|
return Mnemonic.entropyToMnemonic(entropy);
|
8184
8225
|
}
|
8185
8226
|
};
|
@@ -8187,12 +8228,12 @@ var mnemonic_default = Mnemonic;
|
|
8187
8228
|
|
8188
8229
|
// src/hdwallet/hdwallet.ts
|
8189
8230
|
var HARDENED_INDEX = 2147483648;
|
8190
|
-
var MainnetPRV2 = (0,
|
8191
|
-
var MainnetPUB = (0,
|
8192
|
-
var TestnetPRV2 = (0,
|
8193
|
-
var TestnetPUB = (0,
|
8231
|
+
var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
|
8232
|
+
var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
|
8233
|
+
var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
|
8234
|
+
var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
|
8194
8235
|
function base58check(data) {
|
8195
|
-
return (0,
|
8236
|
+
return (0, import_utils36.encodeBase58)((0, import_utils36.concat)([data, (0, import_utils36.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8196
8237
|
}
|
8197
8238
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8198
8239
|
if (isPublic) {
|
@@ -8201,11 +8242,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8201
8242
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8202
8243
|
}
|
8203
8244
|
function isPublicExtendedKey(extendedKey) {
|
8204
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8245
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
|
8205
8246
|
}
|
8206
8247
|
function isValidExtendedKey(extendedKey) {
|
8207
8248
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8208
|
-
(0,
|
8249
|
+
(0, import_utils36.hexlify)(extendedKey.slice(0, 4))
|
8209
8250
|
);
|
8210
8251
|
}
|
8211
8252
|
function parsePath(path2, depth = 0) {
|
@@ -8223,8 +8264,8 @@ function parsePath(path2, depth = 0) {
|
|
8223
8264
|
var HDWallet = class {
|
8224
8265
|
depth = 0;
|
8225
8266
|
index = 0;
|
8226
|
-
fingerprint = (0,
|
8227
|
-
parentFingerprint = (0,
|
8267
|
+
fingerprint = (0, import_utils36.hexlify)("0x00000000");
|
8268
|
+
parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
|
8228
8269
|
privateKey;
|
8229
8270
|
publicKey;
|
8230
8271
|
chainCode;
|
@@ -8236,8 +8277,8 @@ var HDWallet = class {
|
|
8236
8277
|
constructor(config) {
|
8237
8278
|
if (config.privateKey) {
|
8238
8279
|
const signer = new Signer(config.privateKey);
|
8239
|
-
this.publicKey = (0,
|
8240
|
-
this.privateKey = (0,
|
8280
|
+
this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
|
8281
|
+
this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
|
8241
8282
|
} else {
|
8242
8283
|
if (!config.publicKey) {
|
8243
8284
|
throw new import_errors20.FuelError(
|
@@ -8245,10 +8286,10 @@ var HDWallet = class {
|
|
8245
8286
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8246
8287
|
);
|
8247
8288
|
}
|
8248
|
-
this.publicKey = (0,
|
8289
|
+
this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
|
8249
8290
|
}
|
8250
8291
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8251
|
-
this.fingerprint = (0,
|
8292
|
+
this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8252
8293
|
this.depth = config.depth || this.depth;
|
8253
8294
|
this.index = config.index || this.index;
|
8254
8295
|
this.chainCode = config.chainCode;
|
@@ -8264,9 +8305,9 @@ var HDWallet = class {
|
|
8264
8305
|
* @returns A new instance of HDWallet on the derived index
|
8265
8306
|
*/
|
8266
8307
|
deriveIndex(index) {
|
8267
|
-
const privateKey = this.privateKey && (0,
|
8268
|
-
const publicKey = (0,
|
8269
|
-
const chainCode = (0,
|
8308
|
+
const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
|
8309
|
+
const publicKey = (0, import_utils36.arrayify)(this.publicKey);
|
8310
|
+
const chainCode = (0, import_utils36.arrayify)(this.chainCode);
|
8270
8311
|
const data = new Uint8Array(37);
|
8271
8312
|
if (index & HARDENED_INDEX) {
|
8272
8313
|
if (!privateKey) {
|
@@ -8277,10 +8318,10 @@ var HDWallet = class {
|
|
8277
8318
|
}
|
8278
8319
|
data.set(privateKey, 1);
|
8279
8320
|
} else {
|
8280
|
-
data.set((0,
|
8321
|
+
data.set((0, import_utils36.arrayify)(this.publicKey));
|
8281
8322
|
}
|
8282
8323
|
data.set((0, import_math22.toBytes)(index, 4), 33);
|
8283
|
-
const bytes = (0,
|
8324
|
+
const bytes = (0, import_utils36.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
8284
8325
|
const IL = bytes.slice(0, 32);
|
8285
8326
|
const IR = bytes.slice(32);
|
8286
8327
|
if (privateKey) {
|
@@ -8294,7 +8335,7 @@ var HDWallet = class {
|
|
8294
8335
|
parentFingerprint: this.fingerprint
|
8295
8336
|
});
|
8296
8337
|
}
|
8297
|
-
const signer = new Signer((0,
|
8338
|
+
const signer = new Signer((0, import_utils36.hexlify)(IL));
|
8298
8339
|
const Ki = signer.addPoint(publicKey);
|
8299
8340
|
return new HDWallet({
|
8300
8341
|
publicKey: Ki,
|
@@ -8329,12 +8370,12 @@ var HDWallet = class {
|
|
8329
8370
|
);
|
8330
8371
|
}
|
8331
8372
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8332
|
-
const depth = (0,
|
8373
|
+
const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
|
8333
8374
|
const parentFingerprint = this.parentFingerprint;
|
8334
8375
|
const index = (0, import_math22.toHex)(this.index, 4);
|
8335
8376
|
const chainCode = this.chainCode;
|
8336
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8337
|
-
const extendedKey = (0,
|
8377
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8378
|
+
const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8338
8379
|
return base58check(extendedKey);
|
8339
8380
|
}
|
8340
8381
|
/**
|
@@ -8346,13 +8387,13 @@ var HDWallet = class {
|
|
8346
8387
|
static fromSeed(seed) {
|
8347
8388
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8348
8389
|
return new HDWallet({
|
8349
|
-
chainCode: (0,
|
8350
|
-
privateKey: (0,
|
8390
|
+
chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
|
8391
|
+
privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
|
8351
8392
|
});
|
8352
8393
|
}
|
8353
8394
|
static fromExtendedKey(extendedKey) {
|
8354
|
-
const decoded = (0,
|
8355
|
-
const bytes = (0,
|
8395
|
+
const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
|
8396
|
+
const bytes = (0, import_utils36.arrayify)(decoded);
|
8356
8397
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8357
8398
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8358
8399
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8361,9 +8402,9 @@ var HDWallet = class {
|
|
8361
8402
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8362
8403
|
}
|
8363
8404
|
const depth = bytes[4];
|
8364
|
-
const parentFingerprint = (0,
|
8365
|
-
const index = parseInt((0,
|
8366
|
-
const chainCode = (0,
|
8405
|
+
const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
|
8406
|
+
const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8407
|
+
const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
|
8367
8408
|
const key = bytes.slice(45, 78);
|
8368
8409
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8369
8410
|
throw new import_errors20.FuelError(
|
@@ -8550,11 +8591,11 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8550
8591
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8551
8592
|
|
8552
8593
|
// src/test-utils/seedTestWallet.ts
|
8553
|
-
var
|
8594
|
+
var import_crypto7 = require("@fuel-ts/crypto");
|
8554
8595
|
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
8555
8596
|
const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
|
8556
8597
|
const [{ provider }] = accountsToBeFunded;
|
8557
|
-
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0,
|
8598
|
+
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto7.randomBytes)(32), provider);
|
8558
8599
|
const request = new ScriptTransactionRequest();
|
8559
8600
|
quantities.map(coinQuantityfy).forEach(
|
8560
8601
|
({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
|
@@ -8580,11 +8621,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8580
8621
|
};
|
8581
8622
|
|
8582
8623
|
// src/test-utils/launchNode.ts
|
8583
|
-
var
|
8584
|
-
var
|
8585
|
-
var
|
8624
|
+
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
8625
|
+
var import_crypto8 = require("@fuel-ts/crypto");
|
8626
|
+
var import_utils37 = require("@fuel-ts/utils");
|
8586
8627
|
var import_child_process = require("child_process");
|
8587
|
-
var
|
8628
|
+
var import_crypto9 = require("crypto");
|
8588
8629
|
var import_fs = require("fs");
|
8589
8630
|
var import_os = __toESM(require("os"));
|
8590
8631
|
var import_path = __toESM(require("path"));
|
@@ -8621,6 +8662,40 @@ var killNode = (params) => {
|
|
8621
8662
|
}
|
8622
8663
|
}
|
8623
8664
|
};
|
8665
|
+
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8666
|
+
const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8667
|
+
...coin,
|
8668
|
+
amount: "18446744073709551615"
|
8669
|
+
}));
|
8670
|
+
const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8671
|
+
...message,
|
8672
|
+
amount: "18446744073709551615"
|
8673
|
+
}));
|
8674
|
+
const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
|
8675
|
+
const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
|
8676
|
+
if (!process.env.GENESIS_SECRET) {
|
8677
|
+
const pk = Signer.generatePrivateKey();
|
8678
|
+
const signer = new Signer(pk);
|
8679
|
+
process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
|
8680
|
+
coins.push({
|
8681
|
+
tx_id: (0, import_utils37.hexlify)((0, import_crypto8.randomBytes)(import_abi_coder8.BYTES_32)),
|
8682
|
+
owner: signer.address.toHexString(),
|
8683
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8684
|
+
amount: "18446744073709551615",
|
8685
|
+
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8686
|
+
output_index: 0,
|
8687
|
+
tx_pointer_block_height: 0,
|
8688
|
+
tx_pointer_tx_idx: 0
|
8689
|
+
});
|
8690
|
+
}
|
8691
|
+
const json = JSON.stringify({
|
8692
|
+
...stateConfig,
|
8693
|
+
coins,
|
8694
|
+
messages
|
8695
|
+
});
|
8696
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8697
|
+
return json.replace(regexMakeNumber, "$1$2");
|
8698
|
+
}
|
8624
8699
|
var launchNode = async ({
|
8625
8700
|
ip,
|
8626
8701
|
port,
|
@@ -8628,7 +8703,8 @@ var launchNode = async ({
|
|
8628
8703
|
fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
|
8629
8704
|
loggingEnabled = true,
|
8630
8705
|
debugEnabled = false,
|
8631
|
-
basePath
|
8706
|
+
basePath,
|
8707
|
+
snapshotConfig = import_utils37.defaultSnapshotConfigs
|
8632
8708
|
}) => (
|
8633
8709
|
// eslint-disable-next-line no-async-promise-executor
|
8634
8710
|
new Promise(async (resolve, reject) => {
|
@@ -8639,7 +8715,7 @@ var launchNode = async ({
|
|
8639
8715
|
"--poa-instant"
|
8640
8716
|
]);
|
8641
8717
|
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8642
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8718
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
|
8643
8719
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8644
8720
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8645
8721
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8656,57 +8732,24 @@ var launchNode = async ({
|
|
8656
8732
|
})).toString();
|
8657
8733
|
let snapshotDirToUse;
|
8658
8734
|
const prefix = basePath || import_os.default.tmpdir();
|
8659
|
-
const suffix = basePath ? "" : (0,
|
8660
|
-
const
|
8735
|
+
const suffix = basePath ? "" : (0, import_crypto9.randomUUID)();
|
8736
|
+
const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
8661
8737
|
if (snapshotDir) {
|
8662
8738
|
snapshotDirToUse = snapshotDir;
|
8663
8739
|
} else {
|
8664
|
-
if (!(0, import_fs.existsSync)(
|
8665
|
-
(0, import_fs.mkdirSync)(
|
8740
|
+
if (!(0, import_fs.existsSync)(tempDir)) {
|
8741
|
+
(0, import_fs.mkdirSync)(tempDir, { recursive: true });
|
8666
8742
|
}
|
8667
|
-
|
8668
|
-
const
|
8669
|
-
|
8670
|
-
|
8671
|
-
|
8672
|
-
|
8673
|
-
|
8674
|
-
|
8675
|
-
|
8676
|
-
|
8677
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8678
|
-
...message,
|
8679
|
-
amount: "18446744073709551615"
|
8680
|
-
}))
|
8681
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8682
|
-
};
|
8683
|
-
if (!process.env.GENESIS_SECRET) {
|
8684
|
-
const pk = Signer.generatePrivateKey();
|
8685
|
-
const signer = new Signer(pk);
|
8686
|
-
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8687
|
-
stateConfigJson.coins.push({
|
8688
|
-
tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.BYTES_32)),
|
8689
|
-
owner: signer.address.toHexString(),
|
8690
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8691
|
-
amount: "18446744073709551615",
|
8692
|
-
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8693
|
-
output_index: 0,
|
8694
|
-
tx_pointer_block_height: 0,
|
8695
|
-
tx_pointer_tx_idx: 0
|
8696
|
-
});
|
8697
|
-
}
|
8698
|
-
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8699
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8700
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8701
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8702
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8703
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8704
|
-
const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
|
8705
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8706
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8707
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8708
|
-
(0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
|
8709
|
-
snapshotDirToUse = tempDirPath;
|
8743
|
+
const { metadata } = snapshotConfig;
|
8744
|
+
const metadataPath = import_path.default.join(tempDir, "metadata.json");
|
8745
|
+
const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
|
8746
|
+
const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
|
8747
|
+
const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
|
8748
|
+
(0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
8749
|
+
(0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
8750
|
+
(0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
|
8751
|
+
(0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
|
8752
|
+
snapshotDirToUse = tempDir;
|
8710
8753
|
}
|
8711
8754
|
const child = (0, import_child_process.spawn)(
|
8712
8755
|
command,
|
@@ -8714,7 +8757,7 @@ var launchNode = async ({
|
|
8714
8757
|
"run",
|
8715
8758
|
["--ip", ipToUse],
|
8716
8759
|
["--port", portToUse],
|
8717
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8760
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8718
8761
|
["--min-gas-price", "1"],
|
8719
8762
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8720
8763
|
["--native-executor-version", nativeExecutorVersion],
|
@@ -8737,23 +8780,28 @@ var launchNode = async ({
|
|
8737
8780
|
}
|
8738
8781
|
const cleanupConfig = {
|
8739
8782
|
child,
|
8740
|
-
configPath:
|
8783
|
+
configPath: tempDir,
|
8741
8784
|
killFn: import_tree_kill.default,
|
8742
8785
|
state: {
|
8743
8786
|
isDead: false
|
8744
8787
|
}
|
8745
8788
|
};
|
8746
8789
|
child.stderr.on("data", (chunk) => {
|
8747
|
-
|
8790
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
8791
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8792
|
+
const rows = text.split("\n");
|
8793
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8794
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8748
8795
|
resolve({
|
8749
8796
|
cleanup: () => killNode(cleanupConfig),
|
8750
|
-
ip:
|
8751
|
-
port:
|
8797
|
+
ip: realIp,
|
8798
|
+
port: realPort,
|
8799
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8752
8800
|
snapshotDir: snapshotDirToUse
|
8753
8801
|
});
|
8754
8802
|
}
|
8755
|
-
if (/error/i.test(
|
8756
|
-
reject(
|
8803
|
+
if (/error/i.test(text)) {
|
8804
|
+
reject(text.toString());
|
8757
8805
|
}
|
8758
8806
|
});
|
8759
8807
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8786,12 +8834,245 @@ var launchNodeAndGetWallets = async ({
|
|
8786
8834
|
};
|
8787
8835
|
return { wallets, stop: cleanup, provider };
|
8788
8836
|
};
|
8837
|
+
|
8838
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8839
|
+
var import_utils40 = require("@fuel-ts/utils");
|
8840
|
+
var import_ramda5 = require("ramda");
|
8841
|
+
|
8842
|
+
// src/test-utils/asset-id.ts
|
8843
|
+
var import_crypto10 = require("@fuel-ts/crypto");
|
8844
|
+
var import_utils38 = require("@fuel-ts/utils");
|
8845
|
+
var _AssetId = class {
|
8846
|
+
constructor(value) {
|
8847
|
+
this.value = value;
|
8848
|
+
}
|
8849
|
+
static random(count = 1) {
|
8850
|
+
const assetIds = [];
|
8851
|
+
for (let i = 0; i < count; i++) {
|
8852
|
+
assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto10.randomBytes)(32))));
|
8853
|
+
}
|
8854
|
+
return assetIds;
|
8855
|
+
}
|
8856
|
+
};
|
8857
|
+
var AssetId = _AssetId;
|
8858
|
+
__publicField(AssetId, "A", new _AssetId(
|
8859
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8860
|
+
));
|
8861
|
+
__publicField(AssetId, "B", new _AssetId(
|
8862
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8863
|
+
));
|
8864
|
+
|
8865
|
+
// src/test-utils/wallet-config.ts
|
8866
|
+
var import_crypto11 = require("@fuel-ts/crypto");
|
8867
|
+
var import_errors21 = require("@fuel-ts/errors");
|
8868
|
+
var import_utils39 = require("@fuel-ts/utils");
|
8869
|
+
var WalletsConfig = class {
|
8870
|
+
initialState;
|
8871
|
+
options;
|
8872
|
+
wallets;
|
8873
|
+
generateWallets = () => {
|
8874
|
+
const generatedWallets = [];
|
8875
|
+
for (let index = 1; index <= this.options.count; index++) {
|
8876
|
+
generatedWallets.push(new WalletUnlocked((0, import_crypto11.randomBytes)(32)));
|
8877
|
+
}
|
8878
|
+
return generatedWallets;
|
8879
|
+
};
|
8880
|
+
constructor(baseAssetId, config) {
|
8881
|
+
WalletsConfig.validate(config);
|
8882
|
+
this.options = config;
|
8883
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8884
|
+
this.wallets = this.generateWallets();
|
8885
|
+
this.initialState = {
|
8886
|
+
messages: WalletsConfig.createMessages(this.wallets, messages),
|
8887
|
+
coins: WalletsConfig.createCoins(
|
8888
|
+
this.wallets,
|
8889
|
+
baseAssetId,
|
8890
|
+
assets2,
|
8891
|
+
coinsPerAsset,
|
8892
|
+
amountPerCoin
|
8893
|
+
)
|
8894
|
+
};
|
8895
|
+
}
|
8896
|
+
apply(snapshotConfig) {
|
8897
|
+
return {
|
8898
|
+
...snapshotConfig,
|
8899
|
+
stateConfig: {
|
8900
|
+
...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
|
8901
|
+
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8902
|
+
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8903
|
+
}
|
8904
|
+
};
|
8905
|
+
}
|
8906
|
+
/**
|
8907
|
+
* Create messages for the wallets in the format that the chain expects.
|
8908
|
+
*/
|
8909
|
+
static createMessages(wallets, messages) {
|
8910
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8911
|
+
}
|
8912
|
+
/**
|
8913
|
+
* Create coins for the wallets in the format that the chain expects.
|
8914
|
+
*/
|
8915
|
+
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8916
|
+
const coins = [];
|
8917
|
+
let assetIds = [baseAssetId];
|
8918
|
+
if (Array.isArray(assets2)) {
|
8919
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8920
|
+
} else {
|
8921
|
+
assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
|
8922
|
+
}
|
8923
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8924
|
+
assetIds.forEach((assetId) => {
|
8925
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
8926
|
+
coins.push({
|
8927
|
+
amount: amountPerCoin,
|
8928
|
+
asset_id: assetId,
|
8929
|
+
owner: walletAddress,
|
8930
|
+
tx_pointer_block_height: 0,
|
8931
|
+
tx_pointer_tx_idx: 0,
|
8932
|
+
output_index: 0,
|
8933
|
+
tx_id: (0, import_utils39.hexlify)((0, import_crypto11.randomBytes)(32))
|
8934
|
+
});
|
8935
|
+
}
|
8936
|
+
});
|
8937
|
+
});
|
8938
|
+
return coins;
|
8939
|
+
}
|
8940
|
+
static validate({
|
8941
|
+
count: wallets,
|
8942
|
+
assets: assets2,
|
8943
|
+
coinsPerAsset,
|
8944
|
+
amountPerCoin
|
8945
|
+
}) {
|
8946
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8947
|
+
throw new import_errors21.FuelError(
|
8948
|
+
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8949
|
+
"Number of wallets must be greater than zero."
|
8950
|
+
);
|
8951
|
+
}
|
8952
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8953
|
+
throw new import_errors21.FuelError(
|
8954
|
+
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8955
|
+
"Number of assets per wallet must be greater than zero."
|
8956
|
+
);
|
8957
|
+
}
|
8958
|
+
if (coinsPerAsset <= 0) {
|
8959
|
+
throw new import_errors21.FuelError(
|
8960
|
+
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8961
|
+
"Number of coins per asset must be greater than zero."
|
8962
|
+
);
|
8963
|
+
}
|
8964
|
+
if (amountPerCoin <= 0) {
|
8965
|
+
throw new import_errors21.FuelError(
|
8966
|
+
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8967
|
+
"Amount per coin must be greater than zero."
|
8968
|
+
);
|
8969
|
+
}
|
8970
|
+
}
|
8971
|
+
};
|
8972
|
+
|
8973
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8974
|
+
var defaultWalletConfigOptions = {
|
8975
|
+
count: 2,
|
8976
|
+
assets: [AssetId.A, AssetId.B],
|
8977
|
+
coinsPerAsset: 1,
|
8978
|
+
amountPerCoin: 1e10,
|
8979
|
+
messages: []
|
8980
|
+
};
|
8981
|
+
async function setupTestProviderAndWallets({
|
8982
|
+
walletsConfig: walletsConfigOptions = {},
|
8983
|
+
providerOptions,
|
8984
|
+
nodeOptions = {}
|
8985
|
+
} = {}) {
|
8986
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8987
|
+
const walletsConfig = new WalletsConfig(
|
8988
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
|
8989
|
+
{
|
8990
|
+
...defaultWalletConfigOptions,
|
8991
|
+
...walletsConfigOptions
|
8992
|
+
}
|
8993
|
+
);
|
8994
|
+
const { cleanup, url } = await launchNode({
|
8995
|
+
loggingEnabled: false,
|
8996
|
+
...nodeOptions,
|
8997
|
+
snapshotConfig: (0, import_ramda5.mergeDeepRight)(
|
8998
|
+
import_utils40.defaultSnapshotConfigs,
|
8999
|
+
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
9000
|
+
),
|
9001
|
+
port: "0"
|
9002
|
+
});
|
9003
|
+
let provider;
|
9004
|
+
try {
|
9005
|
+
provider = await Provider.create(url, providerOptions);
|
9006
|
+
} catch (err) {
|
9007
|
+
cleanup();
|
9008
|
+
throw err;
|
9009
|
+
}
|
9010
|
+
const wallets = walletsConfig.wallets;
|
9011
|
+
wallets.forEach((wallet) => {
|
9012
|
+
wallet.connect(provider);
|
9013
|
+
});
|
9014
|
+
return {
|
9015
|
+
provider,
|
9016
|
+
wallets,
|
9017
|
+
cleanup,
|
9018
|
+
[Symbol.dispose]: cleanup
|
9019
|
+
};
|
9020
|
+
}
|
9021
|
+
|
9022
|
+
// src/test-utils/test-message.ts
|
9023
|
+
var import_address7 = require("@fuel-ts/address");
|
9024
|
+
var import_crypto12 = require("@fuel-ts/crypto");
|
9025
|
+
var import_math23 = require("@fuel-ts/math");
|
9026
|
+
var import_utils41 = require("@fuel-ts/utils");
|
9027
|
+
var TestMessage = class {
|
9028
|
+
sender;
|
9029
|
+
recipient;
|
9030
|
+
nonce;
|
9031
|
+
amount;
|
9032
|
+
data;
|
9033
|
+
da_height;
|
9034
|
+
/**
|
9035
|
+
* A helper class to create messages for testing purposes.
|
9036
|
+
*
|
9037
|
+
* Used in tandem with `WalletsConfig`.
|
9038
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
9039
|
+
*/
|
9040
|
+
constructor({
|
9041
|
+
sender = import_address7.Address.fromRandom(),
|
9042
|
+
recipient = import_address7.Address.fromRandom(),
|
9043
|
+
nonce = (0, import_utils41.hexlify)((0, import_crypto12.randomBytes)(32)),
|
9044
|
+
amount = 1e6,
|
9045
|
+
data = "02",
|
9046
|
+
da_height = 0
|
9047
|
+
} = {}) {
|
9048
|
+
this.sender = sender;
|
9049
|
+
this.recipient = recipient;
|
9050
|
+
this.nonce = nonce;
|
9051
|
+
this.amount = amount;
|
9052
|
+
this.data = data;
|
9053
|
+
this.da_height = da_height;
|
9054
|
+
}
|
9055
|
+
toChainMessage(recipient) {
|
9056
|
+
return {
|
9057
|
+
sender: this.sender.toB256(),
|
9058
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
9059
|
+
nonce: this.nonce,
|
9060
|
+
amount: (0, import_math23.bn)(this.amount).toNumber(),
|
9061
|
+
data: this.data,
|
9062
|
+
da_height: this.da_height
|
9063
|
+
};
|
9064
|
+
}
|
9065
|
+
};
|
8789
9066
|
// Annotate the CommonJS export names for ESM import in node:
|
8790
9067
|
0 && (module.exports = {
|
9068
|
+
AssetId,
|
9069
|
+
TestMessage,
|
9070
|
+
WalletsConfig,
|
8791
9071
|
generateTestWallet,
|
8792
9072
|
killNode,
|
8793
9073
|
launchNode,
|
8794
9074
|
launchNodeAndGetWallets,
|
8795
|
-
seedTestWallet
|
9075
|
+
seedTestWallet,
|
9076
|
+
setupTestProviderAndWallets
|
8796
9077
|
});
|
8797
9078
|
//# sourceMappingURL=test-utils.js.map
|