Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/permission-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Expose missing public `PermissionController` methods through its messenger ([#8675](https://github.com/MetaMask/core/pull/8675))
- The following actions are now available:
- `PermissionController:acceptPermissionsRequest`,
- `PermissionController:rejectPermissionsRequest`,
- `PermissionController:revokePermission`,
- `PermissionController:updatePermissionsByCaveat`,
- `PermissionController:getPermission`
- Corresponding action types are available as well.

## [13.0.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ export type PermissionControllerGetSubjectNamesAction = {
handler: PermissionController['getSubjectNames'];
};

/**
* Gets the permission for the specified target of the subject corresponding
* to the specified origin.
*
* @param origin - The origin of the subject.
* @param targetName - The method name as invoked by a third party (i.e., not
* a method key).
* @returns The permission if it exists, or undefined otherwise.
*/
export type PermissionControllerGetPermissionAction = {
type: `PermissionController:getPermission`;
handler: PermissionController['getPermission'];
};

/**
* Gets all permissions for the specified subject, if any.
*
Expand Down Expand Up @@ -85,6 +99,20 @@ export type PermissionControllerRevokeAllPermissionsAction = {
handler: PermissionController['revokeAllPermissions'];
};

/**
* Revokes the specified permission from the subject with the specified
* origin.
*
* Throws an error if the subject or the permission does not exist.
*
* @param origin - The origin of the subject whose permission to revoke.
* @param target - The target name of the permission to revoke.
*/
export type PermissionControllerRevokePermissionAction = {
type: `PermissionController:revokePermission`;
handler: PermissionController['revokePermission'];
};

/**
* Revokes the specified permissions from the specified subjects.
*
Expand Down Expand Up @@ -152,6 +180,34 @@ export type PermissionControllerUpdateCaveatAction = {
handler: PermissionController['updateCaveat'];
};

/**
* Updates all caveats with the specified type for all subjects and
* permissions by applying the specified mutator function to them.
*
* ATTN: Permissions can be revoked entirely by the action of this method,
* read on for details.
*
* Caveat mutators are functions that receive a caveat value and return a
* tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new
* value to update the existing caveat with.
*
* For each caveat, depending on the mutator result, this method will:
* - Do nothing ({@link CaveatMutatorOperation.Noop})
* - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
* - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
* - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
*
* This method throws if the validation of any caveat or permission fails.
*
* @param targetCaveatType - The type of the caveats to update.
* @param mutator - The mutator function which will be applied to all caveat
* values.
*/
export type PermissionControllerUpdatePermissionsByCaveatAction = {
type: `PermissionController:updatePermissionsByCaveat`;
handler: PermissionController['updatePermissionsByCaveat'];
};

/**
* Grants _approved_ permissions to the specified subject. Every permission and
* caveat is stringently validated—including by calling their specification
Expand Down Expand Up @@ -266,6 +322,28 @@ export type PermissionControllerRequestPermissionsIncrementalAction = {
handler: PermissionController['requestPermissionsIncremental'];
};

/**
* Accepts a permissions request created by
* {@link PermissionController.requestPermissions}.
*
* @param request - The permissions request.
*/
export type PermissionControllerAcceptPermissionsRequestAction = {
type: `PermissionController:acceptPermissionsRequest`;
handler: PermissionController['acceptPermissionsRequest'];
};

/**
* Rejects a permissions request created by
* {@link PermissionController.requestPermissions}.
*
* @param id - The id of the request to be rejected.
*/
export type PermissionControllerRejectPermissionsRequestAction = {
type: `PermissionController:rejectPermissionsRequest`;
handler: PermissionController['rejectPermissionsRequest'];
};

/**
* Gets the subject's endowments per the specified endowment permission.
* Throws if the subject does not have the required permission or if the
Expand Down Expand Up @@ -320,17 +398,22 @@ export type PermissionControllerMethodActions =
| PermissionControllerHasUnrestrictedMethodAction
| PermissionControllerClearStateAction
| PermissionControllerGetSubjectNamesAction
| PermissionControllerGetPermissionAction
| PermissionControllerGetPermissionsAction
| PermissionControllerHasPermissionAction
| PermissionControllerHasPermissionsAction
| PermissionControllerRevokeAllPermissionsAction
| PermissionControllerRevokePermissionAction
| PermissionControllerRevokePermissionsAction
| PermissionControllerRevokePermissionForAllSubjectsAction
| PermissionControllerGetCaveatAction
| PermissionControllerUpdateCaveatAction
| PermissionControllerUpdatePermissionsByCaveatAction
| PermissionControllerGrantPermissionsAction
| PermissionControllerGrantPermissionsIncrementalAction
| PermissionControllerRequestPermissionsAction
| PermissionControllerRequestPermissionsIncrementalAction
| PermissionControllerAcceptPermissionsRequestAction
| PermissionControllerRejectPermissionsRequestAction
| PermissionControllerGetEndowmentsAction
| PermissionControllerExecuteRestrictedMethodAction;
5 changes: 5 additions & 0 deletions packages/permission-controller/src/PermissionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ const MESSENGER_EXPOSED_METHODS = [
'revokePermissions',
'updateCaveat',
'getCaveat',
'acceptPermissionsRequest',
'rejectPermissionsRequest',
'revokePermission',
'updatePermissionsByCaveat',
'getPermission',
] as const;

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/permission-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export type {
PermissionControllerRevokePermissionForAllSubjectsAction,
PermissionControllerRevokePermissionsAction,
PermissionControllerUpdateCaveatAction,
PermissionControllerGetPermissionAction,
PermissionControllerRevokePermissionAction,
PermissionControllerUpdatePermissionsByCaveatAction,
PermissionControllerAcceptPermissionsRequestAction,
PermissionControllerRejectPermissionsRequestAction,
} from './PermissionController-method-action-types';
export {
createPermissionMiddleware,
Expand Down
Loading