Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Multichain API to Flask #27782

Open
wants to merge 960 commits into
base: main
Choose a base branch
from
Open

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Oct 10, 2024

Description

This branch adds support for the Multichain API to the Flask build of the Extension.

The existing API (via injected provider) should be completely unchanged.

(Very Briefly) What is the MetaMask Multichain API

  • Concurrent connection to any number of chains (no network switching)
  • Unified entry point for all chain ecosystems (EVM, BTC, Solana, Cosmos, Polkadot etc)
  • Accessible (on extension for chromium based browsers) via externally_connectable. Not accessible via an injected global like window.ethereum

Key Documents/Standards

mip = MetaMask Improvement Proposal

  • MIP-5 (Overview of the Multichain API)
    • CAIP-25 (new connection request API)
    • CAIP-27 (new request API, envelope with target scope/chainId included)
  • MIP-6 (Overview of how the Multichain API’s EVM support diverges from the 1193 injected provider)

Manual testing steps

yarn start:flask

Then

(RECOMMENDED) Use the Multichain Test Dapp

OR

Form requests manually

Open in GitHub Codespaces

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • 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.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@jiexi
Copy link
Contributor Author

jiexi commented Oct 14, 2024

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

Copy link

socket-security bot commented Oct 14, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@shanejonas
Copy link
Contributor

this PR needs the patches from here: https://github.com/MetaMask/metamask-extension/pull/27847/files#r1801195961

@jiexi jiexi changed the base branch from caip-multichain to caip25-permission-migration October 15, 2024 16:18
@jiexi jiexi changed the title Multichain: migrate to core package feat: CAIP Multichain Oct 15, 2024
@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 2024

REMINDER: check the original feature branch PR for unresolved comments

@jiexi jiexi changed the title feat: CAIP Multichain feat: CAIP Multichain (New) Oct 15, 2024
@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 2024

TODO: Convert BARAD_DUR flag into flask feature flag

Done here #29003

@shanejonas shanejonas mentioned this pull request Oct 17, 2024
7 tasks
adonesky1 pushed a commit that referenced this pull request Oct 17, 2024
<!--
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**

<!--
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/27940?quickstart=1)

## **Related issues**

Fixes:
#27782 (comment)

## **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**

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

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
@jiexi
Copy link
Contributor Author

jiexi commented Oct 17, 2024

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot
Copy link
Collaborator

❌ Multichain API Spec Test Failed. View the report here.

Copy link

socket-security bot commented Oct 17, 2024

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] 🔁 npm/@metamask/[email protected] None 0 298 kB metamaskbot
npm/@metamask/[email protected] None 0 1.69 MB metamaskbot
npm/@open-rpc/[email protected] 🔁 npm/@open-rpc/[email protected] Transitive: environment, eval +5 1.33 MB belfordz

🚮 Removed packages: npm/[email protected]

View full report↗︎

@metamaskbot
Copy link
Collaborator

❌ Multichain API Spec Test Failed. View the report here.

@adonesky1
Copy link
Contributor

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@adonesky1
Copy link
Contributor

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot
Copy link
Collaborator

❌ Multichain API Spec Test Failed. View the report here.

Gudahtt added a commit that referenced this pull request Feb 19, 2025
The permissions confirmation page currently ignores the
`requestedChainIds` prop when the connection is confirmed. This hasn't
resulted in a bug because this page is only used for snap permissions.
Permission requests for `eth_account` or `endowment:permitted-chains`
are handled by the "ChooseAccount" or "ConnectPage" components (the
former if a snap is also requested alongside, the latter otherwise).

This PR fixes the problem regardless, as it's confusing for the
component to have this prop but to ignore it when processing the
confirmation.

This was extracted from #27782
Gudahtt added a commit that referenced this pull request Feb 19, 2025
The `extensionId` property was accidentally omitted by the ChromeDriver
builder. This was an old mistake, made in #7690. You can see this
property is expected in `test/e2e/webdriver/index.js`, though in
practice we don't use this `extensionId` for anything right now.

This was fixed so that we could use the `extensionId` in the future if
necessary. This was extracted from #27782, which used this ID in some
API spec e2e test helpers.
Gudahtt added a commit that referenced this pull request Feb 19, 2025
The permissions confirmation page currently ignores the
`requestedChainIds` prop when the connection is confirmed. This hasn't
resulted in a bug because this page is only used for snap permissions.
Permission requests for `eth_account` or `endowment:permitted-chains`
are handled by the "ChooseAccount" or "ConnectPage" components (the
former if a snap is also requested alongside, the latter otherwise).

This PR fixes the problem regardless, as it's confusing for the
component to have this prop but to ignore it when processing the
confirmation.

This was extracted from #27782
@@ -20,7 +20,6 @@ import {
BRIDGE_PREFERRED_GAS_ESTIMATE,
BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,
} from '../../../shared/constants/bridge';
import type { BridgeControllerState } from '../../../shared/types/bridge';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This change seems unrelated to the rest of this PR

@@ -20,6 +21,12 @@ const createStaticServer = (options) => {
public: path.resolve('./node_modules'),
});
}

// Handle test-dapp-multichain URLs by removing the prefix
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Link issue so readers can understand why we're doing this

Suggested change
// Handle test-dapp-multichain URLs by removing the prefix
// Handle test-dapp-multichain URLs by removing the prefix
// See here for details: https://github.com/MetaMask/MetaMask-planning/issues/4145

github-merge-queue bot pushed a commit that referenced this pull request Feb 20, 2025
## **Description**

The `extensionId` property was accidentally omitted by the ChromeDriver
builder. This was an old mistake, made in #7690. You can see this
property is expected in `test/e2e/webdriver/index.js`, though in
practice we don't use this `extensionId` for anything right now.

This was fixed so that we could use the `extensionId` in the future if
necessary. This was extracted from #27782, which used this ID in some
API spec e2e test helpers.


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

## **Related issues**

Extracted from #27782

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **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**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
adonesky1 pushed a commit to MetaMask/core that referenced this pull request Feb 21, 2025
## Explanation

This pull request fixes [this
issue](MetaMask/MetaMask-planning#4263).

We appear to be adding an `account` to the wallet scope

Resulting in this failing
[CI](https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/125517/workflows/abdfdb4f-da74-4cc2-9c2f-cf001817f358/jobs/4559282)
for our [Multichain Flask
PR](MetaMask/metamask-extension#27782)

we should add it to the `wallet:eip155` scope (as currently done), but
not just `wallet`.

The fix involves refactoring [core](https://github.com/MetaMask/core)
Multichain package so that creating the `scopeObjects` for each entry,
we make sure that in `wallet` scope string, the accounts property is not
populated.

<!--
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

<!--
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
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/package-a`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: Your change here

### `@metamask/package-b`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: Your change here

## 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 highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
Gudahtt added a commit that referenced this pull request Feb 24, 2025
The permissions confirmation page currently ignores the
`requestedChainIds` prop when the connection is confirmed. This hasn't
resulted in a bug because this page is only used for snap permissions.
Permission requests for `eth_account` or `endowment:permitted-chains`
are handled by the "ChooseAccount" or "ConnectPage" components (the
former if a snap is also requested alongside, the latter otherwise).

This PR fixes the problem regardless, as it's confusing for the
component to have this prop but to ignore it when processing the
confirmation.

This was extracted from #27782
Gudahtt added a commit that referenced this pull request Feb 24, 2025
The permissions confirmation page currently ignores the
`requestedChainIds` prop when the connection is confirmed. This hasn't
resulted in a bug because this page is only used for snap permissions.
Permission requests for `eth_account` or `endowment:permitted-chains`
are handled by the "ChooseAccount" or "ConnectPage" components (the
former if a snap is also requested alongside, the latter otherwise).

This PR fixes the problem regardless, as it's confusing for the
component to have this prop but to ignore it when processing the
confirmation.

This was extracted from #27782
Gudahtt added a commit that referenced this pull request Feb 24, 2025
The E2E test setup function (`withFixtures`) has been updated to pass
the extension ID to E2E tests. This will be useful in the near future
for testing the new multichain API, which is exposed over
`externally_connectable` and requires the extension ID to use.

This was extracted from #27782
@@ -227,6 +232,7 @@ async function withFixtures(options, testSuite) {
mockedEndpoint,
bundlerServer,
mockServer,
extensionId,
Copy link
Member

@Gudahtt Gudahtt Feb 24, 2025

Choose a reason for hiding this comment

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

This has been extracted to this PR: #30539

I left out the variable refactor (the introduction of the wd variable). Probably that was an attempt to clean this up, we have a confusing mix of similar variable names here. But we can clean that up in a follow-up instead. I think we can do something better to address that anyway (use webDriver as the scoped variable, and remove the existing outer-scope webDriver variable).

We appear to be adding an account to the `wallet` scope


![Image](https://github.com/user-attachments/assets/8e7d47a7-1e0c-4184-b05c-0dff629f6a30)

Resulting in this failing CI for our [Multichain Flask
PR](#27782)


https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/125517/workflows/abdfdb4f-da74-4cc2-9c2f-cf001817f358/jobs/4559282

we should add it to the `wallet:eip155` scope (as currently done), but
not just wallet.

The fix involves refactoring [core](https://github.com/MetaMask/core)
`Multichain` package so that creating the `scopeObjects` for each entry,
we make sure that in `wallet` scope string, the accounts property is not
populated.

<!--
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**

<!--
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/30495?quickstart=1)

## **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**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
@metamaskbot
Copy link
Collaborator

❌ Multichain API Spec Test Failed. View the report here.

github-merge-queue bot pushed a commit that referenced this pull request Feb 25, 2025
## **Description**

The E2E test setup function (`withFixtures`) has been updated to pass
the extension ID to E2E tests. This will be useful in the near future
for testing the new multichain API, which is exposed over
`externally_connectable` and requires the extension ID to use.

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

## **Related issues**

This was extracted from #27782

## **Manual testing steps**

N/A, this isn't used yet so there is nothing to manually test.

## **Screenshots/Recordings**

N/A

## **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**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
Gudahtt added a commit that referenced this pull request Feb 25, 2025
The permissions confirmation page currently ignores the
`requestedChainIds` prop when the connection is confirmed. This hasn't
resulted in a bug because this page is only used for snap permissions.
Permission requests for `eth_account` or `endowment:permitted-chains`
are handled by the "ChooseAccount" or "ConnectPage" components (the
former if a snap is also requested alongside, the latter otherwise).

This PR fixes the problem regardless, as it's confusing for the
component to have this prop but to ignore it when processing the
confirmation.

This was extracted from #27782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants