@fuel-ts/account 0.0.0-rc-2037-20240423110545 → 0.0.0-rc-2045-20240423120113

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 +57 -88
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +141 -201
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +64 -118
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/predicate/predicate.d.ts +2 -17
  8. package/dist/predicate/predicate.d.ts.map +1 -1
  9. package/dist/providers/coin.d.ts +1 -2
  10. package/dist/providers/coin.d.ts.map +1 -1
  11. package/dist/providers/message.d.ts +0 -1
  12. package/dist/providers/message.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/index.d.ts +0 -1
  14. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  15. package/dist/providers/transaction-request/transaction-request.d.ts +20 -4
  16. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  17. package/dist/test-utils/index.d.ts +0 -1
  18. package/dist/test-utils/index.d.ts.map +1 -1
  19. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  20. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  21. package/dist/test-utils.global.js +58 -66
  22. package/dist/test-utils.global.js.map +1 -1
  23. package/dist/test-utils.js +135 -173
  24. package/dist/test-utils.js.map +1 -1
  25. package/dist/test-utils.mjs +64 -99
  26. package/dist/test-utils.mjs.map +1 -1
  27. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  28. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  29. package/package.json +15 -15
  30. package/dist/providers/transaction-request/helpers.d.ts +0 -10
  31. package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
  32. package/dist/test-utils/resources.d.ts +0 -4
  33. package/dist/test-utils/resources.d.ts.map +0 -1
  34. package/dist/test-utils/transactionRequest.d.ts +0 -5
  35. package/dist/test-utils/transactionRequest.d.ts.map +0 -1
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 InputType7,
79
+ InputType as InputType6,
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 InputType3,
1176
+ InputType as InputType2,
1177
1177
  OutputType as OutputType2,
1178
1178
  TransactionType
1179
1179
  } from "@fuel-ts/transactions";
@@ -1676,28 +1676,6 @@ 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) => isRequestInputCoin(input) ? input.owner : input.recipient;
1685
- var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1686
- var cacheResources = (resources) => resources.reduce(
1687
- (cache2, resource) => {
1688
- if (isCoin(resource)) {
1689
- cache2.utxos.push(resource.id);
1690
- } else {
1691
- cache2.messages.push(resource.nonce);
1692
- }
1693
- return cache2;
1694
- },
1695
- {
1696
- utxos: [],
1697
- messages: []
1698
- }
1699
- );
1700
-
1701
1679
  // src/providers/transaction-request/witness.ts
1702
1680
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1703
1681
  var witnessify = (value) => {
@@ -1888,7 +1866,7 @@ var BaseTransactionRequest = class {
1888
1866
  */
1889
1867
  getCoinInputs() {
1890
1868
  return this.inputs.filter(
1891
- (input) => input.type === InputType3.Coin
1869
+ (input) => input.type === InputType2.Coin
1892
1870
  );
1893
1871
  }
1894
1872
  /**
@@ -1920,9 +1898,9 @@ var BaseTransactionRequest = class {
1920
1898
  const ownerAddress = addressify(owner);
1921
1899
  const found = this.inputs.find((input) => {
1922
1900
  switch (input.type) {
1923
- case InputType3.Coin:
1901
+ case InputType2.Coin:
1924
1902
  return hexlify7(input.owner) === ownerAddress.toB256();
1925
- case InputType3.Message:
1903
+ case InputType2.Message:
1926
1904
  return hexlify7(input.recipient) === ownerAddress.toB256();
1927
1905
  default:
1928
1906
  return false;
@@ -1938,8 +1916,8 @@ var BaseTransactionRequest = class {
1938
1916
  * @param predicate - Predicate bytes.
1939
1917
  * @param predicateData - Predicate data bytes.
1940
1918
  */
1941
- addCoinInput(coin) {
1942
- const { assetId, owner, amount, id, predicate } = coin;
1919
+ addCoinInput(coin, predicate) {
1920
+ const { assetId, owner, amount } = coin;
1943
1921
  let witnessIndex;
1944
1922
  if (predicate) {
1945
1923
  witnessIndex = 0;
@@ -1950,14 +1928,14 @@ var BaseTransactionRequest = class {
1950
1928
  }
1951
1929
  }
1952
1930
  const input = {
1953
- id,
1954
- type: InputType3.Coin,
1931
+ ...coin,
1932
+ type: InputType2.Coin,
1955
1933
  owner: owner.toB256(),
1956
1934
  amount,
1957
1935
  assetId,
1958
1936
  txPointer: "0x00000000000000000000000000000000",
1959
1937
  witnessIndex,
1960
- predicate
1938
+ predicate: predicate?.bytes
1961
1939
  };
1962
1940
  this.pushInput(input);
1963
1941
  this.addChangeOutput(owner, assetId);
@@ -1970,8 +1948,8 @@ var BaseTransactionRequest = class {
1970
1948
  * @param predicate - Predicate bytes.
1971
1949
  * @param predicateData - Predicate data bytes.
1972
1950
  */
1973
- addMessageInput(message) {
1974
- const { recipient, sender, amount, predicate, nonce } = message;
1951
+ addMessageInput(message, predicate) {
1952
+ const { recipient, sender, amount } = message;
1975
1953
  const assetId = BaseAssetId2;
1976
1954
  let witnessIndex;
1977
1955
  if (predicate) {
@@ -1983,13 +1961,13 @@ var BaseTransactionRequest = class {
1983
1961
  }
1984
1962
  }
1985
1963
  const input = {
1986
- nonce,
1987
- type: InputType3.Message,
1964
+ ...message,
1965
+ type: InputType2.Message,
1988
1966
  sender: sender.toB256(),
1989
1967
  recipient: recipient.toB256(),
1990
1968
  amount,
1991
1969
  witnessIndex,
1992
- predicate
1970
+ predicate: predicate?.bytes
1993
1971
  };
1994
1972
  this.pushInput(input);
1995
1973
  this.addChangeOutput(recipient, assetId);
@@ -2020,6 +1998,32 @@ var BaseTransactionRequest = class {
2020
1998
  resources.forEach((resource) => this.addResource(resource));
2021
1999
  return this;
2022
2000
  }
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
+ }
2023
2027
  /**
2024
2028
  * Adds a coin output to the transaction.
2025
2029
  *
@@ -2168,20 +2172,16 @@ var BaseTransactionRequest = class {
2168
2172
  toJSON() {
2169
2173
  return normalizeJSON(this);
2170
2174
  }
2171
- removeWitness(index) {
2172
- this.witnesses.splice(index, 1);
2173
- this.adjustWitnessIndexes(index);
2174
- }
2175
2175
  updatePredicateInputs(inputs) {
2176
2176
  this.inputs.forEach((i) => {
2177
2177
  let correspondingInput;
2178
2178
  switch (i.type) {
2179
- case InputType3.Coin:
2180
- correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2179
+ case InputType2.Coin:
2180
+ correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2181
2181
  break;
2182
- case InputType3.Message:
2182
+ case InputType2.Message:
2183
2183
  correspondingInput = inputs.find(
2184
- (x) => x.type === InputType3.Message && x.sender === i.sender
2184
+ (x) => x.type === InputType2.Message && x.sender === i.sender
2185
2185
  );
2186
2186
  break;
2187
2187
  default:
@@ -2194,13 +2194,6 @@ var BaseTransactionRequest = class {
2194
2194
  }
2195
2195
  });
2196
2196
  }
2197
- adjustWitnessIndexes(removedIndex) {
2198
- this.inputs.filter(isRequestInputResource).forEach((input) => {
2199
- if (input.witnessIndex > removedIndex) {
2200
- input.witnessIndex -= 1;
2201
- }
2202
- });
2203
- }
2204
2197
  };
2205
2198
 
2206
2199
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2213,7 +2206,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2213
2206
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2214
2207
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2215
2208
  import { bn as bn8 } from "@fuel-ts/math";
2216
- import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2209
+ import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2217
2210
  import { concat as concat2 } from "@fuel-ts/utils";
2218
2211
  import { clone as clone2 } from "ramda";
2219
2212
  function hashTransaction(transactionRequest, chainId) {
@@ -2224,7 +2217,7 @@ function hashTransaction(transactionRequest, chainId) {
2224
2217
  transaction.inputs = transaction.inputs.map((input) => {
2225
2218
  const inputClone = clone2(input);
2226
2219
  switch (inputClone.type) {
2227
- case InputType4.Coin: {
2220
+ case InputType3.Coin: {
2228
2221
  inputClone.txPointer = {
2229
2222
  blockHeight: 0,
2230
2223
  txIndex: 0
@@ -2232,11 +2225,11 @@ function hashTransaction(transactionRequest, chainId) {
2232
2225
  inputClone.predicateGasUsed = bn8(0);
2233
2226
  return inputClone;
2234
2227
  }
2235
- case InputType4.Message: {
2228
+ case InputType3.Message: {
2236
2229
  inputClone.predicateGasUsed = bn8(0);
2237
2230
  return inputClone;
2238
2231
  }
2239
- case InputType4.Contract: {
2232
+ case InputType3.Contract: {
2240
2233
  inputClone.txPointer = {
2241
2234
  blockHeight: 0,
2242
2235
  txIndex: 0
@@ -2402,7 +2395,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2402
2395
  import { addressify as addressify2 } from "@fuel-ts/address";
2403
2396
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2404
2397
  import { bn as bn10 } from "@fuel-ts/math";
2405
- import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2398
+ import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2406
2399
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2407
2400
 
2408
2401
  // src/providers/transaction-request/scripts.ts
@@ -2486,7 +2479,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2486
2479
  */
2487
2480
  getContractInputs() {
2488
2481
  return this.inputs.filter(
2489
- (input) => input.type === InputType5.Contract
2482
+ (input) => input.type === InputType4.Contract
2490
2483
  );
2491
2484
  }
2492
2485
  /**
@@ -2562,7 +2555,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2562
2555
  return this;
2563
2556
  }
2564
2557
  const inputIndex = super.pushInput({
2565
- type: InputType5.Contract,
2558
+ type: InputType4.Contract,
2566
2559
  contractId: contractAddress.toB256(),
2567
2560
  txPointer: "0x00000000000000000000000000000000"
2568
2561
  });
@@ -2757,7 +2750,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2757
2750
 
2758
2751
  // src/providers/transaction-summary/input.ts
2759
2752
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2760
- import { InputType as InputType6 } from "@fuel-ts/transactions";
2753
+ import { InputType as InputType5 } from "@fuel-ts/transactions";
2761
2754
  function getInputsByTypes(inputs, types) {
2762
2755
  return inputs.filter((i) => types.includes(i.type));
2763
2756
  }
@@ -2765,16 +2758,16 @@ function getInputsByType(inputs, type) {
2765
2758
  return inputs.filter((i) => i.type === type);
2766
2759
  }
2767
2760
  function getInputsCoin(inputs) {
2768
- return getInputsByType(inputs, InputType6.Coin);
2761
+ return getInputsByType(inputs, InputType5.Coin);
2769
2762
  }
2770
2763
  function getInputsMessage(inputs) {
2771
- return getInputsByType(inputs, InputType6.Message);
2764
+ return getInputsByType(inputs, InputType5.Message);
2772
2765
  }
2773
2766
  function getInputsCoinAndMessage(inputs) {
2774
- return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2767
+ return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2775
2768
  }
2776
2769
  function getInputsContract(inputs) {
2777
- return getInputsByType(inputs, InputType6.Contract);
2770
+ return getInputsByType(inputs, InputType5.Contract);
2778
2771
  }
2779
2772
  function getInputFromAssetId(inputs, assetId) {
2780
2773
  const coinInputs = getInputsCoin(inputs);
@@ -2793,7 +2786,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2793
2786
  if (!contractInput) {
2794
2787
  return void 0;
2795
2788
  }
2796
- if (contractInput.type !== InputType6.Contract) {
2789
+ if (contractInput.type !== InputType5.Contract) {
2797
2790
  throw new FuelError9(
2798
2791
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2799
2792
  `Contract input should be of type 'contract'.`
@@ -2802,10 +2795,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2802
2795
  return contractInput;
2803
2796
  }
2804
2797
  function getInputAccountAddress(input) {
2805
- if (input.type === InputType6.Coin) {
2798
+ if (input.type === InputType5.Coin) {
2806
2799
  return input.owner.toString();
2807
2800
  }
2808
- if (input.type === InputType6.Message) {
2801
+ if (input.type === InputType5.Message) {
2809
2802
  return input.recipient.toString();
2810
2803
  }
2811
2804
  return "";
@@ -4549,7 +4542,7 @@ cacheInputs_fn = function(inputs) {
4549
4542
  return;
4550
4543
  }
4551
4544
  inputs.forEach((input) => {
4552
- if (input.type === InputType7.Coin) {
4545
+ if (input.type === InputType6.Coin) {
4553
4546
  this.cache?.set(input.id);
4554
4547
  }
4555
4548
  });
@@ -8718,7 +8711,7 @@ import {
8718
8711
  import { Address as Address9 } from "@fuel-ts/address";
8719
8712
  import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8720
8713
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8721
- import { ByteArrayCoder } from "@fuel-ts/transactions";
8714
+ import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8722
8715
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8723
8716
 
8724
8717
  // src/predicate/utils/getPredicateRoot.ts
@@ -8777,15 +8770,10 @@ var Predicate = class extends Account {
8777
8770
  populateTransactionPredicateData(transactionRequestLike) {
8778
8771
  const request = transactionRequestify(transactionRequestLike);
8779
8772
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8780
- const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8781
- if (placeholderIndex !== -1) {
8782
- request.removeWitness(placeholderIndex);
8783
- }
8784
- request.inputs.filter(isRequestInputResource).forEach((input) => {
8785
- if (isRequestInputResourceFromOwner(input, this.address)) {
8773
+ request.inputs?.forEach((input) => {
8774
+ if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8786
8775
  input.predicate = this.bytes;
8787
8776
  input.predicateData = this.getPredicateData(policies.length);
8788
- input.witnessIndex = 0;
8789
8777
  }
8790
8778
  });
8791
8779
  return request;
@@ -8823,20 +8811,6 @@ var Predicate = class extends Account {
8823
8811
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8824
8812
  return super.simulateTransaction(transactionRequest);
8825
8813
  }
8826
- /**
8827
- * Retrieves resources satisfying the spend query for the account.
8828
- *
8829
- * @param quantities - Coins to retrieve.
8830
- * @param excludedIds - IDs of resources to be excluded from the query.
8831
- * @returns A promise that resolves to an array of Resources.
8832
- */
8833
- async getResourcesToSpend(quantities, excludedIds) {
8834
- const resources = await super.getResourcesToSpend(quantities, excludedIds);
8835
- return resources.map((resource) => ({
8836
- ...resource,
8837
- predicate: hexlify19(this.bytes)
8838
- }));
8839
- }
8840
8814
  getPredicateData(policiesLength) {
8841
8815
  if (!this.predicateData.length) {
8842
8816
  return new Uint8Array();
@@ -8916,28 +8890,6 @@ var Predicate = class extends Account {
8916
8890
  }
8917
8891
  return mutatedBytes;
8918
8892
  }
8919
- /**
8920
- * Returns the index of the witness placeholder that was added to this predicate.
8921
- * If no witness placeholder was added, it returns -1.
8922
- * @param request - The transaction request.
8923
- * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
8924
- */
8925
- getIndexFromPlaceholderWitness(request) {
8926
- const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
8927
- let index = -1;
8928
- const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
8929
- if (hasEmptyPredicateInputs) {
8930
- index = hasEmptyPredicateInputs.witnessIndex;
8931
- const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
8932
- if (!allInputsAreEmpty) {
8933
- const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
8934
- if (wasFilledInputAddedFirst) {
8935
- index = -1;
8936
- }
8937
- }
8938
- }
8939
- return index;
8940
- }
8941
8893
  };
8942
8894
 
8943
8895
  // src/connectors/fuel.ts
@@ -9660,7 +9612,6 @@ export {
9660
9612
  assets,
9661
9613
  buildBlockExplorerUrl,
9662
9614
  cacheFor,
9663
- cacheResources,
9664
9615
  calculateMetadataGasForTxCreate,
9665
9616
  calculateMetadataGasForTxScript,
9666
9617
  calculatePriceWithFactor,
@@ -9707,7 +9658,6 @@ export {
9707
9658
  getReceiptsMessageOut,
9708
9659
  getReceiptsTransferOut,
9709
9660
  getReceiptsWithMissingData,
9710
- getRequestInputResourceOwner,
9711
9661
  getTransactionStatusName,
9712
9662
  getTransactionSummary,
9713
9663
  getTransactionSummaryFromRequest,
@@ -9721,10 +9671,6 @@ export {
9721
9671
  isMessage,
9722
9672
  isRawCoin,
9723
9673
  isRawMessage,
9724
- isRequestInputCoin,
9725
- isRequestInputMessage,
9726
- isRequestInputResource,
9727
- isRequestInputResourceFromOwner,
9728
9674
  isType,
9729
9675
  isTypeCreate,
9730
9676
  isTypeMint,