@fuel-ts/account 0.0.0-rc-2143-20240429161457 → 0.0.0-rc-2037-20240430003658

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 (38) hide show
  1. package/README.md +15 -12
  2. package/dist/index.global.js +92 -8
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +215 -118
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +130 -39
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +9 -2
  9. package/dist/predicate/predicate.d.ts.map +1 -1
  10. package/dist/providers/__generated__/operations.d.ts +17 -0
  11. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  12. package/dist/providers/provider.d.ts +8 -1
  13. package/dist/providers/provider.d.ts.map +1 -1
  14. package/dist/providers/transaction-request/helpers.d.ts +10 -0
  15. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  16. package/dist/providers/transaction-request/index.d.ts +1 -0
  17. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/transaction-request.d.ts +2 -0
  19. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  20. package/dist/test-utils/index.d.ts +1 -0
  21. package/dist/test-utils/index.d.ts.map +1 -1
  22. package/dist/test-utils/launchNode.d.ts +2 -4
  23. package/dist/test-utils/launchNode.d.ts.map +1 -1
  24. package/dist/test-utils/resources.d.ts +4 -0
  25. package/dist/test-utils/resources.d.ts.map +1 -0
  26. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  27. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  28. package/dist/test-utils/transactionRequest.d.ts +5 -0
  29. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  30. package/dist/test-utils.global.js +94 -14
  31. package/dist/test-utils.global.js.map +1 -1
  32. package/dist/test-utils.js +203 -117
  33. package/dist/test-utils.js.map +1 -1
  34. package/dist/test-utils.mjs +127 -44
  35. package/dist/test-utils.mjs.map +1 -1
  36. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  37. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  38. package/package.json +15 -15
package/dist/index.mjs CHANGED
@@ -75,7 +75,7 @@ import { Address as Address2 } from "@fuel-ts/address";
75
75
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
76
76
  import { BN, bn as bn16 } from "@fuel-ts/math";
77
77
  import {
78
- InputType as InputType7,
78
+ InputType as InputType8,
79
79
  TransactionType as TransactionType8,
80
80
  InputMessageCoder,
81
81
  TransactionCoder as TransactionCoder5
@@ -858,6 +858,13 @@ var ProduceBlocksDocument = gql`
858
858
  )
859
859
  }
860
860
  `;
861
+ var GetMessageByNonceDocument = gql`
862
+ query getMessageByNonce($nonce: Nonce!) {
863
+ message(nonce: $nonce) {
864
+ ...messageFragment
865
+ }
866
+ }
867
+ ${MessageFragmentFragmentDoc}`;
861
868
  var SubmitAndAwaitDocument = gql`
862
869
  subscription submitAndAwait($encodedTransaction: HexString!) {
863
870
  submitAndAwait(tx: $encodedTransaction) {
@@ -952,6 +959,9 @@ function getSdk(requester) {
952
959
  produceBlocks(variables, options) {
953
960
  return requester(ProduceBlocksDocument, variables, options);
954
961
  },
962
+ getMessageByNonce(variables, options) {
963
+ return requester(GetMessageByNonceDocument, variables, options);
964
+ },
955
965
  submitAndAwait(variables, options) {
956
966
  return requester(SubmitAndAwaitDocument, variables, options);
957
967
  },
@@ -1240,7 +1250,7 @@ import { bn as bn7 } from "@fuel-ts/math";
1240
1250
  import {
1241
1251
  PolicyType,
1242
1252
  TransactionCoder,
1243
- InputType as InputType2,
1253
+ InputType as InputType3,
1244
1254
  OutputType as OutputType2,
1245
1255
  TransactionType
1246
1256
  } from "@fuel-ts/transactions";
@@ -1764,6 +1774,28 @@ var NoWitnessByOwnerError = class extends Error {
1764
1774
  name = "NoWitnessByOwnerError";
1765
1775
  };
1766
1776
 
1777
+ // src/providers/transaction-request/helpers.ts
1778
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1779
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1780
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1781
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1782
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1783
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1784
+ var cacheResources = (resources) => resources.reduce(
1785
+ (cache2, resource) => {
1786
+ if (isCoin(resource)) {
1787
+ cache2.utxos.push(resource.id);
1788
+ } else {
1789
+ cache2.messages.push(resource.nonce);
1790
+ }
1791
+ return cache2;
1792
+ },
1793
+ {
1794
+ utxos: [],
1795
+ messages: []
1796
+ }
1797
+ );
1798
+
1767
1799
  // src/providers/transaction-request/witness.ts
1768
1800
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1769
1801
  var witnessify = (value) => {
@@ -1954,7 +1986,7 @@ var BaseTransactionRequest = class {
1954
1986
  */
1955
1987
  getCoinInputs() {
1956
1988
  return this.inputs.filter(
1957
- (input) => input.type === InputType2.Coin
1989
+ (input) => input.type === InputType3.Coin
1958
1990
  );
1959
1991
  }
1960
1992
  /**
@@ -1986,9 +2018,9 @@ var BaseTransactionRequest = class {
1986
2018
  const ownerAddress = addressify(owner);
1987
2019
  const found = this.inputs.find((input) => {
1988
2020
  switch (input.type) {
1989
- case InputType2.Coin:
2021
+ case InputType3.Coin:
1990
2022
  return hexlify7(input.owner) === ownerAddress.toB256();
1991
- case InputType2.Message:
2023
+ case InputType3.Message:
1992
2024
  return hexlify7(input.recipient) === ownerAddress.toB256();
1993
2025
  default:
1994
2026
  return false;
@@ -2003,7 +2035,7 @@ var BaseTransactionRequest = class {
2003
2035
  * @param coin - Coin resource.
2004
2036
  */
2005
2037
  addCoinInput(coin) {
2006
- const { assetId, owner, amount } = coin;
2038
+ const { assetId, owner, amount, id, predicate } = coin;
2007
2039
  let witnessIndex;
2008
2040
  if (coin.predicate) {
2009
2041
  witnessIndex = 0;
@@ -2014,13 +2046,14 @@ var BaseTransactionRequest = class {
2014
2046
  }
2015
2047
  }
2016
2048
  const input = {
2017
- ...coin,
2018
- type: InputType2.Coin,
2049
+ id,
2050
+ type: InputType3.Coin,
2019
2051
  owner: owner.toB256(),
2020
2052
  amount,
2021
2053
  assetId,
2022
2054
  txPointer: "0x00000000000000000000000000000000",
2023
- witnessIndex
2055
+ witnessIndex,
2056
+ predicate
2024
2057
  };
2025
2058
  this.pushInput(input);
2026
2059
  this.addChangeOutput(owner, assetId);
@@ -2032,7 +2065,7 @@ var BaseTransactionRequest = class {
2032
2065
  * @param message - Message resource.
2033
2066
  */
2034
2067
  addMessageInput(message) {
2035
- const { recipient, sender, amount, assetId } = message;
2068
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
2036
2069
  let witnessIndex;
2037
2070
  if (message.predicate) {
2038
2071
  witnessIndex = 0;
@@ -2043,12 +2076,13 @@ var BaseTransactionRequest = class {
2043
2076
  }
2044
2077
  }
2045
2078
  const input = {
2046
- ...message,
2047
- type: InputType2.Message,
2079
+ nonce,
2080
+ type: InputType3.Message,
2048
2081
  sender: sender.toB256(),
2049
2082
  recipient: recipient.toB256(),
2050
2083
  amount,
2051
- witnessIndex
2084
+ witnessIndex,
2085
+ predicate
2052
2086
  };
2053
2087
  this.pushInput(input);
2054
2088
  this.addChangeOutput(recipient, assetId);
@@ -2232,16 +2266,27 @@ var BaseTransactionRequest = class {
2232
2266
  toJSON() {
2233
2267
  return normalizeJSON(this);
2234
2268
  }
2269
+ removeWitness(index) {
2270
+ this.witnesses.splice(index, 1);
2271
+ this.adjustWitnessIndexes(index);
2272
+ }
2273
+ adjustWitnessIndexes(removedIndex) {
2274
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2275
+ if (input.witnessIndex > removedIndex) {
2276
+ input.witnessIndex -= 1;
2277
+ }
2278
+ });
2279
+ }
2235
2280
  updatePredicateGasUsed(inputs) {
2236
2281
  this.inputs.forEach((i) => {
2237
2282
  let correspondingInput;
2238
2283
  switch (i.type) {
2239
- case InputType2.Coin:
2240
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2284
+ case InputType3.Coin:
2285
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2241
2286
  break;
2242
- case InputType2.Message:
2287
+ case InputType3.Message:
2243
2288
  correspondingInput = inputs.find(
2244
- (x) => x.type === InputType2.Message && x.sender === i.sender
2289
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2245
2290
  );
2246
2291
  break;
2247
2292
  default:
@@ -2275,7 +2320,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2275
2320
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2276
2321
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2277
2322
  import { bn as bn8 } from "@fuel-ts/math";
2278
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2323
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2279
2324
  import { concat as concat2 } from "@fuel-ts/utils";
2280
2325
  import { clone as clone2 } from "ramda";
2281
2326
  function hashTransaction(transactionRequest, chainId) {
@@ -2286,7 +2331,7 @@ function hashTransaction(transactionRequest, chainId) {
2286
2331
  transaction.inputs = transaction.inputs.map((input) => {
2287
2332
  const inputClone = clone2(input);
2288
2333
  switch (inputClone.type) {
2289
- case InputType3.Coin: {
2334
+ case InputType4.Coin: {
2290
2335
  inputClone.txPointer = {
2291
2336
  blockHeight: 0,
2292
2337
  txIndex: 0
@@ -2294,11 +2339,11 @@ function hashTransaction(transactionRequest, chainId) {
2294
2339
  inputClone.predicateGasUsed = bn8(0);
2295
2340
  return inputClone;
2296
2341
  }
2297
- case InputType3.Message: {
2342
+ case InputType4.Message: {
2298
2343
  inputClone.predicateGasUsed = bn8(0);
2299
2344
  return inputClone;
2300
2345
  }
2301
- case InputType3.Contract: {
2346
+ case InputType4.Contract: {
2302
2347
  inputClone.txPointer = {
2303
2348
  blockHeight: 0,
2304
2349
  txIndex: 0
@@ -2458,7 +2503,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2458
2503
  import { addressify as addressify2 } from "@fuel-ts/address";
2459
2504
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2460
2505
  import { bn as bn10 } from "@fuel-ts/math";
2461
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2506
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2462
2507
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2463
2508
 
2464
2509
  // src/providers/transaction-request/scripts.ts
@@ -2542,7 +2587,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2542
2587
  */
2543
2588
  getContractInputs() {
2544
2589
  return this.inputs.filter(
2545
- (input) => input.type === InputType4.Contract
2590
+ (input) => input.type === InputType5.Contract
2546
2591
  );
2547
2592
  }
2548
2593
  /**
@@ -2619,7 +2664,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2619
2664
  return this;
2620
2665
  }
2621
2666
  const inputIndex = super.pushInput({
2622
- type: InputType4.Contract,
2667
+ type: InputType5.Contract,
2623
2668
  contractId: contractAddress.toB256(),
2624
2669
  txPointer: "0x00000000000000000000000000000000"
2625
2670
  });
@@ -2661,7 +2706,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2661
2706
 
2662
2707
  // src/providers/transaction-request/utils.ts
2663
2708
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2664
- import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2709
+ import { TransactionType as TransactionType5, InputType as InputType6 } from "@fuel-ts/transactions";
2665
2710
  var transactionRequestify = (obj) => {
2666
2711
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2667
2712
  return obj;
@@ -2681,10 +2726,10 @@ var transactionRequestify = (obj) => {
2681
2726
  };
2682
2727
  var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2683
2728
  (acc, input) => {
2684
- if (input.type === InputType5.Coin && input.owner === owner) {
2729
+ if (input.type === InputType6.Coin && input.owner === owner) {
2685
2730
  acc.utxos.push(input.id);
2686
2731
  }
2687
- if (input.type === InputType5.Message && input.recipient === owner) {
2732
+ if (input.type === InputType6.Message && input.recipient === owner) {
2688
2733
  acc.messages.push(input.nonce);
2689
2734
  }
2690
2735
  return acc;
@@ -2838,7 +2883,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2838
2883
 
2839
2884
  // src/providers/transaction-summary/input.ts
2840
2885
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2841
- import { InputType as InputType6 } from "@fuel-ts/transactions";
2886
+ import { InputType as InputType7 } from "@fuel-ts/transactions";
2842
2887
  function getInputsByTypes(inputs, types) {
2843
2888
  return inputs.filter((i) => types.includes(i.type));
2844
2889
  }
@@ -2846,16 +2891,16 @@ function getInputsByType(inputs, type) {
2846
2891
  return inputs.filter((i) => i.type === type);
2847
2892
  }
2848
2893
  function getInputsCoin(inputs) {
2849
- return getInputsByType(inputs, InputType6.Coin);
2894
+ return getInputsByType(inputs, InputType7.Coin);
2850
2895
  }
2851
2896
  function getInputsMessage(inputs) {
2852
- return getInputsByType(inputs, InputType6.Message);
2897
+ return getInputsByType(inputs, InputType7.Message);
2853
2898
  }
2854
2899
  function getInputsCoinAndMessage(inputs) {
2855
- return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2900
+ return getInputsByTypes(inputs, [InputType7.Coin, InputType7.Message]);
2856
2901
  }
2857
2902
  function getInputsContract(inputs) {
2858
- return getInputsByType(inputs, InputType6.Contract);
2903
+ return getInputsByType(inputs, InputType7.Contract);
2859
2904
  }
2860
2905
  function getInputFromAssetId(inputs, assetId) {
2861
2906
  const coinInputs = getInputsCoin(inputs);
@@ -2874,7 +2919,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2874
2919
  if (!contractInput) {
2875
2920
  return void 0;
2876
2921
  }
2877
- if (contractInput.type !== InputType6.Contract) {
2922
+ if (contractInput.type !== InputType7.Contract) {
2878
2923
  throw new FuelError9(
2879
2924
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2880
2925
  `Contract input should be of type 'contract'.`
@@ -2883,10 +2928,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2883
2928
  return contractInput;
2884
2929
  }
2885
2930
  function getInputAccountAddress(input) {
2886
- if (input.type === InputType6.Coin) {
2931
+ if (input.type === InputType7.Coin) {
2887
2932
  return input.owner.toString();
2888
2933
  }
2889
- if (input.type === InputType6.Message) {
2934
+ if (input.type === InputType7.Message) {
2890
2935
  return input.recipient.toString();
2891
2936
  }
2892
2937
  return "";
@@ -4762,6 +4807,19 @@ var _Provider = class {
4762
4807
  async getTransactionResponse(transactionId) {
4763
4808
  return new TransactionResponse(transactionId, this);
4764
4809
  }
4810
+ /**
4811
+ * Returns Message for given nonce.
4812
+ *
4813
+ * @param nonce - The nonce of the message to retrieve.
4814
+ * @returns A promise that resolves to the Message object.
4815
+ */
4816
+ async getMessageByNonce(nonce) {
4817
+ const { message } = await this.operations.getMessageByNonce({ nonce });
4818
+ if (!message) {
4819
+ return null;
4820
+ }
4821
+ return message;
4822
+ }
4765
4823
  };
4766
4824
  var Provider = _Provider;
4767
4825
  _cacheInputs = new WeakSet();
@@ -4770,7 +4828,7 @@ cacheInputs_fn = function(inputs) {
4770
4828
  return;
4771
4829
  }
4772
4830
  inputs.forEach((input) => {
4773
- if (input.type === InputType7.Coin) {
4831
+ if (input.type === InputType8.Coin) {
4774
4832
  this.cache?.set(input.id);
4775
4833
  }
4776
4834
  });
@@ -8952,7 +9010,7 @@ import {
8952
9010
  } from "@fuel-ts/abi-coder";
8953
9011
  import { Address as Address9 } from "@fuel-ts/address";
8954
9012
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8955
- import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
9013
+ import { ByteArrayCoder } from "@fuel-ts/transactions";
8956
9014
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8957
9015
 
8958
9016
  // src/predicate/utils/getPredicateRoot.ts
@@ -9011,10 +9069,15 @@ var Predicate = class extends Account {
9011
9069
  populateTransactionPredicateData(transactionRequestLike) {
9012
9070
  const request = transactionRequestify(transactionRequestLike);
9013
9071
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
9014
- request.inputs?.forEach((input) => {
9015
- if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
9072
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
9073
+ if (placeholderIndex !== -1) {
9074
+ request.removeWitness(placeholderIndex);
9075
+ }
9076
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
9077
+ if (isRequestInputResourceFromOwner(input, this.address)) {
9016
9078
  input.predicate = hexlify19(this.bytes);
9017
9079
  input.predicateData = hexlify19(this.getPredicateData(policies.length));
9080
+ input.witnessIndex = 0;
9018
9081
  }
9019
9082
  });
9020
9083
  return request;
@@ -9137,6 +9200,28 @@ var Predicate = class extends Account {
9137
9200
  }
9138
9201
  return mutatedBytes;
9139
9202
  }
9203
+ /**
9204
+ * Returns the index of the witness placeholder that was added to this predicate.
9205
+ * If no witness placeholder was added, it returns -1.
9206
+ * @param request - The transaction request.
9207
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
9208
+ */
9209
+ getIndexFromPlaceholderWitness(request) {
9210
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
9211
+ let index = -1;
9212
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
9213
+ if (hasEmptyPredicateInputs) {
9214
+ index = hasEmptyPredicateInputs.witnessIndex;
9215
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
9216
+ if (!allInputsAreEmpty) {
9217
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
9218
+ if (wasFilledInputAddedFirst) {
9219
+ index = -1;
9220
+ }
9221
+ }
9222
+ }
9223
+ return index;
9224
+ }
9140
9225
  };
9141
9226
 
9142
9227
  // src/connectors/fuel.ts
@@ -9859,6 +9944,7 @@ export {
9859
9944
  assets,
9860
9945
  buildBlockExplorerUrl,
9861
9946
  cacheFor,
9947
+ cacheResources,
9862
9948
  cacheTxInputsFromOwner,
9863
9949
  calculateGasFee,
9864
9950
  calculateMetadataGasForTxCreate,
@@ -9906,6 +9992,7 @@ export {
9906
9992
  getReceiptsMessageOut,
9907
9993
  getReceiptsTransferOut,
9908
9994
  getReceiptsWithMissingData,
9995
+ getRequestInputResourceOwner,
9909
9996
  getTransactionStatusName,
9910
9997
  getTransactionSummary,
9911
9998
  getTransactionSummaryFromRequest,
@@ -9919,6 +10006,10 @@ export {
9919
10006
  isMessage,
9920
10007
  isRawCoin,
9921
10008
  isRawMessage,
10009
+ isRequestInputCoin,
10010
+ isRequestInputMessage,
10011
+ isRequestInputResource,
10012
+ isRequestInputResourceFromOwner,
9922
10013
  isType,
9923
10014
  isTypeCreate,
9924
10015
  isTypeMint,