Add wallet_revokePermissions RPC method#1889
Conversation
| jsonrpc: '2.0', | ||
| id: 1, | ||
| method: 'wallet_revokePermissions', | ||
| params: { snap_dialog: { caveats: [{ type: 'foo', value: 'bar' }] } }, |
There was a problem hiding this comment.
does adding the caveats here only remove that particular caveat?
There was a problem hiding this comment.
Not for this implementation no, but the idea is that we can add that down the line without breaking the API.
So we allow passing in caveats now, but they are effectively ignored until we know how to handle them.
There was a problem hiding this comment.
the previous PR to extension used permissionController.updateCaveat, is there anything wrong with that approach? https://github.com/MetaMask/metamask-extension/pull/21216/files#diff-6fbff2cfe97ac01b77296ef2122c7e0a5b3ff6a84b584b4d1a87482f35eea3d6R3779
There was a problem hiding this comment.
Yeah, it is a flawed approach. Caveat values can be arbitrary JSON and are not standardized: https://github.com/MetaMask/core/blob/main/packages/permission-controller/src/Caveat.ts#L31C19-L31C23
Therefore it is not safe to assume we can modify them in this way.
We need to standardize the caveat format (effectively allowing for caveat merging, easy removal etc) before we implement this. That would be the next iteration of this API, but we have yet to discuss making that change in the PermissionController.
| jsonrpc: '2.0', | ||
| id: 1, | ||
| method: 'wallet_revokePermissions', | ||
| params: [], |
There was a problem hiding this comment.
shouldnt empty just revoke all permissions?
There was a problem hiding this comment.
That seems like it could be a bit confusing to me, but not sure
There was a problem hiding this comment.
the MIP says it should revoke all permissions. but that probably should say to revoke all per domain not all permissions.
There was a problem hiding this comment.
I think that is a dangerous API to expose by default. From my perspective a saner default is to have dapps specify the exact permissions they wish to revoke.
16e3f3f to
7d4f637
Compare
This changes the `revokePermissions` rpc method params to be by-position similar to `requestPermissions`
| revokePermissionsForOrigin( | ||
| permissionKeys as NonEmptyArray<PermissionConstraint['parentCapability']>, | ||
| ); |
There was a problem hiding this comment.
Do we need pass along origin here? Or will the hook have that context somehow?
There was a problem hiding this comment.
Normally the hooks are bound to the requesting origin and thus not needed to be passed
There was a problem hiding this comment.
oh hmm looks like we pass it as an arg for many other hooks. see setNetworkClientIdForDomain and handleWatchAssetRequest for example
There was a problem hiding this comment.
There was a problem hiding this comment.
yeah ok we can do that. We should go and use this pattern for the other handlers that need origin .
There was a problem hiding this comment.
It depends on how the RPC method is implemented. The origin cannot currently be bound in a restricted RPC method handler for instance.
packages/permission-controller/src/rpc-methods/revokePermissions.ts
Outdated
Show resolved
Hide resolved
packages/permission-controller/src/rpc-methods/revokePermissions.test.ts
Show resolved
Hide resolved
0f60648
## **Description** This PR adds `wallet_revokePermissions` rpc method support that was added in `permission-controller/rpc-methods` that went in this PR MetaMask/core#1889. All that is needed is to add the hook as the rpc-method gets automatically added [here](https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L13). ## **Related issues** Fixes: https://github.com/MetaMask/MetaMask-planning/issues/1681 ## **Manual testing steps** 1. Go to this page https://docs.metamask.io/wallet/reference/wallet_requestpermissions/ 2. Hit `Send Request` to request permissions 3. Click Next, Click Connect 4. Go to this page https://docs.metamask.io/wallet/reference/wallet_getpermissions/ 5. Click `Send Request` to get the permissions 6. See that there is permissions 7. paste this in the console: ```js await window.ethereum.request({ "method": "wallet_revokePermissions", "params": [ { "eth_accounts": {} } ] }); ``` 8. Click `Send Request` to get the permissions 9. see that there is no permissions and they have been revoked. ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [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/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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 <adonesky@gmail.com>
This PR adds `wallet_revokePermissions` rpc method support that was added in `permission-controller/rpc-methods` that went in this PR MetaMask/core#1889. All that is needed is to add the hook as the rpc-method gets automatically added [here](https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L13). --------- Co-authored-by: Alex Donesky <adonesky@gmail.com>
Explanation
Adds a
wallet_revokePermissionsRPC method that can be used to revoke permissions that a subject has been granted in the PermissionController. This initial version does not support revoking caveats and will revoke the entire requested permission key.References
Changelog
@metamask/permission-controllerwallet_revokePermissionsRPC methodChecklist