2022-06-29 14:51:35 +02:00
|
|
|
import { endowmentPermissionBuilders } from '@metamask/snap-controllers';
|
2022-02-15 01:02:51 +01:00
|
|
|
import {
|
|
|
|
restrictedMethodPermissionBuilders,
|
|
|
|
selectHooks,
|
|
|
|
} from '@metamask/rpc-methods';
|
2022-03-14 20:37:19 +01:00
|
|
|
import { ExcludedSnapPermissions } from '../../../../../shared/constants/permissions';
|
2022-02-15 01:02:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Record<string, Record<string, unknown>>} All endowment permission
|
|
|
|
* specifications.
|
|
|
|
*/
|
|
|
|
export const buildSnapEndowmentSpecifications = () =>
|
|
|
|
Object.values(endowmentPermissionBuilders).reduce(
|
|
|
|
(allSpecifications, { targetKey, specificationBuilder }) => {
|
|
|
|
allSpecifications[targetKey] = specificationBuilder();
|
|
|
|
return allSpecifications;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Record<string, Function>} hooks - The hooks for the Snap
|
|
|
|
* restricted method implementations.
|
|
|
|
*/
|
|
|
|
export function buildSnapRestrictedMethodSpecifications(hooks) {
|
|
|
|
return Object.values(restrictedMethodPermissionBuilders).reduce(
|
|
|
|
(specifications, { targetKey, specificationBuilder, methodHooks }) => {
|
2022-03-14 20:37:19 +01:00
|
|
|
if (!ExcludedSnapPermissions.has(targetKey)) {
|
|
|
|
specifications[targetKey] = specificationBuilder({
|
|
|
|
methodHooks: selectHooks(hooks, methodHooks),
|
|
|
|
});
|
|
|
|
}
|
2022-02-15 01:02:51 +01:00
|
|
|
return specifications;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
}
|