@metamask/transaction-controller 52.3.0 → 54.0.0

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/dist/TransactionController.cjs +133 -119
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +25 -30
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +25 -30
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +133 -119
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/helpers/GasFeePoller.cjs +2 -1
  11. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  12. package/dist/helpers/GasFeePoller.d.cts +1 -1
  13. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  14. package/dist/helpers/GasFeePoller.d.mts +1 -1
  15. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  16. package/dist/helpers/GasFeePoller.mjs +2 -1
  17. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  18. package/dist/helpers/PendingTransactionTracker.cjs +8 -7
  19. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  20. package/dist/helpers/PendingTransactionTracker.d.cts +1 -2
  21. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  22. package/dist/helpers/PendingTransactionTracker.d.mts +1 -2
  23. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  24. package/dist/helpers/PendingTransactionTracker.mjs +8 -7
  25. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +2 -2
  28. package/dist/index.d.cts.map +1 -1
  29. package/dist/index.d.mts +2 -2
  30. package/dist/index.d.mts.map +1 -1
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/types.cjs +4 -0
  33. package/dist/types.cjs.map +1 -1
  34. package/dist/types.d.cts +60 -8
  35. package/dist/types.d.cts.map +1 -1
  36. package/dist/types.d.mts +60 -8
  37. package/dist/types.d.mts.map +1 -1
  38. package/dist/types.mjs +4 -0
  39. package/dist/types.mjs.map +1 -1
  40. package/dist/utils/batch.cjs +16 -8
  41. package/dist/utils/batch.cjs.map +1 -1
  42. package/dist/utils/batch.d.cts +4 -3
  43. package/dist/utils/batch.d.cts.map +1 -1
  44. package/dist/utils/batch.d.mts +4 -3
  45. package/dist/utils/batch.d.mts.map +1 -1
  46. package/dist/utils/batch.mjs +16 -8
  47. package/dist/utils/batch.mjs.map +1 -1
  48. package/dist/utils/feature-flags.cjs +21 -1
  49. package/dist/utils/feature-flags.cjs.map +1 -1
  50. package/dist/utils/feature-flags.d.cts +35 -0
  51. package/dist/utils/feature-flags.d.cts.map +1 -1
  52. package/dist/utils/feature-flags.d.mts +35 -0
  53. package/dist/utils/feature-flags.d.mts.map +1 -1
  54. package/dist/utils/feature-flags.mjs +19 -0
  55. package/dist/utils/feature-flags.mjs.map +1 -1
  56. package/dist/utils/gas.cjs +10 -4
  57. package/dist/utils/gas.cjs.map +1 -1
  58. package/dist/utils/gas.d.cts +5 -2
  59. package/dist/utils/gas.d.cts.map +1 -1
  60. package/dist/utils/gas.d.mts +5 -2
  61. package/dist/utils/gas.d.mts.map +1 -1
  62. package/dist/utils/gas.mjs +10 -4
  63. package/dist/utils/gas.mjs.map +1 -1
  64. package/dist/utils/nonce.cjs +4 -1
  65. package/dist/utils/nonce.cjs.map +1 -1
  66. package/dist/utils/nonce.d.cts +1 -1
  67. package/dist/utils/nonce.d.cts.map +1 -1
  68. package/dist/utils/nonce.d.mts +1 -1
  69. package/dist/utils/nonce.d.mts.map +1 -1
  70. package/dist/utils/nonce.mjs +4 -1
  71. package/dist/utils/nonce.mjs.map +1 -1
  72. package/dist/utils/validation.cjs +14 -13
  73. package/dist/utils/validation.cjs.map +1 -1
  74. package/dist/utils/validation.d.cts +3 -1
  75. package/dist/utils/validation.d.cts.map +1 -1
  76. package/dist/utils/validation.d.mts +3 -1
  77. package/dist/utils/validation.d.mts.map +1 -1
  78. package/dist/utils/validation.mjs +14 -13
  79. package/dist/utils/validation.mjs.map +1 -1
  80. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,55 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [54.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add `isExternalSign` property to `TransactionMeta` to disable nonce generation and signing ([#5604](https://github.com/MetaMask/core/pull/5604))
15
+ - Add types for `isAtomicBatchSupported` method ([#5600](https://github.com/MetaMask/core/pull/5600))
16
+ - `IsAtomicBatchSupportedRequest`
17
+ - `IsAtomicBatchSupportedResult`
18
+ - `IsAtomicBatchSupportedResultEntry`
19
+
20
+ ### Changed
21
+
22
+ - **BREAKING:** Update signature of `isAtomicBatchSupported` method ([#5600](https://github.com/MetaMask/core/pull/5600))
23
+ - Replace `address` argument with `request` object containing `address` and optional `chainIds`.
24
+ - Return array of `IsAtomicBatchSupportedResultEntry` objects.
25
+ - Skip `origin` validation for `batch` transaction type ([#5586](https://github.com/MetaMask/core/pull/5586))
26
+
27
+ ### Fixed
28
+
29
+ - **BREAKING:** `enableTxParamsGasFeeUpdates` is renamed to `isAutomaticGasFeeUpdateEnabled` now expects a callback function instead of a boolean. ([#5602](https://github.com/MetaMask/core/pull/5602))
30
+ - This callback is invoked before performing `txParams` gas fee updates. The update will proceed only if the callback returns a truthy value.
31
+ - If not set it will default to return `false`.
32
+
33
+ ## [53.0.0]
34
+
35
+ ### Added
36
+
37
+ - Add `gasPayment` to `TransactionType` enum ([#5584](https://github.com/MetaMask/core/pull/5584))
38
+ - Add `TransactionControllerUpdateCustodialTransactionAction` messenger action ([#5045](https://github.com/MetaMask/core/pull/5045))
39
+
40
+ ### Changed
41
+
42
+ - **BREAKING:** Return `Promise` from `beforePublish` and `beforeCheckPendingTransaction` hooks ([#5045](https://github.com/MetaMask/core/pull/5045))
43
+ - Support additional parameters in `updateCustodialTransaction` method ([#5045](https://github.com/MetaMask/core/pull/5045))
44
+ - `gasLimit`
45
+ - `gasPrice`
46
+ - `maxFeePerGas`
47
+ - `maxPriorityFeePerGas`
48
+ - `nonce`
49
+ - `type`
50
+ - Configure gas estimation fallback using remote feature flags ([#5556](https://github.com/MetaMask/core/pull/5556))
51
+ - Throw if `chainId` in `TransactionParams` does not match `networkClientId` when calling `addTransaction` ([#5511](https://github.com/MetaMask/core/pull/5569))
52
+ - Mark `chainId` in `TransactionParams` as deprecated.
53
+ - Bump `@metamask/controller-utils` to `^11.7.0` ([#5583](https://github.com/MetaMask/core/pull/5583))
54
+
55
+ ### Removed
56
+
57
+ - **BREAKING:** Remove `custodyId` and `custodyStatus` properties from `TransactionMeta` ([#5045](https://github.com/MetaMask/core/pull/5045))
58
+
10
59
  ## [52.3.0]
11
60
 
12
61
  ### Added
@@ -1458,7 +1507,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1458
1507
 
1459
1508
  All changes listed after this point were applied to this package following the monorepo conversion.
1460
1509
 
1461
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@52.3.0...HEAD
1510
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@54.0.0...HEAD
1511
+ [54.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@53.0.0...@metamask/transaction-controller@54.0.0
1512
+ [53.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@52.3.0...@metamask/transaction-controller@53.0.0
1462
1513
  [52.3.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@52.2.0...@metamask/transaction-controller@52.3.0
1463
1514
  [52.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@52.1.0...@metamask/transaction-controller@52.2.0
1464
1515
  [52.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@52.0.0...@metamask/transaction-controller@52.1.0
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_publishBatchHook, _TransactionController_publicKeyEIP7702, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_rejectTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_getInternalAccounts, _TransactionController_updateSubmitHistory, _TransactionController_updateGasEstimate, _TransactionController_deleteTransaction, _TransactionController_isRejectError, _TransactionController_rejectTransactionAndThrow;
16
+ var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_publishBatchHook, _TransactionController_publicKeyEIP7702, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_rejectTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_markNonceDuplicatesDropped, _TransactionController_signTransaction, _TransactionController_onConfirmedTransaction, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_getInternalAccounts, _TransactionController_updateSubmitHistory, _TransactionController_updateGasEstimate, _TransactionController_registerActionHandlers, _TransactionController_deleteTransaction, _TransactionController_isRejectError, _TransactionController_rejectTransactionAndThrow;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.TransactionController = exports.ApprovalState = exports.SPEED_UP_RATE = exports.CANCEL_RATE = void 0;
19
19
  const base_controller_1 = require("@metamask/base-controller");
@@ -157,7 +157,7 @@ class TransactionController extends base_controller_1.BaseController {
157
157
  * @param options - The controller options.
158
158
  */
159
159
  constructor(options) {
160
- const { disableHistory, disableSendFlowHistory, disableSwaps, enableTxParamsGasFeeUpdates, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, publicKeyEIP7702, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, } = options;
160
+ const { disableHistory, disableSendFlowHistory, disableSwaps, isAutomaticGasFeeUpdateEnabled, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, publicKeyEIP7702, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, } = options;
161
161
  super({
162
162
  name: controllerName,
163
163
  metadata,
@@ -187,7 +187,8 @@ class TransactionController extends base_controller_1.BaseController {
187
187
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").checkForPendingTransactionAndStartPolling();
188
188
  });
189
189
  this.messagingSystem = messenger;
190
- this.isTxParamsGasFeeUpdatesEnabled = enableTxParamsGasFeeUpdates ?? false;
190
+ this.isTxParamsGasFeeUpdatesEnabled =
191
+ isAutomaticGasFeeUpdateEnabled ?? ((_txMeta) => false);
191
192
  this.getNetworkState = getNetworkState;
192
193
  this.isSendFlowHistoryDisabled = disableSendFlowHistory ?? false;
193
194
  this.isHistoryDisabled = disableHistory ?? false;
@@ -215,10 +216,9 @@ class TransactionController extends base_controller_1.BaseController {
215
216
  __classPrivateFieldSet(this, _TransactionController_trace, trace ?? ((_request, fn) => fn?.()), "f");
216
217
  this.afterSign = hooks?.afterSign ?? (() => true);
217
218
  this.beforeCheckPendingTransaction =
218
- hooks?.beforeCheckPendingTransaction ??
219
- /* istanbul ignore next */
220
- (() => true);
221
- this.beforePublish = hooks?.beforePublish ?? (() => true);
219
+ /* istanbul ignore next */
220
+ hooks?.beforeCheckPendingTransaction ?? (() => Promise.resolve(true));
221
+ this.beforePublish = hooks?.beforePublish ?? (() => Promise.resolve(true));
222
222
  this.getAdditionalSignArguments =
223
223
  hooks?.getAdditionalSignArguments ?? (() => []);
224
224
  this.publish =
@@ -294,6 +294,7 @@ class TransactionController extends base_controller_1.BaseController {
294
294
  });
295
295
  this.onBootCleanup();
296
296
  __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f").call(this);
297
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_registerActionHandlers).call(this);
297
298
  }
298
299
  /**
299
300
  * Stops polling and removes listeners to prepare the controller for garbage collection.
@@ -334,12 +335,12 @@ class TransactionController extends base_controller_1.BaseController {
334
335
  /**
335
336
  * Determine which chains support atomic batch transactions with the given account address.
336
337
  *
337
- * @param address - The address of the account to check.
338
- * @returns The supported chain IDs.
338
+ * @param request - Request object containing the account address and other parameters.
339
+ * @returns Result object containing the supported chains and related information.
339
340
  */
340
- async isAtomicBatchSupported(address) {
341
+ async isAtomicBatchSupported(request) {
341
342
  return (0, batch_1.isAtomicBatchSupported)({
342
- address,
343
+ ...request,
343
344
  getEthQuery: (chainId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { chainId }),
344
345
  messenger: this.messagingSystem,
345
346
  publicKeyEIP7702: __classPrivateFieldGet(this, _TransactionController_publicKeyEIP7702, "f"),
@@ -399,7 +400,7 @@ class TransactionController extends base_controller_1.BaseController {
399
400
  });
400
401
  const delegationAddressPromise = (0, eip7702_1.getDelegationAddress)(txParams.from, ethQuery).catch(() => undefined);
401
402
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
402
- (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
403
+ (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible, chainId);
403
404
  if (!txParams.type) {
404
405
  // Determine transaction type based on transaction parameters and network compatibility
405
406
  (0, utils_2.setEnvelopeType)(txParams, isEIP1559Compatible);
@@ -568,6 +569,7 @@ class TransactionController extends base_controller_1.BaseController {
568
569
  chainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).call(this, networkClientId),
569
570
  ethQuery,
570
571
  isSimulationEnabled: __classPrivateFieldGet(this, _TransactionController_isSimulationEnabled, "f").call(this),
572
+ messenger: this.messagingSystem,
571
573
  txParams: transaction,
572
574
  });
573
575
  return { gas: estimatedGas, simulationFails };
@@ -588,6 +590,7 @@ class TransactionController extends base_controller_1.BaseController {
588
590
  chainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).call(this, networkClientId),
589
591
  ethQuery,
590
592
  isSimulationEnabled: __classPrivateFieldGet(this, _TransactionController_isSimulationEnabled, "f").call(this),
593
+ messenger: this.messagingSystem,
591
594
  txParams: transaction,
592
595
  });
593
596
  const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
@@ -676,12 +679,13 @@ class TransactionController extends base_controller_1.BaseController {
676
679
  updatedTransactionMeta.baseFeePerGas = baseFeePerGas;
677
680
  }
678
681
  // Update same nonce local transactions as dropped and define replacedBy properties.
679
- this.markNonceDuplicatesDropped(transactionId);
682
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_markNonceDuplicatesDropped).call(this, transactionId);
680
683
  // Update external provided transaction with updated gas values and confirmed status.
681
684
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:confirmExternalTransaction - Add external transaction`);
682
685
  this.onTransactionStatusChange(updatedTransactionMeta);
683
686
  // Intentional given potential duration of process.
684
687
  this.updatePostBalance(updatedTransactionMeta).catch((error) => {
688
+ /* istanbul ignore next */
685
689
  (0, logger_1.projectLogger)('Error while updating post balance', error);
686
690
  throw error;
687
691
  });
@@ -930,20 +934,16 @@ class TransactionController extends base_controller_1.BaseController {
930
934
  /**
931
935
  * Update a custodial transaction.
932
936
  *
933
- * @param transactionId - The ID of the transaction to update.
934
- * @param options - The custodial transaction options to update.
935
- * @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
936
- * @param options.hash - The new hash value to be assigned.
937
- * @param options.status - The new status value to be assigned.
937
+ * @param request - The custodial transaction update request.
938
+ *
939
+ * @returns The updated transaction metadata.
938
940
  */
939
- updateCustodialTransaction(transactionId, { errorMessage, hash, status, }) {
941
+ updateCustodialTransaction(request) {
942
+ const { transactionId, errorMessage, hash, status, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, type, } = request;
940
943
  const transactionMeta = this.getTransaction(transactionId);
941
944
  if (!transactionMeta) {
942
945
  throw new Error(`Cannot update custodial transaction as no transaction metadata found`);
943
946
  }
944
- if (!transactionMeta.custodyId) {
945
- throw new Error('Transaction must be a custodian transaction');
946
- }
947
947
  if (status &&
948
948
  ![
949
949
  types_1.TransactionStatus.submitted,
@@ -959,11 +959,27 @@ class TransactionController extends base_controller_1.BaseController {
959
959
  if (updatedTransactionMeta.status === types_1.TransactionStatus.failed) {
960
960
  updatedTransactionMeta.error = (0, utils_2.normalizeTxError)(new Error(errorMessage));
961
961
  }
962
+ // Update txParams properties with a single pickBy operation
963
+ updatedTransactionMeta.txParams = (0, lodash_1.merge)({}, updatedTransactionMeta.txParams, (0, lodash_1.pickBy)({
964
+ gasLimit,
965
+ gasPrice,
966
+ maxFeePerGas,
967
+ maxPriorityFeePerGas,
968
+ nonce,
969
+ type,
970
+ }));
971
+ // Special case for type change to legacy
972
+ if (type === types_1.TransactionEnvelopeType.legacy) {
973
+ delete updatedTransactionMeta.txParams.maxFeePerGas;
974
+ delete updatedTransactionMeta.txParams.maxPriorityFeePerGas;
975
+ }
962
976
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:updateCustodialTransaction - Custodial transaction updated`);
963
- if ([types_1.TransactionStatus.submitted, types_1.TransactionStatus.failed].includes(status)) {
977
+ if (status &&
978
+ [types_1.TransactionStatus.submitted, types_1.TransactionStatus.failed].includes(status)) {
964
979
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, updatedTransactionMeta);
965
980
  __classPrivateFieldGet(this, _TransactionController_internalEvents, "f").emit(`${updatedTransactionMeta.id}:finished`, updatedTransactionMeta);
966
981
  }
982
+ return updatedTransactionMeta;
967
983
  }
968
984
  /**
969
985
  * Search transaction metadata for matching entries.
@@ -1379,13 +1395,13 @@ class TransactionController extends base_controller_1.BaseController {
1379
1395
  }
1380
1396
  });
1381
1397
  this.onTransactionStatusChange(transactionMeta);
1382
- const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1383
- if (!this.beforePublish(transactionMeta)) {
1398
+ const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_signTransaction).call(this, transactionMeta));
1399
+ if (!(await this.beforePublish(transactionMeta))) {
1384
1400
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1385
1401
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
1386
1402
  return ApprovalState.SkippedViaBeforePublishHook;
1387
1403
  }
1388
- if (!rawTx) {
1404
+ if (!rawTx && !transactionMeta.isExternalSign) {
1389
1405
  return ApprovalState.NotApproved;
1390
1406
  }
1391
1407
  const { networkClientId } = transactionMeta;
@@ -1412,7 +1428,7 @@ class TransactionController extends base_controller_1.BaseController {
1412
1428
  }
1413
1429
  await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Publish', parentContext: traceContext }, async () => {
1414
1430
  const publishHook = publishHookOverride ?? this.publish;
1415
- ({ transactionHash: hash } = await publishHook(transactionMeta, rawTx));
1431
+ ({ transactionHash: hash } = await publishHook(transactionMeta, rawTx ?? '0x'));
1416
1432
  if (hash === undefined) {
1417
1433
  hash = await this.publishTransaction(ethQuery, {
1418
1434
  ...transactionMeta,
@@ -1636,44 +1652,6 @@ class TransactionController extends base_controller_1.BaseController {
1636
1652
  });
1637
1653
  return newTransactionMeta;
1638
1654
  }
1639
- /**
1640
- * Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions
1641
- * in the transactions have the same nonce.
1642
- *
1643
- * @param transactionId - Used to identify original transaction.
1644
- */
1645
- markNonceDuplicatesDropped(transactionId) {
1646
- const transactionMeta = this.getTransaction(transactionId);
1647
- if (!transactionMeta) {
1648
- return;
1649
- }
1650
- const nonce = transactionMeta.txParams?.nonce;
1651
- const from = transactionMeta.txParams?.from;
1652
- const { chainId } = transactionMeta;
1653
- const sameNonceTransactions = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
1654
- transaction.txParams.from === from &&
1655
- transaction.txParams.nonce === nonce &&
1656
- transaction.chainId === chainId &&
1657
- transaction.type !== types_1.TransactionType.incoming);
1658
- const sameNonceTransactionIds = sameNonceTransactions.map((transaction) => transaction.id);
1659
- if (sameNonceTransactions.length === 0) {
1660
- return;
1661
- }
1662
- this.update((state) => {
1663
- for (const transaction of state.transactions) {
1664
- if (sameNonceTransactionIds.includes(transaction.id)) {
1665
- transaction.replacedBy = transactionMeta?.hash;
1666
- transaction.replacedById = transactionMeta?.id;
1667
- }
1668
- }
1669
- });
1670
- for (const transaction of this.state.transactions) {
1671
- if (sameNonceTransactionIds.includes(transaction.id) &&
1672
- transaction.status !== types_1.TransactionStatus.failed) {
1673
- this.setTransactionStatusDropped(transaction);
1674
- }
1675
- }
1676
- }
1677
1655
  /**
1678
1656
  * Method to set transaction status to dropped.
1679
1657
  *
@@ -1730,47 +1708,6 @@ class TransactionController extends base_controller_1.BaseController {
1730
1708
  const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1731
1709
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1732
1710
  }
1733
- async signTransaction(transactionMeta) {
1734
- const { txParams } = transactionMeta;
1735
- (0, logger_1.projectLogger)('Signing transaction', txParams);
1736
- const { authorizationList, from } = txParams;
1737
- const finalTxParams = { ...txParams };
1738
- finalTxParams.authorizationList = await (0, eip7702_1.signAuthorizationList)({
1739
- authorizationList,
1740
- messenger: this.messagingSystem,
1741
- transactionMeta,
1742
- });
1743
- const unsignedEthTx = (0, prepare_1.prepareTransaction)(transactionMeta.chainId, finalTxParams);
1744
- this.approvingTransactionIds.add(transactionMeta.id);
1745
- const signedTx = await new Promise((resolve, reject) => {
1746
- this.sign?.(unsignedEthTx, from, ...this.getAdditionalSignArguments(transactionMeta)).then(resolve, reject);
1747
- this.signAbortCallbacks.set(transactionMeta.id, () => reject(new Error('Signing aborted by user')));
1748
- });
1749
- this.signAbortCallbacks.delete(transactionMeta.id);
1750
- if (!signedTx) {
1751
- (0, logger_1.projectLogger)('Skipping signed status as no signed transaction');
1752
- return undefined;
1753
- }
1754
- const transactionMetaFromHook = (0, lodash_1.cloneDeep)(transactionMeta);
1755
- if (!this.afterSign(transactionMetaFromHook, signedTx)) {
1756
- this.updateTransaction(transactionMetaFromHook, 'TransactionController#signTransaction - Update after sign');
1757
- (0, logger_1.projectLogger)('Skipping signed status based on hook');
1758
- return undefined;
1759
- }
1760
- const transactionMetaWithRsv = {
1761
- ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1762
- status: types_1.TransactionStatus.signed,
1763
- txParams: finalTxParams,
1764
- };
1765
- this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1766
- this.onTransactionStatusChange(transactionMetaWithRsv);
1767
- const rawTx = (0, prepare_1.serializeTransaction)(signedTx);
1768
- const transactionMetaWithRawTx = (0, lodash_1.merge)({}, transactionMetaWithRsv, {
1769
- rawTx,
1770
- });
1771
- this.updateTransaction(transactionMetaWithRawTx, 'TransactionController#approveTransaction - RawTransaction added');
1772
- return rawTx;
1773
- }
1774
1711
  onTransactionStatusChange(transactionMeta) {
1775
1712
  this.messagingSystem.publish(`${controllerName}:transactionStatusUpdated`, {
1776
1713
  transactionMeta,
@@ -1779,17 +1716,6 @@ class TransactionController extends base_controller_1.BaseController {
1779
1716
  getNonceTrackerTransactions(statuses, address, chainId) {
1780
1717
  return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(chainId, address, statuses, this.state.transactions);
1781
1718
  }
1782
- onConfirmedTransaction(transactionMeta) {
1783
- (0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
1784
- this.markNonceDuplicatesDropped(transactionMeta.id);
1785
- this.messagingSystem.publish(`${controllerName}:transactionConfirmed`, transactionMeta);
1786
- this.onTransactionStatusChange(transactionMeta);
1787
- // Intentional given potential duration of process.
1788
- this.updatePostBalance(transactionMeta).catch((error) => {
1789
- (0, logger_1.projectLogger)('Error while updating post balance', error);
1790
- throw error;
1791
- });
1792
- }
1793
1719
  async updatePostBalance(transactionMeta) {
1794
1720
  try {
1795
1721
  const { networkClientId, type } = transactionMeta;
@@ -1938,6 +1864,92 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1938
1864
  chainId,
1939
1865
  networkClientId,
1940
1866
  }).provider;
1867
+ }, _TransactionController_markNonceDuplicatesDropped = function _TransactionController_markNonceDuplicatesDropped(transactionId) {
1868
+ const transactionMeta = this.getTransaction(transactionId);
1869
+ if (!transactionMeta) {
1870
+ return;
1871
+ }
1872
+ const nonce = transactionMeta.txParams?.nonce;
1873
+ const from = transactionMeta.txParams?.from;
1874
+ const { chainId } = transactionMeta;
1875
+ const sameNonceTransactions = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
1876
+ transaction.txParams.from === from &&
1877
+ nonce &&
1878
+ transaction.txParams.nonce === nonce &&
1879
+ transaction.chainId === chainId &&
1880
+ transaction.type !== types_1.TransactionType.incoming);
1881
+ const sameNonceTransactionIds = sameNonceTransactions.map((transaction) => transaction.id);
1882
+ if (sameNonceTransactions.length === 0) {
1883
+ return;
1884
+ }
1885
+ this.update((state) => {
1886
+ for (const transaction of state.transactions) {
1887
+ if (sameNonceTransactionIds.includes(transaction.id)) {
1888
+ transaction.replacedBy = transactionMeta?.hash;
1889
+ transaction.replacedById = transactionMeta?.id;
1890
+ }
1891
+ }
1892
+ });
1893
+ for (const transaction of this.state.transactions) {
1894
+ if (sameNonceTransactionIds.includes(transaction.id) &&
1895
+ transaction.status !== types_1.TransactionStatus.failed) {
1896
+ this.setTransactionStatusDropped(transaction);
1897
+ }
1898
+ }
1899
+ }, _TransactionController_signTransaction = async function _TransactionController_signTransaction(transactionMeta) {
1900
+ const { isExternalSign, txParams } = transactionMeta;
1901
+ if (isExternalSign) {
1902
+ (0, logger_1.projectLogger)('Skipping sign as signed externally');
1903
+ return undefined;
1904
+ }
1905
+ (0, logger_1.projectLogger)('Signing transaction', txParams);
1906
+ const { authorizationList, from } = txParams;
1907
+ const finalTxParams = { ...txParams };
1908
+ finalTxParams.authorizationList = await (0, eip7702_1.signAuthorizationList)({
1909
+ authorizationList,
1910
+ messenger: this.messagingSystem,
1911
+ transactionMeta,
1912
+ });
1913
+ const unsignedEthTx = (0, prepare_1.prepareTransaction)(transactionMeta.chainId, finalTxParams);
1914
+ this.approvingTransactionIds.add(transactionMeta.id);
1915
+ const signedTx = await new Promise((resolve, reject) => {
1916
+ this.sign?.(unsignedEthTx, from, ...this.getAdditionalSignArguments(transactionMeta)).then(resolve, reject);
1917
+ this.signAbortCallbacks.set(transactionMeta.id, () => reject(new Error('Signing aborted by user')));
1918
+ });
1919
+ this.signAbortCallbacks.delete(transactionMeta.id);
1920
+ if (!signedTx) {
1921
+ (0, logger_1.projectLogger)('Skipping signed status as no signed transaction');
1922
+ return undefined;
1923
+ }
1924
+ const transactionMetaFromHook = (0, lodash_1.cloneDeep)(transactionMeta);
1925
+ if (!this.afterSign(transactionMetaFromHook, signedTx)) {
1926
+ this.updateTransaction(transactionMetaFromHook, 'TransactionController#signTransaction - Update after sign');
1927
+ (0, logger_1.projectLogger)('Skipping signed status based on hook');
1928
+ return undefined;
1929
+ }
1930
+ const transactionMetaWithRsv = {
1931
+ ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1932
+ status: types_1.TransactionStatus.signed,
1933
+ txParams: finalTxParams,
1934
+ };
1935
+ this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1936
+ this.onTransactionStatusChange(transactionMetaWithRsv);
1937
+ const rawTx = (0, prepare_1.serializeTransaction)(signedTx);
1938
+ const transactionMetaWithRawTx = (0, lodash_1.merge)({}, transactionMetaWithRsv, {
1939
+ rawTx,
1940
+ });
1941
+ this.updateTransaction(transactionMetaWithRawTx, 'TransactionController#approveTransaction - RawTransaction added');
1942
+ return rawTx;
1943
+ }, _TransactionController_onConfirmedTransaction = function _TransactionController_onConfirmedTransaction(transactionMeta) {
1944
+ (0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
1945
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_markNonceDuplicatesDropped).call(this, transactionMeta.id);
1946
+ this.messagingSystem.publish(`${controllerName}:transactionConfirmed`, transactionMeta);
1947
+ this.onTransactionStatusChange(transactionMeta);
1948
+ // Intentional given potential duration of process.
1949
+ this.updatePostBalance(transactionMeta).catch((error) => {
1950
+ (0, logger_1.projectLogger)('Error while updating post balance', error);
1951
+ throw error;
1952
+ });
1941
1953
  }, _TransactionController_createNonceTracker = function _TransactionController_createNonceTracker({ provider, blockTracker, chainId, }) {
1942
1954
  return new nonce_tracker_1.NonceTracker({
1943
1955
  // TODO: Fix types
@@ -1966,7 +1978,6 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1966
1978
  }),
1967
1979
  hooks: {
1968
1980
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1969
- beforePublish: this.beforePublish.bind(this),
1970
1981
  },
1971
1982
  });
1972
1983
  __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);
@@ -1981,7 +1992,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1981
1992
  pendingTransactionTracker.hub.removeAllListeners('transaction-failed');
1982
1993
  pendingTransactionTracker.hub.removeAllListeners('transaction-updated');
1983
1994
  }, _TransactionController_addPendingTransactionTrackerListeners = function _TransactionController_addPendingTransactionTrackerListeners(pendingTransactionTracker) {
1984
- pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
1995
+ pendingTransactionTracker.hub.on('transaction-confirmed', __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_onConfirmedTransaction).bind(this));
1985
1996
  pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
1986
1997
  pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
1987
1998
  pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
@@ -2182,8 +2193,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
2182
2193
  ethQuery,
2183
2194
  isCustomNetwork,
2184
2195
  isSimulationEnabled: __classPrivateFieldGet(this, _TransactionController_isSimulationEnabled, "f").call(this),
2196
+ messenger: this.messagingSystem,
2185
2197
  txMeta: transactionMeta,
2186
2198
  });
2199
+ }, _TransactionController_registerActionHandlers = function _TransactionController_registerActionHandlers() {
2200
+ this.messagingSystem.registerActionHandler(`${controllerName}:updateCustodialTransaction`, this.updateCustodialTransaction.bind(this));
2187
2201
  }, _TransactionController_deleteTransaction = function _TransactionController_deleteTransaction(transactionId) {
2188
2202
  this.update((state) => {
2189
2203
  const transactions = state.transactions.filter(({ id }) => id !== transactionId);