@fuel-ts/account 0.76.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 (33) 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 +840 -1334
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +85 -47
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +145 -115
  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 +9 -0
  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 +23 -14
  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/transaction-response.d.ts.map +1 -1
  27. package/dist/test-utils.global.js +817 -1308
  28. package/dist/test-utils.global.js.map +1 -1
  29. package/dist/test-utils.js +64 -26
  30. package/dist/test-utils.js.map +1 -1
  31. package/dist/test-utils.mjs +105 -75
  32. package/dist/test-utils.mjs.map +1 -1
  33. package/package.json +16 -16
package/dist/index.js CHANGED
@@ -231,7 +231,7 @@ var import_transactions17 = require("@fuel-ts/transactions");
231
231
  var import_utils22 = require("@fuel-ts/utils");
232
232
  var import_versions = require("@fuel-ts/versions");
233
233
  var import_utils23 = require("@noble/curves/abstract/utils");
234
- var import_ethers2 = require("ethers");
234
+ var import_ethers = require("ethers");
235
235
  var import_graphql_request = require("graphql-request");
236
236
  var import_ramda3 = require("ramda");
237
237
 
@@ -296,6 +296,9 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
296
296
  time
297
297
  reason
298
298
  }
299
+ ... on SqueezedOutStatus {
300
+ reason
301
+ }
299
302
  }
300
303
  `;
301
304
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
@@ -1073,7 +1076,16 @@ var _FuelGraphqlSubscriber = class {
1073
1076
  if (!text.startsWith("data:")) {
1074
1077
  continue;
1075
1078
  }
1076
- const { data, errors } = JSON.parse(text.split("data:")[1]);
1079
+ let data;
1080
+ let errors;
1081
+ try {
1082
+ ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
1083
+ } catch (e) {
1084
+ throw new import_errors.FuelError(
1085
+ import_errors.ErrorCode.STREAM_PARSING_ERROR,
1086
+ `Error while parsing stream data response: ${text}`
1087
+ );
1088
+ }
1077
1089
  if (Array.isArray(errors)) {
1078
1090
  throw new import_errors.FuelError(
1079
1091
  import_errors.FuelError.CODES.INVALID_REQUEST,
@@ -1939,7 +1951,7 @@ var BaseTransactionRequest = class {
1939
1951
  txPointer: "0x00000000000000000000000000000000",
1940
1952
  witnessIndex,
1941
1953
  predicate: predicate?.bytes,
1942
- predicateData: predicate?.predicateData
1954
+ predicateData: predicate?.predicateDataBytes
1943
1955
  };
1944
1956
  this.pushInput(input);
1945
1957
  this.addChangeOutput(owner, assetId);
@@ -1972,7 +1984,7 @@ var BaseTransactionRequest = class {
1972
1984
  amount,
1973
1985
  witnessIndex,
1974
1986
  predicate: predicate?.bytes,
1975
- predicateData: predicate?.predicateData
1987
+ predicateData: predicate?.predicateDataBytes
1976
1988
  };
1977
1989
  this.pushInput(input);
1978
1990
  this.addChangeOutput(recipient, assetId);
@@ -2219,7 +2231,6 @@ var import_hasher = require("@fuel-ts/hasher");
2219
2231
  var import_math7 = require("@fuel-ts/math");
2220
2232
  var import_transactions6 = require("@fuel-ts/transactions");
2221
2233
  var import_utils11 = require("@fuel-ts/utils");
2222
- var import_ethers = require("ethers");
2223
2234
  var import_ramda2 = require("ramda");
2224
2235
  function hashTransaction(transactionRequest, chainId) {
2225
2236
  const transaction = transactionRequest.toTransaction();
@@ -2282,7 +2293,7 @@ function hashTransaction(transactionRequest, chainId) {
2282
2293
  transaction.witnesses = [];
2283
2294
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2284
2295
  const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
2285
- return (0, import_ethers.sha256)(concatenatedData);
2296
+ return (0, import_hasher.sha256)(concatenatedData);
2286
2297
  }
2287
2298
 
2288
2299
  // src/providers/transaction-request/storage-slot.ts
@@ -3483,6 +3494,12 @@ var TransactionResponse = class {
3483
3494
  transactionId: this.id
3484
3495
  });
3485
3496
  for await (const { statusChange } of subscription) {
3497
+ if (statusChange.type === "SqueezedOutStatus") {
3498
+ throw new import_errors12.FuelError(
3499
+ import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3500
+ `Transaction Squeezed Out with reason: ${statusChange.reason}`
3501
+ );
3502
+ }
3486
3503
  if (statusChange.type !== "SubmittedStatus") {
3487
3504
  break;
3488
3505
  }
@@ -3660,14 +3677,15 @@ var _Provider = class {
3660
3677
  }
3661
3678
  static getFetchFn(options) {
3662
3679
  const { retryOptions, timeout } = options;
3663
- return autoRetryFetch((...args) => {
3664
- if (options.fetch) {
3665
- return options.fetch(...args);
3666
- }
3680
+ return autoRetryFetch(async (...args) => {
3667
3681
  const url = args[0];
3668
3682
  const request = args[1];
3669
3683
  const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
3670
- return fetch(url, { ...request, signal });
3684
+ let fullRequest = { ...request, signal };
3685
+ if (options.requestMiddleware) {
3686
+ fullRequest = await options.requestMiddleware(fullRequest);
3687
+ }
3688
+ return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
3671
3689
  }, retryOptions);
3672
3690
  }
3673
3691
  /**
@@ -3801,7 +3819,7 @@ var _Provider = class {
3801
3819
  name,
3802
3820
  consensusParameters: { chainId }
3803
3821
  } = await this.getChain();
3804
- const network = new import_ethers2.Network(name, chainId.toNumber());
3822
+ const network = new import_ethers.Network(name, chainId.toNumber());
3805
3823
  return Promise.resolve(network);
3806
3824
  }
3807
3825
  /**
@@ -3873,6 +3891,12 @@ var _Provider = class {
3873
3891
  if (awaitExecution) {
3874
3892
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3875
3893
  for await (const { submitAndAwait } of subscription) {
3894
+ if (submitAndAwait.type === "SqueezedOutStatus") {
3895
+ throw new import_errors13.FuelError(
3896
+ import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3897
+ `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3898
+ );
3899
+ }
3876
3900
  if (submitAndAwait.type !== "SubmittedStatus") {
3877
3901
  break;
3878
3902
  }
@@ -5004,6 +5028,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5004
5028
  * @returns A promise that resolves to the transaction response.
5005
5029
  */
5006
5030
  async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
5031
+ if ((0, import_math17.bn)(amount).lte(0)) {
5032
+ throw new import_errors15.FuelError(
5033
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
5034
+ "Transfer amount must be a positive number."
5035
+ );
5036
+ }
5007
5037
  const request = await this.createTransfer(destination, amount, assetId, txParams);
5008
5038
  return this.sendTransaction(request, { estimateTxDependencies: false });
5009
5039
  }
@@ -5017,6 +5047,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5017
5047
  * @returns A promise that resolves to the transaction response.
5018
5048
  */
5019
5049
  async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
5050
+ if ((0, import_math17.bn)(amount).lte(0)) {
5051
+ throw new import_errors15.FuelError(
5052
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
5053
+ "Transfer amount must be a positive number."
5054
+ );
5055
+ }
5020
5056
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5021
5057
  const { minGasPrice } = this.provider.getGasConfig();
5022
5058
  const params = { gasPrice: minGasPrice, ...txParams };
@@ -5463,15 +5499,17 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5463
5499
 
5464
5500
  // src/hdwallet/hdwallet.ts
5465
5501
  var import_errors19 = require("@fuel-ts/errors");
5502
+ var import_hasher6 = require("@fuel-ts/hasher");
5466
5503
  var import_math19 = require("@fuel-ts/math");
5467
5504
  var import_utils34 = require("@fuel-ts/utils");
5468
- var import_ethers5 = require("ethers");
5505
+ var import_ethers3 = require("ethers");
5469
5506
 
5470
5507
  // src/mnemonic/mnemonic.ts
5471
5508
  var import_crypto3 = require("@fuel-ts/crypto");
5472
5509
  var import_errors18 = require("@fuel-ts/errors");
5510
+ var import_hasher5 = require("@fuel-ts/hasher");
5473
5511
  var import_utils32 = require("@fuel-ts/utils");
5474
- var import_ethers4 = require("ethers");
5512
+ var import_ethers2 = require("ethers");
5475
5513
 
5476
5514
  // src/wordlists/words/english.ts
5477
5515
  var english = [
@@ -7533,8 +7571,8 @@ var Language = /* @__PURE__ */ ((Language2) => {
7533
7571
 
7534
7572
  // src/mnemonic/utils.ts
7535
7573
  var import_errors17 = require("@fuel-ts/errors");
7574
+ var import_hasher4 = require("@fuel-ts/hasher");
7536
7575
  var import_utils31 = require("@fuel-ts/utils");
7537
- var import_ethers3 = require("ethers");
7538
7576
  function toUtf8Bytes(stri) {
7539
7577
  const str = stri.normalize("NFKD");
7540
7578
  const result = [];
@@ -7601,7 +7639,7 @@ function entropyToMnemonicIndices(entropy) {
7601
7639
  }
7602
7640
  }
7603
7641
  const checksumBits = entropy.length / 4;
7604
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy))[0] & getUpperMask(checksumBits);
7642
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7605
7643
  indices[indices.length - 1] <<= checksumBits;
7606
7644
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7607
7645
  return indices;
@@ -7628,7 +7666,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7628
7666
  const entropyBits = 32 * words.length / 3;
7629
7667
  const checksumBits = words.length / 3;
7630
7668
  const checksumMask = getUpperMask(checksumBits);
7631
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7669
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7632
7670
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7633
7671
  throw new import_errors17.FuelError(
7634
7672
  import_errors17.ErrorCode.INVALID_CHECKSUM,
@@ -7725,7 +7763,7 @@ var Mnemonic = class {
7725
7763
  assertMnemonic(getWords(phrase));
7726
7764
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7727
7765
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7728
- return (0, import_ethers4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7766
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7729
7767
  }
7730
7768
  /**
7731
7769
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7787,7 +7825,7 @@ var Mnemonic = class {
7787
7825
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7788
7826
  );
7789
7827
  }
7790
- return (0, import_utils32.arrayify)((0, import_ethers4.computeHmac)("sha512", MasterSecret, seedArray));
7828
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7791
7829
  }
7792
7830
  /**
7793
7831
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7812,8 +7850,8 @@ var Mnemonic = class {
7812
7850
  chainCode,
7813
7851
  (0, import_utils32.concat)(["0x00", privateKey])
7814
7852
  ]);
7815
- const checksum = (0, import_ethers4.dataSlice)((0, import_ethers4.sha256)((0, import_ethers4.sha256)(extendedKey)), 0, 4);
7816
- return (0, import_ethers4.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7853
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7854
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7817
7855
  }
7818
7856
  /**
7819
7857
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7828,7 +7866,7 @@ var Mnemonic = class {
7828
7866
  * @returns A randomly generated mnemonic
7829
7867
  */
7830
7868
  static generate(size = 32, extraEntropy = "") {
7831
- 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);
7869
+ 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);
7832
7870
  return Mnemonic.entropyToMnemonic(entropy);
7833
7871
  }
7834
7872
  };
@@ -7841,7 +7879,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7841
7879
  var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7842
7880
  var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7843
7881
  function base58check(data) {
7844
- 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)]));
7882
+ 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)]));
7845
7883
  }
7846
7884
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7847
7885
  if (isPublic) {
@@ -7897,7 +7935,7 @@ var HDWallet = class {
7897
7935
  this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7898
7936
  }
7899
7937
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7900
- this.fingerprint = (0, import_ethers5.dataSlice)((0, import_ethers5.ripemd160)((0, import_ethers5.sha256)(this.publicKey)), 0, 4);
7938
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7901
7939
  this.depth = config.depth || this.depth;
7902
7940
  this.index = config.index || this.index;
7903
7941
  this.chainCode = config.chainCode;
@@ -7929,7 +7967,7 @@ var HDWallet = class {
7929
7967
  data.set((0, import_utils34.arrayify)(this.publicKey));
7930
7968
  }
7931
7969
  data.set((0, import_math19.toBytes)(index, 4), 33);
7932
- const bytes = (0, import_utils34.arrayify)((0, import_ethers5.computeHmac)("sha512", chainCode, data));
7970
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7933
7971
  const IL = bytes.slice(0, 32);
7934
7972
  const IR = bytes.slice(32);
7935
7973
  if (privateKey) {
@@ -8000,7 +8038,7 @@ var HDWallet = class {
8000
8038
  });
8001
8039
  }
8002
8040
  static fromExtendedKey(extendedKey) {
8003
- const decoded = (0, import_ethers5.toBeHex)((0, import_ethers5.decodeBase58)(extendedKey));
8041
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8004
8042
  const bytes = (0, import_utils34.arrayify)(decoded);
8005
8043
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8006
8044
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
@@ -8621,7 +8659,7 @@ var import_transactions19 = require("@fuel-ts/transactions");
8621
8659
  var import_utils36 = require("@fuel-ts/utils");
8622
8660
 
8623
8661
  // src/predicate/utils/getPredicateRoot.ts
8624
- var import_hasher4 = require("@fuel-ts/hasher");
8662
+ var import_hasher7 = require("@fuel-ts/hasher");
8625
8663
  var import_merkle = require("@fuel-ts/merkle");
8626
8664
  var import_utils35 = require("@fuel-ts/utils");
8627
8665
  var getPredicateRoot = (bytecode) => {
@@ -8629,34 +8667,44 @@ var getPredicateRoot = (bytecode) => {
8629
8667
  const bytes = (0, import_utils35.arrayify)(bytecode);
8630
8668
  const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
8631
8669
  const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
8632
- const predicateRoot = (0, import_hasher4.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8670
+ const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8633
8671
  return predicateRoot;
8634
8672
  };
8635
8673
 
8636
8674
  // src/predicate/predicate.ts
8637
8675
  var Predicate = class extends Account {
8638
8676
  bytes;
8639
- predicateData = Uint8Array.from([]);
8640
- predicateArgs = [];
8677
+ predicateDataBytes = Uint8Array.from([]);
8678
+ predicateData = [];
8641
8679
  interface;
8642
8680
  /**
8643
8681
  * Creates an instance of the Predicate class.
8644
8682
  *
8645
- * @param bytes - The bytes of the predicate.
8683
+ * @param bytecode - The bytecode of the predicate.
8684
+ * @param abi - The JSON ABI of the predicate.
8646
8685
  * @param provider - The provider used to interact with the blockchain.
8647
- * @param jsonAbi - The JSON ABI of the predicate.
8686
+ * @param inputData - The predicate input data (optional).
8648
8687
  * @param configurableConstants - Optional configurable constants for the predicate.
8649
8688
  */
8650
- constructor(bytes, provider, jsonAbi, configurableConstants) {
8689
+ constructor({
8690
+ bytecode,
8691
+ abi,
8692
+ provider,
8693
+ inputData,
8694
+ configurableConstants
8695
+ }) {
8651
8696
  const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
8652
- bytes,
8653
- jsonAbi,
8697
+ bytecode,
8698
+ abi,
8654
8699
  configurableConstants
8655
8700
  );
8656
8701
  const address = import_address10.Address.fromB256(getPredicateRoot(predicateBytes));
8657
8702
  super(address, provider);
8658
8703
  this.bytes = predicateBytes;
8659
8704
  this.interface = predicateInterface;
8705
+ if (inputData !== void 0 && inputData.length > 0) {
8706
+ this.predicateData = inputData;
8707
+ }
8660
8708
  }
8661
8709
  /**
8662
8710
  * Populates the transaction data with predicate data.
@@ -8708,18 +8756,8 @@ var Predicate = class extends Account {
8708
8756
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8709
8757
  return super.simulateTransaction(transactionRequest);
8710
8758
  }
8711
- /**
8712
- * Sets data for the predicate.
8713
- *
8714
- * @param args - Arguments for the predicate function.
8715
- * @returns The Predicate instance with updated predicate data.
8716
- */
8717
- setData(...args) {
8718
- this.predicateArgs = args;
8719
- return this;
8720
- }
8721
8759
  getPredicateData(policiesLength) {
8722
- if (!this.predicateArgs.length) {
8760
+ if (!this.predicateData.length) {
8723
8761
  return new Uint8Array();
8724
8762
  }
8725
8763
  const mainFn = this.interface?.functions.main;
@@ -8728,7 +8766,7 @@ var Predicate = class extends Account {
8728
8766
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8729
8767
  });
8730
8768
  const OFFSET = VM_TX_MEMORY + import_abi_coder5.SCRIPT_FIXED_SIZE + import_abi_coder5.INPUT_COIN_FIXED_SIZE + import_abi_coder5.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder5.WORD_SIZE;
8731
- return mainFn?.encodeArguments(this.predicateArgs, OFFSET) || new Uint8Array();
8769
+ return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
8732
8770
  }
8733
8771
  /**
8734
8772
  * Processes the predicate data and returns the altered bytecode and interface.