Skip to content

Commit fe43b08

Browse files
authored
chore: Expose missing PermissionController methods through the messenger (#8675)
## Explanation This exposes missing methods used in the clients through the messenger after #8201 ## References Progresses https://consensyssoftware.atlassian.net/browse/WPC-989 ## 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/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: this primarily expands the messenger-exposed API surface and TypeScript action types without changing permission logic, but consumers may start depending on these newly exposed actions. > > **Overview** > **Exposes additional `PermissionController` methods via the messenger** by adding new action types and including them in the controller’s `MESSENGER_EXPOSED_METHODS` allowlist. > > Newly exposed actions include `acceptPermissionsRequest`, `rejectPermissionsRequest`, `revokePermission`, `updatePermissionsByCaveat`, and `getPermission`, with corresponding exports from the package entrypoint and a changelog entry documenting the additions. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 092f6a5. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7f2126a commit fe43b08

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

packages/permission-controller/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Expose missing public `PermissionController` methods through its messenger ([#8675](https://github.com/MetaMask/core/pull/8675))
13+
- The following actions are now available:
14+
- `PermissionController:acceptPermissionsRequest`,
15+
- `PermissionController:rejectPermissionsRequest`,
16+
- `PermissionController:revokePermission`,
17+
- `PermissionController:updatePermissionsByCaveat`,
18+
- `PermissionController:getPermission`
19+
- Corresponding action types are available as well.
20+
1021
## [13.0.0]
1122

1223
### Added

packages/permission-controller/src/PermissionController-method-action-types.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ export type PermissionControllerGetSubjectNamesAction = {
3737
handler: PermissionController['getSubjectNames'];
3838
};
3939

40+
/**
41+
* Gets the permission for the specified target of the subject corresponding
42+
* to the specified origin.
43+
*
44+
* @param origin - The origin of the subject.
45+
* @param targetName - The method name as invoked by a third party (i.e., not
46+
* a method key).
47+
* @returns The permission if it exists, or undefined otherwise.
48+
*/
49+
export type PermissionControllerGetPermissionAction = {
50+
type: `PermissionController:getPermission`;
51+
handler: PermissionController['getPermission'];
52+
};
53+
4054
/**
4155
* Gets all permissions for the specified subject, if any.
4256
*
@@ -85,6 +99,20 @@ export type PermissionControllerRevokeAllPermissionsAction = {
8599
handler: PermissionController['revokeAllPermissions'];
86100
};
87101

102+
/**
103+
* Revokes the specified permission from the subject with the specified
104+
* origin.
105+
*
106+
* Throws an error if the subject or the permission does not exist.
107+
*
108+
* @param origin - The origin of the subject whose permission to revoke.
109+
* @param target - The target name of the permission to revoke.
110+
*/
111+
export type PermissionControllerRevokePermissionAction = {
112+
type: `PermissionController:revokePermission`;
113+
handler: PermissionController['revokePermission'];
114+
};
115+
88116
/**
89117
* Revokes the specified permissions from the specified subjects.
90118
*
@@ -152,6 +180,34 @@ export type PermissionControllerUpdateCaveatAction = {
152180
handler: PermissionController['updateCaveat'];
153181
};
154182

183+
/**
184+
* Updates all caveats with the specified type for all subjects and
185+
* permissions by applying the specified mutator function to them.
186+
*
187+
* ATTN: Permissions can be revoked entirely by the action of this method,
188+
* read on for details.
189+
*
190+
* Caveat mutators are functions that receive a caveat value and return a
191+
* tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new
192+
* value to update the existing caveat with.
193+
*
194+
* For each caveat, depending on the mutator result, this method will:
195+
* - Do nothing ({@link CaveatMutatorOperation.Noop})
196+
* - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
197+
* - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
198+
* - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
199+
*
200+
* This method throws if the validation of any caveat or permission fails.
201+
*
202+
* @param targetCaveatType - The type of the caveats to update.
203+
* @param mutator - The mutator function which will be applied to all caveat
204+
* values.
205+
*/
206+
export type PermissionControllerUpdatePermissionsByCaveatAction = {
207+
type: `PermissionController:updatePermissionsByCaveat`;
208+
handler: PermissionController['updatePermissionsByCaveat'];
209+
};
210+
155211
/**
156212
* Grants _approved_ permissions to the specified subject. Every permission and
157213
* caveat is stringently validated—including by calling their specification
@@ -266,6 +322,28 @@ export type PermissionControllerRequestPermissionsIncrementalAction = {
266322
handler: PermissionController['requestPermissionsIncremental'];
267323
};
268324

325+
/**
326+
* Accepts a permissions request created by
327+
* {@link PermissionController.requestPermissions}.
328+
*
329+
* @param request - The permissions request.
330+
*/
331+
export type PermissionControllerAcceptPermissionsRequestAction = {
332+
type: `PermissionController:acceptPermissionsRequest`;
333+
handler: PermissionController['acceptPermissionsRequest'];
334+
};
335+
336+
/**
337+
* Rejects a permissions request created by
338+
* {@link PermissionController.requestPermissions}.
339+
*
340+
* @param id - The id of the request to be rejected.
341+
*/
342+
export type PermissionControllerRejectPermissionsRequestAction = {
343+
type: `PermissionController:rejectPermissionsRequest`;
344+
handler: PermissionController['rejectPermissionsRequest'];
345+
};
346+
269347
/**
270348
* Gets the subject's endowments per the specified endowment permission.
271349
* Throws if the subject does not have the required permission or if the
@@ -320,17 +398,22 @@ export type PermissionControllerMethodActions =
320398
| PermissionControllerHasUnrestrictedMethodAction
321399
| PermissionControllerClearStateAction
322400
| PermissionControllerGetSubjectNamesAction
401+
| PermissionControllerGetPermissionAction
323402
| PermissionControllerGetPermissionsAction
324403
| PermissionControllerHasPermissionAction
325404
| PermissionControllerHasPermissionsAction
326405
| PermissionControllerRevokeAllPermissionsAction
406+
| PermissionControllerRevokePermissionAction
327407
| PermissionControllerRevokePermissionsAction
328408
| PermissionControllerRevokePermissionForAllSubjectsAction
329409
| PermissionControllerGetCaveatAction
330410
| PermissionControllerUpdateCaveatAction
411+
| PermissionControllerUpdatePermissionsByCaveatAction
331412
| PermissionControllerGrantPermissionsAction
332413
| PermissionControllerGrantPermissionsIncrementalAction
333414
| PermissionControllerRequestPermissionsAction
334415
| PermissionControllerRequestPermissionsIncrementalAction
416+
| PermissionControllerAcceptPermissionsRequestAction
417+
| PermissionControllerRejectPermissionsRequestAction
335418
| PermissionControllerGetEndowmentsAction
336419
| PermissionControllerExecuteRestrictedMethodAction;

packages/permission-controller/src/PermissionController.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ const MESSENGER_EXPOSED_METHODS = [
191191
'revokePermissions',
192192
'updateCaveat',
193193
'getCaveat',
194+
'acceptPermissionsRequest',
195+
'rejectPermissionsRequest',
196+
'revokePermission',
197+
'updatePermissionsByCaveat',
198+
'getPermission',
194199
] as const;
195200

196201
/**

packages/permission-controller/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export type {
2121
PermissionControllerRevokePermissionForAllSubjectsAction,
2222
PermissionControllerRevokePermissionsAction,
2323
PermissionControllerUpdateCaveatAction,
24+
PermissionControllerGetPermissionAction,
25+
PermissionControllerRevokePermissionAction,
26+
PermissionControllerUpdatePermissionsByCaveatAction,
27+
PermissionControllerAcceptPermissionsRequestAction,
28+
PermissionControllerRejectPermissionsRequestAction,
2429
} from './PermissionController-method-action-types';
2530
export {
2631
createPermissionMiddleware,

0 commit comments

Comments
 (0)