@fuel-ts/account 0.0.0-rc-2045-20240423120441 → 0.0.0-rc-2037-20240423134048

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
  /**
@@ -39541,6 +39541,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39541
39541
  name = "NoWitnessByOwnerError";
39542
39542
  };
39543
39543
 
39544
+ // src/providers/transaction-request/helpers.ts
39545
+ var isRequestInputCoin = (input) => input.type === InputType.Coin;
39546
+ var isRequestInputMessage = (input) => input.type === InputType.Message;
39547
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
39548
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
39549
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
39550
+ var cacheResources = (resources) => resources.reduce(
39551
+ (cache2, resource) => {
39552
+ if (isCoin(resource)) {
39553
+ cache2.utxos.push(resource.id);
39554
+ } else {
39555
+ cache2.messages.push(resource.nonce);
39556
+ }
39557
+ return cache2;
39558
+ },
39559
+ {
39560
+ utxos: [],
39561
+ messages: []
39562
+ }
39563
+ );
39564
+
39544
39565
  // src/providers/transaction-request/witness.ts
39545
39566
  var witnessify = (value) => {
39546
39567
  const data = arrayify(value);
@@ -39780,8 +39801,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39780
39801
  * @param predicate - Predicate bytes.
39781
39802
  * @param predicateData - Predicate data bytes.
39782
39803
  */
39783
- addCoinInput(coin, predicate) {
39784
- const { assetId, owner, amount } = coin;
39804
+ addCoinInput(coin) {
39805
+ const { assetId, owner, amount, id, predicate } = coin;
39785
39806
  let witnessIndex;
39786
39807
  if (predicate) {
39787
39808
  witnessIndex = 0;
@@ -39792,14 +39813,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39792
39813
  }
39793
39814
  }
39794
39815
  const input = {
39795
- ...coin,
39816
+ id,
39796
39817
  type: InputType.Coin,
39797
39818
  owner: owner.toB256(),
39798
39819
  amount,
39799
39820
  assetId,
39800
39821
  txPointer: "0x00000000000000000000000000000000",
39801
39822
  witnessIndex,
39802
- predicate: predicate?.bytes
39823
+ predicate
39803
39824
  };
39804
39825
  this.pushInput(input);
39805
39826
  this.addChangeOutput(owner, assetId);
@@ -39812,8 +39833,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39812
39833
  * @param predicate - Predicate bytes.
39813
39834
  * @param predicateData - Predicate data bytes.
39814
39835
  */
39815
- addMessageInput(message, predicate) {
39816
- const { recipient, sender, amount } = message;
39836
+ addMessageInput(message) {
39837
+ const { recipient, sender, amount, predicate, nonce } = message;
39817
39838
  const assetId = BaseAssetId;
39818
39839
  let witnessIndex;
39819
39840
  if (predicate) {
@@ -39825,13 +39846,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39825
39846
  }
39826
39847
  }
39827
39848
  const input = {
39828
- ...message,
39849
+ nonce,
39829
39850
  type: InputType.Message,
39830
39851
  sender: sender.toB256(),
39831
39852
  recipient: recipient.toB256(),
39832
39853
  amount,
39833
39854
  witnessIndex,
39834
- predicate: predicate?.bytes
39855
+ predicate
39835
39856
  };
39836
39857
  this.pushInput(input);
39837
39858
  this.addChangeOutput(recipient, assetId);
@@ -39862,32 +39883,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39862
39883
  resources.forEach((resource) => this.addResource(resource));
39863
39884
  return this;
39864
39885
  }
39865
- /**
39866
- * Adds multiple resources to the transaction by adding coin/message inputs and change
39867
- * outputs from the related assetIds.
39868
- *
39869
- * @param resources - The resources to add.
39870
- * @returns This transaction.
39871
- */
39872
- addPredicateResource(resource, predicate) {
39873
- if (isCoin(resource)) {
39874
- this.addCoinInput(resource, predicate);
39875
- } else {
39876
- this.addMessageInput(resource, predicate);
39877
- }
39878
- return this;
39879
- }
39880
- /**
39881
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
39882
- * from the related assetIds.
39883
- *
39884
- * @param resources - The resources to add.
39885
- * @returns This transaction.
39886
- */
39887
- addPredicateResources(resources, predicate) {
39888
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
39889
- return this;
39890
- }
39891
39886
  /**
39892
39887
  * Adds a coin output to the transaction.
39893
39888
  *
@@ -40036,6 +40031,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40036
40031
  toJSON() {
40037
40032
  return normalizeJSON(this);
40038
40033
  }
40034
+ removeWitness(index) {
40035
+ this.witnesses.splice(index, 1);
40036
+ this.adjustWitnessIndexes(index);
40037
+ }
40039
40038
  updatePredicateInputs(inputs) {
40040
40039
  this.inputs.forEach((i) => {
40041
40040
  let correspondingInput;
@@ -40058,6 +40057,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40058
40057
  }
40059
40058
  });
40060
40059
  }
40060
+ adjustWitnessIndexes(removedIndex) {
40061
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
40062
+ if (input.witnessIndex > removedIndex) {
40063
+ input.witnessIndex -= 1;
40064
+ }
40065
+ });
40066
+ }
40061
40067
  };
40062
40068
 
40063
40069
  // src/providers/transaction-request/hash-transaction.ts
@@ -47884,10 +47890,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47884
47890
  populateTransactionPredicateData(transactionRequestLike) {
47885
47891
  const request = transactionRequestify(transactionRequestLike);
47886
47892
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47887
- request.inputs?.forEach((input) => {
47888
- if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
47893
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47894
+ if (placeholderIndex !== -1) {
47895
+ request.removeWitness(placeholderIndex);
47896
+ }
47897
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
47898
+ if (isRequestInputResourceFromOwner(input, this.address)) {
47889
47899
  input.predicate = this.bytes;
47890
47900
  input.predicateData = this.getPredicateData(policies.length);
47901
+ input.witnessIndex = 0;
47891
47902
  }
47892
47903
  });
47893
47904
  return request;
@@ -47925,6 +47936,20 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47925
47936
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
47926
47937
  return super.simulateTransaction(transactionRequest);
47927
47938
  }
47939
+ /**
47940
+ * Retrieves resources satisfying the spend query for the account.
47941
+ *
47942
+ * @param quantities - Coins to retrieve.
47943
+ * @param excludedIds - IDs of resources to be excluded from the query.
47944
+ * @returns A promise that resolves to an array of Resources.
47945
+ */
47946
+ async getResourcesToSpend(quantities, excludedIds) {
47947
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
47948
+ return resources.map((resource) => ({
47949
+ ...resource,
47950
+ predicate: hexlify(this.bytes)
47951
+ }));
47952
+ }
47928
47953
  getPredicateData(policiesLength) {
47929
47954
  if (!this.predicateData.length) {
47930
47955
  return new Uint8Array();
@@ -48004,6 +48029,28 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
48004
48029
  }
48005
48030
  return mutatedBytes;
48006
48031
  }
48032
+ /**
48033
+ * Returns the index of the witness placeholder that was added to this predicate.
48034
+ * If no witness placeholder was added, it returns -1.
48035
+ * @param request - The transaction request.
48036
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
48037
+ */
48038
+ getIndexFromPlaceholderWitness(request) {
48039
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
48040
+ let index = -1;
48041
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
48042
+ if (hasEmptyPredicateInputs) {
48043
+ index = hasEmptyPredicateInputs.witnessIndex;
48044
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
48045
+ if (!allInputsAreEmpty) {
48046
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
48047
+ if (wasFilledInputAddedFirst) {
48048
+ index = -1;
48049
+ }
48050
+ }
48051
+ }
48052
+ return index;
48053
+ }
48007
48054
  };
48008
48055
 
48009
48056
  // src/connectors/fuel-connector.ts