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