Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/snaps-rpc-methods/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module.exports = deepmerge(baseConfig, {
],
coverageThreshold: {
global: {
branches: 97.28,
functions: 98.84,
branches: 97.3,
functions: 98.85,
lines: 99.14,
statements: 98.81,
},
Expand Down
9 changes: 8 additions & 1 deletion packages/snaps-rpc-methods/src/permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ describe('buildSnapRestrictedMethodSpecifications', () => {
it('returns the expected object', () => {
const specifications = buildSnapRestrictedMethodSpecifications(
[],
{},
{
getUnlockPromise: jest.fn(),
getClientCryptography: jest.fn(),
isOnPhishingList: jest.fn(),
maybeUpdatePhishingList: jest.fn(),
getSnapKeyring: jest.fn(),
getPreferences: jest.fn(),
},
new Messenger({ namespace: 'SnapsRestrictedMethods' }),
);
expect(specifications).toMatchInlineSnapshot(`
Expand Down
19 changes: 16 additions & 3 deletions packages/snaps-rpc-methods/src/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selectHooks } from '@metamask/json-rpc-engine/v2';
import { selectHooks, assertExpectedHooks } from '@metamask/json-rpc-engine/v2';
import {
createRestrictedMethodMessenger,
type PermissionConstraint,
Expand Down Expand Up @@ -70,8 +70,20 @@ export const buildSnapRestrictedMethodSpecifications = (
excludedPermissions: string[],
hooks: Record<string, unknown>,
messenger: RestrictedMethodMessenger,
) =>
Object.values(restrictedMethodPermissionBuilders).reduce<
) => {
const permissionBuilders = Object.values(restrictedMethodPermissionBuilders);

const expectedHookNames = new Set(
permissionBuilders.flatMap((builder) =>
builder.methodHooks
? Object.getOwnPropertyNames(builder.methodHooks)
: [],
),
);

assertExpectedHooks(hooks, expectedHookNames);
Comment thread
cursor[bot] marked this conversation as resolved.

return permissionBuilders.reduce<
Record<string, PermissionSpecificationConstraint>
>(
(
Expand All @@ -94,3 +106,4 @@ export const buildSnapRestrictedMethodSpecifications = (
},
{},
);
};
4 changes: 3 additions & 1 deletion packages/snaps-simulation/src/methods/specifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function getPermissionSpecifications({
hooks,
options,
}: GetPermissionSpecificationsOptions): PermissionSpecificationMap<PermissionSpecificationConstraint> {
const { getClientCryptography } = hooks;
return {
[caip25EndowmentBuilder.targetName]:
caip25EndowmentBuilder.specificationBuilder({}),
Expand All @@ -81,11 +82,12 @@ export function getPermissionSpecifications({
EXCLUDED_SNAP_PERMISSIONS,
{
// Shared hooks.
...hooks,
getClientCryptography,

// Snaps-specific hooks.
getPreferences: getGetPreferencesMethodImplementation(options),
getUnlockPromise: asyncResolve(true),
getSnapKeyring: asyncResolve(null),

// TODO: Allow the user to specify the result of this function.
isOnPhishingList: resolve(false),
Expand Down
Loading