@fuel-ts/account 0.75.0 → 0.77.0

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.

Files changed (43) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/hdwallet/hdwallet.d.ts.map +1 -1
  3. package/dist/index.global.js +1002 -2498
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +92 -72
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +156 -140
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  10. package/dist/mnemonic/utils.d.ts.map +1 -1
  11. package/dist/predicate/predicate.d.ts +16 -15
  12. package/dist/predicate/predicate.d.ts.map +1 -1
  13. package/dist/providers/__generated__/operations.d.ts +47 -38
  14. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  15. package/dist/providers/assets/index.d.ts +1 -0
  16. package/dist/providers/assets/index.d.ts.map +1 -1
  17. package/dist/providers/assets/types.d.ts +5 -5
  18. package/dist/providers/assets/types.d.ts.map +1 -1
  19. package/dist/providers/assets/utils/network.d.ts +4 -4
  20. package/dist/providers/assets/utils/network.d.ts.map +1 -1
  21. package/dist/providers/assets/utils/resolveIconPaths.d.ts +1 -1
  22. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  23. package/dist/providers/provider.d.ts +24 -15
  24. package/dist/providers/provider.d.ts.map +1 -1
  25. package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
  26. package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
  27. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  28. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  29. package/dist/providers/transaction-summary/index.d.ts +0 -1
  30. package/dist/providers/transaction-summary/index.d.ts.map +1 -1
  31. package/dist/providers/utils/index.d.ts +0 -1
  32. package/dist/providers/utils/index.d.ts.map +1 -1
  33. package/dist/test-utils.global.js +976 -2469
  34. package/dist/test-utils.global.js.map +1 -1
  35. package/dist/test-utils.js +68 -40
  36. package/dist/test-utils.js.map +1 -1
  37. package/dist/test-utils.mjs +113 -93
  38. package/dist/test-utils.mjs.map +1 -1
  39. package/package.json +16 -16
  40. package/dist/providers/transaction-summary/date.d.ts +0 -3
  41. package/dist/providers/transaction-summary/date.d.ts.map +0 -1
  42. package/dist/providers/utils/time.d.ts +0 -40
  43. package/dist/providers/utils/time.d.ts.map +0 -1
@@ -112,7 +112,7 @@ var import_transactions17 = require("@fuel-ts/transactions");
112
112
  var import_utils22 = require("@fuel-ts/utils");
113
113
  var import_versions = require("@fuel-ts/versions");
114
114
  var import_utils23 = require("@noble/curves/abstract/utils");
115
- var import_ethers2 = require("ethers");
115
+ var import_ethers = require("ethers");
116
116
  var import_graphql_request = require("graphql-request");
117
117
  var import_ramda3 = require("ramda");
118
118
 
@@ -177,6 +177,9 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
177
177
  time
178
178
  reason
179
179
  }
180
+ ... on SqueezedOutStatus {
181
+ reason
182
+ }
180
183
  }
181
184
  `;
182
185
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
@@ -954,7 +957,16 @@ var _FuelGraphqlSubscriber = class {
954
957
  if (!text.startsWith("data:")) {
955
958
  continue;
956
959
  }
957
- const { data, errors } = JSON.parse(text.split("data:")[1]);
960
+ let data;
961
+ let errors;
962
+ try {
963
+ ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
964
+ } catch (e) {
965
+ throw new import_errors.FuelError(
966
+ import_errors.ErrorCode.STREAM_PARSING_ERROR,
967
+ `Error while parsing stream data response: ${text}`
968
+ );
969
+ }
958
970
  if (Array.isArray(errors)) {
959
971
  throw new import_errors.FuelError(
960
972
  import_errors.FuelError.CODES.INVALID_REQUEST,
@@ -1505,9 +1517,6 @@ function sleep(time) {
1505
1517
  });
1506
1518
  }
1507
1519
 
1508
- // src/providers/utils/time.ts
1509
- var fromUnixToTai64 = (unixTimestampMs) => (BigInt(unixTimestampMs) + BigInt(2 ** 62) + BigInt(10)).toString();
1510
-
1511
1520
  // src/providers/transaction-request/errors.ts
1512
1521
  var NoWitnessAtIndexError = class extends Error {
1513
1522
  constructor(index) {
@@ -1749,7 +1758,7 @@ var BaseTransactionRequest = class {
1749
1758
  txPointer: "0x00000000000000000000000000000000",
1750
1759
  witnessIndex,
1751
1760
  predicate: predicate?.bytes,
1752
- predicateData: predicate?.predicateData
1761
+ predicateData: predicate?.predicateDataBytes
1753
1762
  };
1754
1763
  this.pushInput(input);
1755
1764
  this.addChangeOutput(owner, assetId);
@@ -1782,7 +1791,7 @@ var BaseTransactionRequest = class {
1782
1791
  amount,
1783
1792
  witnessIndex,
1784
1793
  predicate: predicate?.bytes,
1785
- predicateData: predicate?.predicateData
1794
+ predicateData: predicate?.predicateDataBytes
1786
1795
  };
1787
1796
  this.pushInput(input);
1788
1797
  this.addChangeOutput(recipient, assetId);
@@ -2029,7 +2038,6 @@ var import_hasher = require("@fuel-ts/hasher");
2029
2038
  var import_math7 = require("@fuel-ts/math");
2030
2039
  var import_transactions6 = require("@fuel-ts/transactions");
2031
2040
  var import_utils11 = require("@fuel-ts/utils");
2032
- var import_ethers = require("ethers");
2033
2041
  var import_ramda2 = require("ramda");
2034
2042
  function hashTransaction(transactionRequest, chainId) {
2035
2043
  const transaction = transactionRequest.toTransaction();
@@ -2092,7 +2100,7 @@ function hashTransaction(transactionRequest, chainId) {
2092
2100
  transaction.witnesses = [];
2093
2101
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2094
2102
  const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
2095
- return (0, import_ethers.sha256)(concatenatedData);
2103
+ return (0, import_hasher.sha256)(concatenatedData);
2096
2104
  }
2097
2105
 
2098
2106
  // src/providers/transaction-request/storage-slot.ts
@@ -2518,13 +2526,6 @@ var calculateTransactionFee = (params) => {
2518
2526
  };
2519
2527
  };
2520
2528
 
2521
- // src/providers/transaction-summary/date.ts
2522
- var import_tai64 = require("tai64");
2523
- var fromTai64ToDate = (tai64Timestamp) => {
2524
- const timestamp = import_tai64.TAI64.fromString(tai64Timestamp, 10).toUnix();
2525
- return new Date(timestamp * 1e3);
2526
- };
2527
-
2528
2529
  // src/providers/transaction-summary/operations.ts
2529
2530
  var import_configs10 = require("@fuel-ts/address/configs");
2530
2531
  var import_errors10 = require("@fuel-ts/errors");
@@ -3118,7 +3119,7 @@ function assembleTransactionSummary(params) {
3118
3119
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3119
3120
  let date;
3120
3121
  if (time) {
3121
- date = fromTai64ToDate(time);
3122
+ date = import_utils19.DateTime.fromTai64(time);
3122
3123
  }
3123
3124
  const transactionSummary = {
3124
3125
  id,
@@ -3253,6 +3254,12 @@ var TransactionResponse = class {
3253
3254
  transactionId: this.id
3254
3255
  });
3255
3256
  for await (const { statusChange } of subscription) {
3257
+ if (statusChange.type === "SqueezedOutStatus") {
3258
+ throw new import_errors12.FuelError(
3259
+ import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3260
+ `Transaction Squeezed Out with reason: ${statusChange.reason}`
3261
+ );
3262
+ }
3256
3263
  if (statusChange.type !== "SubmittedStatus") {
3257
3264
  break;
3258
3265
  }
@@ -3417,14 +3424,15 @@ var _Provider = class {
3417
3424
  }
3418
3425
  static getFetchFn(options) {
3419
3426
  const { retryOptions, timeout } = options;
3420
- return autoRetryFetch((...args) => {
3421
- if (options.fetch) {
3422
- return options.fetch(...args);
3423
- }
3427
+ return autoRetryFetch(async (...args) => {
3424
3428
  const url = args[0];
3425
3429
  const request = args[1];
3426
3430
  const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
3427
- return fetch(url, { ...request, signal });
3431
+ let fullRequest = { ...request, signal };
3432
+ if (options.requestMiddleware) {
3433
+ fullRequest = await options.requestMiddleware(fullRequest);
3434
+ }
3435
+ return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
3428
3436
  }, retryOptions);
3429
3437
  }
3430
3438
  /**
@@ -3558,7 +3566,7 @@ var _Provider = class {
3558
3566
  name,
3559
3567
  consensusParameters: { chainId }
3560
3568
  } = await this.getChain();
3561
- const network = new import_ethers2.Network(name, chainId.toNumber());
3569
+ const network = new import_ethers.Network(name, chainId.toNumber());
3562
3570
  return Promise.resolve(network);
3563
3571
  }
3564
3572
  /**
@@ -3630,6 +3638,12 @@ var _Provider = class {
3630
3638
  if (awaitExecution) {
3631
3639
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3632
3640
  for await (const { submitAndAwait } of subscription) {
3641
+ if (submitAndAwait.type === "SqueezedOutStatus") {
3642
+ throw new import_errors13.FuelError(
3643
+ import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3644
+ `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3645
+ );
3646
+ }
3633
3647
  if (submitAndAwait.type !== "SubmittedStatus") {
3634
3648
  break;
3635
3649
  }
@@ -4226,13 +4240,13 @@ var _Provider = class {
4226
4240
  * Lets you produce blocks with custom timestamps and the block number of the last block produced.
4227
4241
  *
4228
4242
  * @param amount - The amount of blocks to produce
4229
- * @param startTime - The UNIX timestamp to set for the first produced block
4243
+ * @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
4230
4244
  * @returns A promise that resolves to the block number of the last produced block.
4231
4245
  */
4232
4246
  async produceBlocks(amount, startTime) {
4233
4247
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4234
4248
  blocksToProduce: (0, import_math14.bn)(amount).toString(10),
4235
- startTimestamp: startTime ? fromUnixToTai64(startTime) : void 0
4249
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4236
4250
  });
4237
4251
  return (0, import_math14.bn)(latestBlockHeight);
4238
4252
  }
@@ -4314,7 +4328,7 @@ var import_utils26 = require("@fuel-ts/utils");
4314
4328
  var asm = __toESM(require("@fuels/vm-asm"));
4315
4329
  var formatTransferToContractScriptData = (params) => {
4316
4330
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4317
- const numberCoder = new import_abi_coder4.U64Coder();
4331
+ const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4318
4332
  const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
4319
4333
  const scriptData = Uint8Array.from([
4320
4334
  ...(0, import_utils26.arrayify)(hexlifiedContractId),
@@ -4595,6 +4609,12 @@ var Account = class extends import_interfaces.AbstractAccount {
4595
4609
  * @returns A promise that resolves to the transaction response.
4596
4610
  */
4597
4611
  async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
4612
+ if ((0, import_math17.bn)(amount).lte(0)) {
4613
+ throw new import_errors15.FuelError(
4614
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
4615
+ "Transfer amount must be a positive number."
4616
+ );
4617
+ }
4598
4618
  const request = await this.createTransfer(destination, amount, assetId, txParams);
4599
4619
  return this.sendTransaction(request, { estimateTxDependencies: false });
4600
4620
  }
@@ -4608,6 +4628,12 @@ var Account = class extends import_interfaces.AbstractAccount {
4608
4628
  * @returns A promise that resolves to the transaction response.
4609
4629
  */
4610
4630
  async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
4631
+ if ((0, import_math17.bn)(amount).lte(0)) {
4632
+ throw new import_errors15.FuelError(
4633
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
4634
+ "Transfer amount must be a positive number."
4635
+ );
4636
+ }
4611
4637
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4612
4638
  const { minGasPrice } = this.provider.getGasConfig();
4613
4639
  const params = { gasPrice: minGasPrice, ...txParams };
@@ -5050,15 +5076,17 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5050
5076
 
5051
5077
  // src/hdwallet/hdwallet.ts
5052
5078
  var import_errors19 = require("@fuel-ts/errors");
5079
+ var import_hasher6 = require("@fuel-ts/hasher");
5053
5080
  var import_math19 = require("@fuel-ts/math");
5054
5081
  var import_utils34 = require("@fuel-ts/utils");
5055
- var import_ethers5 = require("ethers");
5082
+ var import_ethers3 = require("ethers");
5056
5083
 
5057
5084
  // src/mnemonic/mnemonic.ts
5058
5085
  var import_crypto3 = require("@fuel-ts/crypto");
5059
5086
  var import_errors18 = require("@fuel-ts/errors");
5087
+ var import_hasher5 = require("@fuel-ts/hasher");
5060
5088
  var import_utils32 = require("@fuel-ts/utils");
5061
- var import_ethers4 = require("ethers");
5089
+ var import_ethers2 = require("ethers");
5062
5090
 
5063
5091
  // src/wordlists/words/english.ts
5064
5092
  var english = [
@@ -7114,8 +7142,8 @@ var english = [
7114
7142
 
7115
7143
  // src/mnemonic/utils.ts
7116
7144
  var import_errors17 = require("@fuel-ts/errors");
7145
+ var import_hasher4 = require("@fuel-ts/hasher");
7117
7146
  var import_utils31 = require("@fuel-ts/utils");
7118
- var import_ethers3 = require("ethers");
7119
7147
  function toUtf8Bytes(stri) {
7120
7148
  const str = stri.normalize("NFKD");
7121
7149
  const result = [];
@@ -7182,7 +7210,7 @@ function entropyToMnemonicIndices(entropy) {
7182
7210
  }
7183
7211
  }
7184
7212
  const checksumBits = entropy.length / 4;
7185
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy))[0] & getUpperMask(checksumBits);
7213
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7186
7214
  indices[indices.length - 1] <<= checksumBits;
7187
7215
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7188
7216
  return indices;
@@ -7209,7 +7237,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7209
7237
  const entropyBits = 32 * words.length / 3;
7210
7238
  const checksumBits = words.length / 3;
7211
7239
  const checksumMask = getUpperMask(checksumBits);
7212
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7240
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7213
7241
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7214
7242
  throw new import_errors17.FuelError(
7215
7243
  import_errors17.ErrorCode.INVALID_CHECKSUM,
@@ -7306,7 +7334,7 @@ var Mnemonic = class {
7306
7334
  assertMnemonic(getWords(phrase));
7307
7335
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7308
7336
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7309
- return (0, import_ethers4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7337
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7310
7338
  }
7311
7339
  /**
7312
7340
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7368,7 +7396,7 @@ var Mnemonic = class {
7368
7396
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7369
7397
  );
7370
7398
  }
7371
- return (0, import_utils32.arrayify)((0, import_ethers4.computeHmac)("sha512", MasterSecret, seedArray));
7399
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7372
7400
  }
7373
7401
  /**
7374
7402
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7393,8 +7421,8 @@ var Mnemonic = class {
7393
7421
  chainCode,
7394
7422
  (0, import_utils32.concat)(["0x00", privateKey])
7395
7423
  ]);
7396
- const checksum = (0, import_ethers4.dataSlice)((0, import_ethers4.sha256)((0, import_ethers4.sha256)(extendedKey)), 0, 4);
7397
- return (0, import_ethers4.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7424
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7425
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7398
7426
  }
7399
7427
  /**
7400
7428
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7409,7 +7437,7 @@ var Mnemonic = class {
7409
7437
  * @returns A randomly generated mnemonic
7410
7438
  */
7411
7439
  static generate(size = 32, extraEntropy = "") {
7412
- const entropy = extraEntropy ? (0, import_ethers4.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7440
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7413
7441
  return Mnemonic.entropyToMnemonic(entropy);
7414
7442
  }
7415
7443
  };
@@ -7422,7 +7450,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7422
7450
  var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7423
7451
  var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7424
7452
  function base58check(data) {
7425
- return (0, import_ethers5.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers5.dataSlice)((0, import_ethers5.sha256)((0, import_ethers5.sha256)(data)), 0, 4)]));
7453
+ return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7426
7454
  }
7427
7455
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7428
7456
  if (isPublic) {
@@ -7478,7 +7506,7 @@ var HDWallet = class {
7478
7506
  this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7479
7507
  }
7480
7508
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7481
- this.fingerprint = (0, import_ethers5.dataSlice)((0, import_ethers5.ripemd160)((0, import_ethers5.sha256)(this.publicKey)), 0, 4);
7509
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7482
7510
  this.depth = config.depth || this.depth;
7483
7511
  this.index = config.index || this.index;
7484
7512
  this.chainCode = config.chainCode;
@@ -7510,7 +7538,7 @@ var HDWallet = class {
7510
7538
  data.set((0, import_utils34.arrayify)(this.publicKey));
7511
7539
  }
7512
7540
  data.set((0, import_math19.toBytes)(index, 4), 33);
7513
- const bytes = (0, import_utils34.arrayify)((0, import_ethers5.computeHmac)("sha512", chainCode, data));
7541
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7514
7542
  const IL = bytes.slice(0, 32);
7515
7543
  const IR = bytes.slice(32);
7516
7544
  if (privateKey) {
@@ -7581,7 +7609,7 @@ var HDWallet = class {
7581
7609
  });
7582
7610
  }
7583
7611
  static fromExtendedKey(extendedKey) {
7584
- const decoded = (0, import_ethers5.toBeHex)((0, import_ethers5.decodeBase58)(extendedKey));
7612
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7585
7613
  const bytes = (0, import_utils34.arrayify)(decoded);
7586
7614
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7587
7615
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {