PermissionController Actions
25 actions registered.
PermissionController:acceptPermissionsRequest
Package: @metamask/permission-controller
Accepts a permissions request created by
PermissionController.requestPermissions.
Parameters:
| Name | Description |
|---|---|
request | The permissions request. |
Handler signature:
(request: PermissionsRequest) => Promise<void>
PermissionController:clearState
Package: @metamask/permission-controller
Clears the state of the controller.
Handler signature:
() => void
PermissionController:executeRestrictedMethod
Package: @metamask/permission-controller
Executes a restricted method as the subject with the given origin. The specified params, if any, will be passed to the method implementation.
ATTN: Great caution should be exercised in the use of this method. Methods that cause side effects or affect application state should be avoided.
This method will first attempt to retrieve the requested restricted method implementation, throwing if it does not exist. The method will then be invoked as though the subject with the specified origin had invoked it with the specified parameters. This means that any existing caveats will be applied to the restricted method, and this method will throw if the restricted method or its caveat decorators throw.
In addition, this method will throw if the subject does not have a permission for the specified restricted method.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject to execute the method on behalf of. |
targetName | The name of the method to execute. This must be a valid permission target name. |
params | The parameters to pass to the method implementation. |
Returns: The result of the executed method.
Handler signature:
(origin: OriginString, targetName: ExtractRestrictedMethodPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], params?: RestrictedMethodParameters) => Promise<Json>
PermissionController:getCaveat
Package: @metamask/permission-controller
Gets the caveat of the specified type, if any, for the permission of the subject corresponding to the given origin.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject. |
target | The target name of the permission. |
caveatType | The type of the caveat to get. |
Returns: The caveat, or undefined if the permission is not granted or the caveat does not exist on the permission.
Handler signature:
(origin: OriginString, target: TargetName, caveatType: CaveatType) => ExtractCaveat<ControllerCaveatSpecification, CaveatType> | undefined
PermissionController:getEndowmentsGlobals
Package: @metamask/permission-controller
Gets the JavaScript globals tied to the endowment permissions for a subject.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject whose globals to retrieve. |
Returns: The names of the globals, if any.
Handler signature:
(origin: string) => string[]
PermissionController:getEndowmentsRpcMethods
Package: @metamask/permission-controller
Gets the RPC methods tied to the endowment permissions for a subject.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject whose RPC methods to retrieve. |
Returns: The RPC method names, if any.
Handler signature:
(origin: string) => string[]
PermissionController:getPermission
Package: @metamask/permission-controller
Gets the permission for the specified target of the subject corresponding to the specified origin.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject. |
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.
Handler signature:
(origin: OriginString, targetName: SubjectPermission['parentCapability']) => SubjectPermission | undefined
PermissionController:getPermissions
Package: @metamask/permission-controller
Gets all permissions for the specified subject, if any.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject. |
Returns: The permissions of the subject, if any.
Handler signature:
(origin: OriginString) => SubjectPermissions<ValidPermission<string, ExtractCaveats<ControllerCaveatSpecification>>> | undefined
PermissionController:getState
Package: @metamask/permission-controller
Gets the state of the PermissionController.
Handler signature:
() => PermissionControllerState<PermissionConstraint>
PermissionController:getSubjectNames
Package: @metamask/permission-controller
Gets a list of all origins of subjects.
Returns: The origins (i.e. IDs) of all subjects.
Handler signature:
() => OriginString[]
PermissionController:grantPermissions
Package: @metamask/permission-controller
Grants approved permissions to the specified subject. Every permission and caveat is stringently validated—including by calling their specification validators—and an error is thrown if validation fails.
ATTN: This method does not prompt the user for approval. User consent must first be obtained through some other means.
Parameters:
| Name | Description |
|---|---|
options | Options bag. |
options.approvedPermissions | The requested permissions approved by the user. |
options.requestData | Permission request data. Passed to permission factory functions. |
options.preserveExistingPermissions | Whether to preserve the subject's existing permissions. |
options.subject | The subject to grant permissions to. |
Returns: The subject's new permission state. It may or may not have changed.
Handler signature:
({ approvedPermissions, requestData, preserveExistingPermissions, subject, }: {
approvedPermissions: RequestedPermissions;
subject: PermissionSubjectMetadata;
preserveExistingPermissions?: boolean;
requestData?: Record<string, unknown>;
}) => Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>
PermissionController:grantPermissionsIncremental
Package: @metamask/permission-controller
Incrementally grants approved permissions to the specified subject. Every permission and caveat is stringently validated—including by calling their specification validators—and an error is thrown if validation fails.
ATTN: This method does not prompt the user for approval. User consent must first be obtained through some other means.
Parameters:
| Name | Description |
|---|---|
options | Options bag. |
options.approvedPermissions | The requested permissions approved by the user. |
options.requestData | Permission request data. Passed to permission factory functions. |
options.subject | The subject to grant permissions to. |
Returns: The subject's new permission state. It may or may not have changed.
Handler signature:
({ approvedPermissions, requestData, subject, }: {
approvedPermissions: RequestedPermissions;
subject: PermissionSubjectMetadata;
requestData?: Record<string, unknown>;
}) => Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>
PermissionController:hasPermission
Package: @metamask/permission-controller
Checks whether the subject with the specified origin has the specified permission.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject. |
target | The target name of the permission. |
Returns: Whether the subject has the permission.
Handler signature:
(origin: OriginString, target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']) => boolean
PermissionController:hasPermissions
Package: @metamask/permission-controller
Checks whether the subject with the specified origin has any permissions. Use this if you want to know if a subject "exists".
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject to check. |
Returns: Whether the subject has any permissions.
Handler signature:
(origin: OriginString) => boolean
PermissionController:hasUnrestrictedMethod
Package: @metamask/permission-controller
Checks whether the given method was declared as unrestricted at
construction time. Methods unknown to the controller return false and
would be treated as restricted by callers such as the permission
middleware.
Parameters:
| Name | Description |
|---|---|
method | The name of the method to check. |
Returns: Whether the method is unrestricted.
Handler signature:
(method: string) => boolean
PermissionController:isEndowmentRpcMethod
Package: @metamask/permission-controller
Checks whether an RPC method is tied to an endowment.
Parameters:
| Name | Description |
|---|---|
method | The name of the RPC method. |
Returns: True if the RPC method is tied to an endowment, otherwise false.
Handler signature:
(method: string) => boolean
PermissionController:rejectPermissionsRequest
Package: @metamask/permission-controller
Rejects a permissions request created by
PermissionController.requestPermissions.
Parameters:
| Name | Description |
|---|---|
id | The id of the request to be rejected. |
Handler signature:
(id: string) => Promise<void>
PermissionController:requestPermissions
Package: @metamask/permission-controller
Initiates a permission request that requires user approval.
Either this or PermissionController.requestPermissionsIncremental
should always be used to grant additional permissions to a subject,
unless user approval has been obtained through some other means.
Permissions are validated at every step of the approval process, and this method will reject if validation fails.
Parameters:
| Name | Description |
|---|---|
subject | The grantee subject. |
requestedPermissions | The requested permissions. |
options | Additional options. |
options.id | The id of the permissions request. Defaults to a unique id. |
options.preserveExistingPermissions | Whether to preserve the subject's existing permissions. Defaults to true. |
options.metadata | Additional metadata about the permission request. |
Returns: The granted permissions and request metadata.
Handler signature:
(subject: PermissionSubjectMetadata, requestedPermissions: RequestedPermissions, options?: {
id?: string;
preserveExistingPermissions?: boolean;
metadata?: Record<string, Json>;
}) => Promise<[
Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>,
ApprovedPermissionsMetadata
]>
PermissionController:requestPermissionsIncremental
Package: @metamask/permission-controller
Initiates an incremental permission request that prompts for user approval. Incremental permission requests allow the caller to replace existing and/or add brand new permissions and caveats for the specified subject.
Incremental permission request are merged with the subject's existing permissions through a right-biased union, where the incremental permission are the right-hand side of the merger. If both sides of the merger specify the same caveats for a given permission, the caveats are merged using their specification's caveat value merger property.
Either this or PermissionController.requestPermissions should
always be used to grant additional permissions to a subject, unless user
approval has been obtained through some other means.
Permissions are validated at every step of the approval process, and this method will reject if validation fails.
Parameters:
| Name | Description |
|---|---|
subject | The grantee subject. |
requestedPermissions | The requested permissions. |
options | Additional options. |
options.id | The id of the permissions request. Defaults to a unique id. |
options.metadata | Additional metadata about the permission request. |
Returns: The granted permissions and request metadata.
Handler signature:
(subject: PermissionSubjectMetadata, requestedPermissions: RequestedPermissions, options?: {
id?: string;
metadata?: Record<string, Json>;
}) => Promise<[
Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>,
ApprovedPermissionsMetadata
] | []>
PermissionController:revokeAllPermissions
Package: @metamask/permission-controller
Revokes all permissions from the specified origin.
Throws an error if the origin has no permissions.
Parameters:
| Name | Description |
|---|---|
origin | The origin whose permissions to revoke. |
Handler signature:
(origin: OriginString) => void
PermissionController:revokePermission
Package: @metamask/permission-controller
Revokes the specified permission from the subject with the specified origin.
Throws an error if the subject or the permission does not exist.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject whose permission to revoke. |
target | The target name of the permission to revoke. |
Handler signature:
(origin: OriginString, target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']) => void
PermissionController:revokePermissionForAllSubjects
Package: @metamask/permission-controller
Revokes all permissions corresponding to the specified target for all subjects. Does nothing if no subjects or no such permission exists.
Parameters:
| Name | Description |
|---|---|
target | The name of the target to revoke all permissions for. |
Handler signature:
(target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']) => void
PermissionController:revokePermissions
Package: @metamask/permission-controller
Revokes the specified permissions from the specified subjects.
Throws an error if any of the subjects or permissions do not exist.
Parameters:
| Name | Description |
|---|---|
subjectsAndPermissions | An object mapping subject origins to arrays of permission target names to revoke. |
Handler signature:
(subjectsAndPermissions: Record<OriginString, NonEmptyArray<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']>>) => void
PermissionController:updateCaveat
Package: @metamask/permission-controller
Updates the value of the caveat of the specified type belonging to the permission corresponding to the given subject origin and permission target.
For adding new caveats, use
PermissionController.addCaveat.
Throws an error if no such permission or caveat exists.
Parameters:
| Name | Description |
|---|---|
origin | The origin of the subject. |
target | The target name of the permission. |
caveatType | The type of the caveat to update. |
caveatValue | The new value of the caveat. |
Handler signature:
(origin: OriginString, target: TargetName, caveatType: CaveatType, caveatValue: CaveatValue) => void
PermissionController:updatePermissionsByCaveat
Package: @metamask/permission-controller
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 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 (
CaveatMutatorOperation.Noop) - Update the value of the caveat (
CaveatMutatorOperation.UpdateValue). The caveat specification validator, if any, will be called after updating the value. - Delete the caveat (
CaveatMutatorOperation.DeleteCaveat). The permission specification validator, if any, will be called after deleting the caveat. - Revoke the parent permission (
CaveatMutatorOperation.RevokePermission)
This method throws if the validation of any caveat or permission fails.
Parameters:
| Name | Description |
|---|---|
targetCaveatType | The type of the caveats to update. |
mutator | The mutator function which will be applied to all caveat values. |
Handler signature:
(targetCaveatType: CaveatType, mutator: CaveatMutator<TargetCaveat>) => void