2022-11-22 13:07:08 +01:00
|
|
|
import { endowmentPermissionBuilders } from '@metamask/snaps-controllers';
|
2022-02-15 01:02:51 +01:00
|
|
|
import {
|
|
|
|
restrictedMethodPermissionBuilders,
|
|
|
|
selectHooks,
|
|
|
|
} from '@metamask/rpc-methods';
|
2022-10-07 10:02:35 +02:00
|
|
|
import {
|
|
|
|
ExcludedSnapEndowments,
|
|
|
|
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 }) => {
|
2023-02-15 11:09:47 +01:00
|
|
|
if (!Object.keys(ExcludedSnapEndowments).includes(targetKey)) {
|
2022-10-07 10:02:35 +02:00
|
|
|
allSpecifications[targetKey] = specificationBuilder();
|
|
|
|
}
|
2022-02-15 01:02:51 +01:00
|
|
|
return allSpecifications;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Record<string, Function>} hooks - The hooks for the Snap
|
|
|
|
* restricted method implementations.
|
|
|
|
*/
|
2023-02-15 11:09:47 +01:00
|
|
|
export const buildSnapRestrictedMethodSpecifications = (hooks) =>
|
|
|
|
Object.values(restrictedMethodPermissionBuilders).reduce(
|
2022-02-15 01:02:51 +01:00
|
|
|
(specifications, { targetKey, specificationBuilder, methodHooks }) => {
|
2023-02-15 11:09:47 +01:00
|
|
|
if (!Object.keys(ExcludedSnapPermissions).includes(targetKey)) {
|
2022-03-14 20:37:19 +01:00
|
|
|
specifications[targetKey] = specificationBuilder({
|
|
|
|
methodHooks: selectHooks(hooks, methodHooks),
|
|
|
|
});
|
|
|
|
}
|
2022-02-15 01:02:51 +01:00
|
|
|
return specifications;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|