@metamask/permission-controller 12.3.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -6
- package/dist/Permission.cjs.map +1 -1
- package/dist/Permission.d.cts +9 -15
- package/dist/Permission.d.cts.map +1 -1
- package/dist/Permission.d.mts +9 -15
- package/dist/Permission.d.mts.map +1 -1
- package/dist/Permission.mjs.map +1 -1
- package/dist/PermissionController-method-action-types.cjs.map +1 -1
- package/dist/PermissionController-method-action-types.d.cts +44 -2
- package/dist/PermissionController-method-action-types.d.cts.map +1 -1
- package/dist/PermissionController-method-action-types.d.mts +44 -2
- package/dist/PermissionController-method-action-types.d.mts.map +1 -1
- package/dist/PermissionController-method-action-types.mjs.map +1 -1
- package/dist/PermissionController.cjs +23 -26
- package/dist/PermissionController.cjs.map +1 -1
- package/dist/PermissionController.d.cts +9 -22
- package/dist/PermissionController.d.cts.map +1 -1
- package/dist/PermissionController.d.mts +9 -22
- package/dist/PermissionController.d.mts.map +1 -1
- package/dist/PermissionController.mjs +23 -26
- package/dist/PermissionController.mjs.map +1 -1
- package/dist/createRestrictedMethodMessenger.cjs +20 -0
- package/dist/createRestrictedMethodMessenger.cjs.map +1 -0
- package/dist/createRestrictedMethodMessenger.d.cts +42 -0
- package/dist/createRestrictedMethodMessenger.d.cts.map +1 -0
- package/dist/createRestrictedMethodMessenger.d.mts +42 -0
- package/dist/createRestrictedMethodMessenger.d.mts.map +1 -0
- package/dist/createRestrictedMethodMessenger.mjs +16 -0
- package/dist/createRestrictedMethodMessenger.mjs.map +1 -0
- package/dist/index.cjs +6 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/permission-middleware.cjs +47 -43
- package/dist/permission-middleware.cjs.map +1 -1
- package/dist/permission-middleware.d.cts +40 -25
- package/dist/permission-middleware.d.cts.map +1 -1
- package/dist/permission-middleware.d.mts +40 -25
- package/dist/permission-middleware.d.mts.map +1 -1
- package/dist/permission-middleware.mjs +44 -41
- package/dist/permission-middleware.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +0 -23
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +0 -23
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +20 -19
- package/dist/rpc-methods/getPermissions.cjs +0 -27
- package/dist/rpc-methods/getPermissions.cjs.map +0 -1
- package/dist/rpc-methods/getPermissions.d.cts +0 -9
- package/dist/rpc-methods/getPermissions.d.cts.map +0 -1
- package/dist/rpc-methods/getPermissions.d.mts +0 -9
- package/dist/rpc-methods/getPermissions.d.mts.map +0 -1
- package/dist/rpc-methods/getPermissions.mjs +0 -24
- package/dist/rpc-methods/getPermissions.mjs.map +0 -1
- package/dist/rpc-methods/index.cjs +0 -12
- package/dist/rpc-methods/index.cjs.map +0 -1
- package/dist/rpc-methods/index.d.cts +0 -6
- package/dist/rpc-methods/index.d.cts.map +0 -1
- package/dist/rpc-methods/index.d.mts +0 -6
- package/dist/rpc-methods/index.d.mts.map +0 -1
- package/dist/rpc-methods/index.mjs +0 -9
- package/dist/rpc-methods/index.mjs.map +0 -1
- package/dist/rpc-methods/requestPermissions.cjs +0 -36
- package/dist/rpc-methods/requestPermissions.cjs.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.cts +0 -17
- package/dist/rpc-methods/requestPermissions.d.cts.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.mts +0 -17
- package/dist/rpc-methods/requestPermissions.d.mts.map +0 -1
- package/dist/rpc-methods/requestPermissions.mjs +0 -33
- package/dist/rpc-methods/requestPermissions.mjs.map +0 -1
- package/dist/rpc-methods/revokePermissions.cjs +0 -41
- package/dist/rpc-methods/revokePermissions.cjs.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.cts +0 -11
- package/dist/rpc-methods/revokePermissions.d.cts.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.mts +0 -11
- package/dist/rpc-methods/revokePermissions.d.mts.map +0 -1
- package/dist/rpc-methods/revokePermissions.mjs +0 -38
- package/dist/rpc-methods/revokePermissions.mjs.map +0 -1
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
5
|
import type { PermissionController } from "./PermissionController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether the given method was declared as unrestricted at
|
|
8
|
+
* construction time. Methods unknown to the controller return `false` and
|
|
9
|
+
* would be treated as restricted by callers such as the permission
|
|
10
|
+
* middleware.
|
|
11
|
+
*
|
|
12
|
+
* @param method - The name of the method to check.
|
|
13
|
+
* @returns Whether the method is unrestricted.
|
|
14
|
+
*/
|
|
15
|
+
export type PermissionControllerHasUnrestrictedMethodAction = {
|
|
16
|
+
type: `PermissionController:hasUnrestrictedMethod`;
|
|
17
|
+
handler: PermissionController['hasUnrestrictedMethod'];
|
|
18
|
+
};
|
|
6
19
|
/**
|
|
7
20
|
* Clears the state of the controller.
|
|
8
21
|
*/
|
|
@@ -55,7 +68,7 @@ export type PermissionControllerHasPermissionsAction = {
|
|
|
55
68
|
/**
|
|
56
69
|
* Revokes all permissions from the specified origin.
|
|
57
70
|
*
|
|
58
|
-
* Throws an error
|
|
71
|
+
* Throws an error if the origin has no permissions.
|
|
59
72
|
*
|
|
60
73
|
* @param origin - The origin whose permissions to revoke.
|
|
61
74
|
*/
|
|
@@ -252,8 +265,37 @@ export type PermissionControllerGetEndowmentsAction = {
|
|
|
252
265
|
type: `PermissionController:getEndowments`;
|
|
253
266
|
handler: PermissionController['getEndowments'];
|
|
254
267
|
};
|
|
268
|
+
/**
|
|
269
|
+
* Executes a restricted method as the subject with the given origin.
|
|
270
|
+
* The specified params, if any, will be passed to the method implementation.
|
|
271
|
+
*
|
|
272
|
+
* ATTN: Great caution should be exercised in the use of this method.
|
|
273
|
+
* Methods that cause side effects or affect application state should
|
|
274
|
+
* be avoided.
|
|
275
|
+
*
|
|
276
|
+
* This method will first attempt to retrieve the requested restricted method
|
|
277
|
+
* implementation, throwing if it does not exist. The method will then be
|
|
278
|
+
* invoked as though the subject with the specified origin had invoked it with
|
|
279
|
+
* the specified parameters. This means that any existing caveats will be
|
|
280
|
+
* applied to the restricted method, and this method will throw if the
|
|
281
|
+
* restricted method or its caveat decorators throw.
|
|
282
|
+
*
|
|
283
|
+
* In addition, this method will throw if the subject does not have a
|
|
284
|
+
* permission for the specified restricted method.
|
|
285
|
+
*
|
|
286
|
+
* @param origin - The origin of the subject to execute the method on behalf
|
|
287
|
+
* of.
|
|
288
|
+
* @param targetName - The name of the method to execute. This must be a valid
|
|
289
|
+
* permission target name.
|
|
290
|
+
* @param params - The parameters to pass to the method implementation.
|
|
291
|
+
* @returns The result of the executed method.
|
|
292
|
+
*/
|
|
293
|
+
export type PermissionControllerExecuteRestrictedMethodAction = {
|
|
294
|
+
type: `PermissionController:executeRestrictedMethod`;
|
|
295
|
+
handler: PermissionController['executeRestrictedMethod'];
|
|
296
|
+
};
|
|
255
297
|
/**
|
|
256
298
|
* Union of all PermissionController action types.
|
|
257
299
|
*/
|
|
258
|
-
export type PermissionControllerMethodActions = PermissionControllerClearStateAction | PermissionControllerGetSubjectNamesAction | PermissionControllerGetPermissionsAction | PermissionControllerHasPermissionAction | PermissionControllerHasPermissionsAction | PermissionControllerRevokeAllPermissionsAction | PermissionControllerRevokePermissionsAction | PermissionControllerRevokePermissionForAllSubjectsAction | PermissionControllerGetCaveatAction | PermissionControllerUpdateCaveatAction | PermissionControllerGrantPermissionsAction | PermissionControllerGrantPermissionsIncrementalAction | PermissionControllerRequestPermissionsAction | PermissionControllerRequestPermissionsIncrementalAction | PermissionControllerGetEndowmentsAction;
|
|
300
|
+
export type PermissionControllerMethodActions = PermissionControllerHasUnrestrictedMethodAction | PermissionControllerClearStateAction | PermissionControllerGetSubjectNamesAction | PermissionControllerGetPermissionsAction | PermissionControllerHasPermissionAction | PermissionControllerHasPermissionsAction | PermissionControllerRevokeAllPermissionsAction | PermissionControllerRevokePermissionsAction | PermissionControllerRevokePermissionForAllSubjectsAction | PermissionControllerGetCaveatAction | PermissionControllerUpdateCaveatAction | PermissionControllerGrantPermissionsAction | PermissionControllerGrantPermissionsIncrementalAction | PermissionControllerRequestPermissionsAction | PermissionControllerRequestPermissionsIncrementalAction | PermissionControllerGetEndowmentsAction | PermissionControllerExecuteRestrictedMethodAction;
|
|
259
301
|
//# sourceMappingURL=PermissionController-method-action-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionController-method-action-types.d.mts","sourceRoot":"","sources":["../src/PermissionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CAClD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAA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A4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,oBAAoB,CAAC,oBAAoB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,oBAAoB,CAAC,+BAA+B,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAChD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,oCAAoC,GACpC,yCAAyC,GACzC,wCAAwC,GACxC,uCAAuC,GACvC,wCAAwC,GACxC,8CAA8C,GAC9C,2CAA2C,GAC3C,wDAAwD,GACxD,mCAAmC,GACnC,sCAAsC,GACtC,0CAA0C,GAC1C,qDAAqD,GACrD,4CAA4C,GAC5C,uDAAuD,GACvD,uCAAuC,CAAC"}
|
|
1
|
+
{"version":3,"file":"PermissionController-method-action-types.d.mts","sourceRoot":"","sources":["../src/PermissionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;CACxD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CA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CAAsC,GACtC,0CAA0C,GAC1C,qDAAqD,GACrD,4CAA4C,GAC5C,uDAAuD,GACvD,uCAAuC,GACvC,iDAAiD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionController-method-action-types.mjs","sourceRoot":"","sources":["../src/PermissionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { PermissionController } from './PermissionController';\n\n/**\n * Clears the state of the controller.\n */\nexport type PermissionControllerClearStateAction = {\n type: `PermissionController:clearState`;\n handler: PermissionController['clearState'];\n};\n\n/**\n * Gets a list of all origins of subjects.\n *\n * @returns The origins (i.e. IDs) of all subjects.\n */\nexport type PermissionControllerGetSubjectNamesAction = {\n type: `PermissionController:getSubjectNames`;\n handler: PermissionController['getSubjectNames'];\n};\n\n/**\n * Gets all permissions for the specified subject, if any.\n *\n * @param origin - The origin of the subject.\n * @returns The permissions of the subject, if any.\n */\nexport type PermissionControllerGetPermissionsAction = {\n type: `PermissionController:getPermissions`;\n handler: PermissionController['getPermissions'];\n};\n\n/**\n * Checks whether the subject with the specified origin has the specified\n * permission.\n *\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @returns Whether the subject has the permission.\n */\nexport type PermissionControllerHasPermissionAction = {\n type: `PermissionController:hasPermission`;\n handler: PermissionController['hasPermission'];\n};\n\n/**\n * Checks whether the subject with the specified origin has any permissions.\n * Use this if you want to know if a subject \"exists\".\n *\n * @param origin - The origin of the subject to check.\n * @returns Whether the subject has any permissions.\n */\nexport type PermissionControllerHasPermissionsAction = {\n type: `PermissionController:hasPermissions`;\n handler: PermissionController['hasPermissions'];\n};\n\n/**\n * Revokes all permissions from the specified origin.\n *\n * Throws an error of the origin has no permissions.\n *\n * @param origin - The origin whose permissions to revoke.\n */\nexport type PermissionControllerRevokeAllPermissionsAction = {\n type: `PermissionController:revokeAllPermissions`;\n handler: PermissionController['revokeAllPermissions'];\n};\n\n/**\n * Revokes the specified permissions from the specified subjects.\n *\n * Throws an error if any of the subjects or permissions do not exist.\n *\n * @param subjectsAndPermissions - An object mapping subject origins\n * to arrays of permission target names to revoke.\n */\nexport type PermissionControllerRevokePermissionsAction = {\n type: `PermissionController:revokePermissions`;\n handler: PermissionController['revokePermissions'];\n};\n\n/**\n * Revokes all permissions corresponding to the specified target for all subjects.\n * Does nothing if no subjects or no such permission exists.\n *\n * @param target - The name of the target to revoke all permissions for.\n */\nexport type PermissionControllerRevokePermissionForAllSubjectsAction = {\n type: `PermissionController:revokePermissionForAllSubjects`;\n handler: PermissionController['revokePermissionForAllSubjects'];\n};\n\n/**\n * Gets the caveat of the specified type, if any, for the permission of\n * the subject corresponding to the given origin.\n *\n * Throws an error if the subject does not have a permission with the\n * specified target name.\n *\n * @template TargetName - The permission target name. Should be inferred.\n * @template CaveatType - The valid caveat types for the permission. Should\n * be inferred.\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @param caveatType - The type of the caveat to get.\n * @returns The caveat, or `undefined` if no such caveat exists.\n */\nexport type PermissionControllerGetCaveatAction = {\n type: `PermissionController:getCaveat`;\n handler: PermissionController['getCaveat'];\n};\n\n/**\n * Updates the value of the caveat of the specified type belonging to the\n * permission corresponding to the given subject origin and permission\n * target.\n *\n * For adding new caveats, use\n * {@link PermissionController.addCaveat}.\n *\n * Throws an error if no such permission or caveat exists.\n *\n * @template TargetName - The permission target name. Should be inferred.\n * @template CaveatType - The valid caveat types for the permission. Should\n * be inferred.\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @param caveatType - The type of the caveat to update.\n * @param caveatValue - The new value of the caveat.\n */\nexport type PermissionControllerUpdateCaveatAction = {\n type: `PermissionController:updateCaveat`;\n handler: PermissionController['updateCaveat'];\n};\n\n/**\n * Grants _approved_ permissions to the specified subject. Every permission and\n * caveat is stringently validated—including by calling their specification\n * validators—and an error is thrown if validation fails.\n *\n * ATTN: This method does **not** prompt the user for approval. User consent must\n * first be obtained through some other means.\n *\n * @see {@link PermissionController.requestPermissions} For initiating a\n * permissions request requiring user approval.\n * @param options - Options bag.\n * @param options.approvedPermissions - The requested permissions approved by\n * the user.\n * @param options.requestData - Permission request data. Passed to permission\n * factory functions.\n * @param options.preserveExistingPermissions - Whether to preserve the\n * subject's existing permissions.\n * @param options.subject - The subject to grant permissions to.\n * @returns The subject's new permission state. It may or may not have changed.\n */\nexport type PermissionControllerGrantPermissionsAction = {\n type: `PermissionController:grantPermissions`;\n handler: PermissionController['grantPermissions'];\n};\n\n/**\n * Incrementally grants _approved_ permissions to the specified subject. Every\n * permission and caveat is stringently validated—including by calling their\n * specification validators—and an error is thrown if validation fails.\n *\n * ATTN: This method does **not** prompt the user for approval. User consent must\n * first be obtained through some other means.\n *\n * @see {@link PermissionController.requestPermissionsIncremental} For initiating\n * an incremental permissions request requiring user approval.\n * @param options - Options bag.\n * @param options.approvedPermissions - The requested permissions approved by\n * the user.\n * @param options.requestData - Permission request data. Passed to permission\n * factory functions.\n * @param options.subject - The subject to grant permissions to.\n * @returns The subject's new permission state. It may or may not have changed.\n */\nexport type PermissionControllerGrantPermissionsIncrementalAction = {\n type: `PermissionController:grantPermissionsIncremental`;\n handler: PermissionController['grantPermissionsIncremental'];\n};\n\n/**\n * Initiates a permission request that requires user approval.\n *\n * Either this or {@link PermissionController.requestPermissionsIncremental}\n * should always be used to grant additional permissions to a subject,\n * unless user approval has been obtained through some other means.\n *\n * Permissions are validated at every step of the approval process, and this\n * method will reject if validation fails.\n *\n * @see {@link ApprovalController} For the user approval logic.\n * @see {@link PermissionController.acceptPermissionsRequest} For the method\n * that _accepts_ the request and resolves the user approval promise.\n * @see {@link PermissionController.rejectPermissionsRequest} For the method\n * that _rejects_ the request and the user approval promise.\n * @param subject - The grantee subject.\n * @param requestedPermissions - The requested permissions.\n * @param options - Additional options.\n * @param options.id - The id of the permissions request. Defaults to a unique\n * id.\n * @param options.preserveExistingPermissions - Whether to preserve the\n * subject's existing permissions. Defaults to `true`.\n * @param options.metadata - Additional metadata about the permission request.\n * @returns The granted permissions and request metadata.\n */\nexport type PermissionControllerRequestPermissionsAction = {\n type: `PermissionController:requestPermissions`;\n handler: PermissionController['requestPermissions'];\n};\n\n/**\n * Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or\n * add brand new permissions and caveats for the specified subject.\n *\n * Incremental permission request are merged with the subject's existing permissions\n * through a right-biased union, where the incremental permission are the right-hand\n * side of the merger. If both sides of the merger specify the same caveats for a\n * given permission, the caveats are merged using their specification's caveat value\n * merger property.\n *\n * Either this or {@link PermissionController.requestPermissions} should\n * always be used to grant additional permissions to a subject, unless user\n * approval has been obtained through some other means.\n *\n * Permissions are validated at every step of the approval process, and this\n * method will reject if validation fails.\n *\n * @see {@link ApprovalController} For the user approval logic.\n * @see {@link PermissionController.acceptPermissionsRequest} For the method\n * that _accepts_ the request and resolves the user approval promise.\n * @see {@link PermissionController.rejectPermissionsRequest} For the method\n * that _rejects_ the request and the user approval promise.\n * @param subject - The grantee subject.\n * @param requestedPermissions - The requested permissions.\n * @param options - Additional options.\n * @param options.id - The id of the permissions request. Defaults to a unique\n * id.\n * @param options.metadata - Additional metadata about the permission request.\n * @returns The granted permissions and request metadata.\n */\nexport type PermissionControllerRequestPermissionsIncrementalAction = {\n type: `PermissionController:requestPermissionsIncremental`;\n handler: PermissionController['requestPermissionsIncremental'];\n};\n\n/**\n * Gets the subject's endowments per the specified endowment permission.\n * Throws if the subject does not have the required permission or if the\n * permission is not an endowment permission.\n *\n * @param origin - The origin of the subject whose endowments to retrieve.\n * @param targetName - The name of the endowment permission. This must be a\n * valid permission target name.\n * @param requestData - Additional data associated with the request, if any.\n * Forwarded to the endowment getter function for the permission.\n * @returns The endowments, if any.\n */\nexport type PermissionControllerGetEndowmentsAction = {\n type: `PermissionController:getEndowments`;\n handler: PermissionController['getEndowments'];\n};\n\n/**\n * Union of all PermissionController action types.\n */\nexport type PermissionControllerMethodActions =\n | PermissionControllerClearStateAction\n | PermissionControllerGetSubjectNamesAction\n | PermissionControllerGetPermissionsAction\n | PermissionControllerHasPermissionAction\n | PermissionControllerHasPermissionsAction\n | PermissionControllerRevokeAllPermissionsAction\n | PermissionControllerRevokePermissionsAction\n | PermissionControllerRevokePermissionForAllSubjectsAction\n | PermissionControllerGetCaveatAction\n | PermissionControllerUpdateCaveatAction\n | PermissionControllerGrantPermissionsAction\n | PermissionControllerGrantPermissionsIncrementalAction\n | PermissionControllerRequestPermissionsAction\n | PermissionControllerRequestPermissionsIncrementalAction\n | PermissionControllerGetEndowmentsAction;\n"]}
|
|
1
|
+
{"version":3,"file":"PermissionController-method-action-types.mjs","sourceRoot":"","sources":["../src/PermissionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { PermissionController } from './PermissionController';\n\n/**\n * Checks whether the given method was declared as unrestricted at\n * construction time. Methods unknown to the controller return `false` and\n * would be treated as restricted by callers such as the permission\n * middleware.\n *\n * @param method - The name of the method to check.\n * @returns Whether the method is unrestricted.\n */\nexport type PermissionControllerHasUnrestrictedMethodAction = {\n type: `PermissionController:hasUnrestrictedMethod`;\n handler: PermissionController['hasUnrestrictedMethod'];\n};\n\n/**\n * Clears the state of the controller.\n */\nexport type PermissionControllerClearStateAction = {\n type: `PermissionController:clearState`;\n handler: PermissionController['clearState'];\n};\n\n/**\n * Gets a list of all origins of subjects.\n *\n * @returns The origins (i.e. IDs) of all subjects.\n */\nexport type PermissionControllerGetSubjectNamesAction = {\n type: `PermissionController:getSubjectNames`;\n handler: PermissionController['getSubjectNames'];\n};\n\n/**\n * Gets all permissions for the specified subject, if any.\n *\n * @param origin - The origin of the subject.\n * @returns The permissions of the subject, if any.\n */\nexport type PermissionControllerGetPermissionsAction = {\n type: `PermissionController:getPermissions`;\n handler: PermissionController['getPermissions'];\n};\n\n/**\n * Checks whether the subject with the specified origin has the specified\n * permission.\n *\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @returns Whether the subject has the permission.\n */\nexport type PermissionControllerHasPermissionAction = {\n type: `PermissionController:hasPermission`;\n handler: PermissionController['hasPermission'];\n};\n\n/**\n * Checks whether the subject with the specified origin has any permissions.\n * Use this if you want to know if a subject \"exists\".\n *\n * @param origin - The origin of the subject to check.\n * @returns Whether the subject has any permissions.\n */\nexport type PermissionControllerHasPermissionsAction = {\n type: `PermissionController:hasPermissions`;\n handler: PermissionController['hasPermissions'];\n};\n\n/**\n * Revokes all permissions from the specified origin.\n *\n * Throws an error if the origin has no permissions.\n *\n * @param origin - The origin whose permissions to revoke.\n */\nexport type PermissionControllerRevokeAllPermissionsAction = {\n type: `PermissionController:revokeAllPermissions`;\n handler: PermissionController['revokeAllPermissions'];\n};\n\n/**\n * Revokes the specified permissions from the specified subjects.\n *\n * Throws an error if any of the subjects or permissions do not exist.\n *\n * @param subjectsAndPermissions - An object mapping subject origins\n * to arrays of permission target names to revoke.\n */\nexport type PermissionControllerRevokePermissionsAction = {\n type: `PermissionController:revokePermissions`;\n handler: PermissionController['revokePermissions'];\n};\n\n/**\n * Revokes all permissions corresponding to the specified target for all subjects.\n * Does nothing if no subjects or no such permission exists.\n *\n * @param target - The name of the target to revoke all permissions for.\n */\nexport type PermissionControllerRevokePermissionForAllSubjectsAction = {\n type: `PermissionController:revokePermissionForAllSubjects`;\n handler: PermissionController['revokePermissionForAllSubjects'];\n};\n\n/**\n * Gets the caveat of the specified type, if any, for the permission of\n * the subject corresponding to the given origin.\n *\n * Throws an error if the subject does not have a permission with the\n * specified target name.\n *\n * @template TargetName - The permission target name. Should be inferred.\n * @template CaveatType - The valid caveat types for the permission. Should\n * be inferred.\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @param caveatType - The type of the caveat to get.\n * @returns The caveat, or `undefined` if no such caveat exists.\n */\nexport type PermissionControllerGetCaveatAction = {\n type: `PermissionController:getCaveat`;\n handler: PermissionController['getCaveat'];\n};\n\n/**\n * Updates the value of the caveat of the specified type belonging to the\n * permission corresponding to the given subject origin and permission\n * target.\n *\n * For adding new caveats, use\n * {@link PermissionController.addCaveat}.\n *\n * Throws an error if no such permission or caveat exists.\n *\n * @template TargetName - The permission target name. Should be inferred.\n * @template CaveatType - The valid caveat types for the permission. Should\n * be inferred.\n * @param origin - The origin of the subject.\n * @param target - The target name of the permission.\n * @param caveatType - The type of the caveat to update.\n * @param caveatValue - The new value of the caveat.\n */\nexport type PermissionControllerUpdateCaveatAction = {\n type: `PermissionController:updateCaveat`;\n handler: PermissionController['updateCaveat'];\n};\n\n/**\n * Grants _approved_ permissions to the specified subject. Every permission and\n * caveat is stringently validated—including by calling their specification\n * validators—and an error is thrown if validation fails.\n *\n * ATTN: This method does **not** prompt the user for approval. User consent must\n * first be obtained through some other means.\n *\n * @see {@link PermissionController.requestPermissions} For initiating a\n * permissions request requiring user approval.\n * @param options - Options bag.\n * @param options.approvedPermissions - The requested permissions approved by\n * the user.\n * @param options.requestData - Permission request data. Passed to permission\n * factory functions.\n * @param options.preserveExistingPermissions - Whether to preserve the\n * subject's existing permissions.\n * @param options.subject - The subject to grant permissions to.\n * @returns The subject's new permission state. It may or may not have changed.\n */\nexport type PermissionControllerGrantPermissionsAction = {\n type: `PermissionController:grantPermissions`;\n handler: PermissionController['grantPermissions'];\n};\n\n/**\n * Incrementally grants _approved_ permissions to the specified subject. Every\n * permission and caveat is stringently validated—including by calling their\n * specification validators—and an error is thrown if validation fails.\n *\n * ATTN: This method does **not** prompt the user for approval. User consent must\n * first be obtained through some other means.\n *\n * @see {@link PermissionController.requestPermissionsIncremental} For initiating\n * an incremental permissions request requiring user approval.\n * @param options - Options bag.\n * @param options.approvedPermissions - The requested permissions approved by\n * the user.\n * @param options.requestData - Permission request data. Passed to permission\n * factory functions.\n * @param options.subject - The subject to grant permissions to.\n * @returns The subject's new permission state. It may or may not have changed.\n */\nexport type PermissionControllerGrantPermissionsIncrementalAction = {\n type: `PermissionController:grantPermissionsIncremental`;\n handler: PermissionController['grantPermissionsIncremental'];\n};\n\n/**\n * Initiates a permission request that requires user approval.\n *\n * Either this or {@link PermissionController.requestPermissionsIncremental}\n * should always be used to grant additional permissions to a subject,\n * unless user approval has been obtained through some other means.\n *\n * Permissions are validated at every step of the approval process, and this\n * method will reject if validation fails.\n *\n * @see {@link ApprovalController} For the user approval logic.\n * @see {@link PermissionController.acceptPermissionsRequest} For the method\n * that _accepts_ the request and resolves the user approval promise.\n * @see {@link PermissionController.rejectPermissionsRequest} For the method\n * that _rejects_ the request and the user approval promise.\n * @param subject - The grantee subject.\n * @param requestedPermissions - The requested permissions.\n * @param options - Additional options.\n * @param options.id - The id of the permissions request. Defaults to a unique\n * id.\n * @param options.preserveExistingPermissions - Whether to preserve the\n * subject's existing permissions. Defaults to `true`.\n * @param options.metadata - Additional metadata about the permission request.\n * @returns The granted permissions and request metadata.\n */\nexport type PermissionControllerRequestPermissionsAction = {\n type: `PermissionController:requestPermissions`;\n handler: PermissionController['requestPermissions'];\n};\n\n/**\n * Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or\n * add brand new permissions and caveats for the specified subject.\n *\n * Incremental permission request are merged with the subject's existing permissions\n * through a right-biased union, where the incremental permission are the right-hand\n * side of the merger. If both sides of the merger specify the same caveats for a\n * given permission, the caveats are merged using their specification's caveat value\n * merger property.\n *\n * Either this or {@link PermissionController.requestPermissions} should\n * always be used to grant additional permissions to a subject, unless user\n * approval has been obtained through some other means.\n *\n * Permissions are validated at every step of the approval process, and this\n * method will reject if validation fails.\n *\n * @see {@link ApprovalController} For the user approval logic.\n * @see {@link PermissionController.acceptPermissionsRequest} For the method\n * that _accepts_ the request and resolves the user approval promise.\n * @see {@link PermissionController.rejectPermissionsRequest} For the method\n * that _rejects_ the request and the user approval promise.\n * @param subject - The grantee subject.\n * @param requestedPermissions - The requested permissions.\n * @param options - Additional options.\n * @param options.id - The id of the permissions request. Defaults to a unique\n * id.\n * @param options.metadata - Additional metadata about the permission request.\n * @returns The granted permissions and request metadata.\n */\nexport type PermissionControllerRequestPermissionsIncrementalAction = {\n type: `PermissionController:requestPermissionsIncremental`;\n handler: PermissionController['requestPermissionsIncremental'];\n};\n\n/**\n * Gets the subject's endowments per the specified endowment permission.\n * Throws if the subject does not have the required permission or if the\n * permission is not an endowment permission.\n *\n * @param origin - The origin of the subject whose endowments to retrieve.\n * @param targetName - The name of the endowment permission. This must be a\n * valid permission target name.\n * @param requestData - Additional data associated with the request, if any.\n * Forwarded to the endowment getter function for the permission.\n * @returns The endowments, if any.\n */\nexport type PermissionControllerGetEndowmentsAction = {\n type: `PermissionController:getEndowments`;\n handler: PermissionController['getEndowments'];\n};\n\n/**\n * Executes a restricted method as the subject with the given origin.\n * The specified params, if any, will be passed to the method implementation.\n *\n * ATTN: Great caution should be exercised in the use of this method.\n * Methods that cause side effects or affect application state should\n * be avoided.\n *\n * This method will first attempt to retrieve the requested restricted method\n * implementation, throwing if it does not exist. The method will then be\n * invoked as though the subject with the specified origin had invoked it with\n * the specified parameters. This means that any existing caveats will be\n * applied to the restricted method, and this method will throw if the\n * restricted method or its caveat decorators throw.\n *\n * In addition, this method will throw if the subject does not have a\n * permission for the specified restricted method.\n *\n * @param origin - The origin of the subject to execute the method on behalf\n * of.\n * @param targetName - The name of the method to execute. This must be a valid\n * permission target name.\n * @param params - The parameters to pass to the method implementation.\n * @returns The result of the executed method.\n */\nexport type PermissionControllerExecuteRestrictedMethodAction = {\n type: `PermissionController:executeRestrictedMethod`;\n handler: PermissionController['executeRestrictedMethod'];\n};\n\n/**\n * Union of all PermissionController action types.\n */\nexport type PermissionControllerMethodActions =\n | PermissionControllerHasUnrestrictedMethodAction\n | PermissionControllerClearStateAction\n | PermissionControllerGetSubjectNamesAction\n | PermissionControllerGetPermissionsAction\n | PermissionControllerHasPermissionAction\n | PermissionControllerHasPermissionsAction\n | PermissionControllerRevokeAllPermissionsAction\n | PermissionControllerRevokePermissionsAction\n | PermissionControllerRevokePermissionForAllSubjectsAction\n | PermissionControllerGetCaveatAction\n | PermissionControllerUpdateCaveatAction\n | PermissionControllerGrantPermissionsAction\n | PermissionControllerGrantPermissionsIncrementalAction\n | PermissionControllerRequestPermissionsAction\n | PermissionControllerRequestPermissionsIncrementalAction\n | PermissionControllerGetEndowmentsAction\n | PermissionControllerExecuteRestrictedMethodAction;\n"]}
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _PermissionController_instances, _PermissionController_caveatSpecifications, _PermissionController_permissionSpecifications, _PermissionController_unrestrictedMethods, _PermissionController_getPermissionSpecification, _PermissionController_getCaveatSpecification, _PermissionController_expectGetCaveatMerger, _PermissionController_validatePermissionSpecifications, _PermissionController_getTypedPermissionSpecification, _PermissionController_deletePermission, _PermissionController_setCaveat, _PermissionController_deleteCaveat, _PermissionController_validateModifiedPermission, _PermissionController_targetExists, _PermissionController_applyGrantedPermissions, _PermissionController_validatePermission, _PermissionController_setValidatedPermissions, _PermissionController_constructCaveats, _PermissionController_validateCaveat, _PermissionController_validateRequestedPermissions, _PermissionController_mergeIncrementalPermissions, _PermissionController_mergePermission, _PermissionController_mergeCaveat, _PermissionController_requestUserApproval, _PermissionController_handleApprovedPermissions, _PermissionController_getSideEffects, _PermissionController_executeSideEffects, _PermissionController_validateApprovedPermissions, _PermissionController_hasApprovalRequest, _PermissionController_rejectPermissionsRequest, _PermissionController_executeRestrictedMethod;
|
|
16
|
+
var _PermissionController_instances, _PermissionController_caveatSpecifications, _PermissionController_permissionSpecifications, _PermissionController_unrestrictedMethods, _PermissionController_getPermissionSpecification, _PermissionController_getCaveatSpecification, _PermissionController_expectGetCaveatMerger, _PermissionController_validatePermissionSpecifications, _PermissionController_getTypedPermissionSpecification, _PermissionController_getRestrictedMethod, _PermissionController_deletePermission, _PermissionController_setCaveat, _PermissionController_deleteCaveat, _PermissionController_validateModifiedPermission, _PermissionController_targetExists, _PermissionController_applyGrantedPermissions, _PermissionController_validatePermission, _PermissionController_setValidatedPermissions, _PermissionController_constructCaveats, _PermissionController_validateCaveat, _PermissionController_validateRequestedPermissions, _PermissionController_mergeIncrementalPermissions, _PermissionController_mergePermission, _PermissionController_mergeCaveat, _PermissionController_requestUserApproval, _PermissionController_handleApprovedPermissions, _PermissionController_getSideEffects, _PermissionController_executeSideEffects, _PermissionController_validateApprovedPermissions, _PermissionController_hasApprovalRequest, _PermissionController_rejectPermissionsRequest, _PermissionController_executeRestrictedMethod;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.PermissionController = exports.CaveatMutatorOperation = void 0;
|
|
19
19
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -26,7 +26,6 @@ const nanoid_1 = require("nanoid");
|
|
|
26
26
|
const Caveat_1 = require("./Caveat.cjs");
|
|
27
27
|
const errors_1 = require("./errors.cjs");
|
|
28
28
|
const Permission_1 = require("./Permission.cjs");
|
|
29
|
-
const permission_middleware_1 = require("./permission-middleware.cjs");
|
|
30
29
|
const utils_2 = require("./utils.cjs");
|
|
31
30
|
/**
|
|
32
31
|
* The name of the {@link PermissionController}.
|
|
@@ -34,11 +33,13 @@ const utils_2 = require("./utils.cjs");
|
|
|
34
33
|
const controllerName = 'PermissionController';
|
|
35
34
|
const MESSENGER_EXPOSED_METHODS = [
|
|
36
35
|
'clearState',
|
|
36
|
+
'executeRestrictedMethod',
|
|
37
37
|
'getEndowments',
|
|
38
38
|
'getSubjectNames',
|
|
39
39
|
'getPermissions',
|
|
40
40
|
'hasPermission',
|
|
41
41
|
'hasPermissions',
|
|
42
|
+
'hasUnrestrictedMethod',
|
|
42
43
|
'grantPermissions',
|
|
43
44
|
'grantPermissionsIncremental',
|
|
44
45
|
'requestPermissions',
|
|
@@ -106,6 +107,18 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
106
107
|
get unrestrictedMethods() {
|
|
107
108
|
return __classPrivateFieldGet(this, _PermissionController_unrestrictedMethods, "f");
|
|
108
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Checks whether the given method was declared as unrestricted at
|
|
112
|
+
* construction time. Methods unknown to the controller return `false` and
|
|
113
|
+
* would be treated as restricted by callers such as the permission
|
|
114
|
+
* middleware.
|
|
115
|
+
*
|
|
116
|
+
* @param method - The name of the method to check.
|
|
117
|
+
* @returns Whether the method is unrestricted.
|
|
118
|
+
*/
|
|
119
|
+
hasUnrestrictedMethod(method) {
|
|
120
|
+
return __classPrivateFieldGet(this, _PermissionController_unrestrictedMethods, "f").has(method);
|
|
121
|
+
}
|
|
109
122
|
/**
|
|
110
123
|
* Constructs the PermissionController.
|
|
111
124
|
*
|
|
@@ -145,11 +158,6 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
145
158
|
...permissionSpecifications,
|
|
146
159
|
}), "f");
|
|
147
160
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
148
|
-
this.createPermissionMiddleware = (0, permission_middleware_1.getPermissionMiddlewareFactory)({
|
|
149
|
-
executeRestrictedMethod: __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_executeRestrictedMethod).bind(this),
|
|
150
|
-
getRestrictedMethod: this.getRestrictedMethod.bind(this),
|
|
151
|
-
isUnrestrictedMethod: this.unrestrictedMethods.has.bind(this.unrestrictedMethods),
|
|
152
|
-
});
|
|
153
161
|
}
|
|
154
162
|
/**
|
|
155
163
|
* Clears the state of the controller.
|
|
@@ -161,21 +169,6 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
161
169
|
};
|
|
162
170
|
});
|
|
163
171
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Gets the implementation of the specified restricted method.
|
|
166
|
-
*
|
|
167
|
-
* A JSON-RPC error is thrown if the method does not exist.
|
|
168
|
-
*
|
|
169
|
-
* @see {@link PermissionController.executeRestrictedMethod} and
|
|
170
|
-
* {@link PermissionController.createPermissionMiddleware} for internal usage.
|
|
171
|
-
* @param method - The name of the restricted method.
|
|
172
|
-
* @param origin - The origin associated with the request for the restricted
|
|
173
|
-
* method, if any.
|
|
174
|
-
* @returns The restricted method implementation.
|
|
175
|
-
*/
|
|
176
|
-
getRestrictedMethod(method, origin) {
|
|
177
|
-
return __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_getTypedPermissionSpecification).call(this, Permission_1.PermissionType.RestrictedMethod, method, origin).methodImplementation;
|
|
178
|
-
}
|
|
179
172
|
/**
|
|
180
173
|
* Gets a list of all origins of subjects.
|
|
181
174
|
*
|
|
@@ -229,7 +222,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
229
222
|
/**
|
|
230
223
|
* Revokes all permissions from the specified origin.
|
|
231
224
|
*
|
|
232
|
-
* Throws an error
|
|
225
|
+
* Throws an error if the origin has no permissions.
|
|
233
226
|
*
|
|
234
227
|
* @param origin - The origin whose permissions to revoke.
|
|
235
228
|
*/
|
|
@@ -741,10 +734,12 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
741
734
|
*/
|
|
742
735
|
async executeRestrictedMethod(origin, targetName, params) {
|
|
743
736
|
// Throws if the method does not exist
|
|
744
|
-
const methodImplementation = this.
|
|
737
|
+
const methodImplementation = __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_getRestrictedMethod).call(this, targetName, origin);
|
|
745
738
|
const result = await __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_executeRestrictedMethod).call(this, methodImplementation, { origin }, targetName, params);
|
|
739
|
+
// This is impossible if the restricted method implementation is typed correctly,
|
|
740
|
+
// but we maintain it for backwards compatibility.
|
|
746
741
|
if (result === undefined) {
|
|
747
|
-
throw new Error(`
|
|
742
|
+
throw new Error(`Request for method "${targetName}" as origin "${origin}" returned no result.`);
|
|
748
743
|
}
|
|
749
744
|
return result;
|
|
750
745
|
}
|
|
@@ -789,7 +784,7 @@ _PermissionController_caveatSpecifications = new WeakMap(), _PermissionControlle
|
|
|
789
784
|
});
|
|
790
785
|
}, _PermissionController_getTypedPermissionSpecification = function _PermissionController_getTypedPermissionSpecification(permissionType, targetName, requestingOrigin) {
|
|
791
786
|
const failureError = permissionType === Permission_1.PermissionType.RestrictedMethod
|
|
792
|
-
? (0, errors_1.methodNotFound)(targetName,
|
|
787
|
+
? (0, errors_1.methodNotFound)(targetName, { origin: requestingOrigin })
|
|
793
788
|
: new errors_1.EndowmentPermissionDoesNotExistError(targetName, requestingOrigin);
|
|
794
789
|
if (!__classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_targetExists).call(this, targetName)) {
|
|
795
790
|
throw failureError;
|
|
@@ -799,6 +794,8 @@ _PermissionController_caveatSpecifications = new WeakMap(), _PermissionControlle
|
|
|
799
794
|
throw failureError;
|
|
800
795
|
}
|
|
801
796
|
return specification;
|
|
797
|
+
}, _PermissionController_getRestrictedMethod = function _PermissionController_getRestrictedMethod(method, origin) {
|
|
798
|
+
return __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_getTypedPermissionSpecification).call(this, Permission_1.PermissionType.RestrictedMethod, method, origin).methodImplementation;
|
|
802
799
|
}, _PermissionController_deletePermission = function _PermissionController_deletePermission(subjects, origin, target) {
|
|
803
800
|
const { permissions } = subjects[origin];
|
|
804
801
|
if (Object.keys(permissions).length > 1) {
|