Skip to content

refactor: use caip25 permission merger / differ#30042

Merged
ffmcgee725 merged 92 commits intomainfrom
jl/caip25-permission-refactor/factory-differ
Mar 3, 2025
Merged

refactor: use caip25 permission merger / differ#30042
ffmcgee725 merged 92 commits intomainfrom
jl/caip25-permission-refactor/factory-differ

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Jan 31, 2025

Addressing https://github.com/MetaMask/MetaMask-planning/issues/4017

We want to create a merger for the Caip25Permission specification in order to enable wallet_addEthereumChain and wallet_switchEthereumChain to call to the PermissionController rather than the ApprovalController for incremental permission requests (i.e. for the permittedChains flow).

Merger created in this core PR

Description

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

We can start everything off by making sure we use the dev build of extension via yarn && yarn webpack or yarn && yarn start

wallet_requestPermissions empty eth_accounts request (default)

  1. Send the following request through dev tools console via wallet_requestPermissions
await window.ethereum.request({
  method: 'wallet_requestPermissions',
  params: [
    {
      'eth_accounts': {},
    }
  ]
});
  1. Should render the following UI
Screenshot 2025-02-26 at 18 15 26 Screenshot 2025-02-26 at 18 15 19
  1. After approval, the dapp should also have eth_accounts and endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

wallet_requestPermissions eth_accounts account permission request

  1. Send the following request through dev tools console via wallet_requestPermissions
await window.ethereum.request({
  method: 'wallet_requestPermissions',
  params: [
    {
      'eth_accounts': {
        'caveats': [
        	{
        		'type': 'restrictReturnedAccounts',
        		'value': ["0x0aC9D99d92AB266e33b27469f8ce84FE7C56b6d5"] 
                          // replace this account with your local account public address
        	}
        ]
      },
    }
  ]
});
  1. Should render the following UI
Screenshot 2025-02-26 at 18 19 32 Screenshot 2025-02-26 at 18 19 23
  1. After approval, the dapp should also have eth_accounts and endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

wallet_requestPermissions endowment:permitted-chains chain permission request

  1. Send the following request through dev tools console via wallet_requestPermissions
await window.ethereum.request({
  method: 'wallet_requestPermissions',
  params: [
    {
      'eth_accounts': {
        'caveats': [
        	{
        		'type': 'restrictReturnedAccounts',
        		'value': []
        	}
        ]
      },
      'endowment:permitted-chains': {
      	'caveats': [
      		{
      			'type': 'restrictNetworkSwitching',
      			'value': ["0x1"] // replace with desired chain, here we default to mainnet
      		}
      	]
    }
    }
  ]
});
  1. Should render the following UI
Screenshot 2025-02-26 at 18 22 15 Screenshot 2025-02-26 at 18 22 09
  1. After approval, the dapp should also have eth_accounts and endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

wallet_requestPermissions eth_accounts and endowment:permitted-chains account + chain permission request

  1. Send the following request through dev tools console via wallet_requestPermissions
await window.ethereum.request({
  method: 'wallet_requestPermissions',
  params: [
    {
      'eth_accounts': {
        'caveats': [
        	{
        		'type': 'restrictReturnedAccounts',
        		'value': ["0x0aC9D99d92AB266e33b27469f8ce84FE7C56b6d5"]
                          // replace this account with your local account public address
        	}
        ]
      },
      'endowment:permitted-chains': {
      	'caveats': [
      		{
      			'type': 'restrictNetworkSwitching',
      			'value': ["0x1"] // replace with desired chain, here we default to mainnet
      		}
      	]
    }
    }
  ]
});
  1. Should render the following UI
Screenshot 2025-02-26 at 18 23 34 Screenshot 2025-02-26 at 18 23 29
  1. After approval, the dapp should also have eth_accounts and endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

wallet_requestPermissions malformed eth_accounts address

  1. Send the following request through dev tools console via wallet_requestPermissions
await window.ethereum.request({
  method: 'wallet_requestPermissions',
  params: [
    {
      'eth_accounts': {
        'caveats': [
        	{
        		'type': 'restrictReturnedAccounts',
        		'value': ["malformed.eth"]
        	}
        ]
      },
      'endowment:permitted-chains': {
      	'caveats': [
      		{
      			'type': 'restrictNetworkSwitching',
      			'value': []
      		}
      	]
    }
    }
  ]
});
  1. Should see an exception being thrown in the console, with the message Value must be a hexadecimal string, starting with "0x".
Screenshot 2025-02-27 at 10 16 31

wallet_switchEthereumChain Permissions for new chain

  1. Send the following request through dev tools console via wallet_switchEthereumChain
await window.ethereum.request({
          jsonrpc: '2.0',
          method: 'wallet_switchEthereumChain',
          params: [{ chainId: '0xe705' }], 
          // replace by a chain that's currently not permitted, I used Linea Sepolia
})
  1. Should render the following UI
Screenshot 2025-02-26 at 18 26 20
  1. After approval, the dapp should also have eth_accounts and endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

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.

ffmcgee725 and others added 30 commits January 21, 2025 18:43
…ons implementation to be fully caip25 compliant
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [e586d94]
Page Load Metrics (1659 ± 107 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint41922101596348167
domContentLoaded140222011638221106
load143922081659222107
domInteractive2294482512
backgroundConnect95623147
firstReactRender14104393014
getState44212126
initialActions01000
loadScripts9451639117817383
setupStore775202110
uiStartup166325191937273131
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -1.53 KiB (-0.03%)
  • ui: 114 Bytes (0.00%)
  • common: -71 Bytes (-0.00%)

ffmcgee725 added a commit to MetaMask/core that referenced this pull request Feb 25, 2025
## Explanation
Addressing MetaMask/MetaMask-planning#4017

We want to create a merger for the Caip25Permission specification in
order to enable wallet_addEthereumChain and wallet_switchEthereumChain
to call to the PermissionController rather than the ApprovalController
for incremental permission requests (i.e. for the permittedChains flow).

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

Extension: MetaMask/metamask-extension#30042

## 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/multichain-api`

- **BREAKING**: Renamed `mergeScopes` to `mergeNormalizedScopes`
- ADDED: Added merger to CaveatSpecification returned by
`caip25CaveatBuilder()`
- ADDED: Added `mergeInternalScopes` which merges two
`InternalScopesObject`s

## 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 highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [fdff9c1]
Page Load Metrics (1581 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1422172615816933
domContentLoaded1411168915557034
load1422172715816933
domInteractive2487422311
backgroundConnect105827157
firstReactRender147328199
getState4481195
initialActions01000
loadScripts1035131611656330
setupStore769262311
uiStartup1621193618077637
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -1.53 KiB (-0.03%)
  • ui: 114 Bytes (0.00%)
  • common: 262 Bytes (0.00%)

Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Some of the pieces here aren't totally clear to me. I think there's some context I'm missing. I had some question below if you wouldn't mind answering them.

@mcmire
Copy link
Copy Markdown
Contributor

mcmire commented Feb 28, 2025

@ffmcgee725 Maybe we can add that check that you suggested? Then I think we should be good to go on this PR. (I ran through the manual testing steps and everything worked as described)

@FrederikBolding FrederikBolding self-requested a review February 28, 2025 20:53
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [a7ae90c]
Page Load Metrics (1736 ± 63 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31919571673336161
domContentLoaded15211945171612962
load15311958173613263
domInteractive25110422110
backgroundConnect97724189
firstReactRender1569282010
getState565192010
initialActions00000
loadScripts11161512127211254
setupStore75916167
uiStartup17482269197814972
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -1.45 KiB (-0.03%)
  • ui: 113 Bytes (0.00%)
  • common: 262 Bytes (0.00%)

Copy link
Copy Markdown
Contributor

@hmalik88 hmalik88 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
Copy Markdown
Collaborator

Builds ready [b5a389a]
Page Load Metrics (1685 ± 82 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14702203169017383
domContentLoaded14372194165816881
load14812237168517082
domInteractive24108402211
backgroundConnect107031168
firstReactRender1497322512
getState579262512
initialActions00000
loadScripts10371663122513565
setupStore75716168
uiStartup16792403191217885
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -1.45 KiB (-0.03%)
  • ui: 113 Bytes (0.00%)
  • common: 262 Bytes (0.00%)

Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM!

@ffmcgee725 ffmcgee725 added this pull request to the merge queue Mar 3, 2025
Merged via the queue into main with commit 3464e0d Mar 3, 2025
80 checks passed
@ffmcgee725 ffmcgee725 deleted the jl/caip25-permission-refactor/factory-differ branch March 3, 2025 17:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2025
@metamaskbot metamaskbot added the release-12.15.0 Issue or pull request that will be included in release 12.15.0 label Mar 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-12.15.0 Issue or pull request that will be included in release 12.15.0 team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants