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: revoke CAIP-25 endowment if only eip155 account or scope is removed #4978

Merged
merged 12 commits into from
Nov 26, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Nov 25, 2024

Explanation

Updates the CAIP-25 mutators so that if the only eip155 account or scope is removed then the entire permission is revoked.

References

Related: MetaMask/metamask-extension#28709

Changelog

@metamask/multichain

  • CHANGED: Caip25CaveatMutators.authorizedScopes.removeAccount now revokes the CAIP-25 endowment if the only account is removed.
  • CHANGED: Caip25CaveatMutators.authorizedScopes.removeScope now revokes the CAIP-25 endowment if the only non-wallet scope is removed.
  • CHANGED: setEthAccounts no longer adds wallet:eip155 to the optionalScopes if it does not already exist.

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

@jiexi jiexi marked this pull request as ready for review November 25, 2024 19:53
@jiexi jiexi requested a review from a team as a code owner November 25, 2024 19:53
@jiexi
Copy link
Contributor Author

jiexi commented Nov 25, 2024

this doesn't handle the snaps case for permitted chains. need to update.

EDIT: unsure how to handle this for snaps as the mutator function only receives a caveat value which gives no insight into the Permission's origin

@jiexi
Copy link
Contributor Author

jiexi commented Nov 26, 2024

@metamaskbot publish-previews

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.0-preview-8a7e499b",
  "@metamask-previews/address-book-controller": "6.0.1-preview-8a7e499b",
  "@metamask-previews/announcement-controller": "7.0.1-preview-8a7e499b",
  "@metamask-previews/approval-controller": "7.1.1-preview-8a7e499b",
  "@metamask-previews/assets-controllers": "45.1.0-preview-8a7e499b",
  "@metamask-previews/base-controller": "7.0.2-preview-8a7e499b",
  "@metamask-previews/build-utils": "3.0.1-preview-8a7e499b",
  "@metamask-previews/chain-controller": "0.2.0-preview-8a7e499b",
  "@metamask-previews/composable-controller": "9.0.1-preview-8a7e499b",
  "@metamask-previews/controller-utils": "11.4.3-preview-8a7e499b",
  "@metamask-previews/ens-controller": "15.0.0-preview-8a7e499b",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-8a7e499b",
  "@metamask-previews/gas-fee-controller": "22.0.1-preview-8a7e499b",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-8a7e499b",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-8a7e499b",
  "@metamask-previews/keyring-controller": "19.0.0-preview-8a7e499b",
  "@metamask-previews/logging-controller": "6.0.2-preview-8a7e499b",
  "@metamask-previews/message-manager": "11.0.1-preview-8a7e499b",
  "@metamask-previews/multichain": "1.0.0-preview-8a7e499b",
  "@metamask-previews/name-controller": "8.0.1-preview-8a7e499b",
  "@metamask-previews/network-controller": "22.0.2-preview-8a7e499b",
  "@metamask-previews/notification-controller": "7.0.0-preview-8a7e499b",
  "@metamask-previews/notification-services-controller": "0.14.0-preview-8a7e499b",
  "@metamask-previews/permission-controller": "11.0.3-preview-8a7e499b",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-8a7e499b",
  "@metamask-previews/phishing-controller": "12.3.0-preview-8a7e499b",
  "@metamask-previews/polling-controller": "12.0.1-preview-8a7e499b",
  "@metamask-previews/preferences-controller": "15.0.0-preview-8a7e499b",
  "@metamask-previews/profile-sync-controller": "2.0.0-preview-8a7e499b",
  "@metamask-previews/queued-request-controller": "7.0.1-preview-8a7e499b",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-8a7e499b",
  "@metamask-previews/selected-network-controller": "19.0.0-preview-8a7e499b",
  "@metamask-previews/signature-controller": "23.0.0-preview-8a7e499b",
  "@metamask-previews/transaction-controller": "40.1.0-preview-8a7e499b",
  "@metamask-previews/user-operation-controller": "19.0.0-preview-8a7e499b"
}

});
});

it('does not revoke the permission if the target scope does not exist but the permission only has wallet scopes', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: The "does not revoke" tests are a bit confusing because it's not clear what we do expect to happen. Could we re-phrase them to make clear that we expect the result to be a no-op? The same goes for those added later in this file as well

Copy link
Member

Choose a reason for hiding this comment

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

Actually maybe these cases are already covered? I do see some "account does not exist" and "scope does not exist" test cases already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here d65e8eb

Gudahtt
Gudahtt previously approved these changes Nov 26, 2024
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.

Left a suggestion for the tests, but overall LGTM!

adonesky1
adonesky1 previously approved these changes Nov 26, 2024
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM

@jiexi jiexi dismissed stale reviews from Gudahtt and adonesky1 via 562f847 November 26, 2024 17:23
@jiexi jiexi enabled auto-merge (squash) November 26, 2024 17:27
@jiexi jiexi merged commit 4000c4d into main Nov 26, 2024
120 checks passed
@jiexi jiexi deleted the jl/caip-multichain-revoke-in-mutators branch November 26, 2024 17:28
matthewwalsh0 pushed a commit that referenced this pull request Nov 26, 2024
…oved (#4978)

## Explanation

Updates the CAIP-25 mutators so that if the only eip155 account or scope
is removed then the entire permission is revoked.

## References

Related: MetaMask/metamask-extension#28709

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

- **CHANGED**: `Caip25CaveatMutators.authorizedScopes.removeAccount` now
revokes the CAIP-25 endowment if the only account is removed.
- **CHANGED**: `Caip25CaveatMutators.authorizedScopes.removeScope` now
revokes the CAIP-25 endowment if the only non-wallet scope is removed.
- **CHANGED**: `setEthAccounts` no longer adds `wallet:eip155` to the
optionalScopes if it does not already exist.

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

---------

Co-authored-by: Alex Donesky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants