@fuel-ts/account 0.0.0-rc-2045-20240417092921 → 0.0.0-rc-2037-20240417131250

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 (35) hide show
  1. package/dist/index.global.js +85 -39
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +200 -141
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +117 -64
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/predicate/predicate.d.ts +11 -2
  8. package/dist/predicate/predicate.d.ts.map +1 -1
  9. package/dist/providers/coin.d.ts +2 -1
  10. package/dist/providers/coin.d.ts.map +1 -1
  11. package/dist/providers/message.d.ts +1 -0
  12. package/dist/providers/message.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/helpers.d.ts +10 -0
  14. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  15. package/dist/providers/transaction-request/index.d.ts +1 -0
  16. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  17. package/dist/providers/transaction-request/transaction-request.d.ts +4 -20
  18. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  19. package/dist/test-utils/index.d.ts +1 -0
  20. package/dist/test-utils/index.d.ts.map +1 -1
  21. package/dist/test-utils/resources.d.ts +4 -0
  22. package/dist/test-utils/resources.d.ts.map +1 -0
  23. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  24. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  25. package/dist/test-utils/transactionRequest.d.ts +5 -0
  26. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  27. package/dist/test-utils.global.js +64 -40
  28. package/dist/test-utils.global.js.map +1 -1
  29. package/dist/test-utils.js +173 -135
  30. package/dist/test-utils.js.map +1 -1
  31. package/dist/test-utils.mjs +99 -64
  32. package/dist/test-utils.mjs.map +1 -1
  33. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  34. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  35. package/package.json +15 -15
package/dist/index.mjs CHANGED
@@ -76,7 +76,7 @@ import { Address as Address2 } from "@fuel-ts/address";
76
76
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
77
77
  import { BN, bn as bn15, max } from "@fuel-ts/math";
78
78
  import {
79
- InputType as InputType6,
79
+ InputType as InputType7,
80
80
  TransactionType as TransactionType8,
81
81
  InputMessageCoder,
82
82
  TransactionCoder as TransactionCoder5
@@ -1173,7 +1173,7 @@ import { bn as bn7 } from "@fuel-ts/math";
1173
1173
  import {
1174
1174
  PolicyType,
1175
1175
  TransactionCoder,
1176
- InputType as InputType2,
1176
+ InputType as InputType3,
1177
1177
  OutputType as OutputType2,
1178
1178
  TransactionType
1179
1179
  } from "@fuel-ts/transactions";
@@ -1676,6 +1676,33 @@ var NoWitnessByOwnerError = class extends Error {
1676
1676
  name = "NoWitnessByOwnerError";
1677
1677
  };
1678
1678
 
1679
+ // src/providers/transaction-request/helpers.ts
1680
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1681
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1682
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1683
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1684
+ var getRequestInputResourceOwner = (input) => {
1685
+ if (isRequestInputCoin(input)) {
1686
+ return input.owner;
1687
+ }
1688
+ return input.recipient;
1689
+ };
1690
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1691
+ var cacheResources = (resources) => resources.reduce(
1692
+ (cache2, resource) => {
1693
+ if (isCoin(resource)) {
1694
+ cache2.utxos.push(resource.id);
1695
+ } else {
1696
+ cache2.messages.push(resource.nonce);
1697
+ }
1698
+ return cache2;
1699
+ },
1700
+ {
1701
+ utxos: [],
1702
+ messages: []
1703
+ }
1704
+ );
1705
+
1679
1706
  // src/providers/transaction-request/witness.ts
1680
1707
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1681
1708
  var witnessify = (value) => {
@@ -1866,7 +1893,7 @@ var BaseTransactionRequest = class {
1866
1893
  */
1867
1894
  getCoinInputs() {
1868
1895
  return this.inputs.filter(
1869
- (input) => input.type === InputType2.Coin
1896
+ (input) => input.type === InputType3.Coin
1870
1897
  );
1871
1898
  }
1872
1899
  /**
@@ -1898,9 +1925,9 @@ var BaseTransactionRequest = class {
1898
1925
  const ownerAddress = addressify(owner);
1899
1926
  const found = this.inputs.find((input) => {
1900
1927
  switch (input.type) {
1901
- case InputType2.Coin:
1928
+ case InputType3.Coin:
1902
1929
  return hexlify7(input.owner) === ownerAddress.toB256();
1903
- case InputType2.Message:
1930
+ case InputType3.Message:
1904
1931
  return hexlify7(input.recipient) === ownerAddress.toB256();
1905
1932
  default:
1906
1933
  return false;
@@ -1916,8 +1943,8 @@ var BaseTransactionRequest = class {
1916
1943
  * @param predicate - Predicate bytes.
1917
1944
  * @param predicateData - Predicate data bytes.
1918
1945
  */
1919
- addCoinInput(coin, predicate) {
1920
- const { assetId, owner, amount } = coin;
1946
+ addCoinInput(coin) {
1947
+ const { assetId, owner, amount, id, predicate } = coin;
1921
1948
  let witnessIndex;
1922
1949
  if (predicate) {
1923
1950
  witnessIndex = 0;
@@ -1928,14 +1955,14 @@ var BaseTransactionRequest = class {
1928
1955
  }
1929
1956
  }
1930
1957
  const input = {
1931
- ...coin,
1932
- type: InputType2.Coin,
1958
+ id,
1959
+ type: InputType3.Coin,
1933
1960
  owner: owner.toB256(),
1934
1961
  amount,
1935
1962
  assetId,
1936
1963
  txPointer: "0x00000000000000000000000000000000",
1937
1964
  witnessIndex,
1938
- predicate: predicate?.bytes
1965
+ predicate
1939
1966
  };
1940
1967
  this.pushInput(input);
1941
1968
  this.addChangeOutput(owner, assetId);
@@ -1948,8 +1975,8 @@ var BaseTransactionRequest = class {
1948
1975
  * @param predicate - Predicate bytes.
1949
1976
  * @param predicateData - Predicate data bytes.
1950
1977
  */
1951
- addMessageInput(message, predicate) {
1952
- const { recipient, sender, amount } = message;
1978
+ addMessageInput(message) {
1979
+ const { recipient, sender, amount, predicate, nonce } = message;
1953
1980
  const assetId = BaseAssetId2;
1954
1981
  let witnessIndex;
1955
1982
  if (predicate) {
@@ -1961,13 +1988,13 @@ var BaseTransactionRequest = class {
1961
1988
  }
1962
1989
  }
1963
1990
  const input = {
1964
- ...message,
1965
- type: InputType2.Message,
1991
+ nonce,
1992
+ type: InputType3.Message,
1966
1993
  sender: sender.toB256(),
1967
1994
  recipient: recipient.toB256(),
1968
1995
  amount,
1969
1996
  witnessIndex,
1970
- predicate: predicate?.bytes
1997
+ predicate
1971
1998
  };
1972
1999
  this.pushInput(input);
1973
2000
  this.addChangeOutput(recipient, assetId);
@@ -1998,32 +2025,6 @@ var BaseTransactionRequest = class {
1998
2025
  resources.forEach((resource) => this.addResource(resource));
1999
2026
  return this;
2000
2027
  }
2001
- /**
2002
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2003
- * outputs from the related assetIds.
2004
- *
2005
- * @param resources - The resources to add.
2006
- * @returns This transaction.
2007
- */
2008
- addPredicateResource(resource, predicate) {
2009
- if (isCoin(resource)) {
2010
- this.addCoinInput(resource, predicate);
2011
- } else {
2012
- this.addMessageInput(resource, predicate);
2013
- }
2014
- return this;
2015
- }
2016
- /**
2017
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2018
- * from the related assetIds.
2019
- *
2020
- * @param resources - The resources to add.
2021
- * @returns This transaction.
2022
- */
2023
- addPredicateResources(resources, predicate) {
2024
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2025
- return this;
2026
- }
2027
2028
  /**
2028
2029
  * Adds a coin output to the transaction.
2029
2030
  *
@@ -2172,16 +2173,20 @@ var BaseTransactionRequest = class {
2172
2173
  toJSON() {
2173
2174
  return normalizeJSON(this);
2174
2175
  }
2176
+ removeWitness(index) {
2177
+ this.witnesses.splice(index, 1);
2178
+ this.adjustWitnessIndexes(index);
2179
+ }
2175
2180
  updatePredicateInputs(inputs) {
2176
2181
  this.inputs.forEach((i) => {
2177
2182
  let correspondingInput;
2178
2183
  switch (i.type) {
2179
- case InputType2.Coin:
2180
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2184
+ case InputType3.Coin:
2185
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2181
2186
  break;
2182
- case InputType2.Message:
2187
+ case InputType3.Message:
2183
2188
  correspondingInput = inputs.find(
2184
- (x) => x.type === InputType2.Message && x.sender === i.sender
2189
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2185
2190
  );
2186
2191
  break;
2187
2192
  default:
@@ -2194,6 +2199,13 @@ var BaseTransactionRequest = class {
2194
2199
  }
2195
2200
  });
2196
2201
  }
2202
+ adjustWitnessIndexes(removedIndex) {
2203
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2204
+ if (input.witnessIndex > removedIndex) {
2205
+ input.witnessIndex -= 1;
2206
+ }
2207
+ });
2208
+ }
2197
2209
  };
2198
2210
 
2199
2211
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2206,7 +2218,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2206
2218
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2207
2219
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2208
2220
  import { bn as bn8 } from "@fuel-ts/math";
2209
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2221
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2210
2222
  import { concat as concat2 } from "@fuel-ts/utils";
2211
2223
  import { clone as clone2 } from "ramda";
2212
2224
  function hashTransaction(transactionRequest, chainId) {
@@ -2217,7 +2229,7 @@ function hashTransaction(transactionRequest, chainId) {
2217
2229
  transaction.inputs = transaction.inputs.map((input) => {
2218
2230
  const inputClone = clone2(input);
2219
2231
  switch (inputClone.type) {
2220
- case InputType3.Coin: {
2232
+ case InputType4.Coin: {
2221
2233
  inputClone.txPointer = {
2222
2234
  blockHeight: 0,
2223
2235
  txIndex: 0
@@ -2225,11 +2237,11 @@ function hashTransaction(transactionRequest, chainId) {
2225
2237
  inputClone.predicateGasUsed = bn8(0);
2226
2238
  return inputClone;
2227
2239
  }
2228
- case InputType3.Message: {
2240
+ case InputType4.Message: {
2229
2241
  inputClone.predicateGasUsed = bn8(0);
2230
2242
  return inputClone;
2231
2243
  }
2232
- case InputType3.Contract: {
2244
+ case InputType4.Contract: {
2233
2245
  inputClone.txPointer = {
2234
2246
  blockHeight: 0,
2235
2247
  txIndex: 0
@@ -2395,7 +2407,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2395
2407
  import { addressify as addressify2 } from "@fuel-ts/address";
2396
2408
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2397
2409
  import { bn as bn10 } from "@fuel-ts/math";
2398
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2410
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2399
2411
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2400
2412
 
2401
2413
  // src/providers/transaction-request/scripts.ts
@@ -2479,7 +2491,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2479
2491
  */
2480
2492
  getContractInputs() {
2481
2493
  return this.inputs.filter(
2482
- (input) => input.type === InputType4.Contract
2494
+ (input) => input.type === InputType5.Contract
2483
2495
  );
2484
2496
  }
2485
2497
  /**
@@ -2555,7 +2567,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2555
2567
  return this;
2556
2568
  }
2557
2569
  const inputIndex = super.pushInput({
2558
- type: InputType4.Contract,
2570
+ type: InputType5.Contract,
2559
2571
  contractId: contractAddress.toB256(),
2560
2572
  txPointer: "0x00000000000000000000000000000000"
2561
2573
  });
@@ -2750,7 +2762,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2750
2762
 
2751
2763
  // src/providers/transaction-summary/input.ts
2752
2764
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2753
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2765
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2754
2766
  function getInputsByTypes(inputs, types) {
2755
2767
  return inputs.filter((i) => types.includes(i.type));
2756
2768
  }
@@ -2758,16 +2770,16 @@ function getInputsByType(inputs, type) {
2758
2770
  return inputs.filter((i) => i.type === type);
2759
2771
  }
2760
2772
  function getInputsCoin(inputs) {
2761
- return getInputsByType(inputs, InputType5.Coin);
2773
+ return getInputsByType(inputs, InputType6.Coin);
2762
2774
  }
2763
2775
  function getInputsMessage(inputs) {
2764
- return getInputsByType(inputs, InputType5.Message);
2776
+ return getInputsByType(inputs, InputType6.Message);
2765
2777
  }
2766
2778
  function getInputsCoinAndMessage(inputs) {
2767
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2779
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2768
2780
  }
2769
2781
  function getInputsContract(inputs) {
2770
- return getInputsByType(inputs, InputType5.Contract);
2782
+ return getInputsByType(inputs, InputType6.Contract);
2771
2783
  }
2772
2784
  function getInputFromAssetId(inputs, assetId) {
2773
2785
  const coinInputs = getInputsCoin(inputs);
@@ -2786,7 +2798,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2786
2798
  if (!contractInput) {
2787
2799
  return void 0;
2788
2800
  }
2789
- if (contractInput.type !== InputType5.Contract) {
2801
+ if (contractInput.type !== InputType6.Contract) {
2790
2802
  throw new FuelError9(
2791
2803
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2792
2804
  `Contract input should be of type 'contract'.`
@@ -2795,10 +2807,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2795
2807
  return contractInput;
2796
2808
  }
2797
2809
  function getInputAccountAddress(input) {
2798
- if (input.type === InputType5.Coin) {
2810
+ if (input.type === InputType6.Coin) {
2799
2811
  return input.owner.toString();
2800
2812
  }
2801
- if (input.type === InputType5.Message) {
2813
+ if (input.type === InputType6.Message) {
2802
2814
  return input.recipient.toString();
2803
2815
  }
2804
2816
  return "";
@@ -4542,7 +4554,7 @@ cacheInputs_fn = function(inputs) {
4542
4554
  return;
4543
4555
  }
4544
4556
  inputs.forEach((input) => {
4545
- if (input.type === InputType6.Coin) {
4557
+ if (input.type === InputType7.Coin) {
4546
4558
  this.cache?.set(input.id);
4547
4559
  }
4548
4560
  });
@@ -8711,7 +8723,7 @@ import {
8711
8723
  import { Address as Address9 } from "@fuel-ts/address";
8712
8724
  import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8713
8725
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8714
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8726
+ import { ByteArrayCoder } from "@fuel-ts/transactions";
8715
8727
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8716
8728
 
8717
8729
  // src/predicate/utils/getPredicateRoot.ts
@@ -8770,10 +8782,15 @@ var Predicate = class extends Account {
8770
8782
  populateTransactionPredicateData(transactionRequestLike) {
8771
8783
  const request = transactionRequestify(transactionRequestLike);
8772
8784
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8773
- request.inputs?.forEach((input) => {
8774
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8785
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8786
+ if (placeholderIndex !== -1) {
8787
+ request.removeWitness(placeholderIndex);
8788
+ }
8789
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
8790
+ if (isRequestInputResourceFromOwner(input, this.address)) {
8775
8791
  input.predicate = this.bytes;
8776
8792
  input.predicateData = this.getPredicateData(policies.length);
8793
+ input.witnessIndex = 0;
8777
8794
  }
8778
8795
  });
8779
8796
  return request;
@@ -8811,6 +8828,20 @@ var Predicate = class extends Account {
8811
8828
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8812
8829
  return super.simulateTransaction(transactionRequest);
8813
8830
  }
8831
+ /**
8832
+ * Retrieves resources satisfying the spend query for the account.
8833
+ *
8834
+ * @param quantities - IDs of coins to exclude.
8835
+ * @param excludedIds - IDs of resources to be excluded from the query.
8836
+ * @returns A promise that resolves to an array of Resources.
8837
+ */
8838
+ async getResourcesToSpend(quantities, excludedIds) {
8839
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
8840
+ return resources.map((resource) => ({
8841
+ ...resource,
8842
+ predicate: hexlify19(this.bytes)
8843
+ }));
8844
+ }
8814
8845
  getPredicateData(policiesLength) {
8815
8846
  if (!this.predicateData.length) {
8816
8847
  return new Uint8Array();
@@ -8890,6 +8921,22 @@ var Predicate = class extends Account {
8890
8921
  }
8891
8922
  return mutatedBytes;
8892
8923
  }
8924
+ getIndexFromPlaceholderWitness(request) {
8925
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
8926
+ let index = -1;
8927
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
8928
+ if (hasEmptyPredicateInputs) {
8929
+ index = hasEmptyPredicateInputs.witnessIndex;
8930
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
8931
+ if (!allInputsAreEmpty) {
8932
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
8933
+ if (wasFilledInputAddedFirst) {
8934
+ index = -1;
8935
+ }
8936
+ }
8937
+ }
8938
+ return index;
8939
+ }
8893
8940
  };
8894
8941
 
8895
8942
  // src/connectors/fuel.ts
@@ -9612,6 +9659,7 @@ export {
9612
9659
  assets,
9613
9660
  buildBlockExplorerUrl,
9614
9661
  cacheFor,
9662
+ cacheResources,
9615
9663
  calculateMetadataGasForTxCreate,
9616
9664
  calculateMetadataGasForTxScript,
9617
9665
  calculatePriceWithFactor,
@@ -9658,6 +9706,7 @@ export {
9658
9706
  getReceiptsMessageOut,
9659
9707
  getReceiptsTransferOut,
9660
9708
  getReceiptsWithMissingData,
9709
+ getRequestInputResourceOwner,
9661
9710
  getTransactionStatusName,
9662
9711
  getTransactionSummary,
9663
9712
  getTransactionSummaryFromRequest,
@@ -9671,6 +9720,10 @@ export {
9671
9720
  isMessage,
9672
9721
  isRawCoin,
9673
9722
  isRawMessage,
9723
+ isRequestInputCoin,
9724
+ isRequestInputMessage,
9725
+ isRequestInputResource,
9726
+ isRequestInputResourceFromOwner,
9674
9727
  isType,
9675
9728
  isTypeCreate,
9676
9729
  isTypeMint,