@fuel-ts/account 0.0.0-rc-2143-20240515072133 → 0.0.0-rc-1356-20240515085856

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