@fuel-ts/account 0.0.0-rc-2143-20240429105111 → 0.0.0-rc-2037-20240429115810

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 (33) hide show
  1. package/dist/index.global.js +69 -8
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +192 -118
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +107 -39
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/predicate/predicate.d.ts +9 -2
  8. package/dist/predicate/predicate.d.ts.map +1 -1
  9. package/dist/providers/transaction-request/helpers.d.ts +10 -0
  10. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  11. package/dist/providers/transaction-request/index.d.ts +1 -0
  12. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/transaction-request.d.ts +2 -0
  14. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  15. package/dist/test-utils/index.d.ts +1 -0
  16. package/dist/test-utils/index.d.ts.map +1 -1
  17. package/dist/test-utils/launchNode.d.ts +2 -4
  18. package/dist/test-utils/launchNode.d.ts.map +1 -1
  19. package/dist/test-utils/resources.d.ts +4 -0
  20. package/dist/test-utils/resources.d.ts.map +1 -0
  21. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  22. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  23. package/dist/test-utils/transactionRequest.d.ts +5 -0
  24. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  25. package/dist/test-utils.global.js +63 -14
  26. package/dist/test-utils.global.js.map +1 -1
  27. package/dist/test-utils.js +180 -117
  28. package/dist/test-utils.js.map +1 -1
  29. package/dist/test-utils.mjs +104 -44
  30. package/dist/test-utils.mjs.map +1 -1
  31. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  32. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  33. package/package.json +15 -15
@@ -39638,6 +39638,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39638
39638
  name = "NoWitnessByOwnerError";
39639
39639
  };
39640
39640
 
39641
+ // src/providers/transaction-request/helpers.ts
39642
+ var isRequestInputCoin = (input) => input.type === InputType.Coin;
39643
+ var isRequestInputMessage = (input) => input.type === InputType.Message;
39644
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
39645
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
39646
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
39647
+ var cacheResources = (resources) => resources.reduce(
39648
+ (cache2, resource) => {
39649
+ if (isCoin(resource)) {
39650
+ cache2.utxos.push(resource.id);
39651
+ } else {
39652
+ cache2.messages.push(resource.nonce);
39653
+ }
39654
+ return cache2;
39655
+ },
39656
+ {
39657
+ utxos: [],
39658
+ messages: []
39659
+ }
39660
+ );
39661
+
39641
39662
  // src/providers/transaction-request/witness.ts
39642
39663
  var witnessify = (value) => {
39643
39664
  const data = arrayify(value);
@@ -39876,7 +39897,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39876
39897
  * @param coin - Coin resource.
39877
39898
  */
39878
39899
  addCoinInput(coin) {
39879
- const { assetId, owner, amount } = coin;
39900
+ const { assetId, owner, amount, id, predicate } = coin;
39880
39901
  let witnessIndex;
39881
39902
  if (coin.predicate) {
39882
39903
  witnessIndex = 0;
@@ -39887,13 +39908,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39887
39908
  }
39888
39909
  }
39889
39910
  const input = {
39890
- ...coin,
39911
+ id,
39891
39912
  type: InputType.Coin,
39892
39913
  owner: owner.toB256(),
39893
39914
  amount,
39894
39915
  assetId,
39895
39916
  txPointer: "0x00000000000000000000000000000000",
39896
- witnessIndex
39917
+ witnessIndex,
39918
+ predicate
39897
39919
  };
39898
39920
  this.pushInput(input);
39899
39921
  this.addChangeOutput(owner, assetId);
@@ -39905,7 +39927,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39905
39927
  * @param message - Message resource.
39906
39928
  */
39907
39929
  addMessageInput(message) {
39908
- const { recipient, sender, amount, assetId } = message;
39930
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
39909
39931
  let witnessIndex;
39910
39932
  if (message.predicate) {
39911
39933
  witnessIndex = 0;
@@ -39916,12 +39938,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39916
39938
  }
39917
39939
  }
39918
39940
  const input = {
39919
- ...message,
39941
+ nonce,
39920
39942
  type: InputType.Message,
39921
39943
  sender: sender.toB256(),
39922
39944
  recipient: recipient.toB256(),
39923
39945
  amount,
39924
- witnessIndex
39946
+ witnessIndex,
39947
+ predicate
39925
39948
  };
39926
39949
  this.pushInput(input);
39927
39950
  this.addChangeOutput(recipient, assetId);
@@ -40105,6 +40128,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40105
40128
  toJSON() {
40106
40129
  return normalizeJSON(this);
40107
40130
  }
40131
+ removeWitness(index) {
40132
+ this.witnesses.splice(index, 1);
40133
+ this.adjustWitnessIndexes(index);
40134
+ }
40135
+ adjustWitnessIndexes(removedIndex) {
40136
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
40137
+ if (input.witnessIndex > removedIndex) {
40138
+ input.witnessIndex -= 1;
40139
+ }
40140
+ });
40141
+ }
40108
40142
  updatePredicateGasUsed(inputs) {
40109
40143
  this.inputs.forEach((i) => {
40110
40144
  let correspondingInput;
@@ -48133,10 +48167,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
48133
48167
  populateTransactionPredicateData(transactionRequestLike) {
48134
48168
  const request = transactionRequestify(transactionRequestLike);
48135
48169
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
48136
- request.inputs?.forEach((input) => {
48137
- if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
48170
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
48171
+ if (placeholderIndex !== -1) {
48172
+ request.removeWitness(placeholderIndex);
48173
+ }
48174
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
48175
+ if (isRequestInputResourceFromOwner(input, this.address)) {
48138
48176
  input.predicate = hexlify(this.bytes);
48139
48177
  input.predicateData = hexlify(this.getPredicateData(policies.length));
48178
+ input.witnessIndex = 0;
48140
48179
  }
48141
48180
  });
48142
48181
  return request;
@@ -48259,6 +48298,28 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
48259
48298
  }
48260
48299
  return mutatedBytes;
48261
48300
  }
48301
+ /**
48302
+ * Returns the index of the witness placeholder that was added to this predicate.
48303
+ * If no witness placeholder was added, it returns -1.
48304
+ * @param request - The transaction request.
48305
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
48306
+ */
48307
+ getIndexFromPlaceholderWitness(request) {
48308
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
48309
+ let index = -1;
48310
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
48311
+ if (hasEmptyPredicateInputs) {
48312
+ index = hasEmptyPredicateInputs.witnessIndex;
48313
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
48314
+ if (!allInputsAreEmpty) {
48315
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
48316
+ if (wasFilledInputAddedFirst) {
48317
+ index = -1;
48318
+ }
48319
+ }
48320
+ }
48321
+ return index;
48322
+ }
48262
48323
  };
48263
48324
 
48264
48325
  // src/connectors/fuel-connector.ts