@fuel-ts/account 0.0.0-rc-2037-20240510180649 → 0.0.0-rc-1356-20240513141855

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.

@@ -48,24 +48,28 @@ 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,
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 import_utils31 = require("@fuel-ts/utils");
65
+ var import_utils32 = require("@fuel-ts/utils");
62
66
 
63
67
  // src/account.ts
64
68
  var import_address4 = require("@fuel-ts/address");
65
69
  var import_errors16 = require("@fuel-ts/errors");
66
70
  var import_interfaces = require("@fuel-ts/interfaces");
67
71
  var import_math21 = require("@fuel-ts/math");
68
- var import_utils28 = require("@fuel-ts/utils");
72
+ var import_utils29 = require("@fuel-ts/utils");
69
73
  var import_ramda4 = require("ramda");
70
74
 
71
75
  // src/providers/coin-quantity.ts
@@ -108,9 +112,9 @@ var import_address3 = require("@fuel-ts/address");
108
112
  var import_errors14 = require("@fuel-ts/errors");
109
113
  var import_math18 = require("@fuel-ts/math");
110
114
  var import_transactions20 = require("@fuel-ts/transactions");
111
- var import_utils22 = require("@fuel-ts/utils");
115
+ var import_utils23 = require("@fuel-ts/utils");
112
116
  var import_versions = require("@fuel-ts/versions");
113
- var import_utils23 = require("@noble/curves/abstract/utils");
117
+ var import_utils24 = require("@noble/curves/abstract/utils");
114
118
  var import_graphql_request = require("graphql-request");
115
119
  var import_ramda3 = require("ramda");
116
120
 
@@ -1667,15 +1671,6 @@ function normalizeJSON(root) {
1667
1671
  return normalize((0, import_ramda.clone)(root));
1668
1672
  }
1669
1673
 
1670
- // src/providers/utils/sleep.ts
1671
- function sleep(time) {
1672
- return new Promise((resolve) => {
1673
- setTimeout(() => {
1674
- resolve(true);
1675
- }, time);
1676
- });
1677
- }
1678
-
1679
1674
  // src/providers/utils/extract-tx-error.ts
1680
1675
  var import_errors7 = require("@fuel-ts/errors");
1681
1676
  var import_math6 = require("@fuel-ts/math");
@@ -3639,6 +3634,7 @@ var TransactionResponse = class {
3639
3634
  };
3640
3635
 
3641
3636
  // src/providers/utils/auto-retry-fetch.ts
3637
+ var import_utils22 = require("@fuel-ts/utils");
3642
3638
  function getWaitDelay(options, retryAttemptNum) {
3643
3639
  const duration = options.baseDelay ?? 150;
3644
3640
  switch (options.backoff) {
@@ -3668,7 +3664,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3668
3664
  throw error;
3669
3665
  }
3670
3666
  const delay = getWaitDelay(options, retryNum);
3671
- await sleep(delay);
3667
+ await (0, import_utils22.sleep)(delay);
3672
3668
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3673
3669
  }
3674
3670
  };
@@ -4008,7 +4004,7 @@ Supported fuel-core version: ${supportedVersion}.`
4008
4004
  if (estimateTxDependencies) {
4009
4005
  await this.estimateTxDependencies(transactionRequest);
4010
4006
  }
4011
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4007
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4012
4008
  let abis;
4013
4009
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4014
4010
  abis = transactionRequest.abis;
@@ -4051,7 +4047,7 @@ Supported fuel-core version: ${supportedVersion}.`
4051
4047
  if (estimateTxDependencies) {
4052
4048
  return this.estimateTxDependencies(transactionRequest);
4053
4049
  }
4054
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4050
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4055
4051
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4056
4052
  encodedTransactions: encodedTransaction,
4057
4053
  utxoValidation: utxoValidation || false
@@ -4069,13 +4065,13 @@ Supported fuel-core version: ${supportedVersion}.`
4069
4065
  async estimatePredicates(transactionRequest) {
4070
4066
  const shouldEstimatePredicates = Boolean(
4071
4067
  transactionRequest.inputs.find(
4072
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math18.BN(input.predicateGasUsed).isZero()
4068
+ (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math18.BN(input.predicateGasUsed).isZero()
4073
4069
  )
4074
4070
  );
4075
4071
  if (!shouldEstimatePredicates) {
4076
4072
  return transactionRequest;
4077
4073
  }
4078
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4074
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4079
4075
  const response = await this.operations.estimatePredicates({
4080
4076
  encodedTransaction
4081
4077
  });
@@ -4117,7 +4113,7 @@ Supported fuel-core version: ${supportedVersion}.`
4117
4113
  const {
4118
4114
  dryRun: [{ receipts: rawReceipts, status }]
4119
4115
  } = await this.operations.dryRun({
4120
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4116
+ encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4121
4117
  utxoValidation: false
4122
4118
  });
4123
4119
  receipts = rawReceipts.map(processGqlReceipt);
@@ -4167,7 +4163,7 @@ Supported fuel-core version: ${supportedVersion}.`
4167
4163
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4168
4164
  allRequests.forEach((req, index) => {
4169
4165
  if (req.type === import_transactions20.TransactionType.Script) {
4170
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4166
+ serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4171
4167
  }
4172
4168
  });
4173
4169
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4203,7 +4199,7 @@ Supported fuel-core version: ${supportedVersion}.`
4203
4199
  transactionRequest: request
4204
4200
  });
4205
4201
  request.maxFee = maxFee;
4206
- serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4202
+ serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4207
4203
  nextRoundTransactions.push(requestIdx);
4208
4204
  }
4209
4205
  }
@@ -4216,7 +4212,7 @@ Supported fuel-core version: ${supportedVersion}.`
4216
4212
  if (estimateTxDependencies) {
4217
4213
  return this.estimateMultipleTxDependencies(transactionRequests);
4218
4214
  }
4219
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4215
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4220
4216
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4221
4217
  encodedTransactions,
4222
4218
  utxoValidation: utxoValidation || false
@@ -4289,7 +4285,7 @@ Supported fuel-core version: ${supportedVersion}.`
4289
4285
  if (estimateTxDependencies) {
4290
4286
  return this.estimateTxDependencies(transactionRequest);
4291
4287
  }
4292
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4288
+ const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4293
4289
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4294
4290
  encodedTransactions,
4295
4291
  utxoValidation: true
@@ -4405,7 +4401,7 @@ Supported fuel-core version: ${supportedVersion}.`
4405
4401
  const result = await this.operations.getCoins({
4406
4402
  first: 10,
4407
4403
  ...paginationArgs,
4408
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4404
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4409
4405
  });
4410
4406
  const coins = result.coins.edges.map((edge) => edge.node);
4411
4407
  return coins.map((coin) => ({
@@ -4428,19 +4424,19 @@ Supported fuel-core version: ${supportedVersion}.`
4428
4424
  async getResourcesToSpend(owner, quantities, excludedIds) {
4429
4425
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4430
4426
  const excludeInput = {
4431
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4432
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4427
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4428
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4433
4429
  };
4434
4430
  if (this.cache) {
4435
4431
  const uniqueUtxos = new Set(
4436
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4432
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4437
4433
  );
4438
4434
  excludeInput.utxos = Array.from(uniqueUtxos);
4439
4435
  }
4440
4436
  const coinsQuery = {
4441
4437
  owner: ownerAddress.toB256(),
4442
4438
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4443
- assetId: (0, import_utils22.hexlify)(assetId),
4439
+ assetId: (0, import_utils23.hexlify)(assetId),
4444
4440
  amount: amount.toString(10),
4445
4441
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4446
4442
  })),
@@ -4542,7 +4538,7 @@ Supported fuel-core version: ${supportedVersion}.`
4542
4538
  time: block.header.time,
4543
4539
  transactionIds: block.transactions.map((tx) => tx.id),
4544
4540
  transactions: block.transactions.map(
4545
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4541
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4546
4542
  )
4547
4543
  };
4548
4544
  }
@@ -4558,7 +4554,7 @@ Supported fuel-core version: ${supportedVersion}.`
4558
4554
  return null;
4559
4555
  }
4560
4556
  return new import_transactions20.TransactionCoder().decode(
4561
- (0, import_utils22.arrayify)(transaction.rawPayload),
4557
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4562
4558
  0
4563
4559
  )?.[0];
4564
4560
  }
@@ -4585,7 +4581,7 @@ Supported fuel-core version: ${supportedVersion}.`
4585
4581
  async getContractBalance(contractId, assetId) {
4586
4582
  const { contractBalance } = await this.operations.getContractBalance({
4587
4583
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4588
- asset: (0, import_utils22.hexlify)(assetId)
4584
+ asset: (0, import_utils23.hexlify)(assetId)
4589
4585
  });
4590
4586
  return (0, import_math18.bn)(contractBalance.amount, 10);
4591
4587
  }
@@ -4599,7 +4595,7 @@ Supported fuel-core version: ${supportedVersion}.`
4599
4595
  async getBalance(owner, assetId) {
4600
4596
  const { balance } = await this.operations.getBalance({
4601
4597
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4602
- assetId: (0, import_utils22.hexlify)(assetId)
4598
+ assetId: (0, import_utils23.hexlify)(assetId)
4603
4599
  });
4604
4600
  return (0, import_math18.bn)(balance.amount, 10);
4605
4601
  }
@@ -4776,7 +4772,7 @@ Supported fuel-core version: ${supportedVersion}.`
4776
4772
  async produceBlocks(amount, startTime) {
4777
4773
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4778
4774
  blocksToProduce: (0, import_math18.bn)(amount).toString(10),
4779
- startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4775
+ startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4780
4776
  });
4781
4777
  return (0, import_math18.bn)(latestBlockHeight);
4782
4778
  }
@@ -4826,7 +4822,7 @@ __publicField(Provider, "nodeInfoCache", {});
4826
4822
  var import_errors15 = require("@fuel-ts/errors");
4827
4823
  var import_math19 = require("@fuel-ts/math");
4828
4824
  var import_transactions21 = require("@fuel-ts/transactions");
4829
- var import_utils25 = require("@fuel-ts/utils");
4825
+ var import_utils26 = require("@fuel-ts/utils");
4830
4826
 
4831
4827
  // src/providers/chains.ts
4832
4828
  var CHAIN_IDS = {
@@ -4902,16 +4898,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
4902
4898
  // src/utils/formatTransferToContractScriptData.ts
4903
4899
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4904
4900
  var import_math20 = require("@fuel-ts/math");
4905
- var import_utils27 = require("@fuel-ts/utils");
4901
+ var import_utils28 = require("@fuel-ts/utils");
4906
4902
  var asm = __toESM(require("@fuels/vm-asm"));
4907
4903
  var formatTransferToContractScriptData = (params) => {
4908
4904
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4909
4905
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4910
4906
  const encoded = numberCoder.encode(new import_math20.BN(amountToTransfer).toNumber());
4911
4907
  const scriptData = Uint8Array.from([
4912
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4908
+ ...(0, import_utils28.arrayify)(hexlifiedContractId),
4913
4909
  ...encoded,
4914
- ...(0, import_utils27.arrayify)(assetId)
4910
+ ...(0, import_utils28.arrayify)(assetId)
4915
4911
  ]);
4916
4912
  return scriptData;
4917
4913
  };
@@ -5284,14 +5280,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5284
5280
  */
5285
5281
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5286
5282
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5287
- const recipientDataArray = (0, import_utils28.arrayify)(
5283
+ const recipientDataArray = (0, import_utils29.arrayify)(
5288
5284
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5289
5285
  );
5290
- const amountDataArray = (0, import_utils28.arrayify)(
5286
+ const amountDataArray = (0, import_utils29.arrayify)(
5291
5287
  "0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
5292
5288
  );
5293
5289
  const script = new Uint8Array([
5294
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5290
+ ...(0, import_utils29.arrayify)(withdrawScript.bytes),
5295
5291
  ...recipientDataArray,
5296
5292
  ...amountDataArray
5297
5293
  ]);
@@ -5371,7 +5367,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5371
5367
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5372
5368
  }) {
5373
5369
  const request = transactionRequestify(transactionRequest);
5374
- if (!(0, import_utils28.isDefined)(setGasLimit)) {
5370
+ if (!(0, import_utils29.isDefined)(setGasLimit)) {
5375
5371
  request.gasLimit = gasUsed;
5376
5372
  } else if (gasUsed.gt(setGasLimit)) {
5377
5373
  throw new import_errors16.FuelError(
@@ -5379,7 +5375,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5379
5375
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5380
5376
  );
5381
5377
  }
5382
- if (!(0, import_utils28.isDefined)(setMaxFee)) {
5378
+ if (!(0, import_utils29.isDefined)(setMaxFee)) {
5383
5379
  request.maxFee = maxFee;
5384
5380
  } else if (maxFee.gt(setMaxFee)) {
5385
5381
  throw new import_errors16.FuelError(
@@ -5396,7 +5392,7 @@ var import_address5 = require("@fuel-ts/address");
5396
5392
  var import_crypto2 = require("@fuel-ts/crypto");
5397
5393
  var import_hasher2 = require("@fuel-ts/hasher");
5398
5394
  var import_math22 = require("@fuel-ts/math");
5399
- var import_utils29 = require("@fuel-ts/utils");
5395
+ var import_utils30 = require("@fuel-ts/utils");
5400
5396
  var import_secp256k1 = require("@noble/curves/secp256k1");
5401
5397
  var Signer = class {
5402
5398
  address;
@@ -5416,9 +5412,9 @@ var Signer = class {
5416
5412
  }
5417
5413
  }
5418
5414
  const privateKeyBytes = (0, import_math22.toBytes)(privateKey, 32);
5419
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5420
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5421
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5415
+ this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5416
+ this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5417
+ this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5422
5418
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5423
5419
  }
5424
5420
  /**
@@ -5432,11 +5428,11 @@ var Signer = class {
5432
5428
  * @returns hashed signature
5433
5429
  */
5434
5430
  sign(data) {
5435
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5431
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5436
5432
  const r = (0, import_math22.toBytes)(`0x${signature.r.toString(16)}`, 32);
5437
5433
  const s = (0, import_math22.toBytes)(`0x${signature.s.toString(16)}`, 32);
5438
5434
  s[0] |= (signature.recovery || 0) << 7;
5439
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5435
+ return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5440
5436
  }
5441
5437
  /**
5442
5438
  * Add point on the current elliptic curve
@@ -5445,8 +5441,8 @@ var Signer = class {
5445
5441
  * @returns compressed point on the curve
5446
5442
  */
5447
5443
  addPoint(point) {
5448
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5449
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5444
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5445
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5450
5446
  const result = p0.add(p1);
5451
5447
  return `0x${result.toHex(true)}`;
5452
5448
  }
@@ -5458,16 +5454,16 @@ var Signer = class {
5458
5454
  * @returns public key from signature from the
5459
5455
  */
5460
5456
  static recoverPublicKey(data, signature) {
5461
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5457
+ const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5462
5458
  const r = signedMessageBytes.slice(0, 32);
5463
5459
  const s = signedMessageBytes.slice(32, 64);
5464
5460
  const recoveryParam = (s[0] & 128) >> 7;
5465
5461
  s[0] &= 127;
5466
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5462
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5467
5463
  recoveryParam
5468
5464
  );
5469
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5470
- return (0, import_utils29.hexlify)(publicKey);
5465
+ const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5466
+ return (0, import_utils30.hexlify)(publicKey);
5471
5467
  }
5472
5468
  /**
5473
5469
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5486,7 +5482,7 @@ var Signer = class {
5486
5482
  * @returns random 32-byte hashed
5487
5483
  */
5488
5484
  static generatePrivateKey(entropy) {
5489
- 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);
5485
+ return entropy ? (0, import_hasher2.hash)((0, import_utils30.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils30.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5490
5486
  }
5491
5487
  /**
5492
5488
  * Extended publicKey from a compact publicKey
@@ -5495,8 +5491,8 @@ var Signer = class {
5495
5491
  * @returns extended publicKey
5496
5492
  */
5497
5493
  static extendPublicKey(publicKey) {
5498
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5499
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5494
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5495
+ return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5500
5496
  }
5501
5497
  };
5502
5498
 
@@ -5504,7 +5500,7 @@ var Signer = class {
5504
5500
  var import_address6 = require("@fuel-ts/address");
5505
5501
  var import_crypto3 = require("@fuel-ts/crypto");
5506
5502
  var import_errors17 = require("@fuel-ts/errors");
5507
- var import_utils30 = require("@fuel-ts/utils");
5503
+ var import_utils31 = require("@fuel-ts/utils");
5508
5504
  var import_uuid = require("uuid");
5509
5505
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5510
5506
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5587,7 +5583,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5587
5583
  );
5588
5584
  }
5589
5585
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5590
- const privateKey = (0, import_utils30.hexlify)(buffer);
5586
+ const privateKey = (0, import_utils31.hexlify)(buffer);
5591
5587
  return privateKey;
5592
5588
  }
5593
5589
 
@@ -5632,7 +5628,7 @@ var BaseWalletUnlocked = class extends Account {
5632
5628
  */
5633
5629
  async signMessage(message) {
5634
5630
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5635
- return (0, import_utils31.hexlify)(signedMessage);
5631
+ return (0, import_utils32.hexlify)(signedMessage);
5636
5632
  }
5637
5633
  /**
5638
5634
  * Signs a transaction with the wallet's private key.
@@ -5645,7 +5641,7 @@ var BaseWalletUnlocked = class extends Account {
5645
5641
  const chainId = this.provider.getChainId();
5646
5642
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5647
5643
  const signature = await this.signer().sign(hashedTransaction);
5648
- return (0, import_utils31.hexlify)(signature);
5644
+ return (0, import_utils32.hexlify)(signature);
5649
5645
  }
5650
5646
  /**
5651
5647
  * Populates a transaction with the witnesses signature.
@@ -5704,18 +5700,17 @@ var BaseWalletUnlocked = class extends Account {
5704
5700
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5705
5701
 
5706
5702
  // src/hdwallet/hdwallet.ts
5703
+ var import_crypto5 = require("@fuel-ts/crypto");
5707
5704
  var import_errors20 = require("@fuel-ts/errors");
5708
5705
  var import_hasher6 = require("@fuel-ts/hasher");
5709
5706
  var import_math23 = require("@fuel-ts/math");
5710
- var import_utils35 = require("@fuel-ts/utils");
5711
- var import_ethers2 = require("ethers");
5707
+ var import_utils36 = require("@fuel-ts/utils");
5712
5708
 
5713
5709
  // src/mnemonic/mnemonic.ts
5714
5710
  var import_crypto4 = require("@fuel-ts/crypto");
5715
5711
  var import_errors19 = require("@fuel-ts/errors");
5716
5712
  var import_hasher5 = require("@fuel-ts/hasher");
5717
- var import_utils33 = require("@fuel-ts/utils");
5718
- var import_ethers = require("ethers");
5713
+ var import_utils34 = require("@fuel-ts/utils");
5719
5714
 
5720
5715
  // src/wordlists/words/english.ts
5721
5716
  var english = [
@@ -7772,7 +7767,7 @@ var english = [
7772
7767
  // src/mnemonic/utils.ts
7773
7768
  var import_errors18 = require("@fuel-ts/errors");
7774
7769
  var import_hasher4 = require("@fuel-ts/hasher");
7775
- var import_utils32 = require("@fuel-ts/utils");
7770
+ var import_utils33 = require("@fuel-ts/utils");
7776
7771
  function toUtf8Bytes(stri) {
7777
7772
  const str = stri.normalize("NFKD");
7778
7773
  const result = [];
@@ -7839,14 +7834,14 @@ function entropyToMnemonicIndices(entropy) {
7839
7834
  }
7840
7835
  }
7841
7836
  const checksumBits = entropy.length / 4;
7842
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7837
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7843
7838
  indices[indices.length - 1] <<= checksumBits;
7844
7839
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7845
7840
  return indices;
7846
7841
  }
7847
7842
  function mnemonicWordsToEntropy(words, wordlist) {
7848
7843
  const size = Math.ceil(11 * words.length / 8);
7849
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7844
+ const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
7850
7845
  let offset = 0;
7851
7846
  for (let i = 0; i < words.length; i += 1) {
7852
7847
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7866,7 +7861,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7866
7861
  const entropyBits = 32 * words.length / 3;
7867
7862
  const checksumBits = words.length / 3;
7868
7863
  const checksumMask = getUpperMask(checksumBits);
7869
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7864
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7870
7865
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7871
7866
  throw new import_errors18.FuelError(
7872
7867
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7941,7 +7936,7 @@ var Mnemonic = class {
7941
7936
  static mnemonicToEntropy(phrase, wordlist = english) {
7942
7937
  const words = getWords(phrase);
7943
7938
  assertMnemonic(words);
7944
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7939
+ return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7945
7940
  }
7946
7941
  /**
7947
7942
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7949,7 +7944,7 @@ var Mnemonic = class {
7949
7944
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7950
7945
  */
7951
7946
  static entropyToMnemonic(entropy, wordlist = english) {
7952
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7947
+ const entropyBytes = (0, import_utils34.arrayify)(entropy);
7953
7948
  assertWordList(wordlist);
7954
7949
  assertEntropy(entropyBytes);
7955
7950
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7963,7 +7958,7 @@ var Mnemonic = class {
7963
7958
  assertMnemonic(getWords(phrase));
7964
7959
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7965
7960
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7966
- return (0, import_ethers.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7961
+ return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7967
7962
  }
7968
7963
  /**
7969
7964
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -8018,14 +8013,14 @@ var Mnemonic = class {
8018
8013
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8019
8014
  */
8020
8015
  static masterKeysFromSeed(seed) {
8021
- const seedArray = (0, import_utils33.arrayify)(seed);
8016
+ const seedArray = (0, import_utils34.arrayify)(seed);
8022
8017
  if (seedArray.length < 16 || seedArray.length > 64) {
8023
8018
  throw new import_errors19.FuelError(
8024
8019
  import_errors19.ErrorCode.INVALID_SEED,
8025
8020
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8026
8021
  );
8027
8022
  }
8028
- return (0, import_utils33.arrayify)((0, import_ethers.computeHmac)("sha512", MasterSecret, seedArray));
8023
+ return (0, import_utils34.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
8029
8024
  }
8030
8025
  /**
8031
8026
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8036,22 +8031,22 @@ var Mnemonic = class {
8036
8031
  */
8037
8032
  static seedToExtendedKey(seed, testnet = false) {
8038
8033
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8039
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8034
+ const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8040
8035
  const depth = "0x00";
8041
8036
  const fingerprint = "0x00000000";
8042
8037
  const index = "0x00000000";
8043
8038
  const chainCode = masterKey.slice(32);
8044
8039
  const privateKey = masterKey.slice(0, 32);
8045
- const extendedKey = (0, import_utils33.concat)([
8040
+ const extendedKey = (0, import_utils34.concat)([
8046
8041
  prefix,
8047
8042
  depth,
8048
8043
  fingerprint,
8049
8044
  index,
8050
8045
  chainCode,
8051
- (0, import_utils33.concat)(["0x00", privateKey])
8046
+ (0, import_utils34.concat)(["0x00", privateKey])
8052
8047
  ]);
8053
- const checksum = (0, import_ethers.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8054
- return (0, import_ethers.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8048
+ const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8049
+ return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
8055
8050
  }
8056
8051
  /**
8057
8052
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8066,7 +8061,7 @@ var Mnemonic = class {
8066
8061
  * @returns A randomly generated mnemonic
8067
8062
  */
8068
8063
  static generate(size = 32, extraEntropy = "") {
8069
- 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);
8064
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils34.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils34.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
8070
8065
  return Mnemonic.entropyToMnemonic(entropy);
8071
8066
  }
8072
8067
  };
@@ -8074,12 +8069,12 @@ var mnemonic_default = Mnemonic;
8074
8069
 
8075
8070
  // src/hdwallet/hdwallet.ts
8076
8071
  var HARDENED_INDEX = 2147483648;
8077
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8078
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8079
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8080
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8072
+ var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8073
+ var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8074
+ var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8075
+ var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8081
8076
  function base58check(data) {
8082
- return (0, import_ethers2.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers2.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8077
+ 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)]));
8083
8078
  }
8084
8079
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8085
8080
  if (isPublic) {
@@ -8088,11 +8083,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8088
8083
  return testnet ? TestnetPRV2 : MainnetPRV2;
8089
8084
  }
8090
8085
  function isPublicExtendedKey(extendedKey) {
8091
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8086
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8092
8087
  }
8093
8088
  function isValidExtendedKey(extendedKey) {
8094
8089
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8095
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8090
+ (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8096
8091
  );
8097
8092
  }
8098
8093
  function parsePath(path2, depth = 0) {
@@ -8110,8 +8105,8 @@ function parsePath(path2, depth = 0) {
8110
8105
  var HDWallet = class {
8111
8106
  depth = 0;
8112
8107
  index = 0;
8113
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8114
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8108
+ fingerprint = (0, import_utils36.hexlify)("0x00000000");
8109
+ parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8115
8110
  privateKey;
8116
8111
  publicKey;
8117
8112
  chainCode;
@@ -8123,8 +8118,8 @@ var HDWallet = class {
8123
8118
  constructor(config) {
8124
8119
  if (config.privateKey) {
8125
8120
  const signer = new Signer(config.privateKey);
8126
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8127
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8121
+ this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8122
+ this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8128
8123
  } else {
8129
8124
  if (!config.publicKey) {
8130
8125
  throw new import_errors20.FuelError(
@@ -8132,10 +8127,10 @@ var HDWallet = class {
8132
8127
  "Both public and private Key cannot be missing. At least one should be provided."
8133
8128
  );
8134
8129
  }
8135
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8130
+ this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8136
8131
  }
8137
8132
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8138
- this.fingerprint = (0, import_ethers2.dataSlice)((0, import_ethers2.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8133
+ this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8139
8134
  this.depth = config.depth || this.depth;
8140
8135
  this.index = config.index || this.index;
8141
8136
  this.chainCode = config.chainCode;
@@ -8151,9 +8146,9 @@ var HDWallet = class {
8151
8146
  * @returns A new instance of HDWallet on the derived index
8152
8147
  */
8153
8148
  deriveIndex(index) {
8154
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8155
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8156
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8149
+ const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8150
+ const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8151
+ const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8157
8152
  const data = new Uint8Array(37);
8158
8153
  if (index & HARDENED_INDEX) {
8159
8154
  if (!privateKey) {
@@ -8164,10 +8159,10 @@ var HDWallet = class {
8164
8159
  }
8165
8160
  data.set(privateKey, 1);
8166
8161
  } else {
8167
- data.set((0, import_utils35.arrayify)(this.publicKey));
8162
+ data.set((0, import_utils36.arrayify)(this.publicKey));
8168
8163
  }
8169
8164
  data.set((0, import_math23.toBytes)(index, 4), 33);
8170
- const bytes = (0, import_utils35.arrayify)((0, import_ethers2.computeHmac)("sha512", chainCode, data));
8165
+ const bytes = (0, import_utils36.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8171
8166
  const IL = bytes.slice(0, 32);
8172
8167
  const IR = bytes.slice(32);
8173
8168
  if (privateKey) {
@@ -8181,7 +8176,7 @@ var HDWallet = class {
8181
8176
  parentFingerprint: this.fingerprint
8182
8177
  });
8183
8178
  }
8184
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8179
+ const signer = new Signer((0, import_utils36.hexlify)(IL));
8185
8180
  const Ki = signer.addPoint(publicKey);
8186
8181
  return new HDWallet({
8187
8182
  publicKey: Ki,
@@ -8216,12 +8211,12 @@ var HDWallet = class {
8216
8211
  );
8217
8212
  }
8218
8213
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8219
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8214
+ const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
8220
8215
  const parentFingerprint = this.parentFingerprint;
8221
8216
  const index = (0, import_math23.toHex)(this.index, 4);
8222
8217
  const chainCode = this.chainCode;
8223
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8224
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8218
+ const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8219
+ const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8225
8220
  return base58check(extendedKey);
8226
8221
  }
8227
8222
  /**
@@ -8233,13 +8228,13 @@ var HDWallet = class {
8233
8228
  static fromSeed(seed) {
8234
8229
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8235
8230
  return new HDWallet({
8236
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8237
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8231
+ chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8232
+ privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
8238
8233
  });
8239
8234
  }
8240
8235
  static fromExtendedKey(extendedKey) {
8241
- const decoded = (0, import_ethers2.toBeHex)((0, import_ethers2.decodeBase58)(extendedKey));
8242
- const bytes = (0, import_utils35.arrayify)(decoded);
8236
+ const decoded = (0, import_utils36.hexlify)((0, import_math23.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8237
+ const bytes = (0, import_utils36.arrayify)(decoded);
8243
8238
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8244
8239
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8245
8240
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8248,9 +8243,9 @@ var HDWallet = class {
8248
8243
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8249
8244
  }
8250
8245
  const depth = bytes[4];
8251
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8252
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8253
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8246
+ const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8247
+ const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8248
+ const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
8254
8249
  const key = bytes.slice(45, 78);
8255
8250
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8256
8251
  throw new import_errors20.FuelError(
@@ -8437,11 +8432,11 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
8437
8432
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8438
8433
 
8439
8434
  // src/test-utils/seedTestWallet.ts
8440
- var import_crypto5 = require("@fuel-ts/crypto");
8435
+ var import_crypto6 = require("@fuel-ts/crypto");
8441
8436
  var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8442
8437
  const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
8443
8438
  const [{ provider }] = accountsToBeFunded;
8444
- const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32), provider);
8439
+ const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto6.randomBytes)(32), provider);
8445
8440
  const request = new ScriptTransactionRequest();
8446
8441
  quantities.map(coinQuantityfy).forEach(
8447
8442
  ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
@@ -8468,11 +8463,11 @@ var generateTestWallet = async (provider, quantities) => {
8468
8463
 
8469
8464
  // src/test-utils/launchNode.ts
8470
8465
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
8471
- var import_crypto6 = require("@fuel-ts/crypto");
8472
- var import_utils36 = require("@fuel-ts/utils");
8466
+ var import_crypto7 = require("@fuel-ts/crypto");
8467
+ var import_utils37 = require("@fuel-ts/utils");
8473
8468
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8474
8469
  var import_child_process = require("child_process");
8475
- var import_crypto7 = require("crypto");
8470
+ var import_crypto8 = require("crypto");
8476
8471
  var import_fs = require("fs");
8477
8472
  var import_os = __toESM(require("os"));
8478
8473
  var import_path = __toESM(require("path"));
@@ -8509,6 +8504,40 @@ var killNode = (params) => {
8509
8504
  }
8510
8505
  }
8511
8506
  };
8507
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8508
+ const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8509
+ ...coin,
8510
+ amount: "18446744073709551615"
8511
+ }));
8512
+ const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8513
+ ...message,
8514
+ amount: "18446744073709551615"
8515
+ }));
8516
+ 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);
8517
+ 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);
8518
+ if (!process.env.GENESIS_SECRET) {
8519
+ const pk = Signer.generatePrivateKey();
8520
+ const signer = new Signer(pk);
8521
+ process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8522
+ coins.push({
8523
+ tx_id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8524
+ owner: signer.address.toHexString(),
8525
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8526
+ amount: "18446744073709551615",
8527
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8528
+ output_index: 0,
8529
+ tx_pointer_block_height: 0,
8530
+ tx_pointer_tx_idx: 0
8531
+ });
8532
+ }
8533
+ const json = JSON.stringify({
8534
+ ...stateConfig,
8535
+ coins,
8536
+ messages
8537
+ });
8538
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8539
+ return json.replace(regexMakeNumber, "$1$2");
8540
+ }
8512
8541
  var launchNode = async ({
8513
8542
  ip,
8514
8543
  port,
@@ -8516,7 +8545,8 @@ var launchNode = async ({
8516
8545
  useSystemFuelCore = false,
8517
8546
  loggingEnabled = true,
8518
8547
  debugEnabled = false,
8519
- basePath
8548
+ basePath,
8549
+ snapshotConfig = import_utils37.defaultSnapshotConfigs
8520
8550
  }) => (
8521
8551
  // eslint-disable-next-line no-async-promise-executor
8522
8552
  new Promise(async (resolve, reject) => {
@@ -8527,7 +8557,7 @@ var launchNode = async ({
8527
8557
  "--poa-instant"
8528
8558
  ]);
8529
8559
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8530
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8560
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8531
8561
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8532
8562
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8533
8563
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8544,57 +8574,24 @@ var launchNode = async ({
8544
8574
  })).toString();
8545
8575
  let snapshotDirToUse;
8546
8576
  const prefix = basePath || import_os.default.tmpdir();
8547
- const suffix = basePath ? "" : (0, import_crypto7.randomUUID)();
8548
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8577
+ const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
8578
+ const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8549
8579
  if (snapshotDir) {
8550
8580
  snapshotDirToUse = snapshotDir;
8551
8581
  } else {
8552
- if (!(0, import_fs.existsSync)(tempDirPath)) {
8553
- (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8582
+ if (!(0, import_fs.existsSync)(tempDir)) {
8583
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8554
8584
  }
8555
- let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
8556
- const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
8557
- stateConfigJson = {
8558
- ...stateConfigJson,
8559
- coins: [
8560
- ...stateConfigJson.coins.map((coin) => ({
8561
- ...coin,
8562
- amount: "18446744073709551615"
8563
- }))
8564
- ],
8565
- messages: stateConfigJson.messages.map((message) => ({
8566
- ...message,
8567
- amount: "18446744073709551615"
8568
- }))
8569
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8570
- };
8571
- if (!process.env.GENESIS_SECRET) {
8572
- const pk = Signer.generatePrivateKey();
8573
- const signer = new Signer(pk);
8574
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8575
- stateConfigJson.coins.push({
8576
- tx_id: (0, import_utils36.hexlify)((0, import_crypto6.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8577
- owner: signer.address.toHexString(),
8578
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8579
- amount: "18446744073709551615",
8580
- asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8581
- output_index: 0,
8582
- tx_pointer_block_height: 0,
8583
- tx_pointer_tx_idx: 0
8584
- });
8585
- }
8586
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8587
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8588
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8589
- const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8590
- const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8591
- const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8592
- const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
8593
- (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8594
- (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8595
- (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8596
- (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
8597
- snapshotDirToUse = tempDirPath;
8585
+ const { metadata } = snapshotConfig;
8586
+ const metadataPath = import_path.default.join(tempDir, "metadata.json");
8587
+ const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8588
+ const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8589
+ const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8590
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8591
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8592
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8593
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8594
+ snapshotDirToUse = tempDir;
8598
8595
  }
8599
8596
  const child = (0, import_child_process.spawn)(
8600
8597
  command,
@@ -8602,7 +8599,7 @@ var launchNode = async ({
8602
8599
  "run",
8603
8600
  ["--ip", ipToUse],
8604
8601
  ["--port", portToUse],
8605
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8602
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8606
8603
  ["--min-gas-price", "1"],
8607
8604
  poaInstant ? ["--poa-instant", "true"] : [],
8608
8605
  ["--consensus-key", consensusKey],
@@ -8624,23 +8621,28 @@ var launchNode = async ({
8624
8621
  }
8625
8622
  const cleanupConfig = {
8626
8623
  child,
8627
- configPath: tempDirPath,
8624
+ configPath: tempDir,
8628
8625
  killFn: import_tree_kill.default,
8629
8626
  state: {
8630
8627
  isDead: false
8631
8628
  }
8632
8629
  };
8633
8630
  child.stderr.on("data", (chunk) => {
8634
- if (chunk.indexOf(graphQLStartSubstring) !== -1) {
8631
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
8632
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
8633
+ const rows = text.split("\n");
8634
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8635
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8635
8636
  resolve({
8636
8637
  cleanup: () => killNode(cleanupConfig),
8637
- ip: ipToUse,
8638
- port: portToUse,
8638
+ ip: realIp,
8639
+ port: realPort,
8640
+ url: `http://${realIp}:${realPort}/v1/graphql`,
8639
8641
  snapshotDir: snapshotDirToUse
8640
8642
  });
8641
8643
  }
8642
- if (/error/i.test(chunk)) {
8643
- reject(chunk.toString());
8644
+ if (/error/i.test(text)) {
8645
+ reject(text.toString());
8644
8646
  }
8645
8647
  });
8646
8648
  process.on("exit", () => killNode(cleanupConfig));
@@ -8673,12 +8675,238 @@ var launchNodeAndGetWallets = async ({
8673
8675
  };
8674
8676
  return { wallets, stop: cleanup, provider };
8675
8677
  };
8678
+
8679
+ // src/test-utils/setup-test-provider-and-wallets.ts
8680
+ var import_utils40 = require("@fuel-ts/utils");
8681
+ var import_ramda5 = require("ramda");
8682
+
8683
+ // src/test-utils/asset-id.ts
8684
+ var import_crypto9 = require("@fuel-ts/crypto");
8685
+ var import_utils38 = require("@fuel-ts/utils");
8686
+ var _AssetId = class {
8687
+ constructor(value) {
8688
+ this.value = value;
8689
+ }
8690
+ static random() {
8691
+ return new _AssetId((0, import_utils38.hexlify)((0, import_crypto9.randomBytes)(32)));
8692
+ }
8693
+ };
8694
+ var AssetId = _AssetId;
8695
+ __publicField(AssetId, "A", new _AssetId(
8696
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
8697
+ ));
8698
+ __publicField(AssetId, "B", new _AssetId(
8699
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
8700
+ ));
8701
+
8702
+ // src/test-utils/wallet-config.ts
8703
+ var import_crypto10 = require("@fuel-ts/crypto");
8704
+ var import_errors21 = require("@fuel-ts/errors");
8705
+ var import_utils39 = require("@fuel-ts/utils");
8706
+ var WalletConfig = class {
8707
+ initialState;
8708
+ options;
8709
+ wallets;
8710
+ generateWallets = () => {
8711
+ const generatedWallets = [];
8712
+ for (let index = 1; index <= this.options.count; index++) {
8713
+ generatedWallets.push(new WalletUnlocked((0, import_crypto10.randomBytes)(32)));
8714
+ }
8715
+ return generatedWallets;
8716
+ };
8717
+ constructor(baseAssetId, config) {
8718
+ const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
8719
+ WalletConfig.guard(config);
8720
+ this.options = config;
8721
+ const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8722
+ this.wallets = this.generateWallets();
8723
+ this.initialState = {
8724
+ messages: WalletConfig.createMessages(this.wallets, messages),
8725
+ coins: WalletConfig.createCoins(
8726
+ this.wallets,
8727
+ BASE_ASSET_ID,
8728
+ assets2,
8729
+ coinsPerAsset,
8730
+ amountPerCoin
8731
+ )
8732
+ };
8733
+ }
8734
+ apply(snapshotConfig) {
8735
+ return {
8736
+ ...snapshotConfig,
8737
+ stateConfig: {
8738
+ ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
8739
+ coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8740
+ messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8741
+ }
8742
+ };
8743
+ }
8744
+ static createMessages(wallets, messages) {
8745
+ return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8746
+ }
8747
+ static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
8748
+ const coins = [];
8749
+ let assetIds = [baseAssetId];
8750
+ if (Array.isArray(assets2)) {
8751
+ assetIds = assetIds.concat(assets2.map((a) => a.value));
8752
+ } else {
8753
+ for (let index = 0; index < assets2 - 1; index++) {
8754
+ assetIds.push(AssetId.random().value);
8755
+ }
8756
+ }
8757
+ wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8758
+ assetIds.forEach((assetId) => {
8759
+ for (let index = 0; index < coinsPerAsset; index++) {
8760
+ coins.push({
8761
+ amount: amountPerCoin,
8762
+ asset_id: assetId,
8763
+ owner: walletAddress,
8764
+ tx_pointer_block_height: 0,
8765
+ tx_pointer_tx_idx: 0,
8766
+ output_index: 0,
8767
+ tx_id: (0, import_utils39.hexlify)((0, import_crypto10.randomBytes)(32))
8768
+ });
8769
+ }
8770
+ });
8771
+ });
8772
+ return coins;
8773
+ }
8774
+ static guard({
8775
+ count: wallets,
8776
+ assets: assets2,
8777
+ coinsPerAsset,
8778
+ amountPerCoin
8779
+ }) {
8780
+ if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8781
+ throw new import_errors21.FuelError(
8782
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8783
+ "Number of wallets must be greater than zero."
8784
+ );
8785
+ }
8786
+ if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8787
+ throw new import_errors21.FuelError(
8788
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8789
+ "Number of assets per wallet must be greater than zero."
8790
+ );
8791
+ }
8792
+ if (coinsPerAsset <= 0) {
8793
+ throw new import_errors21.FuelError(
8794
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8795
+ "Number of coins per asset must be greater than zero."
8796
+ );
8797
+ }
8798
+ if (amountPerCoin <= 0) {
8799
+ throw new import_errors21.FuelError(
8800
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8801
+ "Amount per coin must be greater than zero."
8802
+ );
8803
+ }
8804
+ }
8805
+ };
8806
+
8807
+ // src/test-utils/setup-test-provider-and-wallets.ts
8808
+ var defaultWalletConfigOptions = {
8809
+ count: 2,
8810
+ assets: [AssetId.A, AssetId.B],
8811
+ coinsPerAsset: 1,
8812
+ amountPerCoin: 1e10,
8813
+ messages: []
8814
+ };
8815
+ async function setupTestProviderAndWallets({
8816
+ walletConfig: walletConfigOptions = {},
8817
+ providerOptions,
8818
+ nodeOptions = {}
8819
+ } = {}) {
8820
+ Symbol.dispose ??= Symbol("Symbol.dispose");
8821
+ const walletConfig = new WalletConfig(
8822
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
8823
+ {
8824
+ ...defaultWalletConfigOptions,
8825
+ ...walletConfigOptions
8826
+ }
8827
+ );
8828
+ const { cleanup, url } = await launchNode({
8829
+ loggingEnabled: false,
8830
+ ...nodeOptions,
8831
+ snapshotConfig: (0, import_ramda5.mergeDeepRight)(
8832
+ import_utils40.defaultSnapshotConfigs,
8833
+ walletConfig.apply(nodeOptions?.snapshotConfig)
8834
+ ),
8835
+ port: "0"
8836
+ });
8837
+ let provider;
8838
+ try {
8839
+ provider = await Provider.create(url, providerOptions);
8840
+ } catch (err) {
8841
+ cleanup();
8842
+ throw err;
8843
+ }
8844
+ const wallets = walletConfig.wallets;
8845
+ wallets.forEach((wallet) => {
8846
+ wallet.connect(provider);
8847
+ });
8848
+ return {
8849
+ provider,
8850
+ wallets,
8851
+ cleanup,
8852
+ [Symbol.dispose]: cleanup
8853
+ };
8854
+ }
8855
+
8856
+ // src/test-utils/test-message.ts
8857
+ var import_address7 = require("@fuel-ts/address");
8858
+ var import_crypto11 = require("@fuel-ts/crypto");
8859
+ var import_math24 = require("@fuel-ts/math");
8860
+ var import_utils41 = require("@fuel-ts/utils");
8861
+ var TestMessage = class {
8862
+ sender;
8863
+ recipient;
8864
+ nonce;
8865
+ amount;
8866
+ data;
8867
+ da_height;
8868
+ /**
8869
+ * A helper class to create messages for testing purposes.
8870
+ *
8871
+ * Used in tandem with `WalletConfig`.
8872
+ * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
8873
+ */
8874
+ constructor({
8875
+ sender = import_address7.Address.fromRandom(),
8876
+ recipient = import_address7.Address.fromRandom(),
8877
+ nonce = (0, import_utils41.hexlify)((0, import_crypto11.randomBytes)(32)),
8878
+ amount = 1e6,
8879
+ data = "02",
8880
+ da_height = 0
8881
+ } = {}) {
8882
+ this.sender = sender;
8883
+ this.recipient = recipient;
8884
+ this.nonce = nonce;
8885
+ this.amount = amount;
8886
+ this.data = data;
8887
+ this.da_height = da_height;
8888
+ }
8889
+ toChainMessage(recipient) {
8890
+ return {
8891
+ sender: this.sender.toB256(),
8892
+ recipient: recipient?.toB256() ?? this.recipient.toB256(),
8893
+ nonce: this.nonce,
8894
+ amount: (0, import_math24.bn)(this.amount).toNumber(),
8895
+ data: this.data,
8896
+ da_height: this.da_height
8897
+ };
8898
+ }
8899
+ };
8676
8900
  // Annotate the CommonJS export names for ESM import in node:
8677
8901
  0 && (module.exports = {
8902
+ AssetId,
8903
+ TestMessage,
8904
+ WalletConfig,
8678
8905
  generateTestWallet,
8679
8906
  killNode,
8680
8907
  launchNode,
8681
8908
  launchNodeAndGetWallets,
8682
- seedTestWallet
8909
+ seedTestWallet,
8910
+ setupTestProviderAndWallets
8683
8911
  });
8684
8912
  //# sourceMappingURL=test-utils.js.map