@metamask/permission-controller 12.3.0 → 13.1.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +48 -6
  2. package/dist/Permission.cjs.map +1 -1
  3. package/dist/Permission.d.cts +9 -15
  4. package/dist/Permission.d.cts.map +1 -1
  5. package/dist/Permission.d.mts +9 -15
  6. package/dist/Permission.d.mts.map +1 -1
  7. package/dist/Permission.mjs.map +1 -1
  8. package/dist/PermissionController-method-action-types.cjs.map +1 -1
  9. package/dist/PermissionController-method-action-types.d.cts +117 -2
  10. package/dist/PermissionController-method-action-types.d.cts.map +1 -1
  11. package/dist/PermissionController-method-action-types.d.mts +117 -2
  12. package/dist/PermissionController-method-action-types.d.mts.map +1 -1
  13. package/dist/PermissionController-method-action-types.mjs.map +1 -1
  14. package/dist/PermissionController.cjs +28 -26
  15. package/dist/PermissionController.cjs.map +1 -1
  16. package/dist/PermissionController.d.cts +9 -22
  17. package/dist/PermissionController.d.cts.map +1 -1
  18. package/dist/PermissionController.d.mts +9 -22
  19. package/dist/PermissionController.d.mts.map +1 -1
  20. package/dist/PermissionController.mjs +28 -26
  21. package/dist/PermissionController.mjs.map +1 -1
  22. package/dist/createRestrictedMethodMessenger.cjs +20 -0
  23. package/dist/createRestrictedMethodMessenger.cjs.map +1 -0
  24. package/dist/createRestrictedMethodMessenger.d.cts +42 -0
  25. package/dist/createRestrictedMethodMessenger.d.cts.map +1 -0
  26. package/dist/createRestrictedMethodMessenger.d.mts +42 -0
  27. package/dist/createRestrictedMethodMessenger.d.mts.map +1 -0
  28. package/dist/createRestrictedMethodMessenger.mjs +16 -0
  29. package/dist/createRestrictedMethodMessenger.mjs.map +1 -0
  30. package/dist/index.cjs +6 -14
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +4 -3
  33. package/dist/index.d.cts.map +1 -1
  34. package/dist/index.d.mts +4 -3
  35. package/dist/index.d.mts.map +1 -1
  36. package/dist/index.mjs +2 -1
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/permission-middleware.cjs +47 -43
  39. package/dist/permission-middleware.cjs.map +1 -1
  40. package/dist/permission-middleware.d.cts +40 -25
  41. package/dist/permission-middleware.d.cts.map +1 -1
  42. package/dist/permission-middleware.d.mts +40 -25
  43. package/dist/permission-middleware.d.mts.map +1 -1
  44. package/dist/permission-middleware.mjs +44 -41
  45. package/dist/permission-middleware.mjs.map +1 -1
  46. package/dist/utils.cjs.map +1 -1
  47. package/dist/utils.d.cts +0 -23
  48. package/dist/utils.d.cts.map +1 -1
  49. package/dist/utils.d.mts +0 -23
  50. package/dist/utils.d.mts.map +1 -1
  51. package/dist/utils.mjs.map +1 -1
  52. package/package.json +20 -19
  53. package/dist/rpc-methods/getPermissions.cjs +0 -27
  54. package/dist/rpc-methods/getPermissions.cjs.map +0 -1
  55. package/dist/rpc-methods/getPermissions.d.cts +0 -9
  56. package/dist/rpc-methods/getPermissions.d.cts.map +0 -1
  57. package/dist/rpc-methods/getPermissions.d.mts +0 -9
  58. package/dist/rpc-methods/getPermissions.d.mts.map +0 -1
  59. package/dist/rpc-methods/getPermissions.mjs +0 -24
  60. package/dist/rpc-methods/getPermissions.mjs.map +0 -1
  61. package/dist/rpc-methods/index.cjs +0 -12
  62. package/dist/rpc-methods/index.cjs.map +0 -1
  63. package/dist/rpc-methods/index.d.cts +0 -6
  64. package/dist/rpc-methods/index.d.cts.map +0 -1
  65. package/dist/rpc-methods/index.d.mts +0 -6
  66. package/dist/rpc-methods/index.d.mts.map +0 -1
  67. package/dist/rpc-methods/index.mjs +0 -9
  68. package/dist/rpc-methods/index.mjs.map +0 -1
  69. package/dist/rpc-methods/requestPermissions.cjs +0 -36
  70. package/dist/rpc-methods/requestPermissions.cjs.map +0 -1
  71. package/dist/rpc-methods/requestPermissions.d.cts +0 -17
  72. package/dist/rpc-methods/requestPermissions.d.cts.map +0 -1
  73. package/dist/rpc-methods/requestPermissions.d.mts +0 -17
  74. package/dist/rpc-methods/requestPermissions.d.mts.map +0 -1
  75. package/dist/rpc-methods/requestPermissions.mjs +0 -33
  76. package/dist/rpc-methods/requestPermissions.mjs.map +0 -1
  77. package/dist/rpc-methods/revokePermissions.cjs +0 -41
  78. package/dist/rpc-methods/revokePermissions.cjs.map +0 -1
  79. package/dist/rpc-methods/revokePermissions.d.cts +0 -11
  80. package/dist/rpc-methods/revokePermissions.d.cts.map +0 -1
  81. package/dist/rpc-methods/revokePermissions.d.mts +0 -11
  82. package/dist/rpc-methods/revokePermissions.d.mts.map +0 -1
  83. package/dist/rpc-methods/revokePermissions.mjs +0 -38
  84. 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.cjs";
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
  */
@@ -19,6 +32,19 @@ export type PermissionControllerGetSubjectNamesAction = {
19
32
  type: `PermissionController:getSubjectNames`;
20
33
  handler: PermissionController['getSubjectNames'];
21
34
  };
35
+ /**
36
+ * Gets the permission for the specified target of the subject corresponding
37
+ * to the specified origin.
38
+ *
39
+ * @param origin - The origin of the subject.
40
+ * @param targetName - The method name as invoked by a third party (i.e., not
41
+ * a method key).
42
+ * @returns The permission if it exists, or undefined otherwise.
43
+ */
44
+ export type PermissionControllerGetPermissionAction = {
45
+ type: `PermissionController:getPermission`;
46
+ handler: PermissionController['getPermission'];
47
+ };
22
48
  /**
23
49
  * Gets all permissions for the specified subject, if any.
24
50
  *
@@ -55,7 +81,7 @@ export type PermissionControllerHasPermissionsAction = {
55
81
  /**
56
82
  * Revokes all permissions from the specified origin.
57
83
  *
58
- * Throws an error of the origin has no permissions.
84
+ * Throws an error if the origin has no permissions.
59
85
  *
60
86
  * @param origin - The origin whose permissions to revoke.
61
87
  */
@@ -63,6 +89,19 @@ export type PermissionControllerRevokeAllPermissionsAction = {
63
89
  type: `PermissionController:revokeAllPermissions`;
64
90
  handler: PermissionController['revokeAllPermissions'];
65
91
  };
92
+ /**
93
+ * Revokes the specified permission from the subject with the specified
94
+ * origin.
95
+ *
96
+ * Throws an error if the subject or the permission does not exist.
97
+ *
98
+ * @param origin - The origin of the subject whose permission to revoke.
99
+ * @param target - The target name of the permission to revoke.
100
+ */
101
+ export type PermissionControllerRevokePermissionAction = {
102
+ type: `PermissionController:revokePermission`;
103
+ handler: PermissionController['revokePermission'];
104
+ };
66
105
  /**
67
106
  * Revokes the specified permissions from the specified subjects.
68
107
  *
@@ -126,6 +165,33 @@ export type PermissionControllerUpdateCaveatAction = {
126
165
  type: `PermissionController:updateCaveat`;
127
166
  handler: PermissionController['updateCaveat'];
128
167
  };
168
+ /**
169
+ * Updates all caveats with the specified type for all subjects and
170
+ * permissions by applying the specified mutator function to them.
171
+ *
172
+ * ATTN: Permissions can be revoked entirely by the action of this method,
173
+ * read on for details.
174
+ *
175
+ * Caveat mutators are functions that receive a caveat value and return a
176
+ * tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new
177
+ * value to update the existing caveat with.
178
+ *
179
+ * For each caveat, depending on the mutator result, this method will:
180
+ * - Do nothing ({@link CaveatMutatorOperation.Noop})
181
+ * - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
182
+ * - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
183
+ * - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
184
+ *
185
+ * This method throws if the validation of any caveat or permission fails.
186
+ *
187
+ * @param targetCaveatType - The type of the caveats to update.
188
+ * @param mutator - The mutator function which will be applied to all caveat
189
+ * values.
190
+ */
191
+ export type PermissionControllerUpdatePermissionsByCaveatAction = {
192
+ type: `PermissionController:updatePermissionsByCaveat`;
193
+ handler: PermissionController['updatePermissionsByCaveat'];
194
+ };
129
195
  /**
130
196
  * Grants _approved_ permissions to the specified subject. Every permission and
131
197
  * caveat is stringently validated—including by calling their specification
@@ -236,6 +302,26 @@ export type PermissionControllerRequestPermissionsIncrementalAction = {
236
302
  type: `PermissionController:requestPermissionsIncremental`;
237
303
  handler: PermissionController['requestPermissionsIncremental'];
238
304
  };
305
+ /**
306
+ * Accepts a permissions request created by
307
+ * {@link PermissionController.requestPermissions}.
308
+ *
309
+ * @param request - The permissions request.
310
+ */
311
+ export type PermissionControllerAcceptPermissionsRequestAction = {
312
+ type: `PermissionController:acceptPermissionsRequest`;
313
+ handler: PermissionController['acceptPermissionsRequest'];
314
+ };
315
+ /**
316
+ * Rejects a permissions request created by
317
+ * {@link PermissionController.requestPermissions}.
318
+ *
319
+ * @param id - The id of the request to be rejected.
320
+ */
321
+ export type PermissionControllerRejectPermissionsRequestAction = {
322
+ type: `PermissionController:rejectPermissionsRequest`;
323
+ handler: PermissionController['rejectPermissionsRequest'];
324
+ };
239
325
  /**
240
326
  * Gets the subject's endowments per the specified endowment permission.
241
327
  * Throws if the subject does not have the required permission or if the
@@ -252,8 +338,37 @@ export type PermissionControllerGetEndowmentsAction = {
252
338
  type: `PermissionController:getEndowments`;
253
339
  handler: PermissionController['getEndowments'];
254
340
  };
341
+ /**
342
+ * Executes a restricted method as the subject with the given origin.
343
+ * The specified params, if any, will be passed to the method implementation.
344
+ *
345
+ * ATTN: Great caution should be exercised in the use of this method.
346
+ * Methods that cause side effects or affect application state should
347
+ * be avoided.
348
+ *
349
+ * This method will first attempt to retrieve the requested restricted method
350
+ * implementation, throwing if it does not exist. The method will then be
351
+ * invoked as though the subject with the specified origin had invoked it with
352
+ * the specified parameters. This means that any existing caveats will be
353
+ * applied to the restricted method, and this method will throw if the
354
+ * restricted method or its caveat decorators throw.
355
+ *
356
+ * In addition, this method will throw if the subject does not have a
357
+ * permission for the specified restricted method.
358
+ *
359
+ * @param origin - The origin of the subject to execute the method on behalf
360
+ * of.
361
+ * @param targetName - The name of the method to execute. This must be a valid
362
+ * permission target name.
363
+ * @param params - The parameters to pass to the method implementation.
364
+ * @returns The result of the executed method.
365
+ */
366
+ export type PermissionControllerExecuteRestrictedMethodAction = {
367
+ type: `PermissionController:executeRestrictedMethod`;
368
+ handler: PermissionController['executeRestrictedMethod'];
369
+ };
255
370
  /**
256
371
  * Union of all PermissionController action types.
257
372
  */
258
- export type PermissionControllerMethodActions = PermissionControllerClearStateAction | PermissionControllerGetSubjectNamesAction | PermissionControllerGetPermissionsAction | PermissionControllerHasPermissionAction | PermissionControllerHasPermissionsAction | PermissionControllerRevokeAllPermissionsAction | PermissionControllerRevokePermissionsAction | PermissionControllerRevokePermissionForAllSubjectsAction | PermissionControllerGetCaveatAction | PermissionControllerUpdateCaveatAction | PermissionControllerGrantPermissionsAction | PermissionControllerGrantPermissionsIncrementalAction | PermissionControllerRequestPermissionsAction | PermissionControllerRequestPermissionsIncrementalAction | PermissionControllerGetEndowmentsAction;
373
+ 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;
259
374
  //# sourceMappingURL=PermissionController-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionController-method-action-types.d.cts","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,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,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,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.cts","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,CAAC;IAC7C,OAAO,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CAClD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IAC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;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,oBAAoB,CAAC,yBAAyB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,+CAA+C,GAC/C,oCAAoC,GACpC,yCAAyC,GACzC,uCAAuC,GACvC,wCAAwC,GACxC,uCAAuC,GACvC,wCAAwC,GACxC,8CAA8C,GAC9C,0CAA0C,GAC1C,2CAA2C,GAC3C,wDAAwD,GACxD,mCAAmC,GACnC,sCAAsC,GACtC,mDAAmD,GACnD,0CAA0C,GAC1C,qDAAqD,GACrD,4CAA4C,GAC5C,uDAAuD,GACvD,kDAAkD,GAClD,kDAAkD,GAClD,uCAAuC,GACvC,iDAAiD,CAAC"}
@@ -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
  */
@@ -19,6 +32,19 @@ export type PermissionControllerGetSubjectNamesAction = {
19
32
  type: `PermissionController:getSubjectNames`;
20
33
  handler: PermissionController['getSubjectNames'];
21
34
  };
35
+ /**
36
+ * Gets the permission for the specified target of the subject corresponding
37
+ * to the specified origin.
38
+ *
39
+ * @param origin - The origin of the subject.
40
+ * @param targetName - The method name as invoked by a third party (i.e., not
41
+ * a method key).
42
+ * @returns The permission if it exists, or undefined otherwise.
43
+ */
44
+ export type PermissionControllerGetPermissionAction = {
45
+ type: `PermissionController:getPermission`;
46
+ handler: PermissionController['getPermission'];
47
+ };
22
48
  /**
23
49
  * Gets all permissions for the specified subject, if any.
24
50
  *
@@ -55,7 +81,7 @@ export type PermissionControllerHasPermissionsAction = {
55
81
  /**
56
82
  * Revokes all permissions from the specified origin.
57
83
  *
58
- * Throws an error of the origin has no permissions.
84
+ * Throws an error if the origin has no permissions.
59
85
  *
60
86
  * @param origin - The origin whose permissions to revoke.
61
87
  */
@@ -63,6 +89,19 @@ export type PermissionControllerRevokeAllPermissionsAction = {
63
89
  type: `PermissionController:revokeAllPermissions`;
64
90
  handler: PermissionController['revokeAllPermissions'];
65
91
  };
92
+ /**
93
+ * Revokes the specified permission from the subject with the specified
94
+ * origin.
95
+ *
96
+ * Throws an error if the subject or the permission does not exist.
97
+ *
98
+ * @param origin - The origin of the subject whose permission to revoke.
99
+ * @param target - The target name of the permission to revoke.
100
+ */
101
+ export type PermissionControllerRevokePermissionAction = {
102
+ type: `PermissionController:revokePermission`;
103
+ handler: PermissionController['revokePermission'];
104
+ };
66
105
  /**
67
106
  * Revokes the specified permissions from the specified subjects.
68
107
  *
@@ -126,6 +165,33 @@ export type PermissionControllerUpdateCaveatAction = {
126
165
  type: `PermissionController:updateCaveat`;
127
166
  handler: PermissionController['updateCaveat'];
128
167
  };
168
+ /**
169
+ * Updates all caveats with the specified type for all subjects and
170
+ * permissions by applying the specified mutator function to them.
171
+ *
172
+ * ATTN: Permissions can be revoked entirely by the action of this method,
173
+ * read on for details.
174
+ *
175
+ * Caveat mutators are functions that receive a caveat value and return a
176
+ * tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new
177
+ * value to update the existing caveat with.
178
+ *
179
+ * For each caveat, depending on the mutator result, this method will:
180
+ * - Do nothing ({@link CaveatMutatorOperation.Noop})
181
+ * - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
182
+ * - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
183
+ * - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
184
+ *
185
+ * This method throws if the validation of any caveat or permission fails.
186
+ *
187
+ * @param targetCaveatType - The type of the caveats to update.
188
+ * @param mutator - The mutator function which will be applied to all caveat
189
+ * values.
190
+ */
191
+ export type PermissionControllerUpdatePermissionsByCaveatAction = {
192
+ type: `PermissionController:updatePermissionsByCaveat`;
193
+ handler: PermissionController['updatePermissionsByCaveat'];
194
+ };
129
195
  /**
130
196
  * Grants _approved_ permissions to the specified subject. Every permission and
131
197
  * caveat is stringently validated—including by calling their specification
@@ -236,6 +302,26 @@ export type PermissionControllerRequestPermissionsIncrementalAction = {
236
302
  type: `PermissionController:requestPermissionsIncremental`;
237
303
  handler: PermissionController['requestPermissionsIncremental'];
238
304
  };
305
+ /**
306
+ * Accepts a permissions request created by
307
+ * {@link PermissionController.requestPermissions}.
308
+ *
309
+ * @param request - The permissions request.
310
+ */
311
+ export type PermissionControllerAcceptPermissionsRequestAction = {
312
+ type: `PermissionController:acceptPermissionsRequest`;
313
+ handler: PermissionController['acceptPermissionsRequest'];
314
+ };
315
+ /**
316
+ * Rejects a permissions request created by
317
+ * {@link PermissionController.requestPermissions}.
318
+ *
319
+ * @param id - The id of the request to be rejected.
320
+ */
321
+ export type PermissionControllerRejectPermissionsRequestAction = {
322
+ type: `PermissionController:rejectPermissionsRequest`;
323
+ handler: PermissionController['rejectPermissionsRequest'];
324
+ };
239
325
  /**
240
326
  * Gets the subject's endowments per the specified endowment permission.
241
327
  * Throws if the subject does not have the required permission or if the
@@ -252,8 +338,37 @@ export type PermissionControllerGetEndowmentsAction = {
252
338
  type: `PermissionController:getEndowments`;
253
339
  handler: PermissionController['getEndowments'];
254
340
  };
341
+ /**
342
+ * Executes a restricted method as the subject with the given origin.
343
+ * The specified params, if any, will be passed to the method implementation.
344
+ *
345
+ * ATTN: Great caution should be exercised in the use of this method.
346
+ * Methods that cause side effects or affect application state should
347
+ * be avoided.
348
+ *
349
+ * This method will first attempt to retrieve the requested restricted method
350
+ * implementation, throwing if it does not exist. The method will then be
351
+ * invoked as though the subject with the specified origin had invoked it with
352
+ * the specified parameters. This means that any existing caveats will be
353
+ * applied to the restricted method, and this method will throw if the
354
+ * restricted method or its caveat decorators throw.
355
+ *
356
+ * In addition, this method will throw if the subject does not have a
357
+ * permission for the specified restricted method.
358
+ *
359
+ * @param origin - The origin of the subject to execute the method on behalf
360
+ * of.
361
+ * @param targetName - The name of the method to execute. This must be a valid
362
+ * permission target name.
363
+ * @param params - The parameters to pass to the method implementation.
364
+ * @returns The result of the executed method.
365
+ */
366
+ export type PermissionControllerExecuteRestrictedMethodAction = {
367
+ type: `PermissionController:executeRestrictedMethod`;
368
+ handler: PermissionController['executeRestrictedMethod'];
369
+ };
255
370
  /**
256
371
  * Union of all PermissionController action types.
257
372
  */
258
- export type PermissionControllerMethodActions = PermissionControllerClearStateAction | PermissionControllerGetSubjectNamesAction | PermissionControllerGetPermissionsAction | PermissionControllerHasPermissionAction | PermissionControllerHasPermissionsAction | PermissionControllerRevokeAllPermissionsAction | PermissionControllerRevokePermissionsAction | PermissionControllerRevokePermissionForAllSubjectsAction | PermissionControllerGetCaveatAction | PermissionControllerUpdateCaveatAction | PermissionControllerGrantPermissionsAction | PermissionControllerGrantPermissionsIncrementalAction | PermissionControllerRequestPermissionsAction | PermissionControllerRequestPermissionsIncrementalAction | PermissionControllerGetEndowmentsAction;
373
+ 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;
259
374
  //# 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,EAAE,qCAAqC,CAAC;IAC5C,O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AE,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,CAAC;IAC7C,OAAO,EAAE,oBAAoB,C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ACtD,OAAO,EAAE,oBAAoB,CAAC,0BAA0B,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,oBAAoB,CAAC,0BAA0B,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,oBAAoB,CAAC,yBAAyB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,+CAA+C,GAC/C,oCAAoC,GACpC,yCAAyC,GACzC,uCAAuC,GACvC,wCAAwC,GACxC,uCAAuC,GACvC,wCAAwC,GACxC,8CAA8C,GAC9C,0CAA0C,GAC1C,2CAA2C,GAC3C,wDAAwD,GACxD,mCAAmC,GACnC,sCAAsC,GACtC,mDAAmD,GACnD,0CAA0C,GAC1C,qDAAqD,GACrD,4CAA4C,GAC5C,uDAAuD,GACvD,kDAAkD,GAClD,kDAAkD,GAClD,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 the permission for the specified target of the subject corresponding\n * to the specified origin.\n *\n * @param origin - The origin of the subject.\n * @param targetName - The method name as invoked by a third party (i.e., not\n * a method key).\n * @returns The permission if it exists, or undefined otherwise.\n */\nexport type PermissionControllerGetPermissionAction = {\n type: `PermissionController:getPermission`;\n handler: PermissionController['getPermission'];\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 permission from the subject with the specified\n * origin.\n *\n * Throws an error if the subject or the permission does not exist.\n *\n * @param origin - The origin of the subject whose permission to revoke.\n * @param target - The target name of the permission to revoke.\n */\nexport type PermissionControllerRevokePermissionAction = {\n type: `PermissionController:revokePermission`;\n handler: PermissionController['revokePermission'];\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 * Updates all caveats with the specified type for all subjects and\n * permissions by applying the specified mutator function to them.\n *\n * ATTN: Permissions can be revoked entirely by the action of this method,\n * read on for details.\n *\n * Caveat mutators are functions that receive a caveat value and return a\n * tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new\n * value to update the existing caveat with.\n *\n * For each caveat, depending on the mutator result, this method will:\n * - Do nothing ({@link CaveatMutatorOperation.Noop})\n * - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.\n * - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.\n * - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})\n *\n * This method throws if the validation of any caveat or permission fails.\n *\n * @param targetCaveatType - The type of the caveats to update.\n * @param mutator - The mutator function which will be applied to all caveat\n * values.\n */\nexport type PermissionControllerUpdatePermissionsByCaveatAction = {\n type: `PermissionController:updatePermissionsByCaveat`;\n handler: PermissionController['updatePermissionsByCaveat'];\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 * Accepts a permissions request created by\n * {@link PermissionController.requestPermissions}.\n *\n * @param request - The permissions request.\n */\nexport type PermissionControllerAcceptPermissionsRequestAction = {\n type: `PermissionController:acceptPermissionsRequest`;\n handler: PermissionController['acceptPermissionsRequest'];\n};\n\n/**\n * Rejects a permissions request created by\n * {@link PermissionController.requestPermissions}.\n *\n * @param id - The id of the request to be rejected.\n */\nexport type PermissionControllerRejectPermissionsRequestAction = {\n type: `PermissionController:rejectPermissionsRequest`;\n handler: PermissionController['rejectPermissionsRequest'];\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 | PermissionControllerGetPermissionAction\n | PermissionControllerGetPermissionsAction\n | PermissionControllerHasPermissionAction\n | PermissionControllerHasPermissionsAction\n | PermissionControllerRevokeAllPermissionsAction\n | PermissionControllerRevokePermissionAction\n | PermissionControllerRevokePermissionsAction\n | PermissionControllerRevokePermissionForAllSubjectsAction\n | PermissionControllerGetCaveatAction\n | PermissionControllerUpdateCaveatAction\n | PermissionControllerUpdatePermissionsByCaveatAction\n | PermissionControllerGrantPermissionsAction\n | PermissionControllerGrantPermissionsIncrementalAction\n | PermissionControllerRequestPermissionsAction\n | PermissionControllerRequestPermissionsIncrementalAction\n | PermissionControllerAcceptPermissionsRequestAction\n | PermissionControllerRejectPermissionsRequestAction\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',
@@ -48,6 +49,11 @@ const MESSENGER_EXPOSED_METHODS = [
48
49
  'revokePermissions',
49
50
  'updateCaveat',
50
51
  'getCaveat',
52
+ 'acceptPermissionsRequest',
53
+ 'rejectPermissionsRequest',
54
+ 'revokePermission',
55
+ 'updatePermissionsByCaveat',
56
+ 'getPermission',
51
57
  ];
52
58
  /**
53
59
  * Get the state metadata of the {@link PermissionController}.
@@ -106,6 +112,18 @@ class PermissionController extends base_controller_1.BaseController {
106
112
  get unrestrictedMethods() {
107
113
  return __classPrivateFieldGet(this, _PermissionController_unrestrictedMethods, "f");
108
114
  }
115
+ /**
116
+ * Checks whether the given method was declared as unrestricted at
117
+ * construction time. Methods unknown to the controller return `false` and
118
+ * would be treated as restricted by callers such as the permission
119
+ * middleware.
120
+ *
121
+ * @param method - The name of the method to check.
122
+ * @returns Whether the method is unrestricted.
123
+ */
124
+ hasUnrestrictedMethod(method) {
125
+ return __classPrivateFieldGet(this, _PermissionController_unrestrictedMethods, "f").has(method);
126
+ }
109
127
  /**
110
128
  * Constructs the PermissionController.
111
129
  *
@@ -145,11 +163,6 @@ class PermissionController extends base_controller_1.BaseController {
145
163
  ...permissionSpecifications,
146
164
  }), "f");
147
165
  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
166
  }
154
167
  /**
155
168
  * Clears the state of the controller.
@@ -161,21 +174,6 @@ class PermissionController extends base_controller_1.BaseController {
161
174
  };
162
175
  });
163
176
  }
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
177
  /**
180
178
  * Gets a list of all origins of subjects.
181
179
  *
@@ -229,7 +227,7 @@ class PermissionController extends base_controller_1.BaseController {
229
227
  /**
230
228
  * Revokes all permissions from the specified origin.
231
229
  *
232
- * Throws an error of the origin has no permissions.
230
+ * Throws an error if the origin has no permissions.
233
231
  *
234
232
  * @param origin - The origin whose permissions to revoke.
235
233
  */
@@ -741,10 +739,12 @@ class PermissionController extends base_controller_1.BaseController {
741
739
  */
742
740
  async executeRestrictedMethod(origin, targetName, params) {
743
741
  // Throws if the method does not exist
744
- const methodImplementation = this.getRestrictedMethod(targetName, origin);
742
+ const methodImplementation = __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_getRestrictedMethod).call(this, targetName, origin);
745
743
  const result = await __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_executeRestrictedMethod).call(this, methodImplementation, { origin }, targetName, params);
744
+ // This is impossible if the restricted method implementation is typed correctly,
745
+ // but we maintain it for backwards compatibility.
746
746
  if (result === undefined) {
747
- throw new Error(`Internal request for method "${targetName}" as origin "${origin}" returned no result.`);
747
+ throw new Error(`Request for method "${targetName}" as origin "${origin}" returned no result.`);
748
748
  }
749
749
  return result;
750
750
  }
@@ -789,7 +789,7 @@ _PermissionController_caveatSpecifications = new WeakMap(), _PermissionControlle
789
789
  });
790
790
  }, _PermissionController_getTypedPermissionSpecification = function _PermissionController_getTypedPermissionSpecification(permissionType, targetName, requestingOrigin) {
791
791
  const failureError = permissionType === Permission_1.PermissionType.RestrictedMethod
792
- ? (0, errors_1.methodNotFound)(targetName, requestingOrigin ? { origin: requestingOrigin } : undefined)
792
+ ? (0, errors_1.methodNotFound)(targetName, { origin: requestingOrigin })
793
793
  : new errors_1.EndowmentPermissionDoesNotExistError(targetName, requestingOrigin);
794
794
  if (!__classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_targetExists).call(this, targetName)) {
795
795
  throw failureError;
@@ -799,6 +799,8 @@ _PermissionController_caveatSpecifications = new WeakMap(), _PermissionControlle
799
799
  throw failureError;
800
800
  }
801
801
  return specification;
802
+ }, _PermissionController_getRestrictedMethod = function _PermissionController_getRestrictedMethod(method, origin) {
803
+ return __classPrivateFieldGet(this, _PermissionController_instances, "m", _PermissionController_getTypedPermissionSpecification).call(this, Permission_1.PermissionType.RestrictedMethod, method, origin).methodImplementation;
802
804
  }, _PermissionController_deletePermission = function _PermissionController_deletePermission(subjects, origin, target) {
803
805
  const { permissions } = subjects[origin];
804
806
  if (Object.keys(permissions).length > 1) {