Skip to content

Conversation

matthiasgeihs
Copy link
Contributor

@matthiasgeihs matthiasgeihs commented Aug 11, 2025

Explanation

For MetaMask Transaction Shield we want to reroute all transaction simulation requests through a dedicated proxy.
This PR adds the following functionality to the TransactionController to accomplish that.

  • Add optional getSimulationConfig parameter to constructor.
  • If getSimulationConfig parameter is present, call the function to retrieve a new simulation URL and an authorization header. Replace the simulation URL and add the authorization header to the simulation request.

References

Transaction Shield Notion Page

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

/**
* Optional parameters for the transaction shield.
*/
shieldParams?: ShieldParams;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we definitely want to go the client route, instead of a remote-only service / cache of some kind, then the TransactionController should not know about Shield at all.

It's a fundamental controller, so it's vital we abstract and decouple other features and domain for the sake of maintainability and coupling.

Could this instead be something like:

getSimulationConfig?: () => Promise<{url?: string; authorization?: string;}>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will adapt the PR accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to

export type GetSimulationConfig = () => Promise<{
  baseUrl?: string;
  authorization?: string;
}>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realized that we need to provide the current URL as a request parameter included in the proxy URL.
update to

export type GetSimulationConfig = (url: string) => Promise<{
  newUrl?: string;
  authorization?: string;
}>;

@matthiasgeihs matthiasgeihs force-pushed the mg/integrate-shield-gateway branch 3 times, most recently from 55ab505 to 1bafbab Compare August 19, 2025 15:38
@matthiasgeihs matthiasgeihs marked this pull request as ready for review August 19, 2025 15:39
@matthiasgeihs matthiasgeihs requested a review from a team as a code owner August 19, 2025 15:39
@matthiasgeihs matthiasgeihs force-pushed the mg/integrate-shield-gateway branch from 1bafbab to d2c3e3b Compare August 19, 2025 15:40
@matthiasgeihs matthiasgeihs requested a review from a team as a code owner August 19, 2025 15:42
@matthiasgeihs matthiasgeihs force-pushed the mg/integrate-shield-gateway branch 2 times, most recently from ab4ffb1 to 83695c3 Compare August 19, 2025 16:32
Copy link
Member

@OGPoyraz OGPoyraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor suggestion

@matthiasgeihs matthiasgeihs force-pushed the mg/integrate-shield-gateway branch from 5206c99 to 7b6467c Compare August 20, 2025 08:19
@matthiasgeihs
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.9.0-preview-7b6467c",
  "@metamask-previews/accounts-controller": "32.0.2-preview-7b6467c",
  "@metamask-previews/address-book-controller": "6.1.1-preview-7b6467c",
  "@metamask-previews/announcement-controller": "7.0.3-preview-7b6467c",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-7b6467c",
  "@metamask-previews/approval-controller": "7.1.3-preview-7b6467c",
  "@metamask-previews/assets-controllers": "73.3.0-preview-7b6467c",
  "@metamask-previews/base-controller": "8.1.0-preview-7b6467c",
  "@metamask-previews/bridge-controller": "39.1.0-preview-7b6467c",
  "@metamask-previews/bridge-status-controller": "38.1.0-preview-7b6467c",
  "@metamask-previews/build-utils": "3.0.3-preview-7b6467c",
  "@metamask-previews/chain-agnostic-permission": "1.1.0-preview-7b6467c",
  "@metamask-previews/composable-controller": "11.0.0-preview-7b6467c",
  "@metamask-previews/controller-utils": "11.12.0-preview-7b6467c",
  "@metamask-previews/delegation-controller": "0.6.0-preview-7b6467c",
  "@metamask-previews/earn-controller": "5.0.0-preview-7b6467c",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-7b6467c",
  "@metamask-previews/ens-controller": "17.0.1-preview-7b6467c",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-7b6467c",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-7b6467c",
  "@metamask-previews/foundryup": "1.0.1-preview-7b6467c",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-7b6467c",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-7b6467c",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-7b6467c",
  "@metamask-previews/keyring-controller": "22.1.1-preview-7b6467c",
  "@metamask-previews/logging-controller": "6.0.4-preview-7b6467c",
  "@metamask-previews/message-manager": "12.0.2-preview-7b6467c",
  "@metamask-previews/messenger": "0.0.0-preview-7b6467c",
  "@metamask-previews/multichain-account-service": "0.4.0-preview-7b6467c",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-7b6467c",
  "@metamask-previews/multichain-network-controller": "0.11.1-preview-7b6467c",
  "@metamask-previews/multichain-transactions-controller": "4.0.1-preview-7b6467c",
  "@metamask-previews/name-controller": "8.0.3-preview-7b6467c",
  "@metamask-previews/network-controller": "24.1.0-preview-7b6467c",
  "@metamask-previews/network-enablement-controller": "0.2.0-preview-7b6467c",
  "@metamask-previews/notification-services-controller": "16.0.0-preview-7b6467c",
  "@metamask-previews/permission-controller": "11.0.6-preview-7b6467c",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-7b6467c",
  "@metamask-previews/phishing-controller": "13.1.0-preview-7b6467c",
  "@metamask-previews/polling-controller": "14.0.0-preview-7b6467c",
  "@metamask-previews/preferences-controller": "18.4.1-preview-7b6467c",
  "@metamask-previews/profile-sync-controller": "23.0.0-preview-7b6467c",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-7b6467c",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-7b6467c",
  "@metamask-previews/sample-controllers": "1.0.0-preview-7b6467c",
  "@metamask-previews/seedless-onboarding-controller": "2.6.0-preview-7b6467c",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-7b6467c",
  "@metamask-previews/shield-controller": "0.0.0-preview-7b6467c",
  "@metamask-previews/signature-controller": "32.0.0-preview-7b6467c",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-7b6467c",
  "@metamask-previews/transaction-controller": "59.2.0-preview-7b6467c",
  "@metamask-previews/user-operation-controller": "38.0.0-preview-7b6467c"
}

@matthiasgeihs matthiasgeihs requested a review from OGPoyraz August 20, 2025 08:31
OGPoyraz
OGPoyraz previously approved these changes Aug 21, 2025
OGPoyraz
OGPoyraz previously approved these changes Aug 21, 2025
Comment on lines 756 to -754
update,
getEthQuery,
getChainId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@matthiasgeihs
Copy link
Contributor Author

@metamaskbot publish-preview

@matthiasgeihs matthiasgeihs dismissed matthewwalsh0’s stale review August 21, 2025 08:53

Request has been addressed

- sort parameters alphabetically
- make `#getSimulationConfig` class property mandatory
  - update coverage because we can't test the `getSimulationConfig`
    fallback created in the constructor
- make `getSimulationConfig` function parameter mandatory
- fix parameter ordering
@matthiasgeihs
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.10.0-preview-9706a20",
  "@metamask-previews/accounts-controller": "33.0.0-preview-9706a20",
  "@metamask-previews/address-book-controller": "6.1.1-preview-9706a20",
  "@metamask-previews/announcement-controller": "7.0.3-preview-9706a20",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-9706a20",
  "@metamask-previews/approval-controller": "7.1.3-preview-9706a20",
  "@metamask-previews/assets-controllers": "74.0.0-preview-9706a20",
  "@metamask-previews/base-controller": "8.2.0-preview-9706a20",
  "@metamask-previews/bridge-controller": "41.1.0-preview-9706a20",
  "@metamask-previews/bridge-status-controller": "40.1.0-preview-9706a20",
  "@metamask-previews/build-utils": "3.0.3-preview-9706a20",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-9706a20",
  "@metamask-previews/composable-controller": "11.0.0-preview-9706a20",
  "@metamask-previews/controller-utils": "11.12.0-preview-9706a20",
  "@metamask-previews/delegation-controller": "0.7.0-preview-9706a20",
  "@metamask-previews/earn-controller": "6.0.0-preview-9706a20",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-9706a20",
  "@metamask-previews/ens-controller": "17.0.1-preview-9706a20",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-9706a20",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-9706a20",
  "@metamask-previews/foundryup": "1.0.1-preview-9706a20",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-9706a20",
  "@metamask-previews/gator-permissions-controller": "0.0.0-preview-9706a20",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-9706a20",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-9706a20",
  "@metamask-previews/keyring-controller": "23.0.0-preview-9706a20",
  "@metamask-previews/logging-controller": "6.0.4-preview-9706a20",
  "@metamask-previews/message-manager": "12.0.2-preview-9706a20",
  "@metamask-previews/messenger": "0.1.0-preview-9706a20",
  "@metamask-previews/multichain-account-service": "0.5.0-preview-9706a20",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-9706a20",
  "@metamask-previews/multichain-network-controller": "0.12.0-preview-9706a20",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-9706a20",
  "@metamask-previews/name-controller": "8.0.3-preview-9706a20",
  "@metamask-previews/network-controller": "24.1.0-preview-9706a20",
  "@metamask-previews/network-enablement-controller": "0.4.0-preview-9706a20",
  "@metamask-previews/notification-services-controller": "17.0.0-preview-9706a20",
  "@metamask-previews/permission-controller": "11.0.6-preview-9706a20",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-9706a20",
  "@metamask-previews/phishing-controller": "13.1.0-preview-9706a20",
  "@metamask-previews/polling-controller": "14.0.0-preview-9706a20",
  "@metamask-previews/preferences-controller": "19.0.0-preview-9706a20",
  "@metamask-previews/profile-sync-controller": "24.0.0-preview-9706a20",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-9706a20",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-9706a20",
  "@metamask-previews/sample-controllers": "1.0.0-preview-9706a20",
  "@metamask-previews/seedless-onboarding-controller": "3.0.0-preview-9706a20",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-9706a20",
  "@metamask-previews/shield-controller": "0.0.0-preview-9706a20",
  "@metamask-previews/signature-controller": "33.0.0-preview-9706a20",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-9706a20",
  "@metamask-previews/transaction-controller": "60.0.0-preview-9706a20",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-9706a20"
}

@matthiasgeihs matthiasgeihs enabled auto-merge (squash) August 25, 2025 13:17
@matthiasgeihs matthiasgeihs merged commit 0878c1d into main Aug 25, 2025
453 of 455 checks passed
@matthiasgeihs matthiasgeihs deleted the mg/integrate-shield-gateway branch August 25, 2025 13:22
micaelae pushed a commit that referenced this pull request Aug 25, 2025
## Explanation

For MetaMask Transaction Shield we want to reroute all transaction
simulation requests through a dedicated proxy.
This PR adds the following functionality to the TransactionController to
accomplish that.

- Add optional `getSimulationConfig` parameter to constructor.
- If `getSimulationConfig` parameter is present, call the function to
retrieve a new simulation URL and an authorization header. Replace the
simulation URL and add the authorization header to the simulation
request.

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References

[Transaction Shield Notion
Page](https://www.notion.so/Shield-1c3f86d67d68801f8821dae7af4de4bc?source=copy_link)

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Aug 27, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

For MetaMask Transaction Shield, we want to be able to route Security
Alerts API requests through a dedicated proxy, if the user is subscribed
to Shield. This PR adds a corresponding configuration option to the
Security Alerts API, similar to how it was done for the Simulation API
in the TransactionController
(MetaMask/core#6281).

This option is not used yet. It will later be used once the
corresponding backend services are deployed and the new ShieldController
and SubscriptionController are being integrated.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/35396?quickstart=1)

## **Changelog**

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry:

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants