@fuel-ts/account 0.0.0-rc-2152-20240429145747 → 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 (36) hide show
  1. package/README.md +15 -12
  2. package/dist/index.global.js +1097 -126
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +241 -128
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +146 -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 +17 -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/resources.d.ts +4 -0
  23. package/dist/test-utils/resources.d.ts.map +1 -0
  24. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  25. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  26. package/dist/test-utils/transactionRequest.d.ts +5 -0
  27. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  28. package/dist/test-utils.global.js +1104 -136
  29. package/dist/test-utils.global.js.map +1 -1
  30. package/dist/test-utils.js +228 -125
  31. package/dist/test-utils.js.map +1 -1
  32. package/dist/test-utils.mjs +142 -42
  33. package/dist/test-utils.mjs.map +1 -1
  34. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  35. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  36. package/package.json +15 -15
@@ -70,7 +70,7 @@ import { Address as Address2 } from "@fuel-ts/address";
70
70
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
71
71
  import { BN, bn as bn16 } from "@fuel-ts/math";
72
72
  import {
73
- InputType as InputType7,
73
+ InputType as InputType8,
74
74
  TransactionType as TransactionType8,
75
75
  InputMessageCoder,
76
76
  TransactionCoder as TransactionCoder5
@@ -78,6 +78,7 @@ import {
78
78
  import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
79
79
  import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
80
80
  import { equalBytes } from "@noble/curves/abstract/utils";
81
+ import { Network } from "ethers";
81
82
  import { GraphQLClient } from "graphql-request";
82
83
  import { clone as clone3 } from "ramda";
83
84
 
@@ -852,6 +853,13 @@ var ProduceBlocksDocument = gql`
852
853
  )
853
854
  }
854
855
  `;
856
+ var GetMessageByNonceDocument = gql`
857
+ query getMessageByNonce($nonce: Nonce!) {
858
+ message(nonce: $nonce) {
859
+ ...messageFragment
860
+ }
861
+ }
862
+ ${MessageFragmentFragmentDoc}`;
855
863
  var SubmitAndAwaitDocument = gql`
856
864
  subscription submitAndAwait($encodedTransaction: HexString!) {
857
865
  submitAndAwait(tx: $encodedTransaction) {
@@ -946,6 +954,9 @@ function getSdk(requester) {
946
954
  produceBlocks(variables, options) {
947
955
  return requester(ProduceBlocksDocument, variables, options);
948
956
  },
957
+ getMessageByNonce(variables, options) {
958
+ return requester(GetMessageByNonceDocument, variables, options);
959
+ },
949
960
  submitAndAwait(variables, options) {
950
961
  return requester(SubmitAndAwaitDocument, variables, options);
951
962
  },
@@ -1234,7 +1245,7 @@ import { bn as bn7 } from "@fuel-ts/math";
1234
1245
  import {
1235
1246
  PolicyType,
1236
1247
  TransactionCoder,
1237
- InputType as InputType2,
1248
+ InputType as InputType3,
1238
1249
  OutputType as OutputType2,
1239
1250
  TransactionType
1240
1251
  } from "@fuel-ts/transactions";
@@ -1684,6 +1695,12 @@ var NoWitnessAtIndexError = class extends Error {
1684
1695
  name = "NoWitnessAtIndexError";
1685
1696
  };
1686
1697
 
1698
+ // src/providers/transaction-request/helpers.ts
1699
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1700
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1701
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1702
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1703
+
1687
1704
  // src/providers/transaction-request/witness.ts
1688
1705
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1689
1706
  var witnessify = (value) => {
@@ -1874,7 +1891,7 @@ var BaseTransactionRequest = class {
1874
1891
  */
1875
1892
  getCoinInputs() {
1876
1893
  return this.inputs.filter(
1877
- (input) => input.type === InputType2.Coin
1894
+ (input) => input.type === InputType3.Coin
1878
1895
  );
1879
1896
  }
1880
1897
  /**
@@ -1906,9 +1923,9 @@ var BaseTransactionRequest = class {
1906
1923
  const ownerAddress = addressify(owner);
1907
1924
  const found = this.inputs.find((input) => {
1908
1925
  switch (input.type) {
1909
- case InputType2.Coin:
1926
+ case InputType3.Coin:
1910
1927
  return hexlify7(input.owner) === ownerAddress.toB256();
1911
- case InputType2.Message:
1928
+ case InputType3.Message:
1912
1929
  return hexlify7(input.recipient) === ownerAddress.toB256();
1913
1930
  default:
1914
1931
  return false;
@@ -1923,7 +1940,7 @@ var BaseTransactionRequest = class {
1923
1940
  * @param coin - Coin resource.
1924
1941
  */
1925
1942
  addCoinInput(coin) {
1926
- const { assetId, owner, amount } = coin;
1943
+ const { assetId, owner, amount, id, predicate } = coin;
1927
1944
  let witnessIndex;
1928
1945
  if (coin.predicate) {
1929
1946
  witnessIndex = 0;
@@ -1934,13 +1951,14 @@ var BaseTransactionRequest = class {
1934
1951
  }
1935
1952
  }
1936
1953
  const input = {
1937
- ...coin,
1938
- type: InputType2.Coin,
1954
+ id,
1955
+ type: InputType3.Coin,
1939
1956
  owner: owner.toB256(),
1940
1957
  amount,
1941
1958
  assetId,
1942
1959
  txPointer: "0x00000000000000000000000000000000",
1943
- witnessIndex
1960
+ witnessIndex,
1961
+ predicate
1944
1962
  };
1945
1963
  this.pushInput(input);
1946
1964
  this.addChangeOutput(owner, assetId);
@@ -1952,7 +1970,7 @@ var BaseTransactionRequest = class {
1952
1970
  * @param message - Message resource.
1953
1971
  */
1954
1972
  addMessageInput(message) {
1955
- const { recipient, sender, amount, assetId } = message;
1973
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
1956
1974
  let witnessIndex;
1957
1975
  if (message.predicate) {
1958
1976
  witnessIndex = 0;
@@ -1963,12 +1981,13 @@ var BaseTransactionRequest = class {
1963
1981
  }
1964
1982
  }
1965
1983
  const input = {
1966
- ...message,
1967
- type: InputType2.Message,
1984
+ nonce,
1985
+ type: InputType3.Message,
1968
1986
  sender: sender.toB256(),
1969
1987
  recipient: recipient.toB256(),
1970
1988
  amount,
1971
- witnessIndex
1989
+ witnessIndex,
1990
+ predicate
1972
1991
  };
1973
1992
  this.pushInput(input);
1974
1993
  this.addChangeOutput(recipient, assetId);
@@ -2152,16 +2171,27 @@ var BaseTransactionRequest = class {
2152
2171
  toJSON() {
2153
2172
  return normalizeJSON(this);
2154
2173
  }
2174
+ removeWitness(index) {
2175
+ this.witnesses.splice(index, 1);
2176
+ this.adjustWitnessIndexes(index);
2177
+ }
2178
+ adjustWitnessIndexes(removedIndex) {
2179
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2180
+ if (input.witnessIndex > removedIndex) {
2181
+ input.witnessIndex -= 1;
2182
+ }
2183
+ });
2184
+ }
2155
2185
  updatePredicateGasUsed(inputs) {
2156
2186
  this.inputs.forEach((i) => {
2157
2187
  let correspondingInput;
2158
2188
  switch (i.type) {
2159
- case InputType2.Coin:
2160
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2189
+ case InputType3.Coin:
2190
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2161
2191
  break;
2162
- case InputType2.Message:
2192
+ case InputType3.Message:
2163
2193
  correspondingInput = inputs.find(
2164
- (x) => x.type === InputType2.Message && x.sender === i.sender
2194
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2165
2195
  );
2166
2196
  break;
2167
2197
  default:
@@ -2195,7 +2225,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2195
2225
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2196
2226
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2197
2227
  import { bn as bn8 } from "@fuel-ts/math";
2198
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2228
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2199
2229
  import { concat as concat2 } from "@fuel-ts/utils";
2200
2230
  import { clone as clone2 } from "ramda";
2201
2231
  function hashTransaction(transactionRequest, chainId) {
@@ -2206,7 +2236,7 @@ function hashTransaction(transactionRequest, chainId) {
2206
2236
  transaction.inputs = transaction.inputs.map((input) => {
2207
2237
  const inputClone = clone2(input);
2208
2238
  switch (inputClone.type) {
2209
- case InputType3.Coin: {
2239
+ case InputType4.Coin: {
2210
2240
  inputClone.txPointer = {
2211
2241
  blockHeight: 0,
2212
2242
  txIndex: 0
@@ -2214,11 +2244,11 @@ function hashTransaction(transactionRequest, chainId) {
2214
2244
  inputClone.predicateGasUsed = bn8(0);
2215
2245
  return inputClone;
2216
2246
  }
2217
- case InputType3.Message: {
2247
+ case InputType4.Message: {
2218
2248
  inputClone.predicateGasUsed = bn8(0);
2219
2249
  return inputClone;
2220
2250
  }
2221
- case InputType3.Contract: {
2251
+ case InputType4.Contract: {
2222
2252
  inputClone.txPointer = {
2223
2253
  blockHeight: 0,
2224
2254
  txIndex: 0
@@ -2378,7 +2408,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2378
2408
  import { addressify as addressify2 } from "@fuel-ts/address";
2379
2409
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2380
2410
  import { bn as bn10 } from "@fuel-ts/math";
2381
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2411
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2382
2412
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2383
2413
 
2384
2414
  // src/providers/transaction-request/scripts.ts
@@ -2462,7 +2492,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2462
2492
  */
2463
2493
  getContractInputs() {
2464
2494
  return this.inputs.filter(
2465
- (input) => input.type === InputType4.Contract
2495
+ (input) => input.type === InputType5.Contract
2466
2496
  );
2467
2497
  }
2468
2498
  /**
@@ -2539,7 +2569,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2539
2569
  return this;
2540
2570
  }
2541
2571
  const inputIndex = super.pushInput({
2542
- type: InputType4.Contract,
2572
+ type: InputType5.Contract,
2543
2573
  contractId: contractAddress.toB256(),
2544
2574
  txPointer: "0x00000000000000000000000000000000"
2545
2575
  });
@@ -2581,7 +2611,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2581
2611
 
2582
2612
  // src/providers/transaction-request/utils.ts
2583
2613
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2584
- import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2614
+ import { TransactionType as TransactionType5, InputType as InputType6 } from "@fuel-ts/transactions";
2585
2615
  var transactionRequestify = (obj) => {
2586
2616
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2587
2617
  return obj;
@@ -2601,10 +2631,10 @@ var transactionRequestify = (obj) => {
2601
2631
  };
2602
2632
  var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2603
2633
  (acc, input) => {
2604
- if (input.type === InputType5.Coin && input.owner === owner) {
2634
+ if (input.type === InputType6.Coin && input.owner === owner) {
2605
2635
  acc.utxos.push(input.id);
2606
2636
  }
2607
- if (input.type === InputType5.Message && input.recipient === owner) {
2637
+ if (input.type === InputType6.Message && input.recipient === owner) {
2608
2638
  acc.messages.push(input.nonce);
2609
2639
  }
2610
2640
  return acc;
@@ -2758,7 +2788,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2758
2788
 
2759
2789
  // src/providers/transaction-summary/input.ts
2760
2790
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2761
- import { InputType as InputType6 } from "@fuel-ts/transactions";
2791
+ import { InputType as InputType7 } from "@fuel-ts/transactions";
2762
2792
  function getInputsByTypes(inputs, types) {
2763
2793
  return inputs.filter((i) => types.includes(i.type));
2764
2794
  }
@@ -2766,16 +2796,16 @@ function getInputsByType(inputs, type) {
2766
2796
  return inputs.filter((i) => i.type === type);
2767
2797
  }
2768
2798
  function getInputsCoin(inputs) {
2769
- return getInputsByType(inputs, InputType6.Coin);
2799
+ return getInputsByType(inputs, InputType7.Coin);
2770
2800
  }
2771
2801
  function getInputsMessage(inputs) {
2772
- return getInputsByType(inputs, InputType6.Message);
2802
+ return getInputsByType(inputs, InputType7.Message);
2773
2803
  }
2774
2804
  function getInputsCoinAndMessage(inputs) {
2775
- return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2805
+ return getInputsByTypes(inputs, [InputType7.Coin, InputType7.Message]);
2776
2806
  }
2777
2807
  function getInputsContract(inputs) {
2778
- return getInputsByType(inputs, InputType6.Contract);
2808
+ return getInputsByType(inputs, InputType7.Contract);
2779
2809
  }
2780
2810
  function getInputFromAssetId(inputs, assetId) {
2781
2811
  const coinInputs = getInputsCoin(inputs);
@@ -2794,7 +2824,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2794
2824
  if (!contractInput) {
2795
2825
  return void 0;
2796
2826
  }
2797
- if (contractInput.type !== InputType6.Contract) {
2827
+ if (contractInput.type !== InputType7.Contract) {
2798
2828
  throw new FuelError9(
2799
2829
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2800
2830
  `Contract input should be of type 'contract'.`
@@ -2803,10 +2833,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2803
2833
  return contractInput;
2804
2834
  }
2805
2835
  function getInputAccountAddress(input) {
2806
- if (input.type === InputType6.Coin) {
2836
+ if (input.type === InputType7.Coin) {
2807
2837
  return input.owner.toString();
2808
2838
  }
2809
- if (input.type === InputType6.Message) {
2839
+ if (input.type === InputType7.Message) {
2810
2840
  return input.recipient.toString();
2811
2841
  }
2812
2842
  return "";
@@ -3770,6 +3800,21 @@ var _Provider = class {
3770
3800
  } = await this.operations.getVersion();
3771
3801
  return nodeVersion;
3772
3802
  }
3803
+ /**
3804
+ * @hidden
3805
+ *
3806
+ * Returns the network configuration of the connected Fuel node.
3807
+ *
3808
+ * @returns A promise that resolves to the network configuration object
3809
+ */
3810
+ async getNetwork() {
3811
+ const {
3812
+ name,
3813
+ consensusParameters: { chainId }
3814
+ } = await this.getChain();
3815
+ const network = new Network(name, chainId.toNumber());
3816
+ return Promise.resolve(network);
3817
+ }
3773
3818
  /**
3774
3819
  * Returns the block number.
3775
3820
  *
@@ -4620,6 +4665,19 @@ var _Provider = class {
4620
4665
  async getTransactionResponse(transactionId) {
4621
4666
  return new TransactionResponse(transactionId, this);
4622
4667
  }
4668
+ /**
4669
+ * Returns Message for given nonce.
4670
+ *
4671
+ * @param nonce - The nonce of the message to retrieve.
4672
+ * @returns A promise that resolves to the Message object.
4673
+ */
4674
+ async getMessageByNonce(nonce) {
4675
+ const { message } = await this.operations.getMessageByNonce({ nonce });
4676
+ if (!message) {
4677
+ return null;
4678
+ }
4679
+ return message;
4680
+ }
4623
4681
  };
4624
4682
  var Provider = _Provider;
4625
4683
  _cacheInputs = new WeakSet();
@@ -4628,7 +4686,7 @@ cacheInputs_fn = function(inputs) {
4628
4686
  return;
4629
4687
  }
4630
4688
  inputs.forEach((input) => {
4631
- if (input.type === InputType7.Coin) {
4689
+ if (input.type === InputType8.Coin) {
4632
4690
  this.cache?.set(input.id);
4633
4691
  }
4634
4692
  });
@@ -8195,16 +8253,21 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8195
8253
 
8196
8254
  // src/test-utils/seedTestWallet.ts
8197
8255
  import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
8198
- var seedTestWallet = async (wallet, quantities) => {
8256
+ var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8257
+ const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
8199
8258
  const genesisWallet = new WalletUnlocked(
8200
8259
  process.env.GENESIS_SECRET || randomBytes5(32),
8201
- wallet.provider
8260
+ // Connect to the same Provider as wallet
8261
+ toFundAccounts[0].provider
8202
8262
  );
8203
8263
  const request = new ScriptTransactionRequest();
8204
- quantities.forEach((quantity) => {
8205
- const { amount, assetId } = coinQuantityfy(quantity);
8206
- request.addCoinOutput(wallet.address, amount, assetId);
8207
- });
8264
+ quantities.map(coinQuantityfy).forEach(
8265
+ ({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
8266
+ for (let i = 0; i < utxosAmount; i++) {
8267
+ request.addCoinOutput(address, amount.div(utxosAmount), assetId);
8268
+ }
8269
+ })
8270
+ );
8208
8271
  const txCost = await genesisWallet.provider.getTransactionCost(request);
8209
8272
  request.gasLimit = txCost.gasUsed;
8210
8273
  request.maxFee = txCost.maxFee;
@@ -8426,7 +8489,44 @@ var launchNodeAndGetWallets = async ({
8426
8489
  };
8427
8490
  return { wallets, stop: cleanup, provider };
8428
8491
  };
8492
+
8493
+ // src/test-utils/transactionRequest.ts
8494
+ import { UTXO_ID_LEN as UTXO_ID_LEN4 } from "@fuel-ts/abi-coder";
8495
+ import { getRandomB256 } from "@fuel-ts/address";
8496
+ import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8497
+ import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
8498
+ import { bn as bn20 } from "@fuel-ts/math";
8499
+ import { InputType as InputType9 } from "@fuel-ts/transactions";
8500
+ import { hexlify as hexlify19 } from "@fuel-ts/utils";
8501
+ var generateFakeRequestInputCoin = (partial = {}) => ({
8502
+ id: hexlify19(randomBytes7(UTXO_ID_LEN4)),
8503
+ type: InputType9.Coin,
8504
+ owner: getRandomB256(),
8505
+ amount: bn20(100),
8506
+ assetId: ZeroBytes329,
8507
+ txPointer: "0x00000000000000000000000000000000",
8508
+ witnessIndex: 0,
8509
+ ...partial
8510
+ });
8511
+ var generateFakeRequestInputMessage = (partial = {}) => ({
8512
+ nonce: getRandomB256(),
8513
+ type: InputType9.Message,
8514
+ sender: getRandomB256(),
8515
+ recipient: getRandomB256(),
8516
+ amount: bn20(100),
8517
+ witnessIndex: 0,
8518
+ ...partial
8519
+ });
8520
+ var generateFakeRequestInputContract = (partial = {}) => ({
8521
+ contractId: getRandomB256(),
8522
+ type: InputType9.Contract,
8523
+ txPointer: "0x00000000000000000000000000000000",
8524
+ ...partial
8525
+ });
8429
8526
  export {
8527
+ generateFakeRequestInputCoin,
8528
+ generateFakeRequestInputContract,
8529
+ generateFakeRequestInputMessage,
8430
8530
  generateTestWallet,
8431
8531
  killNode,
8432
8532
  launchNode,