refactor!: Add consolidated legacy method middleware#8583
Draft
refactor!: Add consolidated legacy method middleware#8583
Conversation
Add `createMethodMiddlewareFactory` to the legacy (v1) surface, consolidating the near-identical `makeMethodMiddlewareMaker` implementations from metamask-extension and metamask-mobile. The new export is deprecated in favor of the v2 `createMethodMiddleware`. Extract `selectHooks` and `assertExpectedHooks` into a shared `hookUtils.ts` module used by both v1 and v2. v2 now performs the same strict missing/extraneous hook validation as v1 at middleware construction time. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Member
Author
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit be9aaca. Configure here.
…thod middleware Allow `Messenger<string, never>` in the no-actions branch of `CreateMethodMiddlewareFactoryOptions` so callers may still pass a no-op root messenger when handlers declare no actions. Pre-select hooks per handler at curried-call time and store them on a `ResolvedHandler` entry, mirroring v2's dispatch shape and removing `selectHooks` from the per-request path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Member
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
This PR consolidates the bespoke
makeMethodMiddlewareMakerimplementations from the MetaMask extension and mobile clients into a single legacycreateMethodMiddlewareexported from@metamask/json-rpc-engine, and removes the unused permitted method handlers from@metamask/permission-controller.@metamask/json-rpc-enginecreateMethodMiddlewarethat builds aJsonRpcEnginemiddleware from a record of method handlers keyed by method name. It validates handler hooks against the union ofhookNamesdeclared by the handlers (rejecting both missing and extraneous hooks) and dispatches incoming requests bymethod.actionNamesand receive a per-handler delegatedMessengeras the sixth argument toimplementation, mirroring the v2createMethodMiddleware. The legacy and v2 versions now share their hook selection / validation and messenger delegation utilities.createMethodMiddleware. It exists only to give the extension and mobile clients a consolidated migration target before they move toJsonRpcEngineV2.@metamask/permission-controller(BREAKING)getPermissions,requestPermissions,revokePermissions) and the relatedpermissionRpcMethodsandPermittedHandlerExportexports. These were unused in practice. Replacement types are available in@metamask/json-rpc-engine@10.3.0.References
Related to the ongoing migration to
JsonRpcEngineV2.Checklist