@fuel-ts/account 0.0.0-rc-1356-20240520175924 → 0.0.0-rc-2333-20240520180734
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 +36 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +86 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +202 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -22
- package/dist/index.mjs.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/sleep.d.ts +3 -0
- package/dist/providers/utils/sleep.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -8
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +144 -415
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +244 -424
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +142 -318
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -16
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
- package/dist/test-utils/test-message.d.ts +0 -29
- package/dist/test-utils/test-message.d.ts.map +0 -1
- package/dist/test-utils/wallet-config.d.ts +0 -55
- package/dist/test-utils/wallet-config.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -48,28 +48,24 @@ var __privateMethod = (obj, member, method) => {
|
|
48
48
|
// src/test-utils/index.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
-
AssetId: () => AssetId,
|
52
|
-
TestMessage: () => TestMessage,
|
53
|
-
WalletConfig: () => WalletConfig,
|
54
51
|
generateTestWallet: () => generateTestWallet,
|
55
52
|
killNode: () => killNode,
|
56
53
|
launchNode: () => launchNode,
|
57
54
|
launchNodeAndGetWallets: () => launchNodeAndGetWallets,
|
58
|
-
seedTestWallet: () => seedTestWallet
|
59
|
-
setupTestProviderAndWallets: () => setupTestProviderAndWallets
|
55
|
+
seedTestWallet: () => seedTestWallet
|
60
56
|
});
|
61
57
|
module.exports = __toCommonJS(test_utils_exports);
|
62
58
|
|
63
59
|
// src/wallet/base-wallet-unlocked.ts
|
64
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
65
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
66
62
|
|
67
63
|
// src/account.ts
|
68
64
|
var import_address4 = require("@fuel-ts/address");
|
69
65
|
var import_errors16 = require("@fuel-ts/errors");
|
70
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
71
67
|
var import_math20 = require("@fuel-ts/math");
|
72
|
-
var
|
68
|
+
var import_utils28 = require("@fuel-ts/utils");
|
73
69
|
var import_ramda4 = require("ramda");
|
74
70
|
|
75
71
|
// src/providers/coin-quantity.ts
|
@@ -112,9 +108,9 @@ var import_address3 = require("@fuel-ts/address");
|
|
112
108
|
var import_errors14 = require("@fuel-ts/errors");
|
113
109
|
var import_math17 = require("@fuel-ts/math");
|
114
110
|
var import_transactions20 = require("@fuel-ts/transactions");
|
115
|
-
var
|
111
|
+
var import_utils22 = require("@fuel-ts/utils");
|
116
112
|
var import_versions = require("@fuel-ts/versions");
|
117
|
-
var
|
113
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
118
114
|
var import_graphql_request = require("graphql-request");
|
119
115
|
var import_ramda3 = require("ramda");
|
120
116
|
|
@@ -1673,6 +1669,15 @@ function normalizeJSON(root) {
|
|
1673
1669
|
return normalize((0, import_ramda.clone)(root));
|
1674
1670
|
}
|
1675
1671
|
|
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
|
+
|
1676
1681
|
// src/providers/utils/extract-tx-error.ts
|
1677
1682
|
var import_errors7 = require("@fuel-ts/errors");
|
1678
1683
|
var import_math6 = require("@fuel-ts/math");
|
@@ -3613,7 +3618,6 @@ var TransactionResponse = class {
|
|
3613
3618
|
};
|
3614
3619
|
|
3615
3620
|
// src/providers/utils/auto-retry-fetch.ts
|
3616
|
-
var import_utils22 = require("@fuel-ts/utils");
|
3617
3621
|
function getWaitDelay(options, retryAttemptNum) {
|
3618
3622
|
const duration = options.baseDelay ?? 150;
|
3619
3623
|
switch (options.backoff) {
|
@@ -3643,7 +3647,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3643
3647
|
throw error;
|
3644
3648
|
}
|
3645
3649
|
const delay = getWaitDelay(options, retryNum);
|
3646
|
-
await
|
3650
|
+
await sleep(delay);
|
3647
3651
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3648
3652
|
}
|
3649
3653
|
};
|
@@ -3983,7 +3987,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3983
3987
|
if (estimateTxDependencies) {
|
3984
3988
|
await this.estimateTxDependencies(transactionRequest);
|
3985
3989
|
}
|
3986
|
-
const encodedTransaction = (0,
|
3990
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3987
3991
|
let abis;
|
3988
3992
|
if (transactionRequest.type === import_transactions20.TransactionType.Script) {
|
3989
3993
|
abis = transactionRequest.abis;
|
@@ -4026,7 +4030,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4026
4030
|
if (estimateTxDependencies) {
|
4027
4031
|
return this.estimateTxDependencies(transactionRequest);
|
4028
4032
|
}
|
4029
|
-
const encodedTransaction = (0,
|
4033
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4030
4034
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4031
4035
|
encodedTransactions: encodedTransaction,
|
4032
4036
|
utxoValidation: utxoValidation || false
|
@@ -4044,13 +4048,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4044
4048
|
async estimatePredicates(transactionRequest) {
|
4045
4049
|
const shouldEstimatePredicates = Boolean(
|
4046
4050
|
transactionRequest.inputs.find(
|
4047
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4051
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
|
4048
4052
|
)
|
4049
4053
|
);
|
4050
4054
|
if (!shouldEstimatePredicates) {
|
4051
4055
|
return transactionRequest;
|
4052
4056
|
}
|
4053
|
-
const encodedTransaction = (0,
|
4057
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4054
4058
|
const response = await this.operations.estimatePredicates({
|
4055
4059
|
encodedTransaction
|
4056
4060
|
});
|
@@ -4092,7 +4096,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4092
4096
|
const {
|
4093
4097
|
dryRun: [{ receipts: rawReceipts, status }]
|
4094
4098
|
} = await this.operations.dryRun({
|
4095
|
-
encodedTransactions: [(0,
|
4099
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4096
4100
|
utxoValidation: false
|
4097
4101
|
});
|
4098
4102
|
receipts = rawReceipts.map(processGqlReceipt);
|
@@ -4142,7 +4146,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4142
4146
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4143
4147
|
allRequests.forEach((req, index) => {
|
4144
4148
|
if (req.type === import_transactions20.TransactionType.Script) {
|
4145
|
-
serializedTransactionsMap.set(index, (0,
|
4149
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4146
4150
|
}
|
4147
4151
|
});
|
4148
4152
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4178,7 +4182,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4178
4182
|
transactionRequest: request
|
4179
4183
|
});
|
4180
4184
|
request.maxFee = maxFee;
|
4181
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
4185
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
|
4182
4186
|
nextRoundTransactions.push(requestIdx);
|
4183
4187
|
}
|
4184
4188
|
}
|
@@ -4191,7 +4195,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4191
4195
|
if (estimateTxDependencies) {
|
4192
4196
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4193
4197
|
}
|
4194
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
4198
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4195
4199
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4196
4200
|
encodedTransactions,
|
4197
4201
|
utxoValidation: utxoValidation || false
|
@@ -4264,7 +4268,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4264
4268
|
if (estimateTxDependencies) {
|
4265
4269
|
return this.estimateTxDependencies(transactionRequest);
|
4266
4270
|
}
|
4267
|
-
const encodedTransactions = [(0,
|
4271
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4268
4272
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4269
4273
|
encodedTransactions,
|
4270
4274
|
utxoValidation: true
|
@@ -4383,7 +4387,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4383
4387
|
const result = await this.operations.getCoins({
|
4384
4388
|
first: 10,
|
4385
4389
|
...paginationArgs,
|
4386
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4390
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4387
4391
|
});
|
4388
4392
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4389
4393
|
return coins.map((coin) => ({
|
@@ -4406,19 +4410,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4406
4410
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4407
4411
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4408
4412
|
const excludeInput = {
|
4409
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4410
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4413
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4414
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4411
4415
|
};
|
4412
4416
|
if (this.cache) {
|
4413
4417
|
const uniqueUtxos = new Set(
|
4414
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4418
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4415
4419
|
);
|
4416
4420
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4417
4421
|
}
|
4418
4422
|
const coinsQuery = {
|
4419
4423
|
owner: ownerAddress.toB256(),
|
4420
4424
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4421
|
-
assetId: (0,
|
4425
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4422
4426
|
amount: amount.toString(10),
|
4423
4427
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4424
4428
|
})),
|
@@ -4520,7 +4524,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4520
4524
|
time: block.header.time,
|
4521
4525
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4522
4526
|
transactions: block.transactions.map(
|
4523
|
-
(tx) => new import_transactions20.TransactionCoder().decode((0,
|
4527
|
+
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4524
4528
|
)
|
4525
4529
|
};
|
4526
4530
|
}
|
@@ -4536,7 +4540,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4536
4540
|
return null;
|
4537
4541
|
}
|
4538
4542
|
return new import_transactions20.TransactionCoder().decode(
|
4539
|
-
(0,
|
4543
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4540
4544
|
0
|
4541
4545
|
)?.[0];
|
4542
4546
|
}
|
@@ -4563,7 +4567,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4563
4567
|
async getContractBalance(contractId, assetId) {
|
4564
4568
|
const { contractBalance } = await this.operations.getContractBalance({
|
4565
4569
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4566
|
-
asset: (0,
|
4570
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4567
4571
|
});
|
4568
4572
|
return (0, import_math17.bn)(contractBalance.amount, 10);
|
4569
4573
|
}
|
@@ -4577,7 +4581,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4577
4581
|
async getBalance(owner, assetId) {
|
4578
4582
|
const { balance } = await this.operations.getBalance({
|
4579
4583
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4580
|
-
assetId: (0,
|
4584
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4581
4585
|
});
|
4582
4586
|
return (0, import_math17.bn)(balance.amount, 10);
|
4583
4587
|
}
|
@@ -4754,7 +4758,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4754
4758
|
async produceBlocks(amount, startTime) {
|
4755
4759
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4756
4760
|
blocksToProduce: (0, import_math17.bn)(amount).toString(10),
|
4757
|
-
startTimestamp: startTime ?
|
4761
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4758
4762
|
});
|
4759
4763
|
return (0, import_math17.bn)(latestBlockHeight);
|
4760
4764
|
}
|
@@ -4820,7 +4824,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4820
4824
|
var import_errors15 = require("@fuel-ts/errors");
|
4821
4825
|
var import_math18 = require("@fuel-ts/math");
|
4822
4826
|
var import_transactions21 = require("@fuel-ts/transactions");
|
4823
|
-
var
|
4827
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4824
4828
|
|
4825
4829
|
// src/providers/chains.ts
|
4826
4830
|
var CHAIN_IDS = {
|
@@ -4896,16 +4900,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
|
|
4896
4900
|
// src/utils/formatTransferToContractScriptData.ts
|
4897
4901
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4898
4902
|
var import_math19 = require("@fuel-ts/math");
|
4899
|
-
var
|
4903
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4900
4904
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4901
4905
|
var formatTransferToContractScriptData = (params) => {
|
4902
4906
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4903
4907
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4904
4908
|
const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
|
4905
4909
|
const scriptData = Uint8Array.from([
|
4906
|
-
...(0,
|
4910
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4907
4911
|
...encoded,
|
4908
|
-
...(0,
|
4912
|
+
...(0, import_utils27.arrayify)(assetId)
|
4909
4913
|
]);
|
4910
4914
|
return scriptData;
|
4911
4915
|
};
|
@@ -5189,19 +5193,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5189
5193
|
*/
|
5190
5194
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5191
5195
|
let request = new ScriptTransactionRequest(txParams);
|
5192
|
-
|
5193
|
-
request.
|
5194
|
-
const txCost = await this.provider.getTransactionCost(request, {
|
5195
|
-
estimateTxDependencies: true,
|
5196
|
-
resourcesOwner: this
|
5197
|
-
});
|
5198
|
-
request = this.validateGasLimitAndMaxFee({
|
5199
|
-
transactionRequest: request,
|
5200
|
-
gasUsed: txCost.gasUsed,
|
5201
|
-
maxFee: txCost.maxFee,
|
5202
|
-
txParams
|
5203
|
-
});
|
5204
|
-
await this.fund(request, txCost);
|
5196
|
+
request = this.addTransfer(request, { destination, amount, assetId });
|
5197
|
+
request = await this.estimateAndFundTransaction(request, txParams);
|
5205
5198
|
return request;
|
5206
5199
|
}
|
5207
5200
|
/**
|
@@ -5214,16 +5207,57 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5214
5207
|
* @returns A promise that resolves to the transaction response.
|
5215
5208
|
*/
|
5216
5209
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5217
|
-
|
5218
|
-
throw new import_errors16.FuelError(
|
5219
|
-
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5220
|
-
"Transfer amount must be a positive number."
|
5221
|
-
);
|
5222
|
-
}
|
5223
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5224
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5210
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5225
5211
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5226
5212
|
}
|
5213
|
+
/**
|
5214
|
+
* Transfers multiple amounts of a token to multiple recipients.
|
5215
|
+
*
|
5216
|
+
* @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
|
5217
|
+
* @param txParams - Optional transaction parameters.
|
5218
|
+
* @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
|
5219
|
+
*/
|
5220
|
+
async batchTransfer(transferParams, txParams = {}) {
|
5221
|
+
let request = new ScriptTransactionRequest(txParams);
|
5222
|
+
request = this.addBatchTransfer(request, transferParams);
|
5223
|
+
request = await this.estimateAndFundTransaction(request, txParams);
|
5224
|
+
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5225
|
+
}
|
5226
|
+
/**
|
5227
|
+
* Adds a transfer to the given transaction request.
|
5228
|
+
*
|
5229
|
+
* @param request - The script transaction request to add transfers to.
|
5230
|
+
* @param transferParams - The object representing the transfer to be made.
|
5231
|
+
* @returns The updated transaction request with the added transfer.
|
5232
|
+
*/
|
5233
|
+
addTransfer(request, transferParams) {
|
5234
|
+
const { destination, amount, assetId } = transferParams;
|
5235
|
+
this.validateTransferAmount(amount);
|
5236
|
+
request.addCoinOutput(
|
5237
|
+
import_address4.Address.fromAddressOrString(destination),
|
5238
|
+
amount,
|
5239
|
+
assetId ?? this.provider.getBaseAssetId()
|
5240
|
+
);
|
5241
|
+
return request;
|
5242
|
+
}
|
5243
|
+
/**
|
5244
|
+
* Adds multiple transfers to a script transaction request.
|
5245
|
+
*
|
5246
|
+
* @param request - The script transaction request to add transfers to.
|
5247
|
+
* @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
|
5248
|
+
* @returns The updated script transaction request.
|
5249
|
+
*/
|
5250
|
+
addBatchTransfer(request, transferParams) {
|
5251
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5252
|
+
transferParams.forEach(({ destination, amount, assetId }) => {
|
5253
|
+
this.addTransfer(request, {
|
5254
|
+
destination,
|
5255
|
+
amount,
|
5256
|
+
assetId: assetId ?? baseAssetId
|
5257
|
+
});
|
5258
|
+
});
|
5259
|
+
return request;
|
5260
|
+
}
|
5227
5261
|
/**
|
5228
5262
|
* Transfers coins to a contract address.
|
5229
5263
|
*
|
@@ -5276,14 +5310,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5276
5310
|
*/
|
5277
5311
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5278
5312
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5279
|
-
const recipientDataArray = (0,
|
5313
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5280
5314
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5281
5315
|
);
|
5282
|
-
const amountDataArray = (0,
|
5316
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5283
5317
|
"0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5284
5318
|
);
|
5285
5319
|
const script = new Uint8Array([
|
5286
|
-
...(0,
|
5320
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5287
5321
|
...recipientDataArray,
|
5288
5322
|
...amountDataArray
|
5289
5323
|
]);
|
@@ -5301,6 +5335,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5301
5335
|
await this.fund(request, txCost);
|
5302
5336
|
return this.sendTransaction(request);
|
5303
5337
|
}
|
5338
|
+
/** @hidden * */
|
5304
5339
|
async signMessage(message) {
|
5305
5340
|
if (!this._connector) {
|
5306
5341
|
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
@@ -5356,6 +5391,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5356
5391
|
}
|
5357
5392
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5358
5393
|
}
|
5394
|
+
/** @hidden * */
|
5395
|
+
validateTransferAmount(amount) {
|
5396
|
+
if ((0, import_math20.bn)(amount).lte(0)) {
|
5397
|
+
throw new import_errors16.FuelError(
|
5398
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5399
|
+
"Transfer amount must be a positive number."
|
5400
|
+
);
|
5401
|
+
}
|
5402
|
+
}
|
5403
|
+
/** @hidden * */
|
5404
|
+
async estimateAndFundTransaction(transactionRequest, txParams) {
|
5405
|
+
let request = transactionRequest;
|
5406
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5407
|
+
resourcesOwner: this
|
5408
|
+
});
|
5409
|
+
request = this.validateGasLimitAndMaxFee({
|
5410
|
+
transactionRequest: request,
|
5411
|
+
gasUsed: txCost.gasUsed,
|
5412
|
+
maxFee: txCost.maxFee,
|
5413
|
+
txParams
|
5414
|
+
});
|
5415
|
+
request = await this.fund(request, txCost);
|
5416
|
+
return request;
|
5417
|
+
}
|
5418
|
+
/** @hidden * */
|
5359
5419
|
validateGasLimitAndMaxFee({
|
5360
5420
|
gasUsed,
|
5361
5421
|
maxFee,
|
@@ -5363,7 +5423,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5363
5423
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
5364
5424
|
}) {
|
5365
5425
|
const request = transactionRequestify(transactionRequest);
|
5366
|
-
if (!(0,
|
5426
|
+
if (!(0, import_utils28.isDefined)(setGasLimit)) {
|
5367
5427
|
request.gasLimit = gasUsed;
|
5368
5428
|
} else if (gasUsed.gt(setGasLimit)) {
|
5369
5429
|
throw new import_errors16.FuelError(
|
@@ -5371,7 +5431,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5371
5431
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5372
5432
|
);
|
5373
5433
|
}
|
5374
|
-
if (!(0,
|
5434
|
+
if (!(0, import_utils28.isDefined)(setMaxFee)) {
|
5375
5435
|
request.maxFee = maxFee;
|
5376
5436
|
} else if (maxFee.gt(setMaxFee)) {
|
5377
5437
|
throw new import_errors16.FuelError(
|
@@ -5388,7 +5448,7 @@ var import_address5 = require("@fuel-ts/address");
|
|
5388
5448
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5389
5449
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5390
5450
|
var import_math21 = require("@fuel-ts/math");
|
5391
|
-
var
|
5451
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5392
5452
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5393
5453
|
var Signer = class {
|
5394
5454
|
address;
|
@@ -5408,9 +5468,9 @@ var Signer = class {
|
|
5408
5468
|
}
|
5409
5469
|
}
|
5410
5470
|
const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
|
5411
|
-
this.privateKey = (0,
|
5412
|
-
this.publicKey = (0,
|
5413
|
-
this.compressedPublicKey = (0,
|
5471
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5472
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5473
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5414
5474
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5415
5475
|
}
|
5416
5476
|
/**
|
@@ -5424,11 +5484,11 @@ var Signer = class {
|
|
5424
5484
|
* @returns hashed signature
|
5425
5485
|
*/
|
5426
5486
|
sign(data) {
|
5427
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5487
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5428
5488
|
const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5429
5489
|
const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5430
5490
|
s[0] |= (signature.recovery || 0) << 7;
|
5431
|
-
return (0,
|
5491
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5432
5492
|
}
|
5433
5493
|
/**
|
5434
5494
|
* Add point on the current elliptic curve
|
@@ -5437,8 +5497,8 @@ var Signer = class {
|
|
5437
5497
|
* @returns compressed point on the curve
|
5438
5498
|
*/
|
5439
5499
|
addPoint(point) {
|
5440
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5441
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5500
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5501
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5442
5502
|
const result = p0.add(p1);
|
5443
5503
|
return `0x${result.toHex(true)}`;
|
5444
5504
|
}
|
@@ -5450,16 +5510,16 @@ var Signer = class {
|
|
5450
5510
|
* @returns public key from signature from the
|
5451
5511
|
*/
|
5452
5512
|
static recoverPublicKey(data, signature) {
|
5453
|
-
const signedMessageBytes = (0,
|
5513
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5454
5514
|
const r = signedMessageBytes.slice(0, 32);
|
5455
5515
|
const s = signedMessageBytes.slice(32, 64);
|
5456
5516
|
const recoveryParam = (s[0] & 128) >> 7;
|
5457
5517
|
s[0] &= 127;
|
5458
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5518
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5459
5519
|
recoveryParam
|
5460
5520
|
);
|
5461
|
-
const publicKey = sig.recoverPublicKey((0,
|
5462
|
-
return (0,
|
5521
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5522
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5463
5523
|
}
|
5464
5524
|
/**
|
5465
5525
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5478,7 +5538,7 @@ var Signer = class {
|
|
5478
5538
|
* @returns random 32-byte hashed
|
5479
5539
|
*/
|
5480
5540
|
static generatePrivateKey(entropy) {
|
5481
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5541
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5482
5542
|
}
|
5483
5543
|
/**
|
5484
5544
|
* Extended publicKey from a compact publicKey
|
@@ -5487,8 +5547,8 @@ var Signer = class {
|
|
5487
5547
|
* @returns extended publicKey
|
5488
5548
|
*/
|
5489
5549
|
static extendPublicKey(publicKey) {
|
5490
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5491
|
-
return (0,
|
5550
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5551
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5492
5552
|
}
|
5493
5553
|
};
|
5494
5554
|
|
@@ -5496,7 +5556,7 @@ var Signer = class {
|
|
5496
5556
|
var import_address6 = require("@fuel-ts/address");
|
5497
5557
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5498
5558
|
var import_errors17 = require("@fuel-ts/errors");
|
5499
|
-
var
|
5559
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5500
5560
|
var import_uuid = require("uuid");
|
5501
5561
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5502
5562
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5579,7 +5639,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5579
5639
|
);
|
5580
5640
|
}
|
5581
5641
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5582
|
-
const privateKey = (0,
|
5642
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5583
5643
|
return privateKey;
|
5584
5644
|
}
|
5585
5645
|
|
@@ -5624,7 +5684,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5624
5684
|
*/
|
5625
5685
|
async signMessage(message) {
|
5626
5686
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5627
|
-
return (0,
|
5687
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5628
5688
|
}
|
5629
5689
|
/**
|
5630
5690
|
* Signs a transaction with the wallet's private key.
|
@@ -5637,7 +5697,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5637
5697
|
const chainId = this.provider.getChainId();
|
5638
5698
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5639
5699
|
const signature = await this.signer().sign(hashedTransaction);
|
5640
|
-
return (0,
|
5700
|
+
return (0, import_utils31.hexlify)(signature);
|
5641
5701
|
}
|
5642
5702
|
/**
|
5643
5703
|
* Populates a transaction with the witnesses signature.
|
@@ -5700,13 +5760,13 @@ var import_crypto5 = require("@fuel-ts/crypto");
|
|
5700
5760
|
var import_errors20 = require("@fuel-ts/errors");
|
5701
5761
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5702
5762
|
var import_math22 = require("@fuel-ts/math");
|
5703
|
-
var
|
5763
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5704
5764
|
|
5705
5765
|
// src/mnemonic/mnemonic.ts
|
5706
5766
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5707
5767
|
var import_errors19 = require("@fuel-ts/errors");
|
5708
5768
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5709
|
-
var
|
5769
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5710
5770
|
|
5711
5771
|
// src/wordlists/words/english.ts
|
5712
5772
|
var english = [
|
@@ -7763,7 +7823,7 @@ var english = [
|
|
7763
7823
|
// src/mnemonic/utils.ts
|
7764
7824
|
var import_errors18 = require("@fuel-ts/errors");
|
7765
7825
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7766
|
-
var
|
7826
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7767
7827
|
function getLowerMask(bits) {
|
7768
7828
|
return (1 << bits) - 1;
|
7769
7829
|
}
|
@@ -7798,14 +7858,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7798
7858
|
}
|
7799
7859
|
}
|
7800
7860
|
const checksumBits = entropy.length / 4;
|
7801
|
-
const checksum = (0,
|
7861
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7802
7862
|
indices[indices.length - 1] <<= checksumBits;
|
7803
7863
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7804
7864
|
return indices;
|
7805
7865
|
}
|
7806
7866
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7807
7867
|
const size = Math.ceil(11 * words.length / 8);
|
7808
|
-
const entropy = (0,
|
7868
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7809
7869
|
let offset = 0;
|
7810
7870
|
for (let i = 0; i < words.length; i += 1) {
|
7811
7871
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7825,7 +7885,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7825
7885
|
const entropyBits = 32 * words.length / 3;
|
7826
7886
|
const checksumBits = words.length / 3;
|
7827
7887
|
const checksumMask = getUpperMask(checksumBits);
|
7828
|
-
const checksum = (0,
|
7888
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7829
7889
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7830
7890
|
throw new import_errors18.FuelError(
|
7831
7891
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7836,7 +7896,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7836
7896
|
}
|
7837
7897
|
|
7838
7898
|
// src/mnemonic/mnemonic.ts
|
7839
|
-
var MasterSecret = (0,
|
7899
|
+
var MasterSecret = (0, import_utils33.toUtf8Bytes)("Bitcoin seed");
|
7840
7900
|
var MainnetPRV = "0x0488ade4";
|
7841
7901
|
var TestnetPRV = "0x04358394";
|
7842
7902
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
@@ -7900,7 +7960,7 @@ var Mnemonic = class {
|
|
7900
7960
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7901
7961
|
const words = getWords(phrase);
|
7902
7962
|
assertMnemonic(words);
|
7903
|
-
return (0,
|
7963
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7904
7964
|
}
|
7905
7965
|
/**
|
7906
7966
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7908,7 +7968,7 @@ var Mnemonic = class {
|
|
7908
7968
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7909
7969
|
*/
|
7910
7970
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7911
|
-
const entropyBytes = (0,
|
7971
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7912
7972
|
assertWordList(wordlist);
|
7913
7973
|
assertEntropy(entropyBytes);
|
7914
7974
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7920,8 +7980,8 @@ var Mnemonic = class {
|
|
7920
7980
|
*/
|
7921
7981
|
static mnemonicToSeed(phrase, passphrase = "") {
|
7922
7982
|
assertMnemonic(getWords(phrase));
|
7923
|
-
const phraseBytes = (0,
|
7924
|
-
const salt = (0,
|
7983
|
+
const phraseBytes = (0, import_utils33.toUtf8Bytes)(getPhrase(phrase));
|
7984
|
+
const salt = (0, import_utils33.toUtf8Bytes)(`mnemonic${passphrase}`);
|
7925
7985
|
return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7926
7986
|
}
|
7927
7987
|
/**
|
@@ -7977,14 +8037,14 @@ var Mnemonic = class {
|
|
7977
8037
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7978
8038
|
*/
|
7979
8039
|
static masterKeysFromSeed(seed) {
|
7980
|
-
const seedArray = (0,
|
8040
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7981
8041
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7982
8042
|
throw new import_errors19.FuelError(
|
7983
8043
|
import_errors19.ErrorCode.INVALID_SEED,
|
7984
8044
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7985
8045
|
);
|
7986
8046
|
}
|
7987
|
-
return (0,
|
8047
|
+
return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
|
7988
8048
|
}
|
7989
8049
|
/**
|
7990
8050
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7995,22 +8055,22 @@ var Mnemonic = class {
|
|
7995
8055
|
*/
|
7996
8056
|
static seedToExtendedKey(seed, testnet = false) {
|
7997
8057
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7998
|
-
const prefix = (0,
|
8058
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7999
8059
|
const depth = "0x00";
|
8000
8060
|
const fingerprint = "0x00000000";
|
8001
8061
|
const index = "0x00000000";
|
8002
8062
|
const chainCode = masterKey.slice(32);
|
8003
8063
|
const privateKey = masterKey.slice(0, 32);
|
8004
|
-
const extendedKey = (0,
|
8064
|
+
const extendedKey = (0, import_utils33.concat)([
|
8005
8065
|
prefix,
|
8006
8066
|
depth,
|
8007
8067
|
fingerprint,
|
8008
8068
|
index,
|
8009
8069
|
chainCode,
|
8010
|
-
(0,
|
8070
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8011
8071
|
]);
|
8012
|
-
const checksum = (0,
|
8013
|
-
return (0,
|
8072
|
+
const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8073
|
+
return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8014
8074
|
}
|
8015
8075
|
/**
|
8016
8076
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8025,7 +8085,7 @@ var Mnemonic = class {
|
|
8025
8085
|
* @returns A randomly generated mnemonic
|
8026
8086
|
*/
|
8027
8087
|
static generate(size = 32, extraEntropy = "") {
|
8028
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8088
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8029
8089
|
return Mnemonic.entropyToMnemonic(entropy);
|
8030
8090
|
}
|
8031
8091
|
};
|
@@ -8033,12 +8093,12 @@ var mnemonic_default = Mnemonic;
|
|
8033
8093
|
|
8034
8094
|
// src/hdwallet/hdwallet.ts
|
8035
8095
|
var HARDENED_INDEX = 2147483648;
|
8036
|
-
var MainnetPRV2 = (0,
|
8037
|
-
var MainnetPUB = (0,
|
8038
|
-
var TestnetPRV2 = (0,
|
8039
|
-
var TestnetPUB = (0,
|
8096
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8097
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8098
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8099
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8040
8100
|
function base58check(data) {
|
8041
|
-
return (0,
|
8101
|
+
return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([data, (0, import_utils35.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8042
8102
|
}
|
8043
8103
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8044
8104
|
if (isPublic) {
|
@@ -8047,11 +8107,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8047
8107
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8048
8108
|
}
|
8049
8109
|
function isPublicExtendedKey(extendedKey) {
|
8050
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8110
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8051
8111
|
}
|
8052
8112
|
function isValidExtendedKey(extendedKey) {
|
8053
8113
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8054
|
-
(0,
|
8114
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8055
8115
|
);
|
8056
8116
|
}
|
8057
8117
|
function parsePath(path2, depth = 0) {
|
@@ -8069,8 +8129,8 @@ function parsePath(path2, depth = 0) {
|
|
8069
8129
|
var HDWallet = class {
|
8070
8130
|
depth = 0;
|
8071
8131
|
index = 0;
|
8072
|
-
fingerprint = (0,
|
8073
|
-
parentFingerprint = (0,
|
8132
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8133
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8074
8134
|
privateKey;
|
8075
8135
|
publicKey;
|
8076
8136
|
chainCode;
|
@@ -8082,8 +8142,8 @@ var HDWallet = class {
|
|
8082
8142
|
constructor(config) {
|
8083
8143
|
if (config.privateKey) {
|
8084
8144
|
const signer = new Signer(config.privateKey);
|
8085
|
-
this.publicKey = (0,
|
8086
|
-
this.privateKey = (0,
|
8145
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8146
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8087
8147
|
} else {
|
8088
8148
|
if (!config.publicKey) {
|
8089
8149
|
throw new import_errors20.FuelError(
|
@@ -8091,10 +8151,10 @@ var HDWallet = class {
|
|
8091
8151
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8092
8152
|
);
|
8093
8153
|
}
|
8094
|
-
this.publicKey = (0,
|
8154
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8095
8155
|
}
|
8096
8156
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8097
|
-
this.fingerprint = (0,
|
8157
|
+
this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8098
8158
|
this.depth = config.depth || this.depth;
|
8099
8159
|
this.index = config.index || this.index;
|
8100
8160
|
this.chainCode = config.chainCode;
|
@@ -8110,9 +8170,9 @@ var HDWallet = class {
|
|
8110
8170
|
* @returns A new instance of HDWallet on the derived index
|
8111
8171
|
*/
|
8112
8172
|
deriveIndex(index) {
|
8113
|
-
const privateKey = this.privateKey && (0,
|
8114
|
-
const publicKey = (0,
|
8115
|
-
const chainCode = (0,
|
8173
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8174
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8175
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8116
8176
|
const data = new Uint8Array(37);
|
8117
8177
|
if (index & HARDENED_INDEX) {
|
8118
8178
|
if (!privateKey) {
|
@@ -8123,10 +8183,10 @@ var HDWallet = class {
|
|
8123
8183
|
}
|
8124
8184
|
data.set(privateKey, 1);
|
8125
8185
|
} else {
|
8126
|
-
data.set((0,
|
8186
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8127
8187
|
}
|
8128
8188
|
data.set((0, import_math22.toBytes)(index, 4), 33);
|
8129
|
-
const bytes = (0,
|
8189
|
+
const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
|
8130
8190
|
const IL = bytes.slice(0, 32);
|
8131
8191
|
const IR = bytes.slice(32);
|
8132
8192
|
if (privateKey) {
|
@@ -8140,7 +8200,7 @@ var HDWallet = class {
|
|
8140
8200
|
parentFingerprint: this.fingerprint
|
8141
8201
|
});
|
8142
8202
|
}
|
8143
|
-
const signer = new Signer((0,
|
8203
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8144
8204
|
const Ki = signer.addPoint(publicKey);
|
8145
8205
|
return new HDWallet({
|
8146
8206
|
publicKey: Ki,
|
@@ -8175,12 +8235,12 @@ var HDWallet = class {
|
|
8175
8235
|
);
|
8176
8236
|
}
|
8177
8237
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8178
|
-
const depth = (0,
|
8238
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8179
8239
|
const parentFingerprint = this.parentFingerprint;
|
8180
8240
|
const index = (0, import_math22.toHex)(this.index, 4);
|
8181
8241
|
const chainCode = this.chainCode;
|
8182
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8183
|
-
const extendedKey = (0,
|
8242
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8243
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8184
8244
|
return base58check(extendedKey);
|
8185
8245
|
}
|
8186
8246
|
/**
|
@@ -8192,13 +8252,13 @@ var HDWallet = class {
|
|
8192
8252
|
static fromSeed(seed) {
|
8193
8253
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8194
8254
|
return new HDWallet({
|
8195
|
-
chainCode: (0,
|
8196
|
-
privateKey: (0,
|
8255
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8256
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8197
8257
|
});
|
8198
8258
|
}
|
8199
8259
|
static fromExtendedKey(extendedKey) {
|
8200
|
-
const decoded = (0,
|
8201
|
-
const bytes = (0,
|
8260
|
+
const decoded = (0, import_utils35.hexlify)((0, import_math22.toBytes)((0, import_utils35.decodeBase58)(extendedKey)));
|
8261
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8202
8262
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8203
8263
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8204
8264
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8207,9 +8267,9 @@ var HDWallet = class {
|
|
8207
8267
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8208
8268
|
}
|
8209
8269
|
const depth = bytes[4];
|
8210
|
-
const parentFingerprint = (0,
|
8211
|
-
const index = parseInt((0,
|
8212
|
-
const chainCode = (0,
|
8270
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8271
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8272
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8213
8273
|
const key = bytes.slice(45, 78);
|
8214
8274
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8215
8275
|
throw new import_errors20.FuelError(
|
@@ -8428,7 +8488,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8428
8488
|
// src/test-utils/launchNode.ts
|
8429
8489
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8430
8490
|
var import_crypto7 = require("@fuel-ts/crypto");
|
8431
|
-
var
|
8491
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8432
8492
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8433
8493
|
var import_child_process = require("child_process");
|
8434
8494
|
var import_crypto8 = require("crypto");
|
@@ -8468,40 +8528,6 @@ var killNode = (params) => {
|
|
8468
8528
|
}
|
8469
8529
|
}
|
8470
8530
|
};
|
8471
|
-
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8472
|
-
const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8473
|
-
...coin,
|
8474
|
-
amount: "18446744073709551615"
|
8475
|
-
}));
|
8476
|
-
const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8477
|
-
...message,
|
8478
|
-
amount: "18446744073709551615"
|
8479
|
-
}));
|
8480
|
-
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);
|
8481
|
-
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);
|
8482
|
-
if (!process.env.GENESIS_SECRET) {
|
8483
|
-
const pk = Signer.generatePrivateKey();
|
8484
|
-
const signer = new Signer(pk);
|
8485
|
-
process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
|
8486
|
-
coins.push({
|
8487
|
-
tx_id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8488
|
-
owner: signer.address.toHexString(),
|
8489
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8490
|
-
amount: "18446744073709551615",
|
8491
|
-
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8492
|
-
output_index: 0,
|
8493
|
-
tx_pointer_block_height: 0,
|
8494
|
-
tx_pointer_tx_idx: 0
|
8495
|
-
});
|
8496
|
-
}
|
8497
|
-
const json = JSON.stringify({
|
8498
|
-
...stateConfig,
|
8499
|
-
coins,
|
8500
|
-
messages
|
8501
|
-
});
|
8502
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8503
|
-
return json.replace(regexMakeNumber, "$1$2");
|
8504
|
-
}
|
8505
8531
|
var launchNode = async ({
|
8506
8532
|
ip,
|
8507
8533
|
port,
|
@@ -8509,8 +8535,7 @@ var launchNode = async ({
|
|
8509
8535
|
useSystemFuelCore = false,
|
8510
8536
|
loggingEnabled = true,
|
8511
8537
|
debugEnabled = false,
|
8512
|
-
basePath
|
8513
|
-
snapshotConfig = import_utils37.defaultSnapshotConfigs
|
8538
|
+
basePath
|
8514
8539
|
}) => (
|
8515
8540
|
// eslint-disable-next-line no-async-promise-executor
|
8516
8541
|
new Promise(async (resolve, reject) => {
|
@@ -8521,7 +8546,7 @@ var launchNode = async ({
|
|
8521
8546
|
"--poa-instant"
|
8522
8547
|
]);
|
8523
8548
|
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8524
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8549
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8525
8550
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8526
8551
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8527
8552
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8539,23 +8564,56 @@ var launchNode = async ({
|
|
8539
8564
|
let snapshotDirToUse;
|
8540
8565
|
const prefix = basePath || import_os.default.tmpdir();
|
8541
8566
|
const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
|
8542
|
-
const
|
8567
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
8543
8568
|
if (snapshotDir) {
|
8544
8569
|
snapshotDirToUse = snapshotDir;
|
8545
8570
|
} else {
|
8546
|
-
if (!(0, import_fs.existsSync)(
|
8547
|
-
(0, import_fs.mkdirSync)(
|
8571
|
+
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8572
|
+
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8548
8573
|
}
|
8549
|
-
|
8550
|
-
const
|
8551
|
-
|
8552
|
-
|
8553
|
-
|
8554
|
-
|
8555
|
-
|
8556
|
-
|
8557
|
-
|
8558
|
-
|
8574
|
+
let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
|
8575
|
+
const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
|
8576
|
+
stateConfigJson = {
|
8577
|
+
...stateConfigJson,
|
8578
|
+
coins: [
|
8579
|
+
...stateConfigJson.coins.map((coin) => ({
|
8580
|
+
...coin,
|
8581
|
+
amount: "18446744073709551615"
|
8582
|
+
}))
|
8583
|
+
],
|
8584
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8585
|
+
...message,
|
8586
|
+
amount: "18446744073709551615"
|
8587
|
+
}))
|
8588
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8589
|
+
};
|
8590
|
+
if (!process.env.GENESIS_SECRET) {
|
8591
|
+
const pk = Signer.generatePrivateKey();
|
8592
|
+
const signer = new Signer(pk);
|
8593
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8594
|
+
stateConfigJson.coins.push({
|
8595
|
+
tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8596
|
+
owner: signer.address.toHexString(),
|
8597
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8598
|
+
amount: "18446744073709551615",
|
8599
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8600
|
+
output_index: 0,
|
8601
|
+
tx_pointer_block_height: 0,
|
8602
|
+
tx_pointer_tx_idx: 0
|
8603
|
+
});
|
8604
|
+
}
|
8605
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8606
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8607
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8608
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8609
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8610
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8611
|
+
const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
|
8612
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8613
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8614
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8615
|
+
(0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
|
8616
|
+
snapshotDirToUse = tempDirPath;
|
8559
8617
|
}
|
8560
8618
|
const child = (0, import_child_process.spawn)(
|
8561
8619
|
command,
|
@@ -8563,7 +8621,7 @@ var launchNode = async ({
|
|
8563
8621
|
"run",
|
8564
8622
|
["--ip", ipToUse],
|
8565
8623
|
["--port", portToUse],
|
8566
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8624
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8567
8625
|
["--min-gas-price", "1"],
|
8568
8626
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8569
8627
|
["--consensus-key", consensusKey],
|
@@ -8585,28 +8643,23 @@ var launchNode = async ({
|
|
8585
8643
|
}
|
8586
8644
|
const cleanupConfig = {
|
8587
8645
|
child,
|
8588
|
-
configPath:
|
8646
|
+
configPath: tempDirPath,
|
8589
8647
|
killFn: import_tree_kill.default,
|
8590
8648
|
state: {
|
8591
8649
|
isDead: false
|
8592
8650
|
}
|
8593
8651
|
};
|
8594
8652
|
child.stderr.on("data", (chunk) => {
|
8595
|
-
|
8596
|
-
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8597
|
-
const rows = text.split("\n");
|
8598
|
-
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8599
|
-
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8653
|
+
if (chunk.indexOf(graphQLStartSubstring) !== -1) {
|
8600
8654
|
resolve({
|
8601
8655
|
cleanup: () => killNode(cleanupConfig),
|
8602
|
-
ip:
|
8603
|
-
port:
|
8604
|
-
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8656
|
+
ip: ipToUse,
|
8657
|
+
port: portToUse,
|
8605
8658
|
snapshotDir: snapshotDirToUse
|
8606
8659
|
});
|
8607
8660
|
}
|
8608
|
-
if (/error/i.test(
|
8609
|
-
reject(
|
8661
|
+
if (/error/i.test(chunk)) {
|
8662
|
+
reject(chunk.toString());
|
8610
8663
|
}
|
8611
8664
|
});
|
8612
8665
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8639,245 +8692,12 @@ var launchNodeAndGetWallets = async ({
|
|
8639
8692
|
};
|
8640
8693
|
return { wallets, stop: cleanup, provider };
|
8641
8694
|
};
|
8642
|
-
|
8643
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8644
|
-
var import_utils40 = require("@fuel-ts/utils");
|
8645
|
-
var import_ramda5 = require("ramda");
|
8646
|
-
|
8647
|
-
// src/test-utils/asset-id.ts
|
8648
|
-
var import_crypto9 = require("@fuel-ts/crypto");
|
8649
|
-
var import_utils38 = require("@fuel-ts/utils");
|
8650
|
-
var _AssetId = class {
|
8651
|
-
constructor(value) {
|
8652
|
-
this.value = value;
|
8653
|
-
}
|
8654
|
-
static random(count = 1) {
|
8655
|
-
const assetIds = [];
|
8656
|
-
for (let i = 0; i < count; i++) {
|
8657
|
-
assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto9.randomBytes)(32))));
|
8658
|
-
}
|
8659
|
-
return assetIds;
|
8660
|
-
}
|
8661
|
-
};
|
8662
|
-
var AssetId = _AssetId;
|
8663
|
-
__publicField(AssetId, "A", new _AssetId(
|
8664
|
-
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8665
|
-
));
|
8666
|
-
__publicField(AssetId, "B", new _AssetId(
|
8667
|
-
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8668
|
-
));
|
8669
|
-
|
8670
|
-
// src/test-utils/wallet-config.ts
|
8671
|
-
var import_crypto10 = require("@fuel-ts/crypto");
|
8672
|
-
var import_errors21 = require("@fuel-ts/errors");
|
8673
|
-
var import_utils39 = require("@fuel-ts/utils");
|
8674
|
-
var WalletConfig = class {
|
8675
|
-
initialState;
|
8676
|
-
options;
|
8677
|
-
wallets;
|
8678
|
-
generateWallets = () => {
|
8679
|
-
const generatedWallets = [];
|
8680
|
-
for (let index = 1; index <= this.options.count; index++) {
|
8681
|
-
generatedWallets.push(new WalletUnlocked((0, import_crypto10.randomBytes)(32)));
|
8682
|
-
}
|
8683
|
-
return generatedWallets;
|
8684
|
-
};
|
8685
|
-
constructor(baseAssetId, config) {
|
8686
|
-
WalletConfig.validate(config);
|
8687
|
-
this.options = config;
|
8688
|
-
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8689
|
-
this.wallets = this.generateWallets();
|
8690
|
-
this.initialState = {
|
8691
|
-
messages: WalletConfig.createMessages(this.wallets, messages),
|
8692
|
-
coins: WalletConfig.createCoins(
|
8693
|
-
this.wallets,
|
8694
|
-
baseAssetId,
|
8695
|
-
assets2,
|
8696
|
-
coinsPerAsset,
|
8697
|
-
amountPerCoin
|
8698
|
-
)
|
8699
|
-
};
|
8700
|
-
}
|
8701
|
-
apply(snapshotConfig) {
|
8702
|
-
return {
|
8703
|
-
...snapshotConfig,
|
8704
|
-
stateConfig: {
|
8705
|
-
...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
|
8706
|
-
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8707
|
-
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8708
|
-
}
|
8709
|
-
};
|
8710
|
-
}
|
8711
|
-
/**
|
8712
|
-
* Create messages for the wallets in the format that the chain expects.
|
8713
|
-
*/
|
8714
|
-
static createMessages(wallets, messages) {
|
8715
|
-
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8716
|
-
}
|
8717
|
-
/**
|
8718
|
-
* Create coins for the wallets in the format that the chain expects.
|
8719
|
-
*/
|
8720
|
-
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8721
|
-
const coins = [];
|
8722
|
-
let assetIds = [baseAssetId];
|
8723
|
-
if (Array.isArray(assets2)) {
|
8724
|
-
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8725
|
-
} else {
|
8726
|
-
assetIds.concat(AssetId.random(assets2).map((a) => a.value));
|
8727
|
-
}
|
8728
|
-
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8729
|
-
assetIds.forEach((assetId) => {
|
8730
|
-
for (let index = 0; index < coinsPerAsset; index++) {
|
8731
|
-
coins.push({
|
8732
|
-
amount: amountPerCoin,
|
8733
|
-
asset_id: assetId,
|
8734
|
-
owner: walletAddress,
|
8735
|
-
tx_pointer_block_height: 0,
|
8736
|
-
tx_pointer_tx_idx: 0,
|
8737
|
-
output_index: 0,
|
8738
|
-
tx_id: (0, import_utils39.hexlify)((0, import_crypto10.randomBytes)(32))
|
8739
|
-
});
|
8740
|
-
}
|
8741
|
-
});
|
8742
|
-
});
|
8743
|
-
return coins;
|
8744
|
-
}
|
8745
|
-
static validate({
|
8746
|
-
count: wallets,
|
8747
|
-
assets: assets2,
|
8748
|
-
coinsPerAsset,
|
8749
|
-
amountPerCoin
|
8750
|
-
}) {
|
8751
|
-
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8752
|
-
throw new import_errors21.FuelError(
|
8753
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8754
|
-
"Number of wallets must be greater than zero."
|
8755
|
-
);
|
8756
|
-
}
|
8757
|
-
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8758
|
-
throw new import_errors21.FuelError(
|
8759
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8760
|
-
"Number of assets per wallet must be greater than zero."
|
8761
|
-
);
|
8762
|
-
}
|
8763
|
-
if (coinsPerAsset <= 0) {
|
8764
|
-
throw new import_errors21.FuelError(
|
8765
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8766
|
-
"Number of coins per asset must be greater than zero."
|
8767
|
-
);
|
8768
|
-
}
|
8769
|
-
if (amountPerCoin <= 0) {
|
8770
|
-
throw new import_errors21.FuelError(
|
8771
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8772
|
-
"Amount per coin must be greater than zero."
|
8773
|
-
);
|
8774
|
-
}
|
8775
|
-
}
|
8776
|
-
};
|
8777
|
-
|
8778
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8779
|
-
var defaultWalletConfigOptions = {
|
8780
|
-
count: 2,
|
8781
|
-
assets: [AssetId.A, AssetId.B],
|
8782
|
-
coinsPerAsset: 1,
|
8783
|
-
amountPerCoin: 1e10,
|
8784
|
-
messages: []
|
8785
|
-
};
|
8786
|
-
async function setupTestProviderAndWallets({
|
8787
|
-
walletConfig: walletConfigOptions = {},
|
8788
|
-
providerOptions,
|
8789
|
-
nodeOptions = {}
|
8790
|
-
} = {}) {
|
8791
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8792
|
-
const walletConfig = new WalletConfig(
|
8793
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
|
8794
|
-
{
|
8795
|
-
...defaultWalletConfigOptions,
|
8796
|
-
...walletConfigOptions
|
8797
|
-
}
|
8798
|
-
);
|
8799
|
-
const { cleanup, url } = await launchNode({
|
8800
|
-
loggingEnabled: false,
|
8801
|
-
...nodeOptions,
|
8802
|
-
snapshotConfig: (0, import_ramda5.mergeDeepRight)(
|
8803
|
-
import_utils40.defaultSnapshotConfigs,
|
8804
|
-
walletConfig.apply(nodeOptions?.snapshotConfig)
|
8805
|
-
),
|
8806
|
-
port: "0"
|
8807
|
-
});
|
8808
|
-
let provider;
|
8809
|
-
try {
|
8810
|
-
provider = await Provider.create(url, providerOptions);
|
8811
|
-
} catch (err) {
|
8812
|
-
cleanup();
|
8813
|
-
throw err;
|
8814
|
-
}
|
8815
|
-
const wallets = walletConfig.wallets;
|
8816
|
-
wallets.forEach((wallet) => {
|
8817
|
-
wallet.connect(provider);
|
8818
|
-
});
|
8819
|
-
return {
|
8820
|
-
provider,
|
8821
|
-
wallets,
|
8822
|
-
cleanup,
|
8823
|
-
[Symbol.dispose]: cleanup
|
8824
|
-
};
|
8825
|
-
}
|
8826
|
-
|
8827
|
-
// src/test-utils/test-message.ts
|
8828
|
-
var import_address7 = require("@fuel-ts/address");
|
8829
|
-
var import_crypto11 = require("@fuel-ts/crypto");
|
8830
|
-
var import_math23 = require("@fuel-ts/math");
|
8831
|
-
var import_utils41 = require("@fuel-ts/utils");
|
8832
|
-
var TestMessage = class {
|
8833
|
-
sender;
|
8834
|
-
recipient;
|
8835
|
-
nonce;
|
8836
|
-
amount;
|
8837
|
-
data;
|
8838
|
-
da_height;
|
8839
|
-
/**
|
8840
|
-
* A helper class to create messages for testing purposes.
|
8841
|
-
*
|
8842
|
-
* Used in tandem with `WalletConfig`.
|
8843
|
-
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8844
|
-
*/
|
8845
|
-
constructor({
|
8846
|
-
sender = import_address7.Address.fromRandom(),
|
8847
|
-
recipient = import_address7.Address.fromRandom(),
|
8848
|
-
nonce = (0, import_utils41.hexlify)((0, import_crypto11.randomBytes)(32)),
|
8849
|
-
amount = 1e6,
|
8850
|
-
data = "02",
|
8851
|
-
da_height = 0
|
8852
|
-
} = {}) {
|
8853
|
-
this.sender = sender;
|
8854
|
-
this.recipient = recipient;
|
8855
|
-
this.nonce = nonce;
|
8856
|
-
this.amount = amount;
|
8857
|
-
this.data = data;
|
8858
|
-
this.da_height = da_height;
|
8859
|
-
}
|
8860
|
-
toChainMessage(recipient) {
|
8861
|
-
return {
|
8862
|
-
sender: this.sender.toB256(),
|
8863
|
-
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8864
|
-
nonce: this.nonce,
|
8865
|
-
amount: (0, import_math23.bn)(this.amount).toNumber(),
|
8866
|
-
data: this.data,
|
8867
|
-
da_height: this.da_height
|
8868
|
-
};
|
8869
|
-
}
|
8870
|
-
};
|
8871
8695
|
// Annotate the CommonJS export names for ESM import in node:
|
8872
8696
|
0 && (module.exports = {
|
8873
|
-
AssetId,
|
8874
|
-
TestMessage,
|
8875
|
-
WalletConfig,
|
8876
8697
|
generateTestWallet,
|
8877
8698
|
killNode,
|
8878
8699
|
launchNode,
|
8879
8700
|
launchNodeAndGetWallets,
|
8880
|
-
seedTestWallet
|
8881
|
-
setupTestProviderAndWallets
|
8701
|
+
seedTestWallet
|
8882
8702
|
});
|
8883
8703
|
//# sourceMappingURL=test-utils.js.map
|