@fuel-ts/account 0.0.0-rc-2143-20240520152005 → 0.0.0-rc-1356-20240520163254

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_math20 = 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_math17 = 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
 
@@ -1669,15 +1673,6 @@ function normalizeJSON(root) {
1669
1673
  return normalize((0, import_ramda.clone)(root));
1670
1674
  }
1671
1675
 
1672
- // src/providers/utils/sleep.ts
1673
- function sleep(time) {
1674
- return new Promise((resolve) => {
1675
- setTimeout(() => {
1676
- resolve(true);
1677
- }, time);
1678
- });
1679
- }
1680
-
1681
1676
  // src/providers/utils/extract-tx-error.ts
1682
1677
  var import_errors7 = require("@fuel-ts/errors");
1683
1678
  var import_math6 = require("@fuel-ts/math");
@@ -3618,6 +3613,7 @@ var TransactionResponse = class {
3618
3613
  };
3619
3614
 
3620
3615
  // src/providers/utils/auto-retry-fetch.ts
3616
+ var import_utils22 = require("@fuel-ts/utils");
3621
3617
  function getWaitDelay(options, retryAttemptNum) {
3622
3618
  const duration = options.baseDelay ?? 150;
3623
3619
  switch (options.backoff) {
@@ -3647,7 +3643,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3647
3643
  throw error;
3648
3644
  }
3649
3645
  const delay = getWaitDelay(options, retryNum);
3650
- await sleep(delay);
3646
+ await (0, import_utils22.sleep)(delay);
3651
3647
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3652
3648
  }
3653
3649
  };
@@ -3987,7 +3983,7 @@ Supported fuel-core version: ${supportedVersion}.`
3987
3983
  if (estimateTxDependencies) {
3988
3984
  await this.estimateTxDependencies(transactionRequest);
3989
3985
  }
3990
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3986
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3991
3987
  let abis;
3992
3988
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
3993
3989
  abis = transactionRequest.abis;
@@ -4030,7 +4026,7 @@ Supported fuel-core version: ${supportedVersion}.`
4030
4026
  if (estimateTxDependencies) {
4031
4027
  return this.estimateTxDependencies(transactionRequest);
4032
4028
  }
4033
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4029
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4034
4030
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4035
4031
  encodedTransactions: encodedTransaction,
4036
4032
  utxoValidation: utxoValidation || false
@@ -4048,13 +4044,13 @@ Supported fuel-core version: ${supportedVersion}.`
4048
4044
  async estimatePredicates(transactionRequest) {
4049
4045
  const shouldEstimatePredicates = Boolean(
4050
4046
  transactionRequest.inputs.find(
4051
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4047
+ (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
4048
  )
4053
4049
  );
4054
4050
  if (!shouldEstimatePredicates) {
4055
4051
  return transactionRequest;
4056
4052
  }
4057
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4053
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4058
4054
  const response = await this.operations.estimatePredicates({
4059
4055
  encodedTransaction
4060
4056
  });
@@ -4096,7 +4092,7 @@ Supported fuel-core version: ${supportedVersion}.`
4096
4092
  const {
4097
4093
  dryRun: [{ receipts: rawReceipts, status }]
4098
4094
  } = await this.operations.dryRun({
4099
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4095
+ encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4100
4096
  utxoValidation: false
4101
4097
  });
4102
4098
  receipts = rawReceipts.map(processGqlReceipt);
@@ -4146,7 +4142,7 @@ Supported fuel-core version: ${supportedVersion}.`
4146
4142
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4147
4143
  allRequests.forEach((req, index) => {
4148
4144
  if (req.type === import_transactions20.TransactionType.Script) {
4149
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4145
+ serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4150
4146
  }
4151
4147
  });
4152
4148
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4182,7 +4178,7 @@ Supported fuel-core version: ${supportedVersion}.`
4182
4178
  transactionRequest: request
4183
4179
  });
4184
4180
  request.maxFee = maxFee;
4185
- serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4181
+ serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4186
4182
  nextRoundTransactions.push(requestIdx);
4187
4183
  }
4188
4184
  }
@@ -4195,7 +4191,7 @@ Supported fuel-core version: ${supportedVersion}.`
4195
4191
  if (estimateTxDependencies) {
4196
4192
  return this.estimateMultipleTxDependencies(transactionRequests);
4197
4193
  }
4198
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4194
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4199
4195
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4200
4196
  encodedTransactions,
4201
4197
  utxoValidation: utxoValidation || false
@@ -4268,7 +4264,7 @@ Supported fuel-core version: ${supportedVersion}.`
4268
4264
  if (estimateTxDependencies) {
4269
4265
  return this.estimateTxDependencies(transactionRequest);
4270
4266
  }
4271
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4267
+ const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4272
4268
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4273
4269
  encodedTransactions,
4274
4270
  utxoValidation: true
@@ -4387,7 +4383,7 @@ Supported fuel-core version: ${supportedVersion}.`
4387
4383
  const result = await this.operations.getCoins({
4388
4384
  first: 10,
4389
4385
  ...paginationArgs,
4390
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4386
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4391
4387
  });
4392
4388
  const coins = result.coins.edges.map((edge) => edge.node);
4393
4389
  return coins.map((coin) => ({
@@ -4410,19 +4406,19 @@ Supported fuel-core version: ${supportedVersion}.`
4410
4406
  async getResourcesToSpend(owner, quantities, excludedIds) {
4411
4407
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4412
4408
  const excludeInput = {
4413
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4414
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4409
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4410
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4415
4411
  };
4416
4412
  if (this.cache) {
4417
4413
  const uniqueUtxos = new Set(
4418
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4414
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4419
4415
  );
4420
4416
  excludeInput.utxos = Array.from(uniqueUtxos);
4421
4417
  }
4422
4418
  const coinsQuery = {
4423
4419
  owner: ownerAddress.toB256(),
4424
4420
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4425
- assetId: (0, import_utils22.hexlify)(assetId),
4421
+ assetId: (0, import_utils23.hexlify)(assetId),
4426
4422
  amount: amount.toString(10),
4427
4423
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4428
4424
  })),
@@ -4524,7 +4520,7 @@ Supported fuel-core version: ${supportedVersion}.`
4524
4520
  time: block.header.time,
4525
4521
  transactionIds: block.transactions.map((tx) => tx.id),
4526
4522
  transactions: block.transactions.map(
4527
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4523
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4528
4524
  )
4529
4525
  };
4530
4526
  }
@@ -4540,7 +4536,7 @@ Supported fuel-core version: ${supportedVersion}.`
4540
4536
  return null;
4541
4537
  }
4542
4538
  return new import_transactions20.TransactionCoder().decode(
4543
- (0, import_utils22.arrayify)(transaction.rawPayload),
4539
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4544
4540
  0
4545
4541
  )?.[0];
4546
4542
  }
@@ -4567,7 +4563,7 @@ Supported fuel-core version: ${supportedVersion}.`
4567
4563
  async getContractBalance(contractId, assetId) {
4568
4564
  const { contractBalance } = await this.operations.getContractBalance({
4569
4565
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4570
- asset: (0, import_utils22.hexlify)(assetId)
4566
+ asset: (0, import_utils23.hexlify)(assetId)
4571
4567
  });
4572
4568
  return (0, import_math17.bn)(contractBalance.amount, 10);
4573
4569
  }
@@ -4581,7 +4577,7 @@ Supported fuel-core version: ${supportedVersion}.`
4581
4577
  async getBalance(owner, assetId) {
4582
4578
  const { balance } = await this.operations.getBalance({
4583
4579
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4584
- assetId: (0, import_utils22.hexlify)(assetId)
4580
+ assetId: (0, import_utils23.hexlify)(assetId)
4585
4581
  });
4586
4582
  return (0, import_math17.bn)(balance.amount, 10);
4587
4583
  }
@@ -4758,7 +4754,7 @@ Supported fuel-core version: ${supportedVersion}.`
4758
4754
  async produceBlocks(amount, startTime) {
4759
4755
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4760
4756
  blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4761
- startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4757
+ startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4762
4758
  });
4763
4759
  return (0, import_math17.bn)(latestBlockHeight);
4764
4760
  }
@@ -4824,7 +4820,7 @@ __publicField(Provider, "nodeInfoCache", {});
4824
4820
  var import_errors15 = require("@fuel-ts/errors");
4825
4821
  var import_math18 = require("@fuel-ts/math");
4826
4822
  var import_transactions21 = require("@fuel-ts/transactions");
4827
- var import_utils25 = require("@fuel-ts/utils");
4823
+ var import_utils26 = require("@fuel-ts/utils");
4828
4824
 
4829
4825
  // src/providers/chains.ts
4830
4826
  var CHAIN_IDS = {
@@ -4900,16 +4896,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
4900
4896
  // src/utils/formatTransferToContractScriptData.ts
4901
4897
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4902
4898
  var import_math19 = require("@fuel-ts/math");
4903
- var import_utils27 = require("@fuel-ts/utils");
4899
+ var import_utils28 = require("@fuel-ts/utils");
4904
4900
  var asm = __toESM(require("@fuels/vm-asm"));
4905
4901
  var formatTransferToContractScriptData = (params) => {
4906
4902
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4907
4903
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4908
4904
  const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
4909
4905
  const scriptData = Uint8Array.from([
4910
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4906
+ ...(0, import_utils28.arrayify)(hexlifiedContractId),
4911
4907
  ...encoded,
4912
- ...(0, import_utils27.arrayify)(assetId)
4908
+ ...(0, import_utils28.arrayify)(assetId)
4913
4909
  ]);
4914
4910
  return scriptData;
4915
4911
  };
@@ -5280,14 +5276,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5280
5276
  */
5281
5277
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5282
5278
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5283
- const recipientDataArray = (0, import_utils28.arrayify)(
5279
+ const recipientDataArray = (0, import_utils29.arrayify)(
5284
5280
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5285
5281
  );
5286
- const amountDataArray = (0, import_utils28.arrayify)(
5282
+ const amountDataArray = (0, import_utils29.arrayify)(
5287
5283
  "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
5288
5284
  );
5289
5285
  const script = new Uint8Array([
5290
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5286
+ ...(0, import_utils29.arrayify)(withdrawScript.bytes),
5291
5287
  ...recipientDataArray,
5292
5288
  ...amountDataArray
5293
5289
  ]);
@@ -5367,7 +5363,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5367
5363
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5368
5364
  }) {
5369
5365
  const request = transactionRequestify(transactionRequest);
5370
- if (!(0, import_utils28.isDefined)(setGasLimit)) {
5366
+ if (!(0, import_utils29.isDefined)(setGasLimit)) {
5371
5367
  request.gasLimit = gasUsed;
5372
5368
  } else if (gasUsed.gt(setGasLimit)) {
5373
5369
  throw new import_errors16.FuelError(
@@ -5375,7 +5371,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5375
5371
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5376
5372
  );
5377
5373
  }
5378
- if (!(0, import_utils28.isDefined)(setMaxFee)) {
5374
+ if (!(0, import_utils29.isDefined)(setMaxFee)) {
5379
5375
  request.maxFee = maxFee;
5380
5376
  } else if (maxFee.gt(setMaxFee)) {
5381
5377
  throw new import_errors16.FuelError(
@@ -5392,7 +5388,7 @@ var import_address5 = require("@fuel-ts/address");
5392
5388
  var import_crypto2 = require("@fuel-ts/crypto");
5393
5389
  var import_hasher2 = require("@fuel-ts/hasher");
5394
5390
  var import_math21 = require("@fuel-ts/math");
5395
- var import_utils29 = require("@fuel-ts/utils");
5391
+ var import_utils30 = require("@fuel-ts/utils");
5396
5392
  var import_secp256k1 = require("@noble/curves/secp256k1");
5397
5393
  var Signer = class {
5398
5394
  address;
@@ -5412,9 +5408,9 @@ var Signer = class {
5412
5408
  }
5413
5409
  }
5414
5410
  const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5415
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5416
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5417
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5411
+ this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5412
+ this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5413
+ this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5418
5414
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5419
5415
  }
5420
5416
  /**
@@ -5428,11 +5424,11 @@ var Signer = class {
5428
5424
  * @returns hashed signature
5429
5425
  */
5430
5426
  sign(data) {
5431
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5427
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5432
5428
  const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5433
5429
  const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5434
5430
  s[0] |= (signature.recovery || 0) << 7;
5435
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5431
+ return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5436
5432
  }
5437
5433
  /**
5438
5434
  * Add point on the current elliptic curve
@@ -5441,8 +5437,8 @@ var Signer = class {
5441
5437
  * @returns compressed point on the curve
5442
5438
  */
5443
5439
  addPoint(point) {
5444
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5445
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5440
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5441
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5446
5442
  const result = p0.add(p1);
5447
5443
  return `0x${result.toHex(true)}`;
5448
5444
  }
@@ -5454,16 +5450,16 @@ var Signer = class {
5454
5450
  * @returns public key from signature from the
5455
5451
  */
5456
5452
  static recoverPublicKey(data, signature) {
5457
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5453
+ const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5458
5454
  const r = signedMessageBytes.slice(0, 32);
5459
5455
  const s = signedMessageBytes.slice(32, 64);
5460
5456
  const recoveryParam = (s[0] & 128) >> 7;
5461
5457
  s[0] &= 127;
5462
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5458
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5463
5459
  recoveryParam
5464
5460
  );
5465
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5466
- return (0, import_utils29.hexlify)(publicKey);
5461
+ const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5462
+ return (0, import_utils30.hexlify)(publicKey);
5467
5463
  }
5468
5464
  /**
5469
5465
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5482,7 +5478,7 @@ var Signer = class {
5482
5478
  * @returns random 32-byte hashed
5483
5479
  */
5484
5480
  static generatePrivateKey(entropy) {
5485
- 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);
5481
+ 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);
5486
5482
  }
5487
5483
  /**
5488
5484
  * Extended publicKey from a compact publicKey
@@ -5491,8 +5487,8 @@ var Signer = class {
5491
5487
  * @returns extended publicKey
5492
5488
  */
5493
5489
  static extendPublicKey(publicKey) {
5494
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5495
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5490
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5491
+ return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5496
5492
  }
5497
5493
  };
5498
5494
 
@@ -5500,7 +5496,7 @@ var Signer = class {
5500
5496
  var import_address6 = require("@fuel-ts/address");
5501
5497
  var import_crypto3 = require("@fuel-ts/crypto");
5502
5498
  var import_errors17 = require("@fuel-ts/errors");
5503
- var import_utils30 = require("@fuel-ts/utils");
5499
+ var import_utils31 = require("@fuel-ts/utils");
5504
5500
  var import_uuid = require("uuid");
5505
5501
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5506
5502
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5583,7 +5579,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5583
5579
  );
5584
5580
  }
5585
5581
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5586
- const privateKey = (0, import_utils30.hexlify)(buffer);
5582
+ const privateKey = (0, import_utils31.hexlify)(buffer);
5587
5583
  return privateKey;
5588
5584
  }
5589
5585
 
@@ -5628,7 +5624,7 @@ var BaseWalletUnlocked = class extends Account {
5628
5624
  */
5629
5625
  async signMessage(message) {
5630
5626
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5631
- return (0, import_utils31.hexlify)(signedMessage);
5627
+ return (0, import_utils32.hexlify)(signedMessage);
5632
5628
  }
5633
5629
  /**
5634
5630
  * Signs a transaction with the wallet's private key.
@@ -5641,7 +5637,7 @@ var BaseWalletUnlocked = class extends Account {
5641
5637
  const chainId = this.provider.getChainId();
5642
5638
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5643
5639
  const signature = await this.signer().sign(hashedTransaction);
5644
- return (0, import_utils31.hexlify)(signature);
5640
+ return (0, import_utils32.hexlify)(signature);
5645
5641
  }
5646
5642
  /**
5647
5643
  * Populates a transaction with the witnesses signature.
@@ -5704,13 +5700,13 @@ var import_crypto5 = require("@fuel-ts/crypto");
5704
5700
  var import_errors20 = require("@fuel-ts/errors");
5705
5701
  var import_hasher6 = require("@fuel-ts/hasher");
5706
5702
  var import_math22 = require("@fuel-ts/math");
5707
- var import_utils35 = require("@fuel-ts/utils");
5703
+ var import_utils36 = require("@fuel-ts/utils");
5708
5704
 
5709
5705
  // src/mnemonic/mnemonic.ts
5710
5706
  var import_crypto4 = require("@fuel-ts/crypto");
5711
5707
  var import_errors19 = require("@fuel-ts/errors");
5712
5708
  var import_hasher5 = require("@fuel-ts/hasher");
5713
- var import_utils33 = require("@fuel-ts/utils");
5709
+ var import_utils34 = require("@fuel-ts/utils");
5714
5710
 
5715
5711
  // src/wordlists/words/english.ts
5716
5712
  var english = [
@@ -7767,7 +7763,7 @@ var english = [
7767
7763
  // src/mnemonic/utils.ts
7768
7764
  var import_errors18 = require("@fuel-ts/errors");
7769
7765
  var import_hasher4 = require("@fuel-ts/hasher");
7770
- var import_utils32 = require("@fuel-ts/utils");
7766
+ var import_utils33 = require("@fuel-ts/utils");
7771
7767
  function getLowerMask(bits) {
7772
7768
  return (1 << bits) - 1;
7773
7769
  }
@@ -7802,14 +7798,14 @@ function entropyToMnemonicIndices(entropy) {
7802
7798
  }
7803
7799
  }
7804
7800
  const checksumBits = entropy.length / 4;
7805
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7801
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7806
7802
  indices[indices.length - 1] <<= checksumBits;
7807
7803
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7808
7804
  return indices;
7809
7805
  }
7810
7806
  function mnemonicWordsToEntropy(words, wordlist) {
7811
7807
  const size = Math.ceil(11 * words.length / 8);
7812
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7808
+ const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
7813
7809
  let offset = 0;
7814
7810
  for (let i = 0; i < words.length; i += 1) {
7815
7811
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7829,7 +7825,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7829
7825
  const entropyBits = 32 * words.length / 3;
7830
7826
  const checksumBits = words.length / 3;
7831
7827
  const checksumMask = getUpperMask(checksumBits);
7832
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7828
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7833
7829
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7834
7830
  throw new import_errors18.FuelError(
7835
7831
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7840,7 +7836,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7840
7836
  }
7841
7837
 
7842
7838
  // src/mnemonic/mnemonic.ts
7843
- var MasterSecret = (0, import_utils33.toUtf8Bytes)("Bitcoin seed");
7839
+ var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
7844
7840
  var MainnetPRV = "0x0488ade4";
7845
7841
  var TestnetPRV = "0x04358394";
7846
7842
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
@@ -7904,7 +7900,7 @@ var Mnemonic = class {
7904
7900
  static mnemonicToEntropy(phrase, wordlist = english) {
7905
7901
  const words = getWords(phrase);
7906
7902
  assertMnemonic(words);
7907
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7903
+ return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7908
7904
  }
7909
7905
  /**
7910
7906
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7912,7 +7908,7 @@ var Mnemonic = class {
7912
7908
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7913
7909
  */
7914
7910
  static entropyToMnemonic(entropy, wordlist = english) {
7915
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7911
+ const entropyBytes = (0, import_utils34.arrayify)(entropy);
7916
7912
  assertWordList(wordlist);
7917
7913
  assertEntropy(entropyBytes);
7918
7914
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7924,8 +7920,8 @@ var Mnemonic = class {
7924
7920
  */
7925
7921
  static mnemonicToSeed(phrase, passphrase = "") {
7926
7922
  assertMnemonic(getWords(phrase));
7927
- const phraseBytes = (0, import_utils33.toUtf8Bytes)(getPhrase(phrase));
7928
- const salt = (0, import_utils33.toUtf8Bytes)(`mnemonic${passphrase}`);
7923
+ const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
7924
+ const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
7929
7925
  return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7930
7926
  }
7931
7927
  /**
@@ -7981,14 +7977,14 @@ var Mnemonic = class {
7981
7977
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7982
7978
  */
7983
7979
  static masterKeysFromSeed(seed) {
7984
- const seedArray = (0, import_utils33.arrayify)(seed);
7980
+ const seedArray = (0, import_utils34.arrayify)(seed);
7985
7981
  if (seedArray.length < 16 || seedArray.length > 64) {
7986
7982
  throw new import_errors19.FuelError(
7987
7983
  import_errors19.ErrorCode.INVALID_SEED,
7988
7984
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7989
7985
  );
7990
7986
  }
7991
- return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
7987
+ return (0, import_utils34.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
7992
7988
  }
7993
7989
  /**
7994
7990
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7999,22 +7995,22 @@ var Mnemonic = class {
7999
7995
  */
8000
7996
  static seedToExtendedKey(seed, testnet = false) {
8001
7997
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8002
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7998
+ const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8003
7999
  const depth = "0x00";
8004
8000
  const fingerprint = "0x00000000";
8005
8001
  const index = "0x00000000";
8006
8002
  const chainCode = masterKey.slice(32);
8007
8003
  const privateKey = masterKey.slice(0, 32);
8008
- const extendedKey = (0, import_utils33.concat)([
8004
+ const extendedKey = (0, import_utils34.concat)([
8009
8005
  prefix,
8010
8006
  depth,
8011
8007
  fingerprint,
8012
8008
  index,
8013
8009
  chainCode,
8014
- (0, import_utils33.concat)(["0x00", privateKey])
8010
+ (0, import_utils34.concat)(["0x00", privateKey])
8015
8011
  ]);
8016
- const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8017
- return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8012
+ const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8013
+ return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
8018
8014
  }
8019
8015
  /**
8020
8016
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8029,7 +8025,7 @@ var Mnemonic = class {
8029
8025
  * @returns A randomly generated mnemonic
8030
8026
  */
8031
8027
  static generate(size = 32, extraEntropy = "") {
8032
- 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);
8028
+ 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);
8033
8029
  return Mnemonic.entropyToMnemonic(entropy);
8034
8030
  }
8035
8031
  };
@@ -8037,12 +8033,12 @@ var mnemonic_default = Mnemonic;
8037
8033
 
8038
8034
  // src/hdwallet/hdwallet.ts
8039
8035
  var HARDENED_INDEX = 2147483648;
8040
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8041
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8042
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8043
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8036
+ var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8037
+ var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8038
+ var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8039
+ var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8044
8040
  function base58check(data) {
8045
- 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)]));
8041
+ 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)]));
8046
8042
  }
8047
8043
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8048
8044
  if (isPublic) {
@@ -8051,11 +8047,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8051
8047
  return testnet ? TestnetPRV2 : MainnetPRV2;
8052
8048
  }
8053
8049
  function isPublicExtendedKey(extendedKey) {
8054
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8050
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8055
8051
  }
8056
8052
  function isValidExtendedKey(extendedKey) {
8057
8053
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8058
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8054
+ (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8059
8055
  );
8060
8056
  }
8061
8057
  function parsePath(path2, depth = 0) {
@@ -8073,8 +8069,8 @@ function parsePath(path2, depth = 0) {
8073
8069
  var HDWallet = class {
8074
8070
  depth = 0;
8075
8071
  index = 0;
8076
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8077
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8072
+ fingerprint = (0, import_utils36.hexlify)("0x00000000");
8073
+ parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8078
8074
  privateKey;
8079
8075
  publicKey;
8080
8076
  chainCode;
@@ -8086,8 +8082,8 @@ var HDWallet = class {
8086
8082
  constructor(config) {
8087
8083
  if (config.privateKey) {
8088
8084
  const signer = new Signer(config.privateKey);
8089
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8090
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8085
+ this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8086
+ this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8091
8087
  } else {
8092
8088
  if (!config.publicKey) {
8093
8089
  throw new import_errors20.FuelError(
@@ -8095,10 +8091,10 @@ var HDWallet = class {
8095
8091
  "Both public and private Key cannot be missing. At least one should be provided."
8096
8092
  );
8097
8093
  }
8098
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8094
+ this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8099
8095
  }
8100
8096
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8101
- this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8097
+ this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8102
8098
  this.depth = config.depth || this.depth;
8103
8099
  this.index = config.index || this.index;
8104
8100
  this.chainCode = config.chainCode;
@@ -8114,9 +8110,9 @@ var HDWallet = class {
8114
8110
  * @returns A new instance of HDWallet on the derived index
8115
8111
  */
8116
8112
  deriveIndex(index) {
8117
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8118
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8119
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8113
+ const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8114
+ const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8115
+ const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8120
8116
  const data = new Uint8Array(37);
8121
8117
  if (index & HARDENED_INDEX) {
8122
8118
  if (!privateKey) {
@@ -8127,10 +8123,10 @@ var HDWallet = class {
8127
8123
  }
8128
8124
  data.set(privateKey, 1);
8129
8125
  } else {
8130
- data.set((0, import_utils35.arrayify)(this.publicKey));
8126
+ data.set((0, import_utils36.arrayify)(this.publicKey));
8131
8127
  }
8132
8128
  data.set((0, import_math22.toBytes)(index, 4), 33);
8133
- const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8129
+ const bytes = (0, import_utils36.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8134
8130
  const IL = bytes.slice(0, 32);
8135
8131
  const IR = bytes.slice(32);
8136
8132
  if (privateKey) {
@@ -8144,7 +8140,7 @@ var HDWallet = class {
8144
8140
  parentFingerprint: this.fingerprint
8145
8141
  });
8146
8142
  }
8147
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8143
+ const signer = new Signer((0, import_utils36.hexlify)(IL));
8148
8144
  const Ki = signer.addPoint(publicKey);
8149
8145
  return new HDWallet({
8150
8146
  publicKey: Ki,
@@ -8179,12 +8175,12 @@ var HDWallet = class {
8179
8175
  );
8180
8176
  }
8181
8177
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8182
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8178
+ const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
8183
8179
  const parentFingerprint = this.parentFingerprint;
8184
8180
  const index = (0, import_math22.toHex)(this.index, 4);
8185
8181
  const chainCode = this.chainCode;
8186
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8187
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8182
+ const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8183
+ const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8188
8184
  return base58check(extendedKey);
8189
8185
  }
8190
8186
  /**
@@ -8196,13 +8192,13 @@ var HDWallet = class {
8196
8192
  static fromSeed(seed) {
8197
8193
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8198
8194
  return new HDWallet({
8199
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8200
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8195
+ chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8196
+ privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
8201
8197
  });
8202
8198
  }
8203
8199
  static fromExtendedKey(extendedKey) {
8204
- const decoded = (0, import_utils35.hexlify)((0, import_math22.toBytes)((0, import_utils35.decodeBase58)(extendedKey)));
8205
- const bytes = (0, import_utils35.arrayify)(decoded);
8200
+ const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8201
+ const bytes = (0, import_utils36.arrayify)(decoded);
8206
8202
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8207
8203
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8208
8204
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8211,9 +8207,9 @@ var HDWallet = class {
8211
8207
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8212
8208
  }
8213
8209
  const depth = bytes[4];
8214
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8215
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8216
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8210
+ const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8211
+ const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8212
+ const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
8217
8213
  const key = bytes.slice(45, 78);
8218
8214
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8219
8215
  throw new import_errors20.FuelError(
@@ -8432,7 +8428,8 @@ var generateTestWallet = async (provider, quantities) => {
8432
8428
  // src/test-utils/launchNode.ts
8433
8429
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
8434
8430
  var import_crypto7 = require("@fuel-ts/crypto");
8435
- var import_utils36 = require("@fuel-ts/utils");
8431
+ var import_utils37 = require("@fuel-ts/utils");
8432
+ var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8436
8433
  var import_child_process = require("child_process");
8437
8434
  var import_crypto8 = require("crypto");
8438
8435
  var import_fs = require("fs");
@@ -8471,14 +8468,49 @@ var killNode = (params) => {
8471
8468
  }
8472
8469
  }
8473
8470
  };
8471
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8472
+ const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8473
+ ...coin,
8474
+ amount: "18446744073709551615"
8475
+ }));
8476
+ const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8477
+ ...message,
8478
+ amount: "18446744073709551615"
8479
+ }));
8480
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
8481
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
8482
+ if (!process.env.GENESIS_SECRET) {
8483
+ const pk = Signer.generatePrivateKey();
8484
+ const signer = new Signer(pk);
8485
+ process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8486
+ coins.push({
8487
+ tx_id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8488
+ owner: signer.address.toHexString(),
8489
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8490
+ amount: "18446744073709551615",
8491
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8492
+ output_index: 0,
8493
+ tx_pointer_block_height: 0,
8494
+ tx_pointer_tx_idx: 0
8495
+ });
8496
+ }
8497
+ const json = JSON.stringify({
8498
+ ...stateConfig,
8499
+ coins,
8500
+ messages
8501
+ });
8502
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8503
+ return json.replace(regexMakeNumber, "$1$2");
8504
+ }
8474
8505
  var launchNode = async ({
8475
8506
  ip,
8476
8507
  port,
8477
8508
  args = [],
8478
- fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
8509
+ useSystemFuelCore = false,
8479
8510
  loggingEnabled = true,
8480
8511
  debugEnabled = false,
8481
- basePath
8512
+ basePath,
8513
+ snapshotConfig = import_utils37.defaultSnapshotConfigs
8482
8514
  }) => (
8483
8515
  // eslint-disable-next-line no-async-promise-executor
8484
8516
  new Promise(async (resolve, reject) => {
@@ -8489,13 +8521,14 @@ var launchNode = async ({
8489
8521
  "--poa-instant"
8490
8522
  ]);
8491
8523
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8492
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8524
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8493
8525
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8494
8526
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8495
8527
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8496
8528
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8497
8529
  const graphQLStartSubstring = "Binding GraphQL provider to";
8498
- const command = fuelCorePath ?? "fuel-core";
8530
+ const binPath = (0, import_cli_utils.findBinPath)("fuels-core", __dirname);
8531
+ const command = useSystemFuelCore ? "fuel-core" : binPath;
8499
8532
  const ipToUse = ip || "0.0.0.0";
8500
8533
  const portToUse = port || (await (0, import_portfinder.getPortPromise)({
8501
8534
  port: 4e3,
@@ -8506,56 +8539,23 @@ var launchNode = async ({
8506
8539
  let snapshotDirToUse;
8507
8540
  const prefix = basePath || import_os.default.tmpdir();
8508
8541
  const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
8509
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8542
+ const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8510
8543
  if (snapshotDir) {
8511
8544
  snapshotDirToUse = snapshotDir;
8512
8545
  } else {
8513
- if (!(0, import_fs.existsSync)(tempDirPath)) {
8514
- (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8515
- }
8516
- let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
8517
- const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
8518
- stateConfigJson = {
8519
- ...stateConfigJson,
8520
- coins: [
8521
- ...stateConfigJson.coins.map((coin) => ({
8522
- ...coin,
8523
- amount: "18446744073709551615"
8524
- }))
8525
- ],
8526
- messages: stateConfigJson.messages.map((message) => ({
8527
- ...message,
8528
- amount: "18446744073709551615"
8529
- }))
8530
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8531
- };
8532
- if (!process.env.GENESIS_SECRET) {
8533
- const pk = Signer.generatePrivateKey();
8534
- const signer = new Signer(pk);
8535
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8536
- stateConfigJson.coins.push({
8537
- tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8538
- owner: signer.address.toHexString(),
8539
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8540
- amount: "18446744073709551615",
8541
- asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8542
- output_index: 0,
8543
- tx_pointer_block_height: 0,
8544
- tx_pointer_tx_idx: 0
8545
- });
8546
+ if (!(0, import_fs.existsSync)(tempDir)) {
8547
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8546
8548
  }
8547
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8548
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8549
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8550
- const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8551
- const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8552
- const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8553
- const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
8554
- (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8555
- (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8556
- (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8557
- (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
8558
- snapshotDirToUse = tempDirPath;
8549
+ const { metadata } = snapshotConfig;
8550
+ const metadataPath = import_path.default.join(tempDir, "metadata.json");
8551
+ const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8552
+ const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8553
+ const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8554
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8555
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8556
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8557
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8558
+ snapshotDirToUse = tempDir;
8559
8559
  }
8560
8560
  const child = (0, import_child_process.spawn)(
8561
8561
  command,
@@ -8563,7 +8563,7 @@ var launchNode = async ({
8563
8563
  "run",
8564
8564
  ["--ip", ipToUse],
8565
8565
  ["--port", portToUse],
8566
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8566
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8567
8567
  ["--min-gas-price", "1"],
8568
8568
  poaInstant ? ["--poa-instant", "true"] : [],
8569
8569
  ["--consensus-key", consensusKey],
@@ -8585,23 +8585,28 @@ var launchNode = async ({
8585
8585
  }
8586
8586
  const cleanupConfig = {
8587
8587
  child,
8588
- configPath: tempDirPath,
8588
+ configPath: tempDir,
8589
8589
  killFn: import_tree_kill.default,
8590
8590
  state: {
8591
8591
  isDead: false
8592
8592
  }
8593
8593
  };
8594
8594
  child.stderr.on("data", (chunk) => {
8595
- if (chunk.indexOf(graphQLStartSubstring) !== -1) {
8595
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
8596
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
8597
+ const rows = text.split("\n");
8598
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8599
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8596
8600
  resolve({
8597
8601
  cleanup: () => killNode(cleanupConfig),
8598
- ip: ipToUse,
8599
- port: portToUse,
8602
+ ip: realIp,
8603
+ port: realPort,
8604
+ url: `http://${realIp}:${realPort}/v1/graphql`,
8600
8605
  snapshotDir: snapshotDirToUse
8601
8606
  });
8602
8607
  }
8603
- if (/error/i.test(chunk)) {
8604
- reject(chunk.toString());
8608
+ if (/error/i.test(text)) {
8609
+ reject(text.toString());
8605
8610
  }
8606
8611
  });
8607
8612
  process.on("exit", () => killNode(cleanupConfig));
@@ -8634,12 +8639,245 @@ var launchNodeAndGetWallets = async ({
8634
8639
  };
8635
8640
  return { wallets, stop: cleanup, provider };
8636
8641
  };
8642
+
8643
+ // src/test-utils/setup-test-provider-and-wallets.ts
8644
+ var import_utils40 = require("@fuel-ts/utils");
8645
+ var import_ramda5 = require("ramda");
8646
+
8647
+ // src/test-utils/asset-id.ts
8648
+ var import_crypto9 = require("@fuel-ts/crypto");
8649
+ var import_utils38 = require("@fuel-ts/utils");
8650
+ var _AssetId = class {
8651
+ constructor(value) {
8652
+ this.value = value;
8653
+ }
8654
+ static random(count = 1) {
8655
+ const assetIds = [];
8656
+ for (let i = 0; i < count; i++) {
8657
+ assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto9.randomBytes)(32))));
8658
+ }
8659
+ return assetIds;
8660
+ }
8661
+ };
8662
+ var AssetId = _AssetId;
8663
+ __publicField(AssetId, "A", new _AssetId(
8664
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
8665
+ ));
8666
+ __publicField(AssetId, "B", new _AssetId(
8667
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
8668
+ ));
8669
+
8670
+ // src/test-utils/wallet-config.ts
8671
+ var import_crypto10 = require("@fuel-ts/crypto");
8672
+ var import_errors21 = require("@fuel-ts/errors");
8673
+ var import_utils39 = require("@fuel-ts/utils");
8674
+ var WalletConfig = class {
8675
+ initialState;
8676
+ options;
8677
+ wallets;
8678
+ generateWallets = () => {
8679
+ const generatedWallets = [];
8680
+ for (let index = 1; index <= this.options.count; index++) {
8681
+ generatedWallets.push(new WalletUnlocked((0, import_crypto10.randomBytes)(32)));
8682
+ }
8683
+ return generatedWallets;
8684
+ };
8685
+ constructor(baseAssetId, config) {
8686
+ WalletConfig.validate(config);
8687
+ this.options = config;
8688
+ const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8689
+ this.wallets = this.generateWallets();
8690
+ this.initialState = {
8691
+ messages: WalletConfig.createMessages(this.wallets, messages),
8692
+ coins: WalletConfig.createCoins(
8693
+ this.wallets,
8694
+ baseAssetId,
8695
+ assets2,
8696
+ coinsPerAsset,
8697
+ amountPerCoin
8698
+ )
8699
+ };
8700
+ }
8701
+ apply(snapshotConfig) {
8702
+ return {
8703
+ ...snapshotConfig,
8704
+ stateConfig: {
8705
+ ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
8706
+ coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8707
+ messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8708
+ }
8709
+ };
8710
+ }
8711
+ /**
8712
+ * Create messages for the wallets in the format that the chain expects.
8713
+ */
8714
+ static createMessages(wallets, messages) {
8715
+ return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8716
+ }
8717
+ /**
8718
+ * Create coins for the wallets in the format that the chain expects.
8719
+ */
8720
+ static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
8721
+ const coins = [];
8722
+ let assetIds = [baseAssetId];
8723
+ if (Array.isArray(assets2)) {
8724
+ assetIds = assetIds.concat(assets2.map((a) => a.value));
8725
+ } else {
8726
+ assetIds.concat(AssetId.random(assets2).map((a) => a.value));
8727
+ }
8728
+ wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8729
+ assetIds.forEach((assetId) => {
8730
+ for (let index = 0; index < coinsPerAsset; index++) {
8731
+ coins.push({
8732
+ amount: amountPerCoin,
8733
+ asset_id: assetId,
8734
+ owner: walletAddress,
8735
+ tx_pointer_block_height: 0,
8736
+ tx_pointer_tx_idx: 0,
8737
+ output_index: 0,
8738
+ tx_id: (0, import_utils39.hexlify)((0, import_crypto10.randomBytes)(32))
8739
+ });
8740
+ }
8741
+ });
8742
+ });
8743
+ return coins;
8744
+ }
8745
+ static validate({
8746
+ count: wallets,
8747
+ assets: assets2,
8748
+ coinsPerAsset,
8749
+ amountPerCoin
8750
+ }) {
8751
+ if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8752
+ throw new import_errors21.FuelError(
8753
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8754
+ "Number of wallets must be greater than zero."
8755
+ );
8756
+ }
8757
+ if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8758
+ throw new import_errors21.FuelError(
8759
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8760
+ "Number of assets per wallet must be greater than zero."
8761
+ );
8762
+ }
8763
+ if (coinsPerAsset <= 0) {
8764
+ throw new import_errors21.FuelError(
8765
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8766
+ "Number of coins per asset must be greater than zero."
8767
+ );
8768
+ }
8769
+ if (amountPerCoin <= 0) {
8770
+ throw new import_errors21.FuelError(
8771
+ import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8772
+ "Amount per coin must be greater than zero."
8773
+ );
8774
+ }
8775
+ }
8776
+ };
8777
+
8778
+ // src/test-utils/setup-test-provider-and-wallets.ts
8779
+ var defaultWalletConfigOptions = {
8780
+ count: 2,
8781
+ assets: [AssetId.A, AssetId.B],
8782
+ coinsPerAsset: 1,
8783
+ amountPerCoin: 1e10,
8784
+ messages: []
8785
+ };
8786
+ async function setupTestProviderAndWallets({
8787
+ walletConfig: walletConfigOptions = {},
8788
+ providerOptions,
8789
+ nodeOptions = {}
8790
+ } = {}) {
8791
+ Symbol.dispose ??= Symbol("Symbol.dispose");
8792
+ const walletConfig = new WalletConfig(
8793
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
8794
+ {
8795
+ ...defaultWalletConfigOptions,
8796
+ ...walletConfigOptions
8797
+ }
8798
+ );
8799
+ const { cleanup, url } = await launchNode({
8800
+ loggingEnabled: false,
8801
+ ...nodeOptions,
8802
+ snapshotConfig: (0, import_ramda5.mergeDeepRight)(
8803
+ import_utils40.defaultSnapshotConfigs,
8804
+ walletConfig.apply(nodeOptions?.snapshotConfig)
8805
+ ),
8806
+ port: "0"
8807
+ });
8808
+ let provider;
8809
+ try {
8810
+ provider = await Provider.create(url, providerOptions);
8811
+ } catch (err) {
8812
+ cleanup();
8813
+ throw err;
8814
+ }
8815
+ const wallets = walletConfig.wallets;
8816
+ wallets.forEach((wallet) => {
8817
+ wallet.connect(provider);
8818
+ });
8819
+ return {
8820
+ provider,
8821
+ wallets,
8822
+ cleanup,
8823
+ [Symbol.dispose]: cleanup
8824
+ };
8825
+ }
8826
+
8827
+ // src/test-utils/test-message.ts
8828
+ var import_address7 = require("@fuel-ts/address");
8829
+ var import_crypto11 = require("@fuel-ts/crypto");
8830
+ var import_math23 = require("@fuel-ts/math");
8831
+ var import_utils41 = require("@fuel-ts/utils");
8832
+ var TestMessage = class {
8833
+ sender;
8834
+ recipient;
8835
+ nonce;
8836
+ amount;
8837
+ data;
8838
+ da_height;
8839
+ /**
8840
+ * A helper class to create messages for testing purposes.
8841
+ *
8842
+ * Used in tandem with `WalletConfig`.
8843
+ * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
8844
+ */
8845
+ constructor({
8846
+ sender = import_address7.Address.fromRandom(),
8847
+ recipient = import_address7.Address.fromRandom(),
8848
+ nonce = (0, import_utils41.hexlify)((0, import_crypto11.randomBytes)(32)),
8849
+ amount = 1e6,
8850
+ data = "02",
8851
+ da_height = 0
8852
+ } = {}) {
8853
+ this.sender = sender;
8854
+ this.recipient = recipient;
8855
+ this.nonce = nonce;
8856
+ this.amount = amount;
8857
+ this.data = data;
8858
+ this.da_height = da_height;
8859
+ }
8860
+ toChainMessage(recipient) {
8861
+ return {
8862
+ sender: this.sender.toB256(),
8863
+ recipient: recipient?.toB256() ?? this.recipient.toB256(),
8864
+ nonce: this.nonce,
8865
+ amount: (0, import_math23.bn)(this.amount).toNumber(),
8866
+ data: this.data,
8867
+ da_height: this.da_height
8868
+ };
8869
+ }
8870
+ };
8637
8871
  // Annotate the CommonJS export names for ESM import in node:
8638
8872
  0 && (module.exports = {
8873
+ AssetId,
8874
+ TestMessage,
8875
+ WalletConfig,
8639
8876
  generateTestWallet,
8640
8877
  killNode,
8641
8878
  launchNode,
8642
8879
  launchNodeAndGetWallets,
8643
- seedTestWallet
8880
+ seedTestWallet,
8881
+ setupTestProviderAndWallets
8644
8882
  });
8645
8883
  //# sourceMappingURL=test-utils.js.map