@metamask-previews/permission-controller 11.1.0-preview-cd26f001 → 11.1.0-preview-e9856975
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 +5 -0
- package/dist/Caveat.cjs.map +1 -1
- package/dist/Caveat.d.cts.map +1 -1
- package/dist/Caveat.d.mts.map +1 -1
- package/dist/Caveat.mjs.map +1 -1
- package/dist/Permission.cjs.map +1 -1
- package/dist/Permission.d.cts +2 -2
- package/dist/Permission.d.cts.map +1 -1
- package/dist/Permission.d.mts +2 -2
- package/dist/Permission.d.mts.map +1 -1
- package/dist/Permission.mjs.map +1 -1
- package/dist/PermissionController.cjs +25 -26
- package/dist/PermissionController.cjs.map +1 -1
- package/dist/PermissionController.d.cts +9 -9
- package/dist/PermissionController.d.cts.map +1 -1
- package/dist/PermissionController.d.mts +9 -9
- package/dist/PermissionController.d.mts.map +1 -1
- package/dist/PermissionController.mjs +24 -25
- package/dist/PermissionController.mjs.map +1 -1
- package/dist/SubjectMetadataController.cjs +5 -5
- package/dist/SubjectMetadataController.cjs.map +1 -1
- package/dist/SubjectMetadataController.d.cts +4 -3
- package/dist/SubjectMetadataController.d.cts.map +1 -1
- package/dist/SubjectMetadataController.d.mts +4 -3
- package/dist/SubjectMetadataController.d.mts.map +1 -1
- package/dist/SubjectMetadataController.mjs +4 -4
- package/dist/SubjectMetadataController.mjs.map +1 -1
- package/dist/permission-middleware.cjs.map +1 -1
- package/dist/permission-middleware.d.cts.map +1 -1
- package/dist/permission-middleware.d.mts.map +1 -1
- package/dist/permission-middleware.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
var _PermissionController_instances, _PermissionController_expectGetCaveatMerger, _PermissionController_applyGrantedPermissions, _PermissionController_mergeIncrementalPermissions, _PermissionController_mergePermission, _PermissionController_mergeCaveat, _PermissionController_handleApprovedPermissions;
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PermissionController = exports.CaveatMutatorOperation = void 0;
|
|
13
|
-
const
|
|
13
|
+
const next_1 = require("@metamask/base-controller/next");
|
|
14
14
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
15
15
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
16
16
|
const utils_1 = require("@metamask/utils");
|
|
@@ -36,7 +36,7 @@ function getStateMetadata() {
|
|
|
36
36
|
return {
|
|
37
37
|
subjects: {
|
|
38
38
|
includeInStateLogs: true,
|
|
39
|
-
|
|
39
|
+
includeInDebugSnapshot: true,
|
|
40
40
|
persist: true,
|
|
41
41
|
usedInUi: true,
|
|
42
42
|
},
|
|
@@ -74,7 +74,7 @@ var CaveatMutatorOperation;
|
|
|
74
74
|
* @template ControllerCaveatSpecification - A union of the types of all
|
|
75
75
|
* caveat specifications available to the controller.
|
|
76
76
|
*/
|
|
77
|
-
class PermissionController extends
|
|
77
|
+
class PermissionController extends next_1.BaseController {
|
|
78
78
|
/**
|
|
79
79
|
* The names of all JSON-RPC methods that will be ignored by the controller.
|
|
80
80
|
*
|
|
@@ -182,24 +182,23 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
* Constructor helper for registering the controller's
|
|
186
|
-
* actions.
|
|
185
|
+
* Constructor helper for registering the controller's messenger actions.
|
|
187
186
|
*/
|
|
188
187
|
registerMessageHandlers() {
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
194
|
-
this.
|
|
195
|
-
this.
|
|
196
|
-
this.
|
|
197
|
-
this.
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
188
|
+
this.messenger.registerActionHandler(`${controllerName}:clearPermissions`, () => this.clearState());
|
|
189
|
+
this.messenger.registerActionHandler(`${controllerName}:getEndowments`, (origin, targetName, requestData) => this.getEndowments(origin, targetName, requestData));
|
|
190
|
+
this.messenger.registerActionHandler(`${controllerName}:getSubjectNames`, () => this.getSubjectNames());
|
|
191
|
+
this.messenger.registerActionHandler(`${controllerName}:getPermissions`, (origin) => this.getPermissions(origin));
|
|
192
|
+
this.messenger.registerActionHandler(`${controllerName}:hasPermission`, (origin, targetName) => this.hasPermission(origin, targetName));
|
|
193
|
+
this.messenger.registerActionHandler(`${controllerName}:hasPermissions`, (origin) => this.hasPermissions(origin));
|
|
194
|
+
this.messenger.registerActionHandler(`${controllerName}:grantPermissions`, this.grantPermissions.bind(this));
|
|
195
|
+
this.messenger.registerActionHandler(`${controllerName}:grantPermissionsIncremental`, this.grantPermissionsIncremental.bind(this));
|
|
196
|
+
this.messenger.registerActionHandler(`${controllerName}:requestPermissions`, (subject, permissions) => this.requestPermissions(subject, permissions));
|
|
197
|
+
this.messenger.registerActionHandler(`${controllerName}:requestPermissionsIncremental`, (subject, permissions) => this.requestPermissionsIncremental(subject, permissions));
|
|
198
|
+
this.messenger.registerActionHandler(`${controllerName}:revokeAllPermissions`, (origin) => this.revokeAllPermissions(origin));
|
|
199
|
+
this.messenger.registerActionHandler(`${controllerName}:revokePermissionForAllSubjects`, (target) => this.revokePermissionForAllSubjects(target));
|
|
200
|
+
this.messenger.registerActionHandler(`${controllerName}:revokePermissions`, this.revokePermissions.bind(this));
|
|
201
|
+
this.messenger.registerActionHandler(`${controllerName}:updateCaveat`, (origin, target, caveatType, caveatValue) => {
|
|
203
202
|
this.updateCaveat(origin, target, caveatType, caveatValue);
|
|
204
203
|
});
|
|
205
204
|
}
|
|
@@ -786,7 +785,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
786
785
|
const { allowedCaveats, validator, targetName } = specification;
|
|
787
786
|
if (specification.subjectTypes?.length &&
|
|
788
787
|
specification.subjectTypes.length > 0) {
|
|
789
|
-
const metadata = this.
|
|
788
|
+
const metadata = this.messenger.call('SubjectMetadataController:getSubjectMetadata', origin);
|
|
790
789
|
if (!metadata ||
|
|
791
790
|
metadata.subjectType === null ||
|
|
792
791
|
!specification.subjectTypes.includes(metadata.subjectType)) {
|
|
@@ -1074,7 +1073,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1074
1073
|
*/
|
|
1075
1074
|
async requestUserApproval(permissionsRequest) {
|
|
1076
1075
|
const { origin, id } = permissionsRequest.metadata;
|
|
1077
|
-
const approvedRequest = await this.
|
|
1076
|
+
const approvedRequest = await this.messenger.call('ApprovalController:addRequest', {
|
|
1078
1077
|
id,
|
|
1079
1078
|
origin,
|
|
1080
1079
|
requestData: permissionsRequest,
|
|
@@ -1107,7 +1106,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1107
1106
|
}
|
|
1108
1107
|
/**
|
|
1109
1108
|
* Executes the side-effects of the approved permissions while handling the errors if any.
|
|
1110
|
-
* It will pass an instance of the {@link
|
|
1109
|
+
* It will pass an instance of the {@link messenger} and the request data associated with the permission request to the handlers through its params.
|
|
1111
1110
|
*
|
|
1112
1111
|
* @param sideEffects - the side-effect record created by {@link getSideEffects}
|
|
1113
1112
|
* @param requestData - the permissions requestData.
|
|
@@ -1117,7 +1116,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1117
1116
|
const { permittedHandlers, failureHandlers } = sideEffects;
|
|
1118
1117
|
const params = {
|
|
1119
1118
|
requestData,
|
|
1120
|
-
|
|
1119
|
+
messenger: this.messenger,
|
|
1121
1120
|
};
|
|
1122
1121
|
const promiseResults = await Promise.allSettled(Object.values(permittedHandlers).map((permittedHandler) => permittedHandler(params)));
|
|
1123
1122
|
// lib.es2020.promise.d.ts does not export its types so we're using a simple type.
|
|
@@ -1200,7 +1199,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1200
1199
|
return;
|
|
1201
1200
|
}
|
|
1202
1201
|
try {
|
|
1203
|
-
await this.
|
|
1202
|
+
await this.messenger.call('ApprovalController:acceptRequest', id, request);
|
|
1204
1203
|
}
|
|
1205
1204
|
catch (error) {
|
|
1206
1205
|
// If accepting unexpectedly fails, reject the request and re-throw the
|
|
@@ -1232,7 +1231,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1232
1231
|
* @returns Whether the specified request exists.
|
|
1233
1232
|
*/
|
|
1234
1233
|
hasApprovalRequest(options) {
|
|
1235
|
-
return this.
|
|
1234
|
+
return this.messenger.call('ApprovalController:hasRequest', options);
|
|
1236
1235
|
}
|
|
1237
1236
|
/**
|
|
1238
1237
|
* Rejects the permissions request with the specified id, with the specified
|
|
@@ -1246,7 +1245,7 @@ class PermissionController extends base_controller_1.BaseController {
|
|
|
1246
1245
|
* @returns Nothing
|
|
1247
1246
|
*/
|
|
1248
1247
|
_rejectPermissionsRequest(id, error) {
|
|
1249
|
-
return this.
|
|
1248
|
+
return this.messenger.call('ApprovalController:rejectRequest', id, error);
|
|
1250
1249
|
}
|
|
1251
1250
|
/**
|
|
1252
1251
|
* Gets the subject's endowments per the specified endowment permission.
|