-
-
Notifications
You must be signed in to change notification settings - Fork 277
refactor!: Add consolidated legacy method middleware #8583
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
Open
rekmarks
wants to merge
22
commits into
main
Choose a base branch
from
rekm/v2-permitted-handlers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e785683
refactor(permission-controller)!: Remove unrestricted rpc methods
rekmarks 3b9f35a
feat(json-rpc-engine): consolidate legacy `createMethodMiddleware`
rekmarks b7faed3
refactor(json-rpc-engine)!: Support messenger handlers in legacy meth…
rekmarks be9aaca
chore: Update changelogs
rekmarks 77f1777
refactor(json-rpc-engine): Pre-resolve hooks per handler in legacy me…
rekmarks 09b26c5
refactor: Harmonize legacy middleware with v2 version
rekmarks f86425a
Merge branch 'main' into rekm/v2-permitted-handlers
rekmarks dc38a25
chore: Tweak permission-controller changelog
rekmarks fc5c197
refactor: Address review
rekmarks ce46bdb
feat(json-rpc-engine): optional root messenger for method middleware
rekmarks 473387f
feat(json-rpc-engine): optional RequestExtras on legacy MethodHandler
rekmarks afad6dc
refactor(multichain-api-middleware): Migrate to new method handler pa…
rekmarks e7105fc
refactor(eip1193-permission-middleware): Migrate to new method handle…
rekmarks 45a82ea
refactor: Minor fixups
rekmarks 86dd857
fix: Fix legacy method middleware hook inference
rekmarks 3763b57
chore: Lint
rekmarks c4a8339
refactor: Fix trackSessionCreatedEvent optionality
rekmarks f43f664
fix: Require hooks in createMethodMiddleware options
rekmarks 7114b69
test: Round out v2 method middleware test suite
rekmarks 897b1ae
chore: lint
rekmarks 846bfc4
refactor: Address review feedback
rekmarks a1caffc
refactor: Rename method handler exports
rekmarks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,40 @@ | ||
| import { createMethodMiddleware } from '@metamask/json-rpc-engine'; | ||
|
|
||
| import * as allExports from '.'; | ||
| import type { GetPermissionsHooks } from './wallet-getPermissions'; | ||
| import type { RequestPermissionsHooks } from './wallet-requestPermissions'; | ||
| import type { RevokePermissionsHooks } from './wallet-revokePermissions'; | ||
|
|
||
| type Hooks = GetPermissionsHooks & | ||
| RequestPermissionsHooks & | ||
| RevokePermissionsHooks; | ||
|
|
||
| /* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
| const makeMockHooks = () => | ||
| ({ | ||
| getPermissionsForOrigin: (() => ({})) as Hooks['getPermissionsForOrigin'], | ||
| getAccounts: () => ['0x123'], | ||
| requestPermissionsForOrigin: (() => | ||
| Promise.resolve([{}])) as Hooks['requestPermissionsForOrigin'], | ||
| revokePermissionsForOrigin: () => undefined, | ||
| getCaip25PermissionFromLegacyPermissionsForOrigin: () => ({}), | ||
| }) satisfies Hooks; | ||
| /* eslint-enable @typescript-eslint/explicit-function-return-type */ | ||
|
|
||
| describe('@metamask/eip1193-permission-middleware', () => { | ||
| it('has expected JavaScript exports', () => { | ||
| expect(Object.keys(allExports)).toMatchInlineSnapshot(` | ||
| [ | ||
| "getPermissionsHandler", | ||
| "requestPermissionsHandler", | ||
| "revokePermissionsHandler", | ||
| "methodHandlers", | ||
| ] | ||
| `); | ||
| }); | ||
|
|
||
| it('constructs a method middleware from the handlers', () => { | ||
| const middleware = createMethodMiddleware({ | ||
| handlers: allExports.methodHandlers, | ||
| hooks: makeMockHooks(), | ||
| }); | ||
| expect(middleware).toBeDefined(); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| export { getPermissionsHandler } from './wallet-getPermissions'; | ||
| export { requestPermissionsHandler } from './wallet-requestPermissions'; | ||
| export { revokePermissionsHandler } from './wallet-revokePermissions'; | ||
| import { MethodNames } from '@metamask/permission-controller'; | ||
|
|
||
| import { getPermissionsHandler } from './wallet-getPermissions'; | ||
| import { requestPermissionsHandler } from './wallet-requestPermissions'; | ||
| import { revokePermissionsHandler } from './wallet-revokePermissions'; | ||
|
|
||
| type MethodHandlers = { | ||
| [MethodNames.GetPermissions]: typeof getPermissionsHandler; | ||
| [MethodNames.RequestPermissions]: typeof requestPermissionsHandler; | ||
| [MethodNames.RevokePermissions]: typeof revokePermissionsHandler; | ||
| }; | ||
|
|
||
| export const methodHandlers: Readonly<MethodHandlers> = { | ||
| [MethodNames.GetPermissions]: getPermissionsHandler, | ||
| [MethodNames.RequestPermissions]: requestPermissionsHandler, | ||
| [MethodNames.RevokePermissions]: revokePermissionsHandler, | ||
| }; |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.