@metamask/permission-controller 12.2.1 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -6
- package/dist/Permission.cjs.map +1 -1
- package/dist/Permission.d.cts +9 -15
- package/dist/Permission.d.cts.map +1 -1
- package/dist/Permission.d.mts +9 -15
- package/dist/Permission.d.mts.map +1 -1
- package/dist/Permission.mjs.map +1 -1
- package/dist/PermissionController-method-action-types.cjs +7 -0
- package/dist/PermissionController-method-action-types.cjs.map +1 -0
- package/dist/PermissionController-method-action-types.d.cts +301 -0
- package/dist/PermissionController-method-action-types.d.cts.map +1 -0
- package/dist/PermissionController-method-action-types.d.mts +301 -0
- package/dist/PermissionController-method-action-types.d.mts.map +1 -0
- package/dist/PermissionController-method-action-types.mjs +6 -0
- package/dist/PermissionController-method-action-types.mjs.map +1 -0
- package/dist/PermissionController.cjs +41 -45
- package/dist/PermissionController.cjs.map +1 -1
- package/dist/PermissionController.d.cts +59 -33
- package/dist/PermissionController.d.cts.map +1 -1
- package/dist/PermissionController.d.mts +59 -33
- package/dist/PermissionController.d.mts.map +1 -1
- package/dist/PermissionController.mjs +41 -45
- package/dist/PermissionController.mjs.map +1 -1
- package/dist/SubjectMetadataController-method-action-types.cjs +7 -0
- package/dist/SubjectMetadataController-method-action-types.cjs.map +1 -0
- package/dist/SubjectMetadataController-method-action-types.d.cts +51 -0
- package/dist/SubjectMetadataController-method-action-types.d.cts.map +1 -0
- package/dist/SubjectMetadataController-method-action-types.d.mts +51 -0
- package/dist/SubjectMetadataController-method-action-types.d.mts.map +1 -0
- package/dist/SubjectMetadataController-method-action-types.mjs +6 -0
- package/dist/SubjectMetadataController-method-action-types.mjs.map +1 -0
- package/dist/SubjectMetadataController.cjs +7 -2
- package/dist/SubjectMetadataController.cjs.map +1 -1
- package/dist/SubjectMetadataController.d.cts +16 -4
- package/dist/SubjectMetadataController.d.cts.map +1 -1
- package/dist/SubjectMetadataController.d.mts +16 -4
- package/dist/SubjectMetadataController.d.mts.map +1 -1
- package/dist/SubjectMetadataController.mjs +7 -2
- package/dist/SubjectMetadataController.mjs.map +1 -1
- package/dist/createRestrictedMethodMessenger.cjs +20 -0
- package/dist/createRestrictedMethodMessenger.cjs.map +1 -0
- package/dist/createRestrictedMethodMessenger.d.cts +42 -0
- package/dist/createRestrictedMethodMessenger.d.cts.map +1 -0
- package/dist/createRestrictedMethodMessenger.d.mts +42 -0
- package/dist/createRestrictedMethodMessenger.d.mts.map +1 -0
- package/dist/createRestrictedMethodMessenger.mjs +16 -0
- package/dist/createRestrictedMethodMessenger.mjs.map +1 -0
- package/dist/index.cjs +6 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/permission-middleware.cjs +47 -43
- package/dist/permission-middleware.cjs.map +1 -1
- package/dist/permission-middleware.d.cts +40 -25
- package/dist/permission-middleware.d.cts.map +1 -1
- package/dist/permission-middleware.d.mts +40 -25
- package/dist/permission-middleware.d.mts.map +1 -1
- package/dist/permission-middleware.mjs +44 -41
- package/dist/permission-middleware.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +0 -23
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +0 -23
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +22 -19
- package/dist/rpc-methods/getPermissions.cjs +0 -27
- package/dist/rpc-methods/getPermissions.cjs.map +0 -1
- package/dist/rpc-methods/getPermissions.d.cts +0 -9
- package/dist/rpc-methods/getPermissions.d.cts.map +0 -1
- package/dist/rpc-methods/getPermissions.d.mts +0 -9
- package/dist/rpc-methods/getPermissions.d.mts.map +0 -1
- package/dist/rpc-methods/getPermissions.mjs +0 -24
- package/dist/rpc-methods/getPermissions.mjs.map +0 -1
- package/dist/rpc-methods/index.cjs +0 -12
- package/dist/rpc-methods/index.cjs.map +0 -1
- package/dist/rpc-methods/index.d.cts +0 -6
- package/dist/rpc-methods/index.d.cts.map +0 -1
- package/dist/rpc-methods/index.d.mts +0 -6
- package/dist/rpc-methods/index.d.mts.map +0 -1
- package/dist/rpc-methods/index.mjs +0 -9
- package/dist/rpc-methods/index.mjs.map +0 -1
- package/dist/rpc-methods/requestPermissions.cjs +0 -36
- package/dist/rpc-methods/requestPermissions.cjs.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.cts +0 -17
- package/dist/rpc-methods/requestPermissions.d.cts.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.mts +0 -17
- package/dist/rpc-methods/requestPermissions.d.mts.map +0 -1
- package/dist/rpc-methods/requestPermissions.mjs +0 -33
- package/dist/rpc-methods/requestPermissions.mjs.map +0 -1
- package/dist/rpc-methods/revokePermissions.cjs +0 -41
- package/dist/rpc-methods/revokePermissions.cjs.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.cts +0 -11
- package/dist/rpc-methods/revokePermissions.d.cts.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.mts +0 -11
- package/dist/rpc-methods/revokePermissions.d.mts.map +0 -1
- package/dist/rpc-methods/revokePermissions.mjs +0 -38
- package/dist/rpc-methods/revokePermissions.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -10,29 +10,21 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
17
|
+
exports.MethodNames = exports.createPermissionMiddlewareV2 = exports.createPermissionMiddleware = exports.createRestrictedMethodMessenger = void 0;
|
|
30
18
|
__exportStar(require("./Caveat.cjs"), exports);
|
|
19
|
+
var createRestrictedMethodMessenger_1 = require("./createRestrictedMethodMessenger.cjs");
|
|
20
|
+
Object.defineProperty(exports, "createRestrictedMethodMessenger", { enumerable: true, get: function () { return createRestrictedMethodMessenger_1.createRestrictedMethodMessenger; } });
|
|
31
21
|
__exportStar(require("./errors.cjs"), exports);
|
|
32
22
|
__exportStar(require("./Permission.cjs"), exports);
|
|
33
23
|
__exportStar(require("./PermissionController.cjs"), exports);
|
|
24
|
+
var permission_middleware_1 = require("./permission-middleware.cjs");
|
|
25
|
+
Object.defineProperty(exports, "createPermissionMiddleware", { enumerable: true, get: function () { return permission_middleware_1.createPermissionMiddleware; } });
|
|
26
|
+
Object.defineProperty(exports, "createPermissionMiddlewareV2", { enumerable: true, get: function () { return permission_middleware_1.createPermissionMiddlewareV2; } });
|
|
34
27
|
var utils_1 = require("./utils.cjs");
|
|
35
28
|
Object.defineProperty(exports, "MethodNames", { enumerable: true, get: function () { return utils_1.MethodNames; } });
|
|
36
|
-
exports.permissionRpcMethods = __importStar(require("./rpc-methods/index.cjs"));
|
|
37
29
|
__exportStar(require("./SubjectMetadataController.cjs"), exports);
|
|
38
30
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyB;AACzB,yFAAoF;AAA3E,kJAAA,+BAA+B,OAAA;AACxC,+CAAyB;AACzB,mDAA6B;AAC7B,6DAAuC;AAoBvC,qEAIiC;AAH/B,mIAAA,0BAA0B,OAAA;AAC1B,qIAAA,4BAA4B,OAAA;AAI9B,qCAAsC;AAA7B,oGAAA,WAAW,OAAA;AACpB,kEAA4C","sourcesContent":["export * from './Caveat';\nexport { createRestrictedMethodMessenger } from './createRestrictedMethodMessenger';\nexport * from './errors';\nexport * from './Permission';\nexport * from './PermissionController';\nexport type {\n PermissionControllerClearStateAction,\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerGetCaveatAction,\n PermissionControllerGetEndowmentsAction,\n PermissionControllerGetPermissionsAction,\n PermissionControllerGetSubjectNamesAction,\n PermissionControllerGrantPermissionsAction,\n PermissionControllerGrantPermissionsIncrementalAction,\n PermissionControllerHasPermissionAction,\n PermissionControllerHasPermissionsAction,\n PermissionControllerHasUnrestrictedMethodAction,\n PermissionControllerRequestPermissionsAction,\n PermissionControllerRequestPermissionsIncrementalAction,\n PermissionControllerRevokeAllPermissionsAction,\n PermissionControllerRevokePermissionForAllSubjectsAction,\n PermissionControllerRevokePermissionsAction,\n PermissionControllerUpdateCaveatAction,\n} from './PermissionController-method-action-types';\nexport {\n createPermissionMiddleware,\n createPermissionMiddlewareV2,\n type PermissionMiddlewareActions,\n} from './permission-middleware';\nexport type { ExtractSpecifications } from './utils';\nexport { MethodNames } from './utils';\nexport * from './SubjectMetadataController';\nexport type {\n SubjectMetadataControllerClearStateAction,\n SubjectMetadataControllerAddSubjectMetadataAction,\n SubjectMetadataControllerGetSubjectMetadataAction,\n SubjectMetadataControllerTrimMetadataStateAction,\n} from './SubjectMetadataController-method-action-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from "./Caveat.cjs";
|
|
2
|
+
export { createRestrictedMethodMessenger } from "./createRestrictedMethodMessenger.cjs";
|
|
2
3
|
export * from "./errors.cjs";
|
|
3
4
|
export * from "./Permission.cjs";
|
|
4
5
|
export * from "./PermissionController.cjs";
|
|
5
|
-
export type {
|
|
6
|
+
export type { PermissionControllerClearStateAction, PermissionControllerExecuteRestrictedMethodAction, PermissionControllerGetCaveatAction, PermissionControllerGetEndowmentsAction, PermissionControllerGetPermissionsAction, PermissionControllerGetSubjectNamesAction, PermissionControllerGrantPermissionsAction, PermissionControllerGrantPermissionsIncrementalAction, PermissionControllerHasPermissionAction, PermissionControllerHasPermissionsAction, PermissionControllerHasUnrestrictedMethodAction, PermissionControllerRequestPermissionsAction, PermissionControllerRequestPermissionsIncrementalAction, PermissionControllerRevokeAllPermissionsAction, PermissionControllerRevokePermissionForAllSubjectsAction, PermissionControllerRevokePermissionsAction, PermissionControllerUpdateCaveatAction, } from "./PermissionController-method-action-types.cjs";
|
|
7
|
+
export { createPermissionMiddleware, createPermissionMiddlewareV2, type PermissionMiddlewareActions, } from "./permission-middleware.cjs";
|
|
8
|
+
export type { ExtractSpecifications } from "./utils.cjs";
|
|
6
9
|
export { MethodNames } from "./utils.cjs";
|
|
7
|
-
export * as permissionRpcMethods from "./rpc-methods/index.cjs";
|
|
8
10
|
export * from "./SubjectMetadataController.cjs";
|
|
11
|
+
export type { SubjectMetadataControllerClearStateAction, SubjectMetadataControllerAddSubjectMetadataAction, SubjectMetadataControllerGetSubjectMetadataAction, SubjectMetadataControllerTrimMetadataStateAction, } from "./SubjectMetadataController-method-action-types.cjs";
|
|
9
12
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;AACvC,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,OAAO,EAAE,+BAA+B,EAAE,8CAA0C;AACpF,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;AACvC,YAAY,EACV,oCAAoC,EACpC,iDAAiD,EACjD,mCAAmC,EACnC,uCAAuC,EACvC,wCAAwC,EACxC,yCAAyC,EACzC,0CAA0C,EAC1C,qDAAqD,EACrD,uCAAuC,EACvC,wCAAwC,EACxC,+CAA+C,EAC/C,4CAA4C,EAC5C,uDAAuD,EACvD,8CAA8C,EAC9C,wDAAwD,EACxD,2CAA2C,EAC3C,sCAAsC,GACvC,uDAAmD;AACpD,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,KAAK,2BAA2B,GACjC,oCAAgC;AACjC,YAAY,EAAE,qBAAqB,EAAE,oBAAgB;AACrD,OAAO,EAAE,WAAW,EAAE,oBAAgB;AACtC,gDAA4C;AAC5C,YAAY,EACV,yCAAyC,EACzC,iDAAiD,EACjD,iDAAiD,EACjD,gDAAgD,GACjD,4DAAwD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from "./Caveat.mjs";
|
|
2
|
+
export { createRestrictedMethodMessenger } from "./createRestrictedMethodMessenger.mjs";
|
|
2
3
|
export * from "./errors.mjs";
|
|
3
4
|
export * from "./Permission.mjs";
|
|
4
5
|
export * from "./PermissionController.mjs";
|
|
5
|
-
export type {
|
|
6
|
+
export type { PermissionControllerClearStateAction, PermissionControllerExecuteRestrictedMethodAction, PermissionControllerGetCaveatAction, PermissionControllerGetEndowmentsAction, PermissionControllerGetPermissionsAction, PermissionControllerGetSubjectNamesAction, PermissionControllerGrantPermissionsAction, PermissionControllerGrantPermissionsIncrementalAction, PermissionControllerHasPermissionAction, PermissionControllerHasPermissionsAction, PermissionControllerHasUnrestrictedMethodAction, PermissionControllerRequestPermissionsAction, PermissionControllerRequestPermissionsIncrementalAction, PermissionControllerRevokeAllPermissionsAction, PermissionControllerRevokePermissionForAllSubjectsAction, PermissionControllerRevokePermissionsAction, PermissionControllerUpdateCaveatAction, } from "./PermissionController-method-action-types.mjs";
|
|
7
|
+
export { createPermissionMiddleware, createPermissionMiddlewareV2, type PermissionMiddlewareActions, } from "./permission-middleware.mjs";
|
|
8
|
+
export type { ExtractSpecifications } from "./utils.mjs";
|
|
6
9
|
export { MethodNames } from "./utils.mjs";
|
|
7
|
-
export * as permissionRpcMethods from "./rpc-methods/index.mjs";
|
|
8
10
|
export * from "./SubjectMetadataController.mjs";
|
|
11
|
+
export type { SubjectMetadataControllerClearStateAction, SubjectMetadataControllerAddSubjectMetadataAction, SubjectMetadataControllerGetSubjectMetadataAction, SubjectMetadataControllerTrimMetadataStateAction, } from "./SubjectMetadataController-method-action-types.mjs";
|
|
9
12
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;AACvC,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,OAAO,EAAE,+BAA+B,EAAE,8CAA0C;AACpF,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;AACvC,YAAY,EACV,oCAAoC,EACpC,iDAAiD,EACjD,mCAAmC,EACnC,uCAAuC,EACvC,wCAAwC,EACxC,yCAAyC,EACzC,0CAA0C,EAC1C,qDAAqD,EACrD,uCAAuC,EACvC,wCAAwC,EACxC,+CAA+C,EAC/C,4CAA4C,EAC5C,uDAAuD,EACvD,8CAA8C,EAC9C,wDAAwD,EACxD,2CAA2C,EAC3C,sCAAsC,GACvC,uDAAmD;AACpD,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,KAAK,2BAA2B,GACjC,oCAAgC;AACjC,YAAY,EAAE,qBAAqB,EAAE,oBAAgB;AACrD,OAAO,EAAE,WAAW,EAAE,oBAAgB;AACtC,gDAA4C;AAC5C,YAAY,EACV,yCAAyC,EACzC,iDAAiD,EACjD,iDAAiD,EACjD,gDAAgD,GACjD,4DAAwD"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from "./Caveat.mjs";
|
|
2
|
+
export { createRestrictedMethodMessenger } from "./createRestrictedMethodMessenger.mjs";
|
|
2
3
|
export * from "./errors.mjs";
|
|
3
4
|
export * from "./Permission.mjs";
|
|
4
5
|
export * from "./PermissionController.mjs";
|
|
6
|
+
export { createPermissionMiddleware, createPermissionMiddlewareV2 } from "./permission-middleware.mjs";
|
|
5
7
|
export { MethodNames } from "./utils.mjs";
|
|
6
|
-
export * as permissionRpcMethods from "./rpc-methods/index.mjs";
|
|
7
8
|
export * from "./SubjectMetadataController.mjs";
|
|
8
9
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,OAAO,EAAE,+BAA+B,EAAE,8CAA0C;AACpF,6BAAyB;AACzB,iCAA6B;AAC7B,2CAAuC;AAoBvC,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAE7B,oCAAgC;AAEjC,OAAO,EAAE,WAAW,EAAE,oBAAgB;AACtC,gDAA4C","sourcesContent":["export * from './Caveat';\nexport { createRestrictedMethodMessenger } from './createRestrictedMethodMessenger';\nexport * from './errors';\nexport * from './Permission';\nexport * from './PermissionController';\nexport type {\n PermissionControllerClearStateAction,\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerGetCaveatAction,\n PermissionControllerGetEndowmentsAction,\n PermissionControllerGetPermissionsAction,\n PermissionControllerGetSubjectNamesAction,\n PermissionControllerGrantPermissionsAction,\n PermissionControllerGrantPermissionsIncrementalAction,\n PermissionControllerHasPermissionAction,\n PermissionControllerHasPermissionsAction,\n PermissionControllerHasUnrestrictedMethodAction,\n PermissionControllerRequestPermissionsAction,\n PermissionControllerRequestPermissionsIncrementalAction,\n PermissionControllerRevokeAllPermissionsAction,\n PermissionControllerRevokePermissionForAllSubjectsAction,\n PermissionControllerRevokePermissionsAction,\n PermissionControllerUpdateCaveatAction,\n} from './PermissionController-method-action-types';\nexport {\n createPermissionMiddleware,\n createPermissionMiddlewareV2,\n type PermissionMiddlewareActions,\n} from './permission-middleware';\nexport type { ExtractSpecifications } from './utils';\nexport { MethodNames } from './utils';\nexport * from './SubjectMetadataController';\nexport type {\n SubjectMetadataControllerClearStateAction,\n SubjectMetadataControllerAddSubjectMetadataAction,\n SubjectMetadataControllerGetSubjectMetadataAction,\n SubjectMetadataControllerTrimMetadataStateAction,\n} from './SubjectMetadataController-method-action-types';\n"]}
|
|
@@ -1,55 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createPermissionMiddlewareV2 = exports.createPermissionMiddleware = void 0;
|
|
4
4
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
|
-
const errors_1 = require("./errors.cjs");
|
|
6
5
|
/**
|
|
7
|
-
* Creates a
|
|
8
|
-
* in the {@link PermissionController}. Like any {@link JsonRpcEngine}
|
|
9
|
-
* middleware, each middleware will only receive requests from a particular
|
|
10
|
-
* subject / origin. However, each middleware also requires access to some
|
|
11
|
-
* `PermissionController` internals, which is why this "factory factory" exists.
|
|
6
|
+
* Creates a JSON-RPC middleware that enforces permissions for a single subject.
|
|
12
7
|
*
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* If a method is restricted, the middleware will first attempt to retrieve the
|
|
18
|
-
* subject's permission for that method. If the permission is found, the method
|
|
19
|
-
* will be executed. Otherwise, an "unauthorized" error will be returned.
|
|
8
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
9
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
10
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
11
|
+
* the corresponding error is propagated to the JSON-RPC response.
|
|
20
12
|
*
|
|
13
|
+
* @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.
|
|
21
14
|
* @param options - Options bag.
|
|
22
|
-
* @param options.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @returns A
|
|
15
|
+
* @param options.messenger - A messenger with the
|
|
16
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
17
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
18
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
19
|
+
* @returns A `json-rpc-engine` middleware.
|
|
27
20
|
*/
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
if (
|
|
32
|
-
|
|
21
|
+
function createPermissionMiddleware({ messenger, origin, }) {
|
|
22
|
+
const permissionsMiddleware = async (request, response, next) => {
|
|
23
|
+
const { method, params } = request;
|
|
24
|
+
if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {
|
|
25
|
+
return next();
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Skip registered unrestricted methods.
|
|
37
|
-
if (isUnrestrictedMethod(method)) {
|
|
38
|
-
return next();
|
|
39
|
-
}
|
|
40
|
-
// This will throw if no restricted method implementation is found.
|
|
41
|
-
const methodImplementation = getRestrictedMethod(method, origin);
|
|
42
|
-
// This will throw if the permission does not exist.
|
|
43
|
-
const result = await executeRestrictedMethod(methodImplementation, subject, method, params);
|
|
44
|
-
if (result === undefined) {
|
|
45
|
-
res.error = (0, errors_1.internalError)(`Request for method "${req.method}" returned undefined result.`, { request: req });
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
res.result = result;
|
|
49
|
-
return undefined;
|
|
50
|
-
};
|
|
51
|
-
return (0, json_rpc_engine_1.createAsyncMiddleware)(permissionsMiddleware);
|
|
27
|
+
response.result = await messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
|
|
28
|
+
return undefined;
|
|
52
29
|
};
|
|
30
|
+
return (0, json_rpc_engine_1.createAsyncMiddleware)(permissionsMiddleware);
|
|
53
31
|
}
|
|
54
|
-
exports.
|
|
32
|
+
exports.createPermissionMiddleware = createPermissionMiddleware;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a `JsonRpcEngineV2` middleware that enforces permissions for a
|
|
35
|
+
* single subject.
|
|
36
|
+
*
|
|
37
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
38
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
39
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
40
|
+
* the corresponding error is thrown.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Options bag.
|
|
43
|
+
* @param options.messenger - A messenger with the
|
|
44
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
45
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
46
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
47
|
+
* @returns A `JsonRpcEngineV2` middleware.
|
|
48
|
+
*/
|
|
49
|
+
function createPermissionMiddlewareV2({ messenger, origin, }) {
|
|
50
|
+
return async ({ request, next }) => {
|
|
51
|
+
const { method, params } = request;
|
|
52
|
+
if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {
|
|
53
|
+
return next();
|
|
54
|
+
}
|
|
55
|
+
return messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.createPermissionMiddlewareV2 = createPermissionMiddlewareV2;
|
|
55
59
|
//# sourceMappingURL=permission-middleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission-middleware.cjs","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":";;;AAAA,+DAAkE;
|
|
1
|
+
{"version":3,"file":"permission-middleware.cjs","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":";;;AAAA,+DAAkE;AA+BlE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GAC4B;IAIlC,MAAM,qBAAqB,GAAG,KAAK,EACjC,OAAmD,EACnD,QAAgC,EAChC,IAAoC,EACrB,EAAE;QACjB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,QAAQ,CAAC,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CACpC,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,IAAA,uCAAqB,EAAC,qBAAqB,CAAC,CAAC;AACtD,CAAC;AA5BD,gEA4BC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GAC4B;IAClC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,SAAS,CAAC,IAAI,CACnB,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAlBD,oEAkBC","sourcesContent":["import { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n AsyncJsonRpcEngineNextCallback,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from '@metamask/json-rpc-engine/v2';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { RestrictedMethodParameters } from './Permission';\nimport type {\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerHasUnrestrictedMethodAction,\n} from './PermissionController-method-action-types';\n\n/**\n * The set of messenger actions required by the permission middleware.\n */\nexport type PermissionMiddlewareActions =\n | PermissionControllerExecuteRestrictedMethodAction\n | PermissionControllerHasUnrestrictedMethodAction;\n\nexport type CreatePermissionMiddlewareOptions = {\n messenger: Messenger<string, PermissionMiddlewareActions>;\n origin: string;\n};\n\n/**\n * Creates a JSON-RPC middleware that enforces permissions for a single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is propagated to the JSON-RPC response.\n *\n * @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `json-rpc-engine` middleware.\n */\nexport function createPermissionMiddleware({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddleware<\n RestrictedMethodParameters,\n Json\n> {\n const permissionsMiddleware = async (\n request: JsonRpcRequest<RestrictedMethodParameters>,\n response: PendingJsonRpcResponse,\n next: AsyncJsonRpcEngineNextCallback,\n ): Promise<void> => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n response.result = await messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n return undefined;\n };\n\n return createAsyncMiddleware(permissionsMiddleware);\n}\n\n/**\n * Creates a `JsonRpcEngineV2` middleware that enforces permissions for a\n * single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is thrown.\n *\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `JsonRpcEngineV2` middleware.\n */\nexport function createPermissionMiddlewareV2({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2 {\n return async ({ request, next }) => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n return messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n };\n}\n"]}
|
|
@@ -1,34 +1,49 @@
|
|
|
1
1
|
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
4
|
import type { Json } from "@metamask/utils";
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import type { RestrictedMethodParameters } from "./Permission.cjs";
|
|
6
|
+
import type { PermissionControllerExecuteRestrictedMethodAction, PermissionControllerHasUnrestrictedMethodAction } from "./PermissionController-method-action-types.cjs";
|
|
7
|
+
/**
|
|
8
|
+
* The set of messenger actions required by the permission middleware.
|
|
9
|
+
*/
|
|
10
|
+
export type PermissionMiddlewareActions = PermissionControllerExecuteRestrictedMethodAction | PermissionControllerHasUnrestrictedMethodAction;
|
|
11
|
+
export type CreatePermissionMiddlewareOptions = {
|
|
12
|
+
messenger: Messenger<string, PermissionMiddlewareActions>;
|
|
13
|
+
origin: string;
|
|
9
14
|
};
|
|
10
15
|
/**
|
|
11
|
-
* Creates a
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Creates a JSON-RPC middleware that enforces permissions for a single subject.
|
|
17
|
+
*
|
|
18
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
19
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
20
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
21
|
+
* the corresponding error is propagated to the JSON-RPC response.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.
|
|
24
|
+
* @param options - Options bag.
|
|
25
|
+
* @param options.messenger - A messenger with the
|
|
26
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
27
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
28
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
29
|
+
* @returns A `json-rpc-engine` middleware.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPermissionMiddleware({ messenger, origin, }: CreatePermissionMiddlewareOptions): JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a `JsonRpcEngineV2` middleware that enforces permissions for a
|
|
34
|
+
* single subject.
|
|
16
35
|
*
|
|
17
|
-
* The
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* If a method is restricted, the middleware will first attempt to retrieve the
|
|
22
|
-
* subject's permission for that method. If the permission is found, the method
|
|
23
|
-
* will be executed. Otherwise, an "unauthorized" error will be returned.
|
|
36
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
37
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
38
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
39
|
+
* the corresponding error is thrown.
|
|
24
40
|
*
|
|
25
41
|
* @param options - Options bag.
|
|
26
|
-
* @param options.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @returns A
|
|
42
|
+
* @param options.messenger - A messenger with the
|
|
43
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
44
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
45
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
46
|
+
* @returns A `JsonRpcEngineV2` middleware.
|
|
31
47
|
*/
|
|
32
|
-
export declare function
|
|
33
|
-
export {};
|
|
48
|
+
export declare function createPermissionMiddlewareV2({ messenger, origin, }: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2;
|
|
34
49
|
//# sourceMappingURL=permission-middleware.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission-middleware.d.cts","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"permission-middleware.d.cts","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,iBAAiB,EAClB,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,IAAI,mBAAmB,EAAE,qCAAqC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,IAAI,EAGL,wBAAwB;AAEzB,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EACV,iDAAiD,EACjD,+CAA+C,EAChD,uDAAmD;AAEpD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,iDAAiD,GACjD,+CAA+C,CAAC;AAEpD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IAC1D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,iBAAiB,CACtD,0BAA0B,EAC1B,IAAI,CACL,CAsBA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,mBAAmB,CAezD"}
|
|
@@ -1,34 +1,49 @@
|
|
|
1
1
|
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
4
|
import type { Json } from "@metamask/utils";
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import type { RestrictedMethodParameters } from "./Permission.mjs";
|
|
6
|
+
import type { PermissionControllerExecuteRestrictedMethodAction, PermissionControllerHasUnrestrictedMethodAction } from "./PermissionController-method-action-types.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* The set of messenger actions required by the permission middleware.
|
|
9
|
+
*/
|
|
10
|
+
export type PermissionMiddlewareActions = PermissionControllerExecuteRestrictedMethodAction | PermissionControllerHasUnrestrictedMethodAction;
|
|
11
|
+
export type CreatePermissionMiddlewareOptions = {
|
|
12
|
+
messenger: Messenger<string, PermissionMiddlewareActions>;
|
|
13
|
+
origin: string;
|
|
9
14
|
};
|
|
10
15
|
/**
|
|
11
|
-
* Creates a
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Creates a JSON-RPC middleware that enforces permissions for a single subject.
|
|
17
|
+
*
|
|
18
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
19
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
20
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
21
|
+
* the corresponding error is propagated to the JSON-RPC response.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.
|
|
24
|
+
* @param options - Options bag.
|
|
25
|
+
* @param options.messenger - A messenger with the
|
|
26
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
27
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
28
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
29
|
+
* @returns A `json-rpc-engine` middleware.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPermissionMiddleware({ messenger, origin, }: CreatePermissionMiddlewareOptions): JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a `JsonRpcEngineV2` middleware that enforces permissions for a
|
|
34
|
+
* single subject.
|
|
16
35
|
*
|
|
17
|
-
* The
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* If a method is restricted, the middleware will first attempt to retrieve the
|
|
22
|
-
* subject's permission for that method. If the permission is found, the method
|
|
23
|
-
* will be executed. Otherwise, an "unauthorized" error will be returned.
|
|
36
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
37
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
38
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
39
|
+
* the corresponding error is thrown.
|
|
24
40
|
*
|
|
25
41
|
* @param options - Options bag.
|
|
26
|
-
* @param options.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @returns A
|
|
42
|
+
* @param options.messenger - A messenger with the
|
|
43
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
44
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
45
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
46
|
+
* @returns A `JsonRpcEngineV2` middleware.
|
|
31
47
|
*/
|
|
32
|
-
export declare function
|
|
33
|
-
export {};
|
|
48
|
+
export declare function createPermissionMiddlewareV2({ messenger, origin, }: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2;
|
|
34
49
|
//# sourceMappingURL=permission-middleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission-middleware.d.mts","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"permission-middleware.d.mts","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,iBAAiB,EAClB,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,IAAI,mBAAmB,EAAE,qCAAqC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,IAAI,EAGL,wBAAwB;AAEzB,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EACV,iDAAiD,EACjD,+CAA+C,EAChD,uDAAmD;AAEpD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,iDAAiD,GACjD,+CAA+C,CAAC;AAEpD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IAC1D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,iBAAiB,CACtD,0BAA0B,EAC1B,IAAI,CACL,CAsBA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,mBAAmB,CAezD"}
|
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import { internalError } from "./errors.mjs";
|
|
3
2
|
/**
|
|
4
|
-
* Creates a
|
|
5
|
-
* in the {@link PermissionController}. Like any {@link JsonRpcEngine}
|
|
6
|
-
* middleware, each middleware will only receive requests from a particular
|
|
7
|
-
* subject / origin. However, each middleware also requires access to some
|
|
8
|
-
* `PermissionController` internals, which is why this "factory factory" exists.
|
|
3
|
+
* Creates a JSON-RPC middleware that enforces permissions for a single subject.
|
|
9
4
|
*
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* If a method is restricted, the middleware will first attempt to retrieve the
|
|
15
|
-
* subject's permission for that method. If the permission is found, the method
|
|
16
|
-
* will be executed. Otherwise, an "unauthorized" error will be returned.
|
|
5
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
6
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
7
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
8
|
+
* the corresponding error is propagated to the JSON-RPC response.
|
|
17
9
|
*
|
|
10
|
+
* @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.
|
|
18
11
|
* @param options - Options bag.
|
|
19
|
-
* @param options.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @returns A
|
|
12
|
+
* @param options.messenger - A messenger with the
|
|
13
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
14
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
15
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
16
|
+
* @returns A `json-rpc-engine` middleware.
|
|
24
17
|
*/
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
if (
|
|
29
|
-
|
|
18
|
+
export function createPermissionMiddleware({ messenger, origin, }) {
|
|
19
|
+
const permissionsMiddleware = async (request, response, next) => {
|
|
20
|
+
const { method, params } = request;
|
|
21
|
+
if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {
|
|
22
|
+
return next();
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
24
|
+
response.result = await messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
return createAsyncMiddleware(permissionsMiddleware);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a `JsonRpcEngineV2` middleware that enforces permissions for a
|
|
31
|
+
* single subject.
|
|
32
|
+
*
|
|
33
|
+
* The middleware passes through unrestricted methods, and otherwise dispatches
|
|
34
|
+
* restricted methods to the `PermissionController` via messenger actions. If
|
|
35
|
+
* the subject lacks the required permission, or if the method does not exist,
|
|
36
|
+
* the corresponding error is thrown.
|
|
37
|
+
*
|
|
38
|
+
* @param options - Options bag.
|
|
39
|
+
* @param options.messenger - A messenger with the
|
|
40
|
+
* `PermissionController:executeRestrictedMethod` and
|
|
41
|
+
* `PermissionController:hasUnrestrictedMethod` actions.
|
|
42
|
+
* @param options.origin - The origin of the subject for which to create the middleware.
|
|
43
|
+
* @returns A `JsonRpcEngineV2` middleware.
|
|
44
|
+
*/
|
|
45
|
+
export function createPermissionMiddlewareV2({ messenger, origin, }) {
|
|
46
|
+
return async ({ request, next }) => {
|
|
47
|
+
const { method, params } = request;
|
|
48
|
+
if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
return messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
//# sourceMappingURL=permission-middleware.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission-middleware.mjs","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"permission-middleware.mjs","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kCAAkC;AA+BlE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GAC4B;IAIlC,MAAM,qBAAqB,GAAG,KAAK,EACjC,OAAmD,EACnD,QAAgC,EAChC,IAAoC,EACrB,EAAE;QACjB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,QAAQ,CAAC,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CACpC,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GAC4B;IAClC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,SAAS,CAAC,IAAI,CACnB,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n AsyncJsonRpcEngineNextCallback,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from '@metamask/json-rpc-engine/v2';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { RestrictedMethodParameters } from './Permission';\nimport type {\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerHasUnrestrictedMethodAction,\n} from './PermissionController-method-action-types';\n\n/**\n * The set of messenger actions required by the permission middleware.\n */\nexport type PermissionMiddlewareActions =\n | PermissionControllerExecuteRestrictedMethodAction\n | PermissionControllerHasUnrestrictedMethodAction;\n\nexport type CreatePermissionMiddlewareOptions = {\n messenger: Messenger<string, PermissionMiddlewareActions>;\n origin: string;\n};\n\n/**\n * Creates a JSON-RPC middleware that enforces permissions for a single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is propagated to the JSON-RPC response.\n *\n * @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `json-rpc-engine` middleware.\n */\nexport function createPermissionMiddleware({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddleware<\n RestrictedMethodParameters,\n Json\n> {\n const permissionsMiddleware = async (\n request: JsonRpcRequest<RestrictedMethodParameters>,\n response: PendingJsonRpcResponse,\n next: AsyncJsonRpcEngineNextCallback,\n ): Promise<void> => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n response.result = await messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n return undefined;\n };\n\n return createAsyncMiddleware(permissionsMiddleware);\n}\n\n/**\n * Creates a `JsonRpcEngineV2` middleware that enforces permissions for a\n * single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is thrown.\n *\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `JsonRpcEngineV2` middleware.\n */\nexport function createPermissionMiddlewareV2({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2 {\n return async ({ request, next }) => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n return messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n };\n}\n"]}
|