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: Migrate eth_accounts and permittedChains to CAIP-25 endowment #27847

Merged
merged 348 commits into from
Jan 20, 2025

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Oct 14, 2024

Description

This PR replaces the replaces the internal eth_accounts and endowment:permittedChains permission structure with a CAIP-25 endowment. It adds adapter logic to translate to and from the new internal CAIP-25 permissions. This change should be transparent to wallet users and to dapps except for one two cases, see below. This change is required in order to support CAIP-25 and CAIP-27 requests in a follow-up PR that enables the Multichain API.

Open in GitHub Codespaces

Related issues

Related: MetaMask/core#4784

Manual testing steps

There should be no user or dapp facing difference in behavior except:

  • When calling wallet_revokePermissions and specifying either eth_accounts or endowment:permitted-chains, the entire CAIP-25 permission will be revoked. It will appear to the dapp as if both eth_accounts and endowment:permitted-chains were revoked.
  • When calling wallet_getPermissions for a permitted dapp when the wallet is locked, eth_accounts should be returned in addition to endowment:permitted-chains. Currently there is a regression on main where only endowment:permitted-chains gets returned when the wallet is locked.
await window.ethereum.request({
 "method": "wallet_revokePermissions",
 "params": [
  {
    eth_accounts: {}
  }
],
});

await window.ethereum.request({
 "method": "wallet_revokePermissions",
 "params": [
  {
    'endowment:permitted-chains': {}
  }
],
});

await window.ethereum.request({
 "method": "wallet_getPermissions",
 "params": [],
});

Locked Wallet Behavior with dapp connected

Other than the two noted items below, this behavior matches that in main

  • eth_accounts returns []
  • wallet_getPermissions returns permissions incl eth_accounts
  • wallet_revokePermissions works as usual and revokes eth_accounts and revoke permitted-chains together
    • Note this fixes a regression in main where eth_accounts and permitted-chains aren't revoked as a pair if either is revoked
  • eth_requestAccounts prompts for unlock, after unlock returns accounts if any are permitted, otherwise shows connection prompt
  • wallet_requestPermissions prompts for unlock
  • signature methods fails with method or accounts not authorized
  • non-signature methods work as usual
  • accountsChanged empty array on lock. no event after revokePermissions which makes sense since the dapp was told empty array on lock and now it's actually empty array so no changes have occurred as far as the dapp should be concerned.
  • CHANGED: for dapps that were granted chain permissions via the wallet_addEthereum or wallet_switchEthereumChain flows without account permissions, these permissions will be removed with this migration. We think this ok because:
    • This is a very uncommon scenario for dapps to request chain switches without account permissions.
    • These permissions can be regained very trivially with subsequent chain switch requests.

Testing the migration

  • Create a dev build from main
  • Install the dev build from the dist/chrome directory and proceed through onboarding
  • Run this command in the background console:
    chrome.storage.local.get(
      null,
      (state) => {
        state.data.PermissionController = {}; // Replace this line based on instructions below
        chrome.storage.local.set(state, () => chrome.runtime.reload());
      }
    );
    
  • Disable the extension
  • Switch to main and create a dev build
  • Enable and reload the extension
    • You should see in the console that migration 139 has failed

Repeat the above steps but with the line above replaced with the following for example:

  • state.data.NetworkController = {};
  • state.data.NetworkController = 'foobar';
  • state.data.NetworkController.selectedNetworkClientId = null;
  • state.data.NetworkController.networkConfigurationsByChainId = 'foobar';

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Copy link

socket-security bot commented Oct 14, 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 270 kB metamaskbot
npm/@metamask/[email protected] None 0 318 kB metamaskbot
npm/@open-rpc/[email protected] 🔁 npm/@open-rpc/[email protected] None 0 38.4 kB belfordz

🚮 Removed packages: npm/@json-schema-spec/[email protected], npm/@json-schema-tools/[email protected]

View full report↗︎

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↗︎

@jiexi
Copy link
Contributor Author

jiexi commented Oct 14, 2024

@metamask-bot update-policies

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 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

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 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

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 2024

@SocketSecurity ignore npm/@metamask/[email protected]

i know that mcmire guy

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 2024

@SocketSecurity ignore npm/@metamask/[email protected]

i still know that mcmire fellow

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 2024

@SocketSecurity ignore npm/@metamask/[email protected]

the fetch isn't new, but even then it's fine because it fetches caller supplied url

@jiexi
Copy link
Contributor Author

jiexi commented Oct 15, 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

@jiexi
Copy link
Contributor Author

jiexi commented Oct 16, 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

@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

github-merge-queue bot pushed a commit that referenced this pull request Jan 16, 2025
…cenario to wallet_revokePermissions e2e test (#29761)

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

* Fix incorrect snap-account-signature e2e test fixtures / starting
state (accounts permissioned before they exist in the wallet)
* Add `endowment:permitted-chains` scenario to
`wallet_revokePermissions` e2e test

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

## **Related issues**

See: #27847

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

---------

Co-authored-by: Alex Donesky <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
@Gudahtt Gudahtt mentioned this pull request Jan 17, 2025
7 tasks
@@ -479,10 +479,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: [
Copy link
Member

Choose a reason for hiding this comment

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

I have attempted to extract this here: #29783

@Gudahtt
Copy link
Member

Gudahtt commented Jan 17, 2025

It would be helpful to have manual testing instructions in the PR description for the migration, e.g. how to test that everything works correctly when updating.

I've provided similar instructions in the past on how to do "update testing", e.g. in this PR: #26485
That might be a good starting point.

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

Two of the permission fixture builders were adding permissions for
accounts that do not exist. They have been updated to only grant
permissions for the selected account, which is the only account
guaranteed to exist in the default fixture.

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

## **Related issues**

This was extracted from
#27847

## **Manual testing steps**

See that E2E tests still pass

## **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.
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [18440d6]
Page Load Metrics (1692 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14851959169811555
domContentLoaded14781901166810651
load14871959169211555
domInteractive267546157
backgroundConnect674252110
firstReactRender15101422713
getState566182010
initialActions01000
loadScripts1053142512169546
setupStore690162311
uiStartup173127501965209100
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 16.07 KiB (0.27%)
  • ui: 659 Bytes (0.01%)
  • common: 132.64 KiB (1.53%)

@metamaskbot
Copy link
Collaborator

Builds ready [15fa319]
Page Load Metrics (1581 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1408175515859445
domContentLoaded1400173715608943
load1408175815819345
domInteractive247234157
backgroundConnect57520189
firstReactRender15104322813
getState45917189
initialActions01000
loadScripts1026133011567938
setupStore588182311
uiStartup160923221923230111
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 16.21 KiB (0.27%)
  • ui: 659 Bytes (0.01%)
  • common: 132.64 KiB (1.53%)

@Gudahtt Gudahtt enabled auto-merge January 20, 2025 13:37
@Gudahtt Gudahtt added this pull request to the merge queue Jan 20, 2025
Merged via the queue into main with commit d5cd7fd Jan 20, 2025
87 checks passed
@Gudahtt Gudahtt deleted the caip25-permission-migration branch January 20, 2025 15:01
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2025
@metamaskbot metamaskbot added the release-12.12.0 Issue or pull request that will be included in release 12.12.0 label Jan 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.12.0 Issue or pull request that will be included in release 12.12.0 team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.