Skip to content

Split up multichain package into 3 packages - #5476

Merged
adonesky1 merged 20 commits into
mainfrom
extract-wallet-api-packages
Mar 18, 2025
Merged

Split up multichain package into 3 packages#5476
adonesky1 merged 20 commits into
mainfrom
extract-wallet-api-packages

Conversation

@mcmire

@mcmiremcmire commented Mar 13, 2025

Copy link
Copy Markdown
Collaborator

Explanation

Not everything in @metamask/multichain is strictly multichain-related. We could rename this package to @metamask/caip25, but not everything is CAIP-25-related, either.

To better highlight the purpose of the different parts of @metamask/multichain, this commit splits it up into 3 packages:

  • @metamask/chain-agnostic-permission: Defines an endowment type permission designed to persist the account and chain components of a CAIP-25 request. This package also includes adapters and utility functions for interfacing with this permission.
  • @metamask/eip1193-permission-middleware: Implements the JSON-RPC methods for managing permissions as referenced in EIP-2255 and MIP-2, but adapted to support chain-agnostic permission caveats.
  • @metamask/multichain-api-middleware: JSON-RPC methods and middleware to support the the MetaMask Multichain API.

Note that the existing code in @metamask/multichain has not been touched. We will deprecate and remove this package later.

References

Closeshttps://github.com/MetaMask/MetaMask-planning/issues/4395.

Changelog

(No updates to changelogs needed)

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

This commit adjusts the constraints in `yarn.config.cjs`:
- Remove `expectControllerDependenciesListedAsPeerDependencies`. As its
name implies, this constraint ensured that dependencies which referred
to controllers were always listed as peer dependencies. This is
incorrect, because in some cases we may simply want to list them as
"production" dependencies.
- Correct `expectDependenciesNotInBothProdAndDev` (now
`expectDependenciesNotInBothProdAndDevOrPeer`) to not only ensure that
a dependency is not listed in both `dependencies` and
`devDependencies` but also both `dependencies` and `peerDependencies`
(only `devDependencies` + `peerDependencies` is allowed, as
combinations go).
- Add `expectPeerDependenciesAlsoListedAsDevDependencies` constraint
to ensure that peer dependencies are also listed as dev dependencies.
- Fix `expectUpToDateWorkspaceDependenciesAndDevDependencies` to skip
validation of "production" dependencies that are also listed in peer
dependencies (this avoids conflicting constraints).
- Correct `expectConsistentDependenciesAndDevDependencies` to skip
workspace dependencies, as that is already being handled by
`expectUpToDateWorkspaceDependenciesAndDevDependencies` (this avoids
conflicting constraints).
Note that because of these changes, several controllers have also been
corrected to fit.
Not everything in `@metamask/multichain` is strictly multichain-related.
We could rename this package to `@metamask/caip25`, but not everything
is CAIP-25-related, either.
To better highlight the purpose of the different parts of
`@metamask/multichain`, this commit extracts those parts to 3 packages:
- `@metamask/chain-agnostic-permission`: Defines a permission caveat and
endowment designed to match [CAIP-25][1] and related specifications.
- `@metamask/eip1193-permission-middleware`: Implements JSON-RPC methods
for managing permissions as described in [EIP-2255][2] and [MIP-2][3].
- `@metamask/multichain-api-middleware`: Implements JSON-RPC methods in
the [MetaMask Multichain API][4] that manage and utilize
[chain-agnostic permissions][5].
Note that the existing code in `@metamask/multichain` has not been
touched. We will deprecate and remove this package in a future commit.
[1]: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md
[2]: https://eips.ethereum.org/EIPS/eip-2255
[3]: https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md
[4]: https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-5.md
[5]: https://github.com/MetaMask/chain-agnostic-permission
@mcmire
mcmireforce-pushed the extract-wallet-api-packages branch from 74b0f6a to 48096e6CompareMarch 13, 2025 20:55
Comment threadpackages/chain-agnostic-permission/README.md Outdated
Comment threadpackages/eip1193-permission-middleware/README.md Outdated
Comment threadpackages/multichain-api-middleware/README.md Outdated
Comment thread.github/CODEOWNERS Outdated
Comment thread.github/CODEOWNERS Outdated
Comment threadpackages/chain-agnostic-permission/src/index.test.ts
Comment threadpackages/eip1193-permission-middleware/src/wallet-getPermissions.test.ts Outdated
Comment threadpackages/multichain-api-middleware/src/handlers/wallet-getSession.test.ts Outdated
ffmcgee725
ffmcgee725 previously approved these changes Mar 14, 2025

@ffmcgee725ffmcgee725 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! 🚀

Comment threadpackages/chain-agnostic-permission/README.md Outdated
@adonesky1

Copy link
Copy Markdown
Contributor

Would it be possible to create preview builds and replace uses of the @metamask/multichain package with these packages in an extension branch? Or is this not possible on this PR where the packages are first introduced?

@mcmire

Copy link
Copy Markdown
CollaboratorAuthor

@adonesky1 Hmm I think that is possible! I will give it a shot.

Comment threadpackages/eip1193-permission-middleware/README.md Outdated
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Base automatically changed from allow-controller-to-only-be-listed-in-deps to mainMarch 14, 2025 17:49
@mcmire
mcmire dismissed ffmcgee725’s stale reviewMarch 14, 2025 17:49

The base branch was changed.

@mcmire

Copy link
Copy Markdown
CollaboratorAuthor

@metamaskbot publish-previews

@mcmire
mcmire marked this pull request as ready for review March 14, 2025 19:22
@mcmire
mcmire requested review from a team as code ownersMarch 14, 2025 19:22
@mcmire

Copy link
Copy Markdown
CollaboratorAuthor

@adonesky1 I just checked and it's not possible to publish a preview build of a not-yet-published package. I tried to fix this and it would take a bit of time to fix, so I don't think it's something we can address right now.

Comment threadpackages/profile-sync-controller/CHANGELOG.md
@adonesky1

Copy link
Copy Markdown
Contributor

A few small outstanding comments otherwise LGTM!

Comment threadpackages/chain-agnostic-permission/src/types.ts
@mcmire

Copy link
Copy Markdown
CollaboratorAuthor

I believe I've addressed all the comments here. Ready for re-review.

Object.keys(caip25EquivalentPermissions).length > 0;

if (hasCaip25EquivalentPermissions) {
const caip25Permission = getCaip25PermissionFromLegacyPermissionsForOrigin(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we move the getCaip25PermissionFromLegacyPermissions hook over from extension? The only platform specific thing I may be worried about is the special handling for snap origins

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ahh sorry. ignore this. definitely outside the scope of this PR. my bad

@adonesky1

Copy link
Copy Markdown
Contributor

Other than @jiexi's outstanding comment that needs a fix/cleanup, LGTM!

@adonesky1adonesky1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jiexijiexi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚀 ➡️ 🚀 🚀 🚀

@adonesky1
adonesky1 enabled auto-merge (squash) March 17, 2025 18:53

@cryptodev-2scryptodev-2s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@adonesky1
adonesky1 merged commit acca1ea into mainMar 18, 2025
@adonesky1
adonesky1 deleted the extract-wallet-api-packages branch March 18, 2025 14:13
ffmcgee725 added a commit that referenced this pull request Jun 12, 2025
## Explanation
As follow-up work to the previous splitting of the `multichain` package
into 3 new packages
`@metamask/chain-agnostic-permission`
`@metamask/eip1193-permission-middleware`
`@multichain/multichain-api-middleware`
done in the [following PR](#5476),
we now want to completely deprecate/remove the legacy package and later
mark it as deprecated while also linking to the new packages in npm.
<!--
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
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
* Fixes : MetaMask/MetaMask-planning#4729
* Related to MetaMask/MetaMask-planning#4395
## Changelog
<!--
THIS SECTION IS NO LONGER NEEDED.
The process for updating changelogs has changed. Please consult the
"Updating changelogs" section of the Contributing doc for more.
-->
## 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 communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
Sign up for freeto 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.

5 participants

@mcmire@adonesky1@jiexi@ffmcgee725@cryptodev-2s