MetaMask / snaps

Extend the functionality of MetaMask using Snaps
https://metamask.io/snaps/
Other
711 stars 546 forks source link

refactor!(snaps-rpc-methods): Use hooks in `wallet_invokeSnap` instead of remapping the request to `wallet_snap` #2406

Closed rekmarks closed 1 month ago

rekmarks commented 1 month ago

Supersedes: #2398

We are moving our permission middleware ahead of all RPC method implementations in the extension (https://github.com/MetaMask/metamask-extension/pull/24472) and mobile (https://github.com/MetaMask/metamask-mobile/pull/9521). This breaks the current implementation of wallet_invokeSnap, which assumes that it's called before the permission middleware (which calls the implementation of wallet_snap, which is a restricted method).

This PR refactors wallet_invokeSnap to use an invokeSnap() hook, intended to be PermissionController.executeRestrictedMethod() bound to the requesting origin and 'wallet_snap'.