mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-04 23:14:56 +01:00
7ba0f78a84
* snaps-skunkworks@0.22.0 * Update LavaMoat policies * Bump execution environment and fix a breaking change * Fix caveat and permissions * Fix test * Exclude keyring endowment for now * Fix test * Fix snap_confirm missing title
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import { endowmentPermissionBuilders } from '@metamask/snap-controllers';
|
|
import {
|
|
restrictedMethodPermissionBuilders,
|
|
selectHooks,
|
|
} from '@metamask/rpc-methods';
|
|
import {
|
|
ExcludedSnapEndowments,
|
|
ExcludedSnapPermissions,
|
|
} from '../../../../../shared/constants/permissions';
|
|
|
|
/**
|
|
* @returns {Record<string, Record<string, unknown>>} All endowment permission
|
|
* specifications.
|
|
*/
|
|
export const buildSnapEndowmentSpecifications = () =>
|
|
Object.values(endowmentPermissionBuilders).reduce(
|
|
(allSpecifications, { targetKey, specificationBuilder }) => {
|
|
if (!ExcludedSnapEndowments.has(targetKey)) {
|
|
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 }) => {
|
|
if (!ExcludedSnapPermissions.has(targetKey)) {
|
|
specifications[targetKey] = specificationBuilder({
|
|
methodHooks: selectHooks(hooks, methodHooks),
|
|
});
|
|
}
|
|
return specifications;
|
|
},
|
|
{},
|
|
);
|
|
}
|