@metamask/permission-controller 14.0.0 → 15.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 +44 -1
- package/dist/Permission.d.ts +9 -25
- package/dist/Permission.d.ts.map +1 -1
- package/dist/Permission.js.map +1 -1
- package/dist/PermissionController-method-action-types.d.ts +29 -14
- package/dist/PermissionController-method-action-types.d.ts.map +1 -1
- package/dist/PermissionController-method-action-types.js.map +1 -1
- package/dist/PermissionController.d.ts +20 -20
- package/dist/PermissionController.d.ts.map +1 -1
- package/dist/PermissionController.js +52 -20
- package/dist/PermissionController.js.map +1 -1
- package/dist/SubjectMetadataController.d.ts.map +1 -1
- package/dist/SubjectMetadataController.js +5 -1
- package/dist/SubjectMetadataController.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/permission-middleware.d.ts +10 -14
- package/dist/permission-middleware.d.ts.map +1 -1
- package/dist/permission-middleware.js +40 -13
- package/dist/permission-middleware.js.map +1 -1
- package/package.json +26 -26
|
@@ -16,7 +16,9 @@ const controllerName = 'PermissionController';
|
|
|
16
16
|
const MESSENGER_EXPOSED_METHODS = [
|
|
17
17
|
'clearState',
|
|
18
18
|
'executeRestrictedMethod',
|
|
19
|
-
'
|
|
19
|
+
'getEndowmentsGlobals',
|
|
20
|
+
'getEndowmentsRpcMethods',
|
|
21
|
+
'isEndowmentRpcMethod',
|
|
20
22
|
'getSubjectNames',
|
|
21
23
|
'getPermissions',
|
|
22
24
|
'hasPermission',
|
|
@@ -535,9 +537,6 @@ export class PermissionController extends BaseController {
|
|
|
535
537
|
if (permission.caveats) {
|
|
536
538
|
const caveatIndex = permission.caveats.findIndex((existingCaveat) => existingCaveat.type === caveat.type);
|
|
537
539
|
if (caveatIndex === -1) {
|
|
538
|
-
// This error appeared when upgrading to TypeScript 7.
|
|
539
|
-
// @ts-expect-error: TS2589: Type instantiation is excessively deep
|
|
540
|
-
// and possibly infinite.
|
|
541
540
|
permission.caveats.push(caveat);
|
|
542
541
|
addedCaveat = true;
|
|
543
542
|
}
|
|
@@ -707,7 +706,11 @@ export class PermissionController extends BaseController {
|
|
|
707
706
|
if (!this.#targetExists(permission.parentCapability)) {
|
|
708
707
|
throw new Error(`Fatal: Existing permission target "${permission.parentCapability}" has no specification.`);
|
|
709
708
|
}
|
|
710
|
-
this.#validatePermission(this.#getPermissionSpecification(permission.parentCapability),
|
|
709
|
+
this.#validatePermission(this.#getPermissionSpecification(permission.parentCapability),
|
|
710
|
+
/* oxlint-disable typescript/no-unnecessary-type-assertion */
|
|
711
|
+
permission,
|
|
712
|
+
/* oxlint-enable typescript/no-unnecessary-type-assertion */
|
|
713
|
+
origin, validationFlags);
|
|
711
714
|
}
|
|
712
715
|
/**
|
|
713
716
|
* Verifies the existence the specified permission target, i.e. whether it has
|
|
@@ -795,6 +798,7 @@ export class PermissionController extends BaseController {
|
|
|
795
798
|
}
|
|
796
799
|
// We have verified that the target exists, and reassign it to change its
|
|
797
800
|
// type.
|
|
801
|
+
// oxlint-disable-next-line typescript/no-unnecessary-type-assertion
|
|
798
802
|
const targetName = requestedTarget;
|
|
799
803
|
const specification = this.#getPermissionSpecification(targetName);
|
|
800
804
|
// The requested caveats are validated here.
|
|
@@ -1452,22 +1456,50 @@ export class PermissionController extends BaseController {
|
|
|
1452
1456
|
return this.messenger.call('ApprovalController:rejectRequest', id, error);
|
|
1453
1457
|
}
|
|
1454
1458
|
/**
|
|
1455
|
-
* Gets the
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1458
|
-
*
|
|
1459
|
-
* @
|
|
1460
|
-
* @param targetName - The name of the endowment permission. This must be a
|
|
1461
|
-
* valid permission target name.
|
|
1462
|
-
* @param requestData - Additional data associated with the request, if any.
|
|
1463
|
-
* Forwarded to the endowment getter function for the permission.
|
|
1464
|
-
* @returns The endowments, if any.
|
|
1459
|
+
* Gets the JavaScript globals tied to the endowment permissions for a
|
|
1460
|
+
* subject.
|
|
1461
|
+
*
|
|
1462
|
+
* @param origin - The origin of the subject whose globals to retrieve.
|
|
1463
|
+
* @returns The names of the globals, if any.
|
|
1465
1464
|
*/
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1465
|
+
getEndowmentsGlobals(origin) {
|
|
1466
|
+
const permissions = Object.values(this.getPermissions(origin) ?? {});
|
|
1467
|
+
return permissions.flatMap((permission) => {
|
|
1468
|
+
const specification = this.#getPermissionSpecification(permission.parentCapability);
|
|
1469
|
+
if (hasSpecificationType(specification, PermissionType.Endowment) &&
|
|
1470
|
+
specification.globals) {
|
|
1471
|
+
return specification.globals;
|
|
1472
|
+
}
|
|
1473
|
+
return [];
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Gets the RPC methods tied to the endowment permissions for a subject.
|
|
1478
|
+
*
|
|
1479
|
+
* @param origin - The origin of the subject whose RPC methods to retrieve.
|
|
1480
|
+
* @returns The RPC method names, if any.
|
|
1481
|
+
*/
|
|
1482
|
+
getEndowmentsRpcMethods(origin) {
|
|
1483
|
+
const permissions = Object.values(this.getPermissions(origin) ?? {});
|
|
1484
|
+
return permissions.flatMap((permission) => {
|
|
1485
|
+
const specification = this.#getPermissionSpecification(permission.parentCapability);
|
|
1486
|
+
if (hasSpecificationType(specification, PermissionType.Endowment) &&
|
|
1487
|
+
specification.rpcMethods) {
|
|
1488
|
+
return specification.rpcMethods;
|
|
1489
|
+
}
|
|
1490
|
+
return [];
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Checks whether an RPC method is tied to an endowment.
|
|
1495
|
+
*
|
|
1496
|
+
* @param method - The name of the RPC method.
|
|
1497
|
+
* @returns True if the RPC method is tied to an endowment, otherwise false.
|
|
1498
|
+
*/
|
|
1499
|
+
isEndowmentRpcMethod(method) {
|
|
1500
|
+
const specifications = Object.values(this.#permissionSpecifications);
|
|
1501
|
+
return specifications.some((specification) => hasSpecificationType(specification, PermissionType.Endowment) &&
|
|
1502
|
+
(specification.rpcMethods?.includes(method) ?? false));
|
|
1471
1503
|
}
|
|
1472
1504
|
/**
|
|
1473
1505
|
* Executes a restricted method as the subject with the given origin.
|