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: Add caip25CaveatBuilder to @metamask/multichain #5064

Merged
merged 9 commits into from
Dec 16, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Dec 12, 2024

Explanation

Moves the validator from the caip25EndowmentBuilder into a new caip25CaveatBuilder helper to fix the incorrect full validation of the CAIP-25 caveat inside the CAIP-25 permission.

References

See: MetaMask/metamask-extension#27847 (comment)
Extension: MetaMask/metamask-extension#29166

Changelog

@metamask/multichain

  • BREAKING: The validator returned by caip25EndowmentBuilder now only verifies that there is single CAIP-25 caveat and nothing else.
  • ADDED: Adds caip25CaveatBuilder helper that builds a specification for the CAIP-25 caveat that can be passed to the relevant PermissionController constructor param.

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
Copy link
Contributor Author

jiexi commented Dec 12, 2024

@metamaskbot publish-preview

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.2-preview-cdf3e01b",
  "@metamask-previews/address-book-controller": "6.0.2-preview-cdf3e01b",
  "@metamask-previews/announcement-controller": "7.0.2-preview-cdf3e01b",
  "@metamask-previews/approval-controller": "7.1.1-preview-cdf3e01b",
  "@metamask-previews/assets-controllers": "45.1.2-preview-cdf3e01b",
  "@metamask-previews/base-controller": "7.0.2-preview-cdf3e01b",
  "@metamask-previews/build-utils": "3.0.2-preview-cdf3e01b",
  "@metamask-previews/chain-controller": "0.2.2-preview-cdf3e01b",
  "@metamask-previews/composable-controller": "10.0.0-preview-cdf3e01b",
  "@metamask-previews/controller-utils": "11.4.4-preview-cdf3e01b",
  "@metamask-previews/ens-controller": "15.0.1-preview-cdf3e01b",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-cdf3e01b",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-cdf3e01b",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-cdf3e01b",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-cdf3e01b",
  "@metamask-previews/keyring-controller": "19.0.2-preview-cdf3e01b",
  "@metamask-previews/logging-controller": "6.0.3-preview-cdf3e01b",
  "@metamask-previews/message-manager": "11.0.3-preview-cdf3e01b",
  "@metamask-previews/multichain": "1.1.2-preview-cdf3e01b",
  "@metamask-previews/name-controller": "8.0.2-preview-cdf3e01b",
  "@metamask-previews/network-controller": "22.1.1-preview-cdf3e01b",
  "@metamask-previews/notification-services-controller": "0.15.0-preview-cdf3e01b",
  "@metamask-previews/permission-controller": "11.0.4-preview-cdf3e01b",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-cdf3e01b",
  "@metamask-previews/phishing-controller": "12.3.1-preview-cdf3e01b",
  "@metamask-previews/polling-controller": "12.0.2-preview-cdf3e01b",
  "@metamask-previews/preferences-controller": "15.0.1-preview-cdf3e01b",
  "@metamask-previews/profile-sync-controller": "3.1.1-preview-cdf3e01b",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-cdf3e01b",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-cdf3e01b",
  "@metamask-previews/remote-feature-flag-controller": "1.2.0-preview-cdf3e01b",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-cdf3e01b",
  "@metamask-previews/signature-controller": "23.1.0-preview-cdf3e01b",
  "@metamask-previews/transaction-controller": "42.0.0-preview-cdf3e01b",
  "@metamask-previews/user-operation-controller": "21.0.0-preview-cdf3e01b"
}

adonesky1
adonesky1 previously approved these changes Dec 12, 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!

listAccounts,
},
});
const { validator } = caip25EndowmentBuilder.specificationBuilder({});
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Strange that it lets you pass in an empty object here 🤔 It looks like it should take no parameters?

Suggested change
const { validator } = caip25EndowmentBuilder.specificationBuilder({});
const { validator } = caip25EndowmentBuilder.specificationBuilder();

Copy link
Member

Choose a reason for hiding this comment

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

Ah, the type does require an options object, but we have it typed as Record<never, never>. Probably we should revert my suggestion here for now, but ultimately I think we should consider updating the specification builder type to let us exclude the options completely.

Gudahtt
Gudahtt previously approved these changes Dec 13, 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.

LGTM!

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
@adonesky1 adonesky1 dismissed stale reviews from Gudahtt and themself via 0e68a23 December 13, 2024 15:56
adonesky1
adonesky1 previously approved these changes Dec 13, 2024
@jiexi jiexi enabled auto-merge (squash) December 16, 2024 17:15
@jiexi jiexi merged commit 3ba1147 into main Dec 16, 2024
120 checks passed
@jiexi jiexi deleted the jl/caip-25-move-validator-into-caveat branch December 16, 2024 17:24
jiexi added a commit to MetaMask/metamask-extension that referenced this pull request Dec 16, 2024
…29166)

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

Adopts `@metamask/mutlichain` changes that move validation logic out of
the CAIP-25 permission and into the caveat itself.

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

## **Related issues**

Core: MetaMask/core#5064

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