1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/controllers/permissions/snaps/snap-permissions.js
Frederik Bolding f03f2d3f79
[FLASK] snaps@0.34.0-flask.1 (#19377)
* snaps@0.34.0-flask.1

* Update LavaMoat policies

* Replace instances of targetKey with targetName

* Replace use of PermissionKeys with PermissionNames

* Use Flask packages in tests for now

* Bump execution env

* Add another mock

* Fix lint
2023-06-05 13:51:19 +02:00

44 lines
1.4 KiB
JavaScript

import { endowmentPermissionBuilders } from '@metamask/snaps-controllers';
import {
restrictedMethodPermissionBuilders,
selectHooks,
} from '@metamask/rpc-methods';
import {
ExcludedSnapEndowments,
ExcludedSnapPermissions,
} from '../../../../../shared/constants/permissions';
// TODO: Use the exported versions of these functions from the snaps monorepo after stable release.
/**
* @returns {Record<string, Record<string, unknown>>} All endowment permission
* specifications.
*/
export const buildSnapEndowmentSpecifications = () =>
Object.values(endowmentPermissionBuilders).reduce(
(allSpecifications, { targetName, specificationBuilder }) => {
if (!Object.keys(ExcludedSnapEndowments).includes(targetName)) {
allSpecifications[targetName] = specificationBuilder();
}
return allSpecifications;
},
{},
);
/**
* @param {Record<string, Function>} hooks - The hooks for the Snap
* restricted method implementations.
*/
export const buildSnapRestrictedMethodSpecifications = (hooks) =>
Object.values(restrictedMethodPermissionBuilders).reduce(
(specifications, { targetName, specificationBuilder, methodHooks }) => {
if (!Object.keys(ExcludedSnapPermissions).includes(targetName)) {
specifications[targetName] = specificationBuilder({
methodHooks: selectHooks(hooks, methodHooks),
});
}
return specifications;
},
{},
);