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

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 +86 -39
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +201 -141
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +118 -64
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/predicate/predicate.d.ts +17 -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
@@ -28952,7 +28952,7 @@ spurious results.`);
28952
28952
  // ../versions/dist/index.mjs
28953
28953
  function getBuiltinVersions() {
28954
28954
  return {
28955
- FORC: "0.55.0",
28955
+ FORC: "0.49.3",
28956
28956
  FUEL_CORE: "0.22.1",
28957
28957
  FUELS: "0.81.0"
28958
28958
  };
@@ -31144,7 +31144,7 @@ This unreleased fuel-core build may include features and updates not yet support
31144
31144
  toEvmAddress() {
31145
31145
  const b256Address = toB256(this.bech32Address);
31146
31146
  return {
31147
- bits: clearFirst12BytesFromB256(b256Address)
31147
+ value: clearFirst12BytesFromB256(b256Address)
31148
31148
  };
31149
31149
  }
31150
31150
  /**
@@ -31154,7 +31154,7 @@ This unreleased fuel-core build may include features and updates not yet support
31154
31154
  */
31155
31155
  toAssetId() {
31156
31156
  return {
31157
- bits: this.toB256()
31157
+ value: this.toB256()
31158
31158
  };
31159
31159
  }
31160
31160
  /**
@@ -39525,6 +39525,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39525
39525
  name = "NoWitnessByOwnerError";
39526
39526
  };
39527
39527
 
39528
+ // src/providers/transaction-request/helpers.ts
39529
+ var isRequestInputCoin = (input) => input.type === InputType.Coin;
39530
+ var isRequestInputMessage = (input) => input.type === InputType.Message;
39531
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
39532
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
39533
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
39534
+ var cacheResources = (resources) => resources.reduce(
39535
+ (cache2, resource) => {
39536
+ if (isCoin(resource)) {
39537
+ cache2.utxos.push(resource.id);
39538
+ } else {
39539
+ cache2.messages.push(resource.nonce);
39540
+ }
39541
+ return cache2;
39542
+ },
39543
+ {
39544
+ utxos: [],
39545
+ messages: []
39546
+ }
39547
+ );
39548
+
39528
39549
  // src/providers/transaction-request/witness.ts
39529
39550
  var witnessify = (value) => {
39530
39551
  const data = arrayify(value);
@@ -39764,8 +39785,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39764
39785
  * @param predicate - Predicate bytes.
39765
39786
  * @param predicateData - Predicate data bytes.
39766
39787
  */
39767
- addCoinInput(coin, predicate) {
39768
- const { assetId, owner, amount } = coin;
39788
+ addCoinInput(coin) {
39789
+ const { assetId, owner, amount, id, predicate } = coin;
39769
39790
  let witnessIndex;
39770
39791
  if (predicate) {
39771
39792
  witnessIndex = 0;
@@ -39776,14 +39797,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39776
39797
  }
39777
39798
  }
39778
39799
  const input = {
39779
- ...coin,
39800
+ id,
39780
39801
  type: InputType.Coin,
39781
39802
  owner: owner.toB256(),
39782
39803
  amount,
39783
39804
  assetId,
39784
39805
  txPointer: "0x00000000000000000000000000000000",
39785
39806
  witnessIndex,
39786
- predicate: predicate?.bytes
39807
+ predicate
39787
39808
  };
39788
39809
  this.pushInput(input);
39789
39810
  this.addChangeOutput(owner, assetId);
@@ -39796,8 +39817,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39796
39817
  * @param predicate - Predicate bytes.
39797
39818
  * @param predicateData - Predicate data bytes.
39798
39819
  */
39799
- addMessageInput(message, predicate) {
39800
- const { recipient, sender, amount } = message;
39820
+ addMessageInput(message) {
39821
+ const { recipient, sender, amount, predicate, nonce } = message;
39801
39822
  const assetId = BaseAssetId;
39802
39823
  let witnessIndex;
39803
39824
  if (predicate) {
@@ -39809,13 +39830,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39809
39830
  }
39810
39831
  }
39811
39832
  const input = {
39812
- ...message,
39833
+ nonce,
39813
39834
  type: InputType.Message,
39814
39835
  sender: sender.toB256(),
39815
39836
  recipient: recipient.toB256(),
39816
39837
  amount,
39817
39838
  witnessIndex,
39818
- predicate: predicate?.bytes
39839
+ predicate
39819
39840
  };
39820
39841
  this.pushInput(input);
39821
39842
  this.addChangeOutput(recipient, assetId);
@@ -39846,32 +39867,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39846
39867
  resources.forEach((resource) => this.addResource(resource));
39847
39868
  return this;
39848
39869
  }
39849
- /**
39850
- * Adds multiple resources to the transaction by adding coin/message inputs and change
39851
- * outputs from the related assetIds.
39852
- *
39853
- * @param resources - The resources to add.
39854
- * @returns This transaction.
39855
- */
39856
- addPredicateResource(resource, predicate) {
39857
- if (isCoin(resource)) {
39858
- this.addCoinInput(resource, predicate);
39859
- } else {
39860
- this.addMessageInput(resource, predicate);
39861
- }
39862
- return this;
39863
- }
39864
- /**
39865
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
39866
- * from the related assetIds.
39867
- *
39868
- * @param resources - The resources to add.
39869
- * @returns This transaction.
39870
- */
39871
- addPredicateResources(resources, predicate) {
39872
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
39873
- return this;
39874
- }
39875
39870
  /**
39876
39871
  * Adds a coin output to the transaction.
39877
39872
  *
@@ -40020,6 +40015,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40020
40015
  toJSON() {
40021
40016
  return normalizeJSON(this);
40022
40017
  }
40018
+ removeWitness(index) {
40019
+ this.witnesses.splice(index, 1);
40020
+ this.adjustWitnessIndexes(index);
40021
+ }
40023
40022
  updatePredicateInputs(inputs) {
40024
40023
  this.inputs.forEach((i) => {
40025
40024
  let correspondingInput;
@@ -40042,6 +40041,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40042
40041
  }
40043
40042
  });
40044
40043
  }
40044
+ adjustWitnessIndexes(removedIndex) {
40045
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
40046
+ if (input.witnessIndex > removedIndex) {
40047
+ input.witnessIndex -= 1;
40048
+ }
40049
+ });
40050
+ }
40045
40051
  };
40046
40052
 
40047
40053
  // src/providers/transaction-request/hash-transaction.ts
@@ -47868,10 +47874,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47868
47874
  populateTransactionPredicateData(transactionRequestLike) {
47869
47875
  const request = transactionRequestify(transactionRequestLike);
47870
47876
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47871
- request.inputs?.forEach((input) => {
47872
- if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
47877
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47878
+ if (placeholderIndex !== -1) {
47879
+ request.removeWitness(placeholderIndex);
47880
+ }
47881
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
47882
+ if (isRequestInputResourceFromOwner(input, this.address)) {
47873
47883
  input.predicate = this.bytes;
47874
47884
  input.predicateData = this.getPredicateData(policies.length);
47885
+ input.witnessIndex = 0;
47875
47886
  }
47876
47887
  });
47877
47888
  return request;
@@ -47909,6 +47920,20 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47909
47920
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
47910
47921
  return super.simulateTransaction(transactionRequest);
47911
47922
  }
47923
+ /**
47924
+ * Retrieves resources satisfying the spend query for the account.
47925
+ *
47926
+ * @param quantities - Coins to retrieve.
47927
+ * @param excludedIds - IDs of resources to be excluded from the query.
47928
+ * @returns A promise that resolves to an array of Resources.
47929
+ */
47930
+ async getResourcesToSpend(quantities, excludedIds) {
47931
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
47932
+ return resources.map((resource) => ({
47933
+ ...resource,
47934
+ predicate: hexlify(this.bytes)
47935
+ }));
47936
+ }
47912
47937
  getPredicateData(policiesLength) {
47913
47938
  if (!this.predicateData.length) {
47914
47939
  return new Uint8Array();
@@ -47988,6 +48013,28 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47988
48013
  }
47989
48014
  return mutatedBytes;
47990
48015
  }
48016
+ /**
48017
+ * Returns the index of the witness placeholder that was added to this predicate.
48018
+ * If no witness placeholder was added, it returns -1.
48019
+ * @param request - The transaction request.
48020
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
48021
+ */
48022
+ getIndexFromPlaceholderWitness(request) {
48023
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
48024
+ let index = -1;
48025
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
48026
+ if (hasEmptyPredicateInputs) {
48027
+ index = hasEmptyPredicateInputs.witnessIndex;
48028
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
48029
+ if (!allInputsAreEmpty) {
48030
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
48031
+ if (wasFilledInputAddedFirst) {
48032
+ index = -1;
48033
+ }
48034
+ }
48035
+ }
48036
+ return index;
48037
+ }
47991
48038
  };
47992
48039
 
47993
48040
  // src/connectors/fuel-connector.ts