@fuel-ts/account 0.0.0-rc-1356-20240515091838 → 0.0.0-rc-2143-20240515092507

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,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 import_utils32 = require("@fuel-ts/utils");
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 import_utils29 = require("@fuel-ts/utils");
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 import_utils23 = require("@fuel-ts/utils");
111
+ var import_utils22 = require("@fuel-ts/utils");
116
112
  var import_versions = require("@fuel-ts/versions");
117
- var import_utils24 = require("@noble/curves/abstract/utils");
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
 
@@ -1671,6 +1667,15 @@ function normalizeJSON(root) {
1671
1667
  return normalize((0, import_ramda.clone)(root));
1672
1668
  }
1673
1669
 
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
+
1674
1679
  // src/providers/utils/extract-tx-error.ts
1675
1680
  var import_errors7 = require("@fuel-ts/errors");
1676
1681
  var import_math6 = require("@fuel-ts/math");
@@ -3614,7 +3619,6 @@ var TransactionResponse = class {
3614
3619
  };
3615
3620
 
3616
3621
  // src/providers/utils/auto-retry-fetch.ts
3617
- var import_utils22 = require("@fuel-ts/utils");
3618
3622
  function getWaitDelay(options, retryAttemptNum) {
3619
3623
  const duration = options.baseDelay ?? 150;
3620
3624
  switch (options.backoff) {
@@ -3644,7 +3648,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3644
3648
  throw error;
3645
3649
  }
3646
3650
  const delay = getWaitDelay(options, retryNum);
3647
- await (0, import_utils22.sleep)(delay);
3651
+ await sleep(delay);
3648
3652
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3649
3653
  }
3650
3654
  };
@@ -3984,7 +3988,7 @@ Supported fuel-core version: ${supportedVersion}.`
3984
3988
  if (estimateTxDependencies) {
3985
3989
  await this.estimateTxDependencies(transactionRequest);
3986
3990
  }
3987
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3991
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3988
3992
  let abis;
3989
3993
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
3990
3994
  abis = transactionRequest.abis;
@@ -4027,7 +4031,7 @@ Supported fuel-core version: ${supportedVersion}.`
4027
4031
  if (estimateTxDependencies) {
4028
4032
  return this.estimateTxDependencies(transactionRequest);
4029
4033
  }
4030
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4034
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4031
4035
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4032
4036
  encodedTransactions: encodedTransaction,
4033
4037
  utxoValidation: utxoValidation || false
@@ -4045,13 +4049,13 @@ Supported fuel-core version: ${supportedVersion}.`
4045
4049
  async estimatePredicates(transactionRequest) {
4046
4050
  const shouldEstimatePredicates = Boolean(
4047
4051
  transactionRequest.inputs.find(
4048
- (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4052
+ (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()
4049
4053
  )
4050
4054
  );
4051
4055
  if (!shouldEstimatePredicates) {
4052
4056
  return transactionRequest;
4053
4057
  }
4054
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4058
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4055
4059
  const response = await this.operations.estimatePredicates({
4056
4060
  encodedTransaction
4057
4061
  });
@@ -4093,7 +4097,7 @@ Supported fuel-core version: ${supportedVersion}.`
4093
4097
  const {
4094
4098
  dryRun: [{ receipts: rawReceipts, status }]
4095
4099
  } = await this.operations.dryRun({
4096
- encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4100
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4097
4101
  utxoValidation: false
4098
4102
  });
4099
4103
  receipts = rawReceipts.map(processGqlReceipt);
@@ -4143,7 +4147,7 @@ Supported fuel-core version: ${supportedVersion}.`
4143
4147
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4144
4148
  allRequests.forEach((req, index) => {
4145
4149
  if (req.type === import_transactions20.TransactionType.Script) {
4146
- serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4150
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4147
4151
  }
4148
4152
  });
4149
4153
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4179,7 +4183,7 @@ Supported fuel-core version: ${supportedVersion}.`
4179
4183
  transactionRequest: request
4180
4184
  });
4181
4185
  request.maxFee = maxFee;
4182
- serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4186
+ serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4183
4187
  nextRoundTransactions.push(requestIdx);
4184
4188
  }
4185
4189
  }
@@ -4192,7 +4196,7 @@ Supported fuel-core version: ${supportedVersion}.`
4192
4196
  if (estimateTxDependencies) {
4193
4197
  return this.estimateMultipleTxDependencies(transactionRequests);
4194
4198
  }
4195
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4199
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4196
4200
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4197
4201
  encodedTransactions,
4198
4202
  utxoValidation: utxoValidation || false
@@ -4265,7 +4269,7 @@ Supported fuel-core version: ${supportedVersion}.`
4265
4269
  if (estimateTxDependencies) {
4266
4270
  return this.estimateTxDependencies(transactionRequest);
4267
4271
  }
4268
- const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4272
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4269
4273
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4270
4274
  encodedTransactions,
4271
4275
  utxoValidation: true
@@ -4381,7 +4385,7 @@ Supported fuel-core version: ${supportedVersion}.`
4381
4385
  const result = await this.operations.getCoins({
4382
4386
  first: 10,
4383
4387
  ...paginationArgs,
4384
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4388
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4385
4389
  });
4386
4390
  const coins = result.coins.edges.map((edge) => edge.node);
4387
4391
  return coins.map((coin) => ({
@@ -4404,19 +4408,19 @@ Supported fuel-core version: ${supportedVersion}.`
4404
4408
  async getResourcesToSpend(owner, quantities, excludedIds) {
4405
4409
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4406
4410
  const excludeInput = {
4407
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4408
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4411
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4412
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4409
4413
  };
4410
4414
  if (this.cache) {
4411
4415
  const uniqueUtxos = new Set(
4412
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4416
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4413
4417
  );
4414
4418
  excludeInput.utxos = Array.from(uniqueUtxos);
4415
4419
  }
4416
4420
  const coinsQuery = {
4417
4421
  owner: ownerAddress.toB256(),
4418
4422
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4419
- assetId: (0, import_utils23.hexlify)(assetId),
4423
+ assetId: (0, import_utils22.hexlify)(assetId),
4420
4424
  amount: amount.toString(10),
4421
4425
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4422
4426
  })),
@@ -4518,7 +4522,7 @@ Supported fuel-core version: ${supportedVersion}.`
4518
4522
  time: block.header.time,
4519
4523
  transactionIds: block.transactions.map((tx) => tx.id),
4520
4524
  transactions: block.transactions.map(
4521
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4525
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4522
4526
  )
4523
4527
  };
4524
4528
  }
@@ -4534,7 +4538,7 @@ Supported fuel-core version: ${supportedVersion}.`
4534
4538
  return null;
4535
4539
  }
4536
4540
  return new import_transactions20.TransactionCoder().decode(
4537
- (0, import_utils23.arrayify)(transaction.rawPayload),
4541
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4538
4542
  0
4539
4543
  )?.[0];
4540
4544
  }
@@ -4561,7 +4565,7 @@ Supported fuel-core version: ${supportedVersion}.`
4561
4565
  async getContractBalance(contractId, assetId) {
4562
4566
  const { contractBalance } = await this.operations.getContractBalance({
4563
4567
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4564
- asset: (0, import_utils23.hexlify)(assetId)
4568
+ asset: (0, import_utils22.hexlify)(assetId)
4565
4569
  });
4566
4570
  return (0, import_math17.bn)(contractBalance.amount, 10);
4567
4571
  }
@@ -4575,7 +4579,7 @@ Supported fuel-core version: ${supportedVersion}.`
4575
4579
  async getBalance(owner, assetId) {
4576
4580
  const { balance } = await this.operations.getBalance({
4577
4581
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4578
- assetId: (0, import_utils23.hexlify)(assetId)
4582
+ assetId: (0, import_utils22.hexlify)(assetId)
4579
4583
  });
4580
4584
  return (0, import_math17.bn)(balance.amount, 10);
4581
4585
  }
@@ -4752,7 +4756,7 @@ Supported fuel-core version: ${supportedVersion}.`
4752
4756
  async produceBlocks(amount, startTime) {
4753
4757
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4754
4758
  blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4755
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4759
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4756
4760
  });
4757
4761
  return (0, import_math17.bn)(latestBlockHeight);
4758
4762
  }
@@ -4802,7 +4806,7 @@ __publicField(Provider, "nodeInfoCache", {});
4802
4806
  var import_errors15 = require("@fuel-ts/errors");
4803
4807
  var import_math18 = require("@fuel-ts/math");
4804
4808
  var import_transactions21 = require("@fuel-ts/transactions");
4805
- var import_utils26 = require("@fuel-ts/utils");
4809
+ var import_utils25 = require("@fuel-ts/utils");
4806
4810
 
4807
4811
  // src/providers/chains.ts
4808
4812
  var CHAIN_IDS = {
@@ -4878,16 +4882,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
4878
4882
  // src/utils/formatTransferToContractScriptData.ts
4879
4883
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4880
4884
  var import_math19 = require("@fuel-ts/math");
4881
- var import_utils28 = require("@fuel-ts/utils");
4885
+ var import_utils27 = require("@fuel-ts/utils");
4882
4886
  var asm = __toESM(require("@fuels/vm-asm"));
4883
4887
  var formatTransferToContractScriptData = (params) => {
4884
4888
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4885
4889
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4886
4890
  const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
4887
4891
  const scriptData = Uint8Array.from([
4888
- ...(0, import_utils28.arrayify)(hexlifiedContractId),
4892
+ ...(0, import_utils27.arrayify)(hexlifiedContractId),
4889
4893
  ...encoded,
4890
- ...(0, import_utils28.arrayify)(assetId)
4894
+ ...(0, import_utils27.arrayify)(assetId)
4891
4895
  ]);
4892
4896
  return scriptData;
4893
4897
  };
@@ -5258,14 +5262,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5258
5262
  */
5259
5263
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5260
5264
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5261
- const recipientDataArray = (0, import_utils29.arrayify)(
5265
+ const recipientDataArray = (0, import_utils28.arrayify)(
5262
5266
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5263
5267
  );
5264
- const amountDataArray = (0, import_utils29.arrayify)(
5268
+ const amountDataArray = (0, import_utils28.arrayify)(
5265
5269
  "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
5266
5270
  );
5267
5271
  const script = new Uint8Array([
5268
- ...(0, import_utils29.arrayify)(withdrawScript.bytes),
5272
+ ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5269
5273
  ...recipientDataArray,
5270
5274
  ...amountDataArray
5271
5275
  ]);
@@ -5345,7 +5349,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5345
5349
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5346
5350
  }) {
5347
5351
  const request = transactionRequestify(transactionRequest);
5348
- if (!(0, import_utils29.isDefined)(setGasLimit)) {
5352
+ if (!(0, import_utils28.isDefined)(setGasLimit)) {
5349
5353
  request.gasLimit = gasUsed;
5350
5354
  } else if (gasUsed.gt(setGasLimit)) {
5351
5355
  throw new import_errors16.FuelError(
@@ -5353,7 +5357,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5353
5357
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5354
5358
  );
5355
5359
  }
5356
- if (!(0, import_utils29.isDefined)(setMaxFee)) {
5360
+ if (!(0, import_utils28.isDefined)(setMaxFee)) {
5357
5361
  request.maxFee = maxFee;
5358
5362
  } else if (maxFee.gt(setMaxFee)) {
5359
5363
  throw new import_errors16.FuelError(
@@ -5370,7 +5374,7 @@ var import_address5 = require("@fuel-ts/address");
5370
5374
  var import_crypto2 = require("@fuel-ts/crypto");
5371
5375
  var import_hasher2 = require("@fuel-ts/hasher");
5372
5376
  var import_math21 = require("@fuel-ts/math");
5373
- var import_utils30 = require("@fuel-ts/utils");
5377
+ var import_utils29 = require("@fuel-ts/utils");
5374
5378
  var import_secp256k1 = require("@noble/curves/secp256k1");
5375
5379
  var Signer = class {
5376
5380
  address;
@@ -5390,9 +5394,9 @@ var Signer = class {
5390
5394
  }
5391
5395
  }
5392
5396
  const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5393
- this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5394
- this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5395
- this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5397
+ this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5398
+ this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5399
+ this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5396
5400
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5397
5401
  }
5398
5402
  /**
@@ -5406,11 +5410,11 @@ var Signer = class {
5406
5410
  * @returns hashed signature
5407
5411
  */
5408
5412
  sign(data) {
5409
- const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5413
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5410
5414
  const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5411
5415
  const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5412
5416
  s[0] |= (signature.recovery || 0) << 7;
5413
- return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5417
+ return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5414
5418
  }
5415
5419
  /**
5416
5420
  * Add point on the current elliptic curve
@@ -5419,8 +5423,8 @@ var Signer = class {
5419
5423
  * @returns compressed point on the curve
5420
5424
  */
5421
5425
  addPoint(point) {
5422
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5423
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5426
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5427
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5424
5428
  const result = p0.add(p1);
5425
5429
  return `0x${result.toHex(true)}`;
5426
5430
  }
@@ -5432,16 +5436,16 @@ var Signer = class {
5432
5436
  * @returns public key from signature from the
5433
5437
  */
5434
5438
  static recoverPublicKey(data, signature) {
5435
- const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5439
+ const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5436
5440
  const r = signedMessageBytes.slice(0, 32);
5437
5441
  const s = signedMessageBytes.slice(32, 64);
5438
5442
  const recoveryParam = (s[0] & 128) >> 7;
5439
5443
  s[0] &= 127;
5440
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5444
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5441
5445
  recoveryParam
5442
5446
  );
5443
- const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5444
- return (0, import_utils30.hexlify)(publicKey);
5447
+ const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5448
+ return (0, import_utils29.hexlify)(publicKey);
5445
5449
  }
5446
5450
  /**
5447
5451
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5460,7 +5464,7 @@ var Signer = class {
5460
5464
  * @returns random 32-byte hashed
5461
5465
  */
5462
5466
  static generatePrivateKey(entropy) {
5463
- 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);
5467
+ 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);
5464
5468
  }
5465
5469
  /**
5466
5470
  * Extended publicKey from a compact publicKey
@@ -5469,8 +5473,8 @@ var Signer = class {
5469
5473
  * @returns extended publicKey
5470
5474
  */
5471
5475
  static extendPublicKey(publicKey) {
5472
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5473
- return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5476
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5477
+ return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5474
5478
  }
5475
5479
  };
5476
5480
 
@@ -5478,7 +5482,7 @@ var Signer = class {
5478
5482
  var import_address6 = require("@fuel-ts/address");
5479
5483
  var import_crypto3 = require("@fuel-ts/crypto");
5480
5484
  var import_errors17 = require("@fuel-ts/errors");
5481
- var import_utils31 = require("@fuel-ts/utils");
5485
+ var import_utils30 = require("@fuel-ts/utils");
5482
5486
  var import_uuid = require("uuid");
5483
5487
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5484
5488
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5561,7 +5565,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5561
5565
  );
5562
5566
  }
5563
5567
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5564
- const privateKey = (0, import_utils31.hexlify)(buffer);
5568
+ const privateKey = (0, import_utils30.hexlify)(buffer);
5565
5569
  return privateKey;
5566
5570
  }
5567
5571
 
@@ -5606,7 +5610,7 @@ var BaseWalletUnlocked = class extends Account {
5606
5610
  */
5607
5611
  async signMessage(message) {
5608
5612
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5609
- return (0, import_utils32.hexlify)(signedMessage);
5613
+ return (0, import_utils31.hexlify)(signedMessage);
5610
5614
  }
5611
5615
  /**
5612
5616
  * Signs a transaction with the wallet's private key.
@@ -5619,7 +5623,7 @@ var BaseWalletUnlocked = class extends Account {
5619
5623
  const chainId = this.provider.getChainId();
5620
5624
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5621
5625
  const signature = await this.signer().sign(hashedTransaction);
5622
- return (0, import_utils32.hexlify)(signature);
5626
+ return (0, import_utils31.hexlify)(signature);
5623
5627
  }
5624
5628
  /**
5625
5629
  * Populates a transaction with the witnesses signature.
@@ -5682,13 +5686,13 @@ var import_crypto5 = require("@fuel-ts/crypto");
5682
5686
  var import_errors20 = require("@fuel-ts/errors");
5683
5687
  var import_hasher6 = require("@fuel-ts/hasher");
5684
5688
  var import_math22 = require("@fuel-ts/math");
5685
- var import_utils36 = require("@fuel-ts/utils");
5689
+ var import_utils35 = require("@fuel-ts/utils");
5686
5690
 
5687
5691
  // src/mnemonic/mnemonic.ts
5688
5692
  var import_crypto4 = require("@fuel-ts/crypto");
5689
5693
  var import_errors19 = require("@fuel-ts/errors");
5690
5694
  var import_hasher5 = require("@fuel-ts/hasher");
5691
- var import_utils34 = require("@fuel-ts/utils");
5695
+ var import_utils33 = require("@fuel-ts/utils");
5692
5696
 
5693
5697
  // src/wordlists/words/english.ts
5694
5698
  var english = [
@@ -7745,7 +7749,7 @@ var english = [
7745
7749
  // src/mnemonic/utils.ts
7746
7750
  var import_errors18 = require("@fuel-ts/errors");
7747
7751
  var import_hasher4 = require("@fuel-ts/hasher");
7748
- var import_utils33 = require("@fuel-ts/utils");
7752
+ var import_utils32 = require("@fuel-ts/utils");
7749
7753
  function getLowerMask(bits) {
7750
7754
  return (1 << bits) - 1;
7751
7755
  }
@@ -7780,14 +7784,14 @@ function entropyToMnemonicIndices(entropy) {
7780
7784
  }
7781
7785
  }
7782
7786
  const checksumBits = entropy.length / 4;
7783
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7787
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7784
7788
  indices[indices.length - 1] <<= checksumBits;
7785
7789
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7786
7790
  return indices;
7787
7791
  }
7788
7792
  function mnemonicWordsToEntropy(words, wordlist) {
7789
7793
  const size = Math.ceil(11 * words.length / 8);
7790
- const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
7794
+ const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7791
7795
  let offset = 0;
7792
7796
  for (let i = 0; i < words.length; i += 1) {
7793
7797
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7807,7 +7811,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7807
7811
  const entropyBits = 32 * words.length / 3;
7808
7812
  const checksumBits = words.length / 3;
7809
7813
  const checksumMask = getUpperMask(checksumBits);
7810
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7814
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7811
7815
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7812
7816
  throw new import_errors18.FuelError(
7813
7817
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7818,7 +7822,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7818
7822
  }
7819
7823
 
7820
7824
  // src/mnemonic/mnemonic.ts
7821
- var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
7825
+ var MasterSecret = (0, import_utils33.toUtf8Bytes)("Bitcoin seed");
7822
7826
  var MainnetPRV = "0x0488ade4";
7823
7827
  var TestnetPRV = "0x04358394";
7824
7828
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
@@ -7882,7 +7886,7 @@ var Mnemonic = class {
7882
7886
  static mnemonicToEntropy(phrase, wordlist = english) {
7883
7887
  const words = getWords(phrase);
7884
7888
  assertMnemonic(words);
7885
- return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7889
+ return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7886
7890
  }
7887
7891
  /**
7888
7892
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7890,7 +7894,7 @@ var Mnemonic = class {
7890
7894
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7891
7895
  */
7892
7896
  static entropyToMnemonic(entropy, wordlist = english) {
7893
- const entropyBytes = (0, import_utils34.arrayify)(entropy);
7897
+ const entropyBytes = (0, import_utils33.arrayify)(entropy);
7894
7898
  assertWordList(wordlist);
7895
7899
  assertEntropy(entropyBytes);
7896
7900
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7902,8 +7906,8 @@ var Mnemonic = class {
7902
7906
  */
7903
7907
  static mnemonicToSeed(phrase, passphrase = "") {
7904
7908
  assertMnemonic(getWords(phrase));
7905
- const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
7906
- const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
7909
+ const phraseBytes = (0, import_utils33.toUtf8Bytes)(getPhrase(phrase));
7910
+ const salt = (0, import_utils33.toUtf8Bytes)(`mnemonic${passphrase}`);
7907
7911
  return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7908
7912
  }
7909
7913
  /**
@@ -7959,14 +7963,14 @@ var Mnemonic = class {
7959
7963
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7960
7964
  */
7961
7965
  static masterKeysFromSeed(seed) {
7962
- const seedArray = (0, import_utils34.arrayify)(seed);
7966
+ const seedArray = (0, import_utils33.arrayify)(seed);
7963
7967
  if (seedArray.length < 16 || seedArray.length > 64) {
7964
7968
  throw new import_errors19.FuelError(
7965
7969
  import_errors19.ErrorCode.INVALID_SEED,
7966
7970
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7967
7971
  );
7968
7972
  }
7969
- return (0, import_utils34.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
7973
+ return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
7970
7974
  }
7971
7975
  /**
7972
7976
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7977,22 +7981,22 @@ var Mnemonic = class {
7977
7981
  */
7978
7982
  static seedToExtendedKey(seed, testnet = false) {
7979
7983
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7980
- const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7984
+ const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7981
7985
  const depth = "0x00";
7982
7986
  const fingerprint = "0x00000000";
7983
7987
  const index = "0x00000000";
7984
7988
  const chainCode = masterKey.slice(32);
7985
7989
  const privateKey = masterKey.slice(0, 32);
7986
- const extendedKey = (0, import_utils34.concat)([
7990
+ const extendedKey = (0, import_utils33.concat)([
7987
7991
  prefix,
7988
7992
  depth,
7989
7993
  fingerprint,
7990
7994
  index,
7991
7995
  chainCode,
7992
- (0, import_utils34.concat)(["0x00", privateKey])
7996
+ (0, import_utils33.concat)(["0x00", privateKey])
7993
7997
  ]);
7994
- const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7995
- return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
7998
+ const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7999
+ return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7996
8000
  }
7997
8001
  /**
7998
8002
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8007,7 +8011,7 @@ var Mnemonic = class {
8007
8011
  * @returns A randomly generated mnemonic
8008
8012
  */
8009
8013
  static generate(size = 32, extraEntropy = "") {
8010
- 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);
8014
+ 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);
8011
8015
  return Mnemonic.entropyToMnemonic(entropy);
8012
8016
  }
8013
8017
  };
@@ -8015,12 +8019,12 @@ var mnemonic_default = Mnemonic;
8015
8019
 
8016
8020
  // src/hdwallet/hdwallet.ts
8017
8021
  var HARDENED_INDEX = 2147483648;
8018
- var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8019
- var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8020
- var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8021
- var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8022
+ var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8023
+ var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8024
+ var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8025
+ var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8022
8026
  function base58check(data) {
8023
- 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)]));
8027
+ 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)]));
8024
8028
  }
8025
8029
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8026
8030
  if (isPublic) {
@@ -8029,11 +8033,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8029
8033
  return testnet ? TestnetPRV2 : MainnetPRV2;
8030
8034
  }
8031
8035
  function isPublicExtendedKey(extendedKey) {
8032
- return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8036
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8033
8037
  }
8034
8038
  function isValidExtendedKey(extendedKey) {
8035
8039
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8036
- (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8040
+ (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8037
8041
  );
8038
8042
  }
8039
8043
  function parsePath(path2, depth = 0) {
@@ -8051,8 +8055,8 @@ function parsePath(path2, depth = 0) {
8051
8055
  var HDWallet = class {
8052
8056
  depth = 0;
8053
8057
  index = 0;
8054
- fingerprint = (0, import_utils36.hexlify)("0x00000000");
8055
- parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8058
+ fingerprint = (0, import_utils35.hexlify)("0x00000000");
8059
+ parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8056
8060
  privateKey;
8057
8061
  publicKey;
8058
8062
  chainCode;
@@ -8064,8 +8068,8 @@ var HDWallet = class {
8064
8068
  constructor(config) {
8065
8069
  if (config.privateKey) {
8066
8070
  const signer = new Signer(config.privateKey);
8067
- this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8068
- this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8071
+ this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8072
+ this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8069
8073
  } else {
8070
8074
  if (!config.publicKey) {
8071
8075
  throw new import_errors20.FuelError(
@@ -8073,10 +8077,10 @@ var HDWallet = class {
8073
8077
  "Both public and private Key cannot be missing. At least one should be provided."
8074
8078
  );
8075
8079
  }
8076
- this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8080
+ this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8077
8081
  }
8078
8082
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8079
- this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8083
+ this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8080
8084
  this.depth = config.depth || this.depth;
8081
8085
  this.index = config.index || this.index;
8082
8086
  this.chainCode = config.chainCode;
@@ -8092,9 +8096,9 @@ var HDWallet = class {
8092
8096
  * @returns A new instance of HDWallet on the derived index
8093
8097
  */
8094
8098
  deriveIndex(index) {
8095
- const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8096
- const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8097
- const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8099
+ const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8100
+ const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8101
+ const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8098
8102
  const data = new Uint8Array(37);
8099
8103
  if (index & HARDENED_INDEX) {
8100
8104
  if (!privateKey) {
@@ -8105,10 +8109,10 @@ var HDWallet = class {
8105
8109
  }
8106
8110
  data.set(privateKey, 1);
8107
8111
  } else {
8108
- data.set((0, import_utils36.arrayify)(this.publicKey));
8112
+ data.set((0, import_utils35.arrayify)(this.publicKey));
8109
8113
  }
8110
8114
  data.set((0, import_math22.toBytes)(index, 4), 33);
8111
- const bytes = (0, import_utils36.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8115
+ const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8112
8116
  const IL = bytes.slice(0, 32);
8113
8117
  const IR = bytes.slice(32);
8114
8118
  if (privateKey) {
@@ -8122,7 +8126,7 @@ var HDWallet = class {
8122
8126
  parentFingerprint: this.fingerprint
8123
8127
  });
8124
8128
  }
8125
- const signer = new Signer((0, import_utils36.hexlify)(IL));
8129
+ const signer = new Signer((0, import_utils35.hexlify)(IL));
8126
8130
  const Ki = signer.addPoint(publicKey);
8127
8131
  return new HDWallet({
8128
8132
  publicKey: Ki,
@@ -8157,12 +8161,12 @@ var HDWallet = class {
8157
8161
  );
8158
8162
  }
8159
8163
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8160
- const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
8164
+ const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8161
8165
  const parentFingerprint = this.parentFingerprint;
8162
8166
  const index = (0, import_math22.toHex)(this.index, 4);
8163
8167
  const chainCode = this.chainCode;
8164
- const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8165
- const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8168
+ const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8169
+ const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8166
8170
  return base58check(extendedKey);
8167
8171
  }
8168
8172
  /**
@@ -8174,13 +8178,13 @@ var HDWallet = class {
8174
8178
  static fromSeed(seed) {
8175
8179
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8176
8180
  return new HDWallet({
8177
- chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8178
- privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
8181
+ chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8182
+ privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8179
8183
  });
8180
8184
  }
8181
8185
  static fromExtendedKey(extendedKey) {
8182
- const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8183
- const bytes = (0, import_utils36.arrayify)(decoded);
8186
+ const decoded = (0, import_utils35.hexlify)((0, import_math22.toBytes)((0, import_utils35.decodeBase58)(extendedKey)));
8187
+ const bytes = (0, import_utils35.arrayify)(decoded);
8184
8188
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8185
8189
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8186
8190
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8189,9 +8193,9 @@ var HDWallet = class {
8189
8193
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8190
8194
  }
8191
8195
  const depth = bytes[4];
8192
- const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8193
- const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8194
- const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
8196
+ const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8197
+ const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8198
+ const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8195
8199
  const key = bytes.slice(45, 78);
8196
8200
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8197
8201
  throw new import_errors20.FuelError(
@@ -8410,7 +8414,7 @@ var generateTestWallet = async (provider, quantities) => {
8410
8414
  // src/test-utils/launchNode.ts
8411
8415
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
8412
8416
  var import_crypto7 = require("@fuel-ts/crypto");
8413
- var import_utils37 = require("@fuel-ts/utils");
8417
+ var import_utils36 = require("@fuel-ts/utils");
8414
8418
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8415
8419
  var import_child_process = require("child_process");
8416
8420
  var import_crypto8 = require("crypto");
@@ -8450,49 +8454,15 @@ var killNode = (params) => {
8450
8454
  }
8451
8455
  }
8452
8456
  };
8453
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8454
- const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8455
- ...coin,
8456
- amount: "18446744073709551615"
8457
- }));
8458
- const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8459
- ...message,
8460
- amount: "18446744073709551615"
8461
- }));
8462
- 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);
8463
- 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);
8464
- if (!process.env.GENESIS_SECRET) {
8465
- const pk = Signer.generatePrivateKey();
8466
- const signer = new Signer(pk);
8467
- process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8468
- coins.push({
8469
- tx_id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8470
- owner: signer.address.toHexString(),
8471
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8472
- amount: "18446744073709551615",
8473
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8474
- output_index: 0,
8475
- tx_pointer_block_height: 0,
8476
- tx_pointer_tx_idx: 0
8477
- });
8478
- }
8479
- const json = JSON.stringify({
8480
- ...stateConfig,
8481
- coins,
8482
- messages
8483
- });
8484
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8485
- return json.replace(regexMakeNumber, "$1$2");
8486
- }
8487
8457
  var launchNode = async ({
8488
8458
  ip,
8489
8459
  port,
8490
8460
  args = [],
8461
+ fuelCorePath = void 0,
8491
8462
  useSystemFuelCore = false,
8492
8463
  loggingEnabled = true,
8493
8464
  debugEnabled = false,
8494
- basePath,
8495
- snapshotConfig = import_utils37.defaultSnapshotConfigs
8465
+ basePath
8496
8466
  }) => (
8497
8467
  // eslint-disable-next-line no-async-promise-executor
8498
8468
  new Promise(async (resolve, reject) => {
@@ -8503,13 +8473,13 @@ var launchNode = async ({
8503
8473
  "--poa-instant"
8504
8474
  ]);
8505
8475
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8506
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8476
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8507
8477
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8508
8478
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8509
8479
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8510
8480
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8511
8481
  const graphQLStartSubstring = "Binding GraphQL provider to";
8512
- const binPath = (0, import_cli_utils.findBinPath)("fuels-core", __dirname);
8482
+ const binPath = fuelCorePath ?? (0, import_cli_utils.findBinPath)("fuels-core", __dirname);
8513
8483
  const command = useSystemFuelCore ? "fuel-core" : binPath;
8514
8484
  const ipToUse = ip || "0.0.0.0";
8515
8485
  const portToUse = port || (await (0, import_portfinder.getPortPromise)({
@@ -8521,23 +8491,56 @@ var launchNode = async ({
8521
8491
  let snapshotDirToUse;
8522
8492
  const prefix = basePath || import_os.default.tmpdir();
8523
8493
  const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
8524
- const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8494
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8525
8495
  if (snapshotDir) {
8526
8496
  snapshotDirToUse = snapshotDir;
8527
8497
  } else {
8528
- if (!(0, import_fs.existsSync)(tempDir)) {
8529
- (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8498
+ if (!(0, import_fs.existsSync)(tempDirPath)) {
8499
+ (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8500
+ }
8501
+ let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
8502
+ const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
8503
+ stateConfigJson = {
8504
+ ...stateConfigJson,
8505
+ coins: [
8506
+ ...stateConfigJson.coins.map((coin) => ({
8507
+ ...coin,
8508
+ amount: "18446744073709551615"
8509
+ }))
8510
+ ],
8511
+ messages: stateConfigJson.messages.map((message) => ({
8512
+ ...message,
8513
+ amount: "18446744073709551615"
8514
+ }))
8515
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8516
+ };
8517
+ if (!process.env.GENESIS_SECRET) {
8518
+ const pk = Signer.generatePrivateKey();
8519
+ const signer = new Signer(pk);
8520
+ process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8521
+ stateConfigJson.coins.push({
8522
+ tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8523
+ owner: signer.address.toHexString(),
8524
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8525
+ amount: "18446744073709551615",
8526
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8527
+ output_index: 0,
8528
+ tx_pointer_block_height: 0,
8529
+ tx_pointer_tx_idx: 0
8530
+ });
8530
8531
  }
8531
- const { metadata } = snapshotConfig;
8532
- const metadataPath = import_path.default.join(tempDir, "metadata.json");
8533
- const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8534
- const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8535
- const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8536
- (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8537
- (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8538
- (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8539
- (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8540
- snapshotDirToUse = tempDir;
8532
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8533
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8534
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8535
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8536
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8537
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8538
+ const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
8539
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8540
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8541
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8542
+ (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
8543
+ snapshotDirToUse = tempDirPath;
8541
8544
  }
8542
8545
  const child = (0, import_child_process.spawn)(
8543
8546
  command,
@@ -8545,7 +8548,7 @@ var launchNode = async ({
8545
8548
  "run",
8546
8549
  ["--ip", ipToUse],
8547
8550
  ["--port", portToUse],
8548
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8551
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8549
8552
  ["--min-gas-price", "1"],
8550
8553
  poaInstant ? ["--poa-instant", "true"] : [],
8551
8554
  ["--consensus-key", consensusKey],
@@ -8567,28 +8570,23 @@ var launchNode = async ({
8567
8570
  }
8568
8571
  const cleanupConfig = {
8569
8572
  child,
8570
- configPath: tempDir,
8573
+ configPath: tempDirPath,
8571
8574
  killFn: import_tree_kill.default,
8572
8575
  state: {
8573
8576
  isDead: false
8574
8577
  }
8575
8578
  };
8576
8579
  child.stderr.on("data", (chunk) => {
8577
- const text = typeof chunk === "string" ? chunk : chunk.toString();
8578
- if (text.indexOf(graphQLStartSubstring) !== -1) {
8579
- const rows = text.split("\n");
8580
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8581
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8580
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
8582
8581
  resolve({
8583
8582
  cleanup: () => killNode(cleanupConfig),
8584
- ip: realIp,
8585
- port: realPort,
8586
- url: `http://${realIp}:${realPort}/v1/graphql`,
8583
+ ip: ipToUse,
8584
+ port: portToUse,
8587
8585
  snapshotDir: snapshotDirToUse
8588
8586
  });
8589
8587
  }
8590
- if (/error/i.test(text)) {
8591
- reject(text.toString());
8588
+ if (/error/i.test(chunk)) {
8589
+ reject(chunk.toString());
8592
8590
  }
8593
8591
  });
8594
8592
  process.on("exit", () => killNode(cleanupConfig));
@@ -8621,243 +8619,12 @@ var launchNodeAndGetWallets = async ({
8621
8619
  };
8622
8620
  return { wallets, stop: cleanup, provider };
8623
8621
  };
8624
-
8625
- // src/test-utils/setup-test-provider-and-wallets.ts
8626
- var import_utils40 = require("@fuel-ts/utils");
8627
- var import_ramda5 = require("ramda");
8628
-
8629
- // src/test-utils/asset-id.ts
8630
- var import_crypto9 = require("@fuel-ts/crypto");
8631
- var import_utils38 = require("@fuel-ts/utils");
8632
- var _AssetId = class {
8633
- constructor(value) {
8634
- this.value = value;
8635
- }
8636
- static random() {
8637
- return new _AssetId((0, import_utils38.hexlify)((0, import_crypto9.randomBytes)(32)));
8638
- }
8639
- };
8640
- var AssetId = _AssetId;
8641
- __publicField(AssetId, "A", new _AssetId(
8642
- "0x0101010101010101010101010101010101010101010101010101010101010101"
8643
- ));
8644
- __publicField(AssetId, "B", new _AssetId(
8645
- "0x0202020202020202020202020202020202020202020202020202020202020202"
8646
- ));
8647
-
8648
- // src/test-utils/wallet-config.ts
8649
- var import_crypto10 = require("@fuel-ts/crypto");
8650
- var import_errors21 = require("@fuel-ts/errors");
8651
- var import_utils39 = require("@fuel-ts/utils");
8652
- var WalletConfig = class {
8653
- initialState;
8654
- options;
8655
- wallets;
8656
- generateWallets = () => {
8657
- const generatedWallets = [];
8658
- for (let index = 1; index <= this.options.count; index++) {
8659
- generatedWallets.push(new WalletUnlocked((0, import_crypto10.randomBytes)(32)));
8660
- }
8661
- return generatedWallets;
8662
- };
8663
- constructor(baseAssetId, config) {
8664
- WalletConfig.validate(config);
8665
- this.options = config;
8666
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8667
- this.wallets = this.generateWallets();
8668
- this.initialState = {
8669
- messages: WalletConfig.createMessages(this.wallets, messages),
8670
- coins: WalletConfig.createCoins(
8671
- this.wallets,
8672
- baseAssetId,
8673
- assets2,
8674
- coinsPerAsset,
8675
- amountPerCoin
8676
- )
8677
- };
8678
- }
8679
- apply(snapshotConfig) {
8680
- return {
8681
- ...snapshotConfig,
8682
- stateConfig: {
8683
- ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
8684
- coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8685
- messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8686
- }
8687
- };
8688
- }
8689
- /**
8690
- * Create messages for the wallets in the format that the chain expects.
8691
- */
8692
- static createMessages(wallets, messages) {
8693
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8694
- }
8695
- /**
8696
- * Create coins for the wallets in the format that the chain expects.
8697
- */
8698
- static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
8699
- const coins = [];
8700
- let assetIds = [baseAssetId];
8701
- if (Array.isArray(assets2)) {
8702
- assetIds = assetIds.concat(assets2.map((a) => a.value));
8703
- } else {
8704
- for (let index = 0; index < assets2 - 1; index++) {
8705
- assetIds.push(AssetId.random().value);
8706
- }
8707
- }
8708
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8709
- assetIds.forEach((assetId) => {
8710
- for (let index = 0; index < coinsPerAsset; index++) {
8711
- coins.push({
8712
- amount: amountPerCoin,
8713
- asset_id: assetId,
8714
- owner: walletAddress,
8715
- tx_pointer_block_height: 0,
8716
- tx_pointer_tx_idx: 0,
8717
- output_index: 0,
8718
- tx_id: (0, import_utils39.hexlify)((0, import_crypto10.randomBytes)(32))
8719
- });
8720
- }
8721
- });
8722
- });
8723
- return coins;
8724
- }
8725
- static validate({
8726
- count: wallets,
8727
- assets: assets2,
8728
- coinsPerAsset,
8729
- amountPerCoin
8730
- }) {
8731
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8732
- throw new import_errors21.FuelError(
8733
- import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8734
- "Number of wallets must be greater than zero."
8735
- );
8736
- }
8737
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8738
- throw new import_errors21.FuelError(
8739
- import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8740
- "Number of assets per wallet must be greater than zero."
8741
- );
8742
- }
8743
- if (coinsPerAsset <= 0) {
8744
- throw new import_errors21.FuelError(
8745
- import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8746
- "Number of coins per asset must be greater than zero."
8747
- );
8748
- }
8749
- if (amountPerCoin <= 0) {
8750
- throw new import_errors21.FuelError(
8751
- import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8752
- "Amount per coin must be greater than zero."
8753
- );
8754
- }
8755
- }
8756
- };
8757
-
8758
- // src/test-utils/setup-test-provider-and-wallets.ts
8759
- var defaultWalletConfigOptions = {
8760
- count: 2,
8761
- assets: [AssetId.A, AssetId.B],
8762
- coinsPerAsset: 1,
8763
- amountPerCoin: 1e10,
8764
- messages: []
8765
- };
8766
- async function setupTestProviderAndWallets({
8767
- walletConfig: walletConfigOptions = {},
8768
- providerOptions,
8769
- nodeOptions = {}
8770
- } = {}) {
8771
- Symbol.dispose ??= Symbol("Symbol.dispose");
8772
- const walletConfig = new WalletConfig(
8773
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
8774
- {
8775
- ...defaultWalletConfigOptions,
8776
- ...walletConfigOptions
8777
- }
8778
- );
8779
- const { cleanup, url } = await launchNode({
8780
- loggingEnabled: false,
8781
- ...nodeOptions,
8782
- snapshotConfig: (0, import_ramda5.mergeDeepRight)(
8783
- import_utils40.defaultSnapshotConfigs,
8784
- walletConfig.apply(nodeOptions?.snapshotConfig)
8785
- ),
8786
- port: "0"
8787
- });
8788
- let provider;
8789
- try {
8790
- provider = await Provider.create(url, providerOptions);
8791
- } catch (err) {
8792
- cleanup();
8793
- throw err;
8794
- }
8795
- const wallets = walletConfig.wallets;
8796
- wallets.forEach((wallet) => {
8797
- wallet.connect(provider);
8798
- });
8799
- return {
8800
- provider,
8801
- wallets,
8802
- cleanup,
8803
- [Symbol.dispose]: cleanup
8804
- };
8805
- }
8806
-
8807
- // src/test-utils/test-message.ts
8808
- var import_address7 = require("@fuel-ts/address");
8809
- var import_crypto11 = require("@fuel-ts/crypto");
8810
- var import_math23 = require("@fuel-ts/math");
8811
- var import_utils41 = require("@fuel-ts/utils");
8812
- var TestMessage = class {
8813
- sender;
8814
- recipient;
8815
- nonce;
8816
- amount;
8817
- data;
8818
- da_height;
8819
- /**
8820
- * A helper class to create messages for testing purposes.
8821
- *
8822
- * Used in tandem with `WalletConfig`.
8823
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
8824
- */
8825
- constructor({
8826
- sender = import_address7.Address.fromRandom(),
8827
- recipient = import_address7.Address.fromRandom(),
8828
- nonce = (0, import_utils41.hexlify)((0, import_crypto11.randomBytes)(32)),
8829
- amount = 1e6,
8830
- data = "02",
8831
- da_height = 0
8832
- } = {}) {
8833
- this.sender = sender;
8834
- this.recipient = recipient;
8835
- this.nonce = nonce;
8836
- this.amount = amount;
8837
- this.data = data;
8838
- this.da_height = da_height;
8839
- }
8840
- toChainMessage(recipient) {
8841
- return {
8842
- sender: this.sender.toB256(),
8843
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
8844
- nonce: this.nonce,
8845
- amount: (0, import_math23.bn)(this.amount).toNumber(),
8846
- data: this.data,
8847
- da_height: this.da_height
8848
- };
8849
- }
8850
- };
8851
8622
  // Annotate the CommonJS export names for ESM import in node:
8852
8623
  0 && (module.exports = {
8853
- AssetId,
8854
- TestMessage,
8855
- WalletConfig,
8856
8624
  generateTestWallet,
8857
8625
  killNode,
8858
8626
  launchNode,
8859
8627
  launchNodeAndGetWallets,
8860
- seedTestWallet,
8861
- setupTestProviderAndWallets
8628
+ seedTestWallet
8862
8629
  });
8863
8630
  //# sourceMappingURL=test-utils.js.map