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

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 +9 -2
  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/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # `@fuel-ts/wallet`
1
+ # `@fuel-ts/account`
2
2
 
3
- **@fuel-ts/wallet** is a sub-module for interacting with **Fuel**.
3
+ **@fuel-ts/account** is a sub-module for interacting with **Fuel**.
4
4
 
5
- This module contains the class to manage a private key and signing for a standard Externally Owned Account (EOA)
5
+ This module contains the class to manage a private key and signing for a standard Externally Owned Account (EOA).
6
6
 
7
- # Table of contents
7
+ ## Table of contents
8
8
 
9
9
  - [Documentation](#documentation)
10
10
  - [Usage](#usage)
@@ -23,9 +23,9 @@ See [Fuels-ts Documentation](https://docs.fuel.network/docs/fuels-ts/wallets/)
23
23
  ### Installation
24
24
 
25
25
  ```sh
26
- pnpm add @fuel-ts/wallet
26
+ pnpm add @fuel-ts/account
27
27
  # or
28
- npm add @fuel-ts/wallet
28
+ npm add @fuel-ts/account
29
29
  ```
30
30
 
31
31
  ### Full SDK Installation
@@ -38,13 +38,16 @@ pnpm add fuels
38
38
  npm add fuels
39
39
  ```
40
40
 
41
- # Test Utilities
41
+ ## Test Utilities
42
42
 
43
43
  These test utilities are exported to assist in testing apps using Fuels.
44
44
 
45
45
  ```ts
46
46
  import { bn } from "@fuel-ts/math";
47
- import { seedTestWallet, generateTestWallet } from "@account/test-utils";
47
+ import {
48
+ seedTestWallet,
49
+ generateTestWallet,
50
+ } from "@fuel-ts/account/test-utils";
48
51
 
49
52
  const provider = await Provider.create("http://127.0.0.1:4000/v1/graphql");
50
53
 
@@ -54,17 +57,17 @@ const baseAssetId = provider.getBaseAssetId();
54
57
  seedTestWallet(wallet, [{ assetId: baseAssetId, amount: bn(100_000) }]);
55
58
 
56
59
  // generating
57
- const wallet = await generateTestWallet(provider, [[1_000, BaseAssetId]]);
60
+ const wallet = await generateTestWallet(provider, [[1_000, baseAssetId]]);
58
61
  ```
59
62
 
60
63
  ## Contributing
61
64
 
62
- In order to contribute to `@fuel-ts/wallet`, please see the main [fuels-ts](https://github.com/FuelLabs/fuels-ts) monorepo.
65
+ In order to contribute to `@fuel-ts/account`, please see the main [fuels-ts](https://github.com/FuelLabs/fuels-ts) monorepo.
63
66
 
64
67
  ## Changelog
65
68
 
66
- The `@fuel-ts/wallet` changelog can be found at [CHANGELOG](./CHANGELOG.md).
69
+ The `@fuel-ts/account` changelog can be found at [CHANGELOG](./CHANGELOG.md).
67
70
 
68
71
  ## License
69
72
 
70
- The primary license for `@fuel-ts/wallet` is `Apache 2.0`, see [LICENSE](./LICENSE).
73
+ The primary license for `@fuel-ts/account` is `Apache 2.0`, see [LICENSE](./LICENSE).
@@ -38727,6 +38727,13 @@ ${MessageCoinFragmentFragmentDoc}`;
38727
38727
  )
38728
38728
  }
38729
38729
  `;
38730
+ var GetMessageByNonceDocument = lib_default2`
38731
+ query getMessageByNonce($nonce: Nonce!) {
38732
+ message(nonce: $nonce) {
38733
+ ...messageFragment
38734
+ }
38735
+ }
38736
+ ${MessageFragmentFragmentDoc}`;
38730
38737
  var SubmitAndAwaitDocument = lib_default2`
38731
38738
  subscription submitAndAwait($encodedTransaction: HexString!) {
38732
38739
  submitAndAwait(tx: $encodedTransaction) {
@@ -38821,6 +38828,9 @@ ${MessageCoinFragmentFragmentDoc}`;
38821
38828
  produceBlocks(variables, options) {
38822
38829
  return requester(ProduceBlocksDocument, variables, options);
38823
38830
  },
38831
+ getMessageByNonce(variables, options) {
38832
+ return requester(GetMessageByNonceDocument, variables, options);
38833
+ },
38824
38834
  submitAndAwait(variables, options) {
38825
38835
  return requester(SubmitAndAwaitDocument, variables, options);
38826
38836
  },
@@ -39638,6 +39648,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39638
39648
  name = "NoWitnessByOwnerError";
39639
39649
  };
39640
39650
 
39651
+ // src/providers/transaction-request/helpers.ts
39652
+ var isRequestInputCoin = (input) => input.type === InputType.Coin;
39653
+ var isRequestInputMessage = (input) => input.type === InputType.Message;
39654
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
39655
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
39656
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
39657
+ var cacheResources = (resources) => resources.reduce(
39658
+ (cache2, resource) => {
39659
+ if (isCoin(resource)) {
39660
+ cache2.utxos.push(resource.id);
39661
+ } else {
39662
+ cache2.messages.push(resource.nonce);
39663
+ }
39664
+ return cache2;
39665
+ },
39666
+ {
39667
+ utxos: [],
39668
+ messages: []
39669
+ }
39670
+ );
39671
+
39641
39672
  // src/providers/transaction-request/witness.ts
39642
39673
  var witnessify = (value) => {
39643
39674
  const data = arrayify(value);
@@ -39876,7 +39907,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39876
39907
  * @param coin - Coin resource.
39877
39908
  */
39878
39909
  addCoinInput(coin) {
39879
- const { assetId, owner, amount } = coin;
39910
+ const { assetId, owner, amount, id, predicate } = coin;
39880
39911
  let witnessIndex;
39881
39912
  if (coin.predicate) {
39882
39913
  witnessIndex = 0;
@@ -39887,13 +39918,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39887
39918
  }
39888
39919
  }
39889
39920
  const input = {
39890
- ...coin,
39921
+ id,
39891
39922
  type: InputType.Coin,
39892
39923
  owner: owner.toB256(),
39893
39924
  amount,
39894
39925
  assetId,
39895
39926
  txPointer: "0x00000000000000000000000000000000",
39896
- witnessIndex
39927
+ witnessIndex,
39928
+ predicate
39897
39929
  };
39898
39930
  this.pushInput(input);
39899
39931
  this.addChangeOutput(owner, assetId);
@@ -39905,7 +39937,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39905
39937
  * @param message - Message resource.
39906
39938
  */
39907
39939
  addMessageInput(message) {
39908
- const { recipient, sender, amount, assetId } = message;
39940
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
39909
39941
  let witnessIndex;
39910
39942
  if (message.predicate) {
39911
39943
  witnessIndex = 0;
@@ -39916,12 +39948,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39916
39948
  }
39917
39949
  }
39918
39950
  const input = {
39919
- ...message,
39951
+ nonce,
39920
39952
  type: InputType.Message,
39921
39953
  sender: sender.toB256(),
39922
39954
  recipient: recipient.toB256(),
39923
39955
  amount,
39924
- witnessIndex
39956
+ witnessIndex,
39957
+ predicate
39925
39958
  };
39926
39959
  this.pushInput(input);
39927
39960
  this.addChangeOutput(recipient, assetId);
@@ -40105,6 +40138,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40105
40138
  toJSON() {
40106
40139
  return normalizeJSON(this);
40107
40140
  }
40141
+ removeWitness(index) {
40142
+ this.witnesses.splice(index, 1);
40143
+ this.adjustWitnessIndexes(index);
40144
+ }
40145
+ adjustWitnessIndexes(removedIndex) {
40146
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
40147
+ if (input.witnessIndex > removedIndex) {
40148
+ input.witnessIndex -= 1;
40149
+ }
40150
+ });
40151
+ }
40108
40152
  updatePredicateGasUsed(inputs) {
40109
40153
  this.inputs.forEach((i) => {
40110
40154
  let correspondingInput;
@@ -42582,6 +42626,19 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42582
42626
  async getTransactionResponse(transactionId) {
42583
42627
  return new TransactionResponse2(transactionId, this);
42584
42628
  }
42629
+ /**
42630
+ * Returns Message for given nonce.
42631
+ *
42632
+ * @param nonce - The nonce of the message to retrieve.
42633
+ * @returns A promise that resolves to the Message object.
42634
+ */
42635
+ async getMessageByNonce(nonce) {
42636
+ const { message } = await this.operations.getMessageByNonce({ nonce });
42637
+ if (!message) {
42638
+ return null;
42639
+ }
42640
+ return message;
42641
+ }
42585
42642
  };
42586
42643
  var Provider = _Provider;
42587
42644
  _cacheInputs = new WeakSet();
@@ -48133,10 +48190,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
48133
48190
  populateTransactionPredicateData(transactionRequestLike) {
48134
48191
  const request = transactionRequestify(transactionRequestLike);
48135
48192
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
48136
- request.inputs?.forEach((input) => {
48137
- if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
48193
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
48194
+ if (placeholderIndex !== -1) {
48195
+ request.removeWitness(placeholderIndex);
48196
+ }
48197
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
48198
+ if (isRequestInputResourceFromOwner(input, this.address)) {
48138
48199
  input.predicate = hexlify(this.bytes);
48139
48200
  input.predicateData = hexlify(this.getPredicateData(policies.length));
48201
+ input.witnessIndex = 0;
48140
48202
  }
48141
48203
  });
48142
48204
  return request;
@@ -48259,6 +48321,28 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
48259
48321
  }
48260
48322
  return mutatedBytes;
48261
48323
  }
48324
+ /**
48325
+ * Returns the index of the witness placeholder that was added to this predicate.
48326
+ * If no witness placeholder was added, it returns -1.
48327
+ * @param request - The transaction request.
48328
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
48329
+ */
48330
+ getIndexFromPlaceholderWitness(request) {
48331
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
48332
+ let index = -1;
48333
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
48334
+ if (hasEmptyPredicateInputs) {
48335
+ index = hasEmptyPredicateInputs.witnessIndex;
48336
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
48337
+ if (!allInputsAreEmpty) {
48338
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
48339
+ if (wasFilledInputAddedFirst) {
48340
+ index = -1;
48341
+ }
48342
+ }
48343
+ }
48344
+ return index;
48345
+ }
48262
48346
  };
48263
48347
 
48264
48348
  // src/connectors/fuel-connector.ts