@metamask/permission-controller 8.0.1 → 9.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 +23 -1
- package/dist/Caveat.js +11 -56
- package/dist/Caveat.js.map +1 -1
- package/dist/Caveat.mjs +12 -0
- package/dist/Caveat.mjs.map +1 -0
- package/dist/Permission.js +13 -65
- package/dist/Permission.js.map +1 -1
- package/dist/Permission.mjs +14 -0
- package/dist/Permission.mjs.map +1 -0
- package/dist/PermissionController.js +14 -1294
- package/dist/PermissionController.js.map +1 -1
- package/dist/PermissionController.mjs +15 -0
- package/dist/PermissionController.mjs.map +1 -0
- package/dist/SubjectMetadataController.js +9 -143
- package/dist/SubjectMetadataController.js.map +1 -1
- package/dist/SubjectMetadataController.mjs +10 -0
- package/dist/SubjectMetadataController.mjs.map +1 -0
- package/dist/chunk-4D2RVWNF.mjs +154 -0
- package/dist/chunk-4D2RVWNF.mjs.map +1 -0
- package/dist/chunk-5C5SZO74.mjs +29 -0
- package/dist/chunk-5C5SZO74.mjs.map +1 -0
- package/dist/chunk-5L2IOZE2.js +1393 -0
- package/dist/chunk-5L2IOZE2.js.map +1 -0
- package/dist/chunk-6CID6TBW.js +31 -0
- package/dist/chunk-6CID6TBW.js.map +1 -0
- package/dist/chunk-73M67Z5X.mjs +17 -0
- package/dist/chunk-73M67Z5X.mjs.map +1 -0
- package/dist/chunk-7CTPRFQ3.js +29 -0
- package/dist/chunk-7CTPRFQ3.js.map +1 -0
- package/dist/chunk-AQ35E2HU.js +46 -0
- package/dist/chunk-AQ35E2HU.js.map +1 -0
- package/dist/chunk-BEQEQLRE.mjs +34 -0
- package/dist/chunk-BEQEQLRE.mjs.map +1 -0
- package/dist/chunk-CSAU5B4Q.js +10 -0
- package/dist/chunk-CSAU5B4Q.js.map +1 -0
- package/dist/chunk-CXKOMB77.mjs +1393 -0
- package/dist/chunk-CXKOMB77.mjs.map +1 -0
- package/dist/chunk-EGNDXGRG.js +37 -0
- package/dist/chunk-EGNDXGRG.js.map +1 -0
- package/dist/chunk-FEXS6SJF.mjs +192 -0
- package/dist/chunk-FEXS6SJF.mjs.map +1 -0
- package/dist/chunk-HRDKMOYS.js +17 -0
- package/dist/chunk-HRDKMOYS.js.map +1 -0
- package/dist/chunk-K5R57Y57.js +12 -0
- package/dist/chunk-K5R57Y57.js.map +1 -0
- package/dist/chunk-KVKKNDYV.mjs +12 -0
- package/dist/chunk-KVKKNDYV.mjs.map +1 -0
- package/dist/chunk-N4KQ2BHF.mjs +46 -0
- package/dist/chunk-N4KQ2BHF.mjs.map +1 -0
- package/dist/chunk-ODCVB4BB.mjs +31 -0
- package/dist/chunk-ODCVB4BB.mjs.map +1 -0
- package/dist/chunk-SFKE5HHK.js +154 -0
- package/dist/chunk-SFKE5HHK.js.map +1 -0
- package/dist/chunk-U5LTEXSU.js +192 -0
- package/dist/chunk-U5LTEXSU.js.map +1 -0
- package/dist/chunk-XBFHEZRU.mjs +37 -0
- package/dist/chunk-XBFHEZRU.mjs.map +1 -0
- package/dist/chunk-YRNH4R3G.js +30 -0
- package/dist/chunk-YRNH4R3G.js.map +1 -0
- package/dist/chunk-YVXIWLBE.mjs +30 -0
- package/dist/chunk-YVXIWLBE.mjs.map +1 -0
- package/dist/chunk-ZSTKOCBT.mjs +10 -0
- package/dist/chunk-ZSTKOCBT.mjs.map +1 -0
- package/dist/chunk-ZVO26XPN.js +34 -0
- package/dist/chunk-ZVO26XPN.js.map +1 -0
- package/dist/errors.js +51 -195
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +52 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.js +91 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -0
- package/dist/index.mjs.map +1 -0
- package/dist/permission-middleware.js +8 -63
- package/dist/permission-middleware.js.map +1 -1
- package/dist/permission-middleware.mjs +9 -0
- package/dist/permission-middleware.mjs.map +1 -0
- package/dist/rpc-methods/getPermissions.js +8 -37
- package/dist/rpc-methods/getPermissions.js.map +1 -1
- package/dist/rpc-methods/getPermissions.mjs +9 -0
- package/dist/rpc-methods/getPermissions.mjs.map +1 -0
- package/dist/rpc-methods/index.js +12 -11
- package/dist/rpc-methods/index.js.map +1 -1
- package/dist/rpc-methods/index.mjs +13 -0
- package/dist/rpc-methods/index.mjs.map +1 -0
- package/dist/rpc-methods/requestPermissions.js +9 -46
- package/dist/rpc-methods/requestPermissions.js.map +1 -1
- package/dist/rpc-methods/requestPermissions.mjs +10 -0
- package/dist/rpc-methods/requestPermissions.mjs.map +1 -0
- package/dist/rpc-methods/revokePermissions.js +9 -51
- package/dist/rpc-methods/revokePermissions.js.map +1 -1
- package/dist/rpc-methods/revokePermissions.mjs +10 -0
- package/dist/rpc-methods/revokePermissions.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/Caveat.d.ts.map +1 -0
- package/dist/types/Permission.d.ts.map +1 -0
- package/dist/{PermissionController.d.ts → types/PermissionController.d.ts} +1 -1
- package/dist/types/PermissionController.d.ts.map +1 -0
- package/dist/types/SubjectMetadataController.d.ts.map +1 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/permission-middleware.d.ts.map +1 -0
- package/dist/types/rpc-methods/getPermissions.d.ts.map +1 -0
- package/dist/types/rpc-methods/index.d.ts.map +1 -0
- package/dist/types/rpc-methods/requestPermissions.d.ts.map +1 -0
- package/dist/types/rpc-methods/revokePermissions.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +8 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +16 -6
- package/dist/Caveat.d.ts.map +0 -1
- package/dist/Permission.d.ts.map +0 -1
- package/dist/PermissionController.d.ts.map +0 -1
- package/dist/SubjectMetadataController.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/permission-middleware.d.ts.map +0 -1
- package/dist/rpc-methods/getPermissions.d.ts.map +0 -1
- package/dist/rpc-methods/index.d.ts.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.ts.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- /package/dist/{Caveat.d.ts → types/Caveat.d.ts} +0 -0
- /package/dist/{Permission.d.ts → types/Permission.d.ts} +0 -0
- /package/dist/{SubjectMetadataController.d.ts → types/SubjectMetadataController.d.ts} +0 -0
- /package/dist/{errors.d.ts → types/errors.d.ts} +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{permission-middleware.d.ts → types/permission-middleware.d.ts} +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/getPermissions.d.ts +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/index.d.ts +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/requestPermissions.d.ts +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/revokePermissions.d.ts +0 -0
- /package/dist/{utils.d.ts → types/utils.d.ts} +0 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rpc_methods_exports
|
|
3
|
+
} from "./chunk-5C5SZO74.mjs";
|
|
4
|
+
import "./chunk-73M67Z5X.mjs";
|
|
5
|
+
import "./chunk-YVXIWLBE.mjs";
|
|
6
|
+
import "./chunk-BEQEQLRE.mjs";
|
|
7
|
+
import {
|
|
8
|
+
CaveatMutatorOperation,
|
|
9
|
+
PermissionController
|
|
10
|
+
} from "./chunk-CXKOMB77.mjs";
|
|
11
|
+
import {
|
|
12
|
+
decorateWithCaveats,
|
|
13
|
+
isRestrictedMethodCaveatSpecification
|
|
14
|
+
} from "./chunk-XBFHEZRU.mjs";
|
|
15
|
+
import {
|
|
16
|
+
PermissionType,
|
|
17
|
+
constructPermission,
|
|
18
|
+
findCaveat,
|
|
19
|
+
hasSpecificationType
|
|
20
|
+
} from "./chunk-ODCVB4BB.mjs";
|
|
21
|
+
import {
|
|
22
|
+
SubjectMetadataController,
|
|
23
|
+
SubjectType
|
|
24
|
+
} from "./chunk-4D2RVWNF.mjs";
|
|
25
|
+
import "./chunk-N4KQ2BHF.mjs";
|
|
26
|
+
import {
|
|
27
|
+
CaveatAlreadyExistsError,
|
|
28
|
+
CaveatDoesNotExistError,
|
|
29
|
+
CaveatInvalidJsonError,
|
|
30
|
+
CaveatMissingValueError,
|
|
31
|
+
CaveatSpecificationMismatchError,
|
|
32
|
+
DuplicateCaveatError,
|
|
33
|
+
EndowmentPermissionDoesNotExistError,
|
|
34
|
+
ForbiddenCaveatError,
|
|
35
|
+
InvalidApprovedPermissionError,
|
|
36
|
+
InvalidCaveatError,
|
|
37
|
+
InvalidCaveatFieldsError,
|
|
38
|
+
InvalidCaveatTypeError,
|
|
39
|
+
InvalidCaveatsPropertyError,
|
|
40
|
+
InvalidSubjectIdentifierError,
|
|
41
|
+
PermissionDoesNotExistError,
|
|
42
|
+
PermissionsRequestNotFoundError,
|
|
43
|
+
UnrecognizedCaveatTypeError,
|
|
44
|
+
UnrecognizedSubjectError,
|
|
45
|
+
internalError,
|
|
46
|
+
invalidParams,
|
|
47
|
+
methodNotFound,
|
|
48
|
+
unauthorized,
|
|
49
|
+
userRejectedRequest
|
|
50
|
+
} from "./chunk-FEXS6SJF.mjs";
|
|
51
|
+
import {
|
|
52
|
+
MethodNames
|
|
53
|
+
} from "./chunk-KVKKNDYV.mjs";
|
|
54
|
+
import "./chunk-ZSTKOCBT.mjs";
|
|
55
|
+
export {
|
|
56
|
+
CaveatAlreadyExistsError,
|
|
57
|
+
CaveatDoesNotExistError,
|
|
58
|
+
CaveatInvalidJsonError,
|
|
59
|
+
CaveatMissingValueError,
|
|
60
|
+
CaveatMutatorOperation,
|
|
61
|
+
CaveatSpecificationMismatchError,
|
|
62
|
+
DuplicateCaveatError,
|
|
63
|
+
EndowmentPermissionDoesNotExistError,
|
|
64
|
+
ForbiddenCaveatError,
|
|
65
|
+
InvalidApprovedPermissionError,
|
|
66
|
+
InvalidCaveatError,
|
|
67
|
+
InvalidCaveatFieldsError,
|
|
68
|
+
InvalidCaveatTypeError,
|
|
69
|
+
InvalidCaveatsPropertyError,
|
|
70
|
+
InvalidSubjectIdentifierError,
|
|
71
|
+
MethodNames,
|
|
72
|
+
PermissionController,
|
|
73
|
+
PermissionDoesNotExistError,
|
|
74
|
+
PermissionType,
|
|
75
|
+
PermissionsRequestNotFoundError,
|
|
76
|
+
SubjectMetadataController,
|
|
77
|
+
SubjectType,
|
|
78
|
+
UnrecognizedCaveatTypeError,
|
|
79
|
+
UnrecognizedSubjectError,
|
|
80
|
+
constructPermission,
|
|
81
|
+
decorateWithCaveats,
|
|
82
|
+
findCaveat,
|
|
83
|
+
hasSpecificationType,
|
|
84
|
+
internalError,
|
|
85
|
+
invalidParams,
|
|
86
|
+
isRestrictedMethodCaveatSpecification,
|
|
87
|
+
methodNotFound,
|
|
88
|
+
rpc_methods_exports as permissionRpcMethods,
|
|
89
|
+
unauthorized,
|
|
90
|
+
userRejectedRequest
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,64 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPermissionMiddlewareFactory = void 0;
|
|
13
|
-
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
14
|
-
const errors_1 = require("./errors");
|
|
15
|
-
/**
|
|
16
|
-
* Creates a permission middleware function factory. Intended for internal use
|
|
17
|
-
* in the {@link PermissionController}. Like any {@link JsonRpcEngine}
|
|
18
|
-
* middleware, each middleware will only receive requests from a particular
|
|
19
|
-
* subject / origin. However, each middleware also requires access to some
|
|
20
|
-
* `PermissionController` internals, which is why this "factory factory" exists.
|
|
21
|
-
*
|
|
22
|
-
* The middlewares returned by the factory will pass through requests for
|
|
23
|
-
* unrestricted methods, and attempt to execute restricted methods. If a method
|
|
24
|
-
* is neither restricted nor unrestricted, a "method not found" error will be
|
|
25
|
-
* returned.
|
|
26
|
-
* If a method is restricted, the middleware will first attempt to retrieve the
|
|
27
|
-
* subject's permission for that method. If the permission is found, the method
|
|
28
|
-
* will be executed. Otherwise, an "unauthorized" error will be returned.
|
|
29
|
-
*
|
|
30
|
-
* @param options - Options bag.
|
|
31
|
-
* @param options.executeRestrictedMethod - {@link PermissionController._executeRestrictedMethod}.
|
|
32
|
-
* @param options.getRestrictedMethod - {@link PermissionController.getRestrictedMethod}.
|
|
33
|
-
* @param options.isUnrestrictedMethod - A function that checks whether a
|
|
34
|
-
* particular method is unrestricted.
|
|
35
|
-
* @returns A permission middleware factory function.
|
|
36
|
-
*/
|
|
37
|
-
function getPermissionMiddlewareFactory({ executeRestrictedMethod, getRestrictedMethod, isUnrestrictedMethod, }) {
|
|
38
|
-
return function createPermissionMiddleware(subject) {
|
|
39
|
-
const { origin } = subject;
|
|
40
|
-
if (typeof origin !== 'string' || !origin) {
|
|
41
|
-
throw new Error('The subject "origin" must be a non-empty string.');
|
|
42
|
-
}
|
|
43
|
-
const permissionsMiddleware = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const { method, params } = req;
|
|
45
|
-
// Skip registered unrestricted methods.
|
|
46
|
-
if (isUnrestrictedMethod(method)) {
|
|
47
|
-
return next();
|
|
48
|
-
}
|
|
49
|
-
// This will throw if no restricted method implementation is found.
|
|
50
|
-
const methodImplementation = getRestrictedMethod(method, origin);
|
|
51
|
-
// This will throw if the permission does not exist.
|
|
52
|
-
const result = yield executeRestrictedMethod(methodImplementation, subject, method, params);
|
|
53
|
-
if (result === undefined) {
|
|
54
|
-
res.error = (0, errors_1.internalError)(`Request for method "${req.method}" returned undefined result.`, { request: req });
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
res.result = result;
|
|
58
|
-
return undefined;
|
|
59
|
-
});
|
|
60
|
-
return (0, json_rpc_engine_1.createAsyncMiddleware)(permissionsMiddleware);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
exports.getPermissionMiddlewareFactory = getPermissionMiddlewareFactory;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkAQ35E2HUjs = require('./chunk-AQ35E2HU.js');
|
|
4
|
+
require('./chunk-U5LTEXSU.js');
|
|
5
|
+
require('./chunk-CSAU5B4Q.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.getPermissionMiddlewareFactory = _chunkAQ35E2HUjs.getPermissionMiddlewareFactory;
|
|
64
9
|
//# sourceMappingURL=permission-middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,38 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPermissionsHandler = void 0;
|
|
13
|
-
const utils_1 = require("../utils");
|
|
14
|
-
exports.getPermissionsHandler = {
|
|
15
|
-
methodNames: [utils_1.MethodNames.getPermissions],
|
|
16
|
-
implementation: getPermissionsImplementation,
|
|
17
|
-
hookNames: {
|
|
18
|
-
getPermissionsForOrigin: true,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Get Permissions implementation to be used in JsonRpcEngine middleware.
|
|
23
|
-
*
|
|
24
|
-
* @param _req - The JsonRpcEngine request - unused
|
|
25
|
-
* @param res - The JsonRpcEngine result object
|
|
26
|
-
* @param _next - JsonRpcEngine next() callback - unused
|
|
27
|
-
* @param end - JsonRpcEngine end() callback
|
|
28
|
-
* @param options - Method hooks passed to the method implementation
|
|
29
|
-
* @param options.getPermissionsForOrigin - The specific method hook needed for this method implementation
|
|
30
|
-
* @returns A promise that resolves to nothing
|
|
31
|
-
*/
|
|
32
|
-
function getPermissionsImplementation(_req, res, _next, end, { getPermissionsForOrigin }) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
res.result = Object.values(getPermissionsForOrigin() || {});
|
|
35
|
-
return end();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkHRDKMOYSjs = require('../chunk-HRDKMOYS.js');
|
|
4
|
+
require('../chunk-K5R57Y57.js');
|
|
5
|
+
require('../chunk-CSAU5B4Q.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.getPermissionsHandler = _chunkHRDKMOYSjs.getPermissionsHandler;
|
|
38
9
|
//# sourceMappingURL=getPermissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk7CTPRFQ3js = require('../chunk-7CTPRFQ3.js');
|
|
4
|
+
require('../chunk-HRDKMOYS.js');
|
|
5
|
+
require('../chunk-YRNH4R3G.js');
|
|
6
|
+
require('../chunk-ZVO26XPN.js');
|
|
7
|
+
require('../chunk-U5LTEXSU.js');
|
|
8
|
+
require('../chunk-K5R57Y57.js');
|
|
9
|
+
require('../chunk-CSAU5B4Q.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.handlers = _chunk7CTPRFQ3js.handlers;
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handlers
|
|
3
|
+
} from "../chunk-5C5SZO74.mjs";
|
|
4
|
+
import "../chunk-73M67Z5X.mjs";
|
|
5
|
+
import "../chunk-YVXIWLBE.mjs";
|
|
6
|
+
import "../chunk-BEQEQLRE.mjs";
|
|
7
|
+
import "../chunk-FEXS6SJF.mjs";
|
|
8
|
+
import "../chunk-KVKKNDYV.mjs";
|
|
9
|
+
import "../chunk-ZSTKOCBT.mjs";
|
|
10
|
+
export {
|
|
11
|
+
handlers
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,47 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.requestPermissionsHandler = void 0;
|
|
13
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
14
|
-
const errors_1 = require("../errors");
|
|
15
|
-
const utils_1 = require("../utils");
|
|
16
|
-
exports.requestPermissionsHandler = {
|
|
17
|
-
methodNames: [utils_1.MethodNames.requestPermissions],
|
|
18
|
-
implementation: requestPermissionsImplementation,
|
|
19
|
-
hookNames: {
|
|
20
|
-
requestPermissionsForOrigin: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Request Permissions implementation to be used in JsonRpcEngine middleware.
|
|
25
|
-
*
|
|
26
|
-
* @param req - The JsonRpcEngine request
|
|
27
|
-
* @param res - The JsonRpcEngine result object
|
|
28
|
-
* @param _next - JsonRpcEngine next() callback - unused
|
|
29
|
-
* @param end - JsonRpcEngine end() callback
|
|
30
|
-
* @param options - Method hooks passed to the method implementation
|
|
31
|
-
* @param options.requestPermissionsForOrigin - The specific method hook needed for this method implementation
|
|
32
|
-
* @returns A promise that resolves to nothing
|
|
33
|
-
*/
|
|
34
|
-
function requestPermissionsImplementation(req, res, _next, end, { requestPermissionsForOrigin }) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { params } = req;
|
|
37
|
-
if (!Array.isArray(params) || !(0, controller_utils_1.isPlainObject)(params[0])) {
|
|
38
|
-
return end((0, errors_1.invalidParams)({ data: { request: req } }));
|
|
39
|
-
}
|
|
40
|
-
const [requestedPermissions] = params;
|
|
41
|
-
const [grantedPermissions] = yield requestPermissionsForOrigin(requestedPermissions);
|
|
42
|
-
// `wallet_requestPermission` is specified to return an array.
|
|
43
|
-
res.result = Object.values(grantedPermissions);
|
|
44
|
-
return end();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkYRNH4R3Gjs = require('../chunk-YRNH4R3G.js');
|
|
4
|
+
require('../chunk-U5LTEXSU.js');
|
|
5
|
+
require('../chunk-K5R57Y57.js');
|
|
6
|
+
require('../chunk-CSAU5B4Q.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.requestPermissionsHandler = _chunkYRNH4R3Gjs.requestPermissionsHandler;
|
|
47
10
|
//# sourceMappingURL=requestPermissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
requestPermissionsHandler
|
|
3
|
+
} from "../chunk-YVXIWLBE.mjs";
|
|
4
|
+
import "../chunk-FEXS6SJF.mjs";
|
|
5
|
+
import "../chunk-KVKKNDYV.mjs";
|
|
6
|
+
import "../chunk-ZSTKOCBT.mjs";
|
|
7
|
+
export {
|
|
8
|
+
requestPermissionsHandler
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=requestPermissions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,52 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.revokePermissionsHandler = void 0;
|
|
13
|
-
const utils_1 = require("@metamask/utils");
|
|
14
|
-
const errors_1 = require("../errors");
|
|
15
|
-
const utils_2 = require("../utils");
|
|
16
|
-
exports.revokePermissionsHandler = {
|
|
17
|
-
methodNames: [utils_2.MethodNames.revokePermissions],
|
|
18
|
-
implementation: revokePermissionsImplementation,
|
|
19
|
-
hookNames: {
|
|
20
|
-
revokePermissionsForOrigin: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Revoke Permissions implementation to be used in JsonRpcEngine middleware.
|
|
25
|
-
*
|
|
26
|
-
* @param req - The JsonRpcEngine request
|
|
27
|
-
* @param res - The JsonRpcEngine result object
|
|
28
|
-
* @param _next - JsonRpcEngine next() callback - unused
|
|
29
|
-
* @param end - JsonRpcEngine end() callback
|
|
30
|
-
* @param options - Method hooks passed to the method implementation
|
|
31
|
-
* @param options.revokePermissionsForOrigin - A hook that revokes given permission keys for an origin
|
|
32
|
-
* @returns A promise that resolves to nothing
|
|
33
|
-
*/
|
|
34
|
-
function revokePermissionsImplementation(req, res, _next, end, { revokePermissionsForOrigin }) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { params } = req;
|
|
37
|
-
const param = params === null || params === void 0 ? void 0 : params[0];
|
|
38
|
-
if (!param) {
|
|
39
|
-
return end((0, errors_1.invalidParams)({ data: { request: req } }));
|
|
40
|
-
}
|
|
41
|
-
// For now, this API revokes the entire permission key
|
|
42
|
-
// even if caveats are specified.
|
|
43
|
-
const permissionKeys = Object.keys(param);
|
|
44
|
-
if (!(0, utils_1.isNonEmptyArray)(permissionKeys)) {
|
|
45
|
-
return end((0, errors_1.invalidParams)({ data: { request: req } }));
|
|
46
|
-
}
|
|
47
|
-
revokePermissionsForOrigin(permissionKeys);
|
|
48
|
-
res.result = null;
|
|
49
|
-
return end();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkZVO26XPNjs = require('../chunk-ZVO26XPN.js');
|
|
4
|
+
require('../chunk-U5LTEXSU.js');
|
|
5
|
+
require('../chunk-K5R57Y57.js');
|
|
6
|
+
require('../chunk-CSAU5B4Q.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.revokePermissionsHandler = _chunkZVO26XPNjs.revokePermissionsHandler;
|
|
52
10
|
//# sourceMappingURL=revokePermissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
revokePermissionsHandler
|
|
3
|
+
} from "../chunk-BEQEQLRE.mjs";
|
|
4
|
+
import "../chunk-FEXS6SJF.mjs";
|
|
5
|
+
import "../chunk-KVKKNDYV.mjs";
|
|
6
|
+
import "../chunk-ZSTKOCBT.mjs";
|
|
7
|
+
export {
|
|
8
|
+
revokePermissionsHandler
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=revokePermissions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|