mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-28 23:06:37 +01:00
de955f3faa
* snaps-monorepo@0.24.0 * Fix imports and regen LavaMoat policies * Bump iframe-execution-environment * Fix tests * Add permissions * Bump patch * Bump test-snaps * [FLASK] Fix update e2e test to catch snaps with caveats (#16546) * changed snap to update to bip32 * small changes to test * Fix lint * Fix E2E * Update copy * Update icon Co-authored-by: Bowen Sanders <bowensanders@gmail.com>
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import { endowmentPermissionBuilders } from '@metamask/snaps-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;
|
|
},
|
|
{},
|
|
);
|
|
}
|