From 9a22c8fb3737fc9c45e2d0259f502a3d70ee0bd6 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 24 Mar 2026 16:23:01 +0100 Subject: [PATCH 01/11] Standardise `SnapsRegistry` action names and types --- packages/snaps-controllers/CHANGELOG.md | 11 +++ .../src/snaps/SnapController.test.tsx | 2 +- .../src/snaps/SnapController.ts | 35 ++++---- ...sRegistryController-method-action-types.ts | 55 ++++++++++++ ...est.ts => SnapsRegistryController.test.ts} | 84 +++++++++++-------- .../{json.ts => SnapsRegistryController.ts} | 83 ++++++------------ .../src/snaps/registry/index.ts | 24 +++++- .../src/test-utils/controller.tsx | 10 +-- .../src/test-utils/registry.ts | 10 +-- 9 files changed, 192 insertions(+), 122 deletions(-) create mode 100644 packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts rename packages/snaps-controllers/src/snaps/registry/{json.test.ts => SnapsRegistryController.test.ts} (87%) rename packages/snaps-controllers/src/snaps/registry/{json.ts => SnapsRegistryController.ts} (87%) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index cc6ae41682..bc03e1666e 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -56,6 +56,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `HandleRequest` is now `ExecutionServiceHandleRequestAction`. - `TerminateSnap` is now `ExecutionServiceTerminateSnapAction`. - `GetExecutionStatus` is now `ExecutionServiceGetExecutionStatusAction`. + - `SnapsRegistryController` actions: + - `GetResult` is now `SnapsRegistryControllerGetSnapAction`. + - Note: The method is now called `getSnap` instead of `get`. + - `GetMetadata` is now `SnapsRegistryControllerGetSnapMetadataAction`. + - Note: The method is now called `getSnapMetadata` instead of `getMetadata`. + - `ResolveVersion` is now `SnapsRegistryControllerResolveSnapVersionAction`. + - Note: The method is now called `resolveSnapVersion` instead of `resolveVersion`. + - `Update` is now `SnapsRegistryControllerUpdateRegistryAction`. + - Note: The method is now called `updateRegistry` instead of `update`. - **BREAKING:** All event types were renamed from `OnSomething` to `ControllerOnSomethingEvent` ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3916](https://github.com/MetaMask/snaps/pull/3916)) - `SnapController` events: - `SnapStateChange` was removed in favour of `SnapControllerStateChangeEvent`. @@ -76,6 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `OutboundResponse` is now `ExecutionServiceOutboundResponseEvent`. - **BREAKING:**: Rename `MultichainRouter` to `MultichainRoutingService` and update action types accordingly ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - This is consistent with the naming of other services. +- **BREAKING:** Rename `JsonSnapsRegistry` to `SnapsRegistryController` and update action types accordingly ([#3917](https://github.com/MetaMask/snaps/pull/3917)) + - This is consistent with the naming of other controllers. - **BREAKING:** `MultichainRoutingService` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - **BREAKING:** `SnapInsightsController` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3915](https://github.com/MetaMask/snaps/pull/3915)) - **RREAKING:** Replace `ExecutionService` interface with abstract class ([#3916](https://github.com/MetaMask/snaps/pull/3916)) diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index e81c630ae1..02116ce1b6 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -817,7 +817,7 @@ describe('SnapController', () => { expect(options.messenger.call).toHaveBeenNthCalledWith( 2, - 'SnapsRegistry:get', + 'SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0', diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 2e47e79aad..1f7cefa79d 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -161,13 +161,13 @@ import { import type { SnapLocation } from './location'; import { detectSnapLocation } from './location'; import type { - GetMetadata, - GetResult, - ResolveVersion, + SnapsRegistryControllerGetSnapAction, + SnapsRegistryControllerGetSnapMetadataAction, + SnapsRegistryControllerResolveSnapVersionAction, + SnapsRegistryControllerUpdateRegistryAction, SnapsRegistryInfo, SnapsRegistryRequest, SnapsRegistryStateChangeEvent, - Update, } from './registry'; import { SnapsRegistryStatus } from './registry'; import { getRunnableSnaps } from './selectors'; @@ -535,10 +535,10 @@ export type AllowedActions = | ExecutionServiceTerminateSnapAction | UpdateCaveat | ApprovalControllerUpdateRequestStateAction - | GetResult - | GetMetadata - | Update - | ResolveVersion + | SnapsRegistryControllerGetSnapAction + | SnapsRegistryControllerGetSnapMetadataAction + | SnapsRegistryControllerUpdateRegistryAction + | SnapsRegistryControllerResolveSnapVersionAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction | SnapInterfaceControllerSetInterfaceDisplayedAction @@ -980,7 +980,7 @@ export class SnapController extends BaseController< ); this.messenger.subscribe( - 'SnapsRegistry:stateChange', + 'SnapsRegistryController:stateChange', () => { this.#handleRegistryUpdate().catch((error) => { logError( @@ -1003,7 +1003,7 @@ export class SnapController extends BaseController< this.#trackSnapExport = throttleTracking( (snapId: SnapId, handler: string, success: boolean, origin: string) => { const snapMetadata = this.messenger.call( - 'SnapsRegistry:getMetadata', + 'SnapsRegistryController:getSnapMetadata', snapId, ); this.#trackEvent({ @@ -1457,7 +1457,7 @@ export class SnapController extends BaseController< */ async updateRegistry(): Promise { await this.#ensureCanUsePlatform(); - await this.messenger.call('SnapsRegistry:update'); + await this.messenger.call('SnapsRegistryController:updateRegistry'); } /** @@ -1469,7 +1469,7 @@ export class SnapController extends BaseController< */ async #handleRegistryUpdate() { const blockedSnaps = await this.messenger.call( - 'SnapsRegistry:get', + 'SnapsRegistryController:getSnap', Object.values(this.state.snaps).reduce( (blockListArg, snap) => { blockListArg[snap.id] = { @@ -1596,9 +1596,12 @@ export class SnapController extends BaseController< platformVersion: string | undefined; }, ) { - const results = await this.messenger.call('SnapsRegistry:get', { - [snapId]: snapInfo, - }); + const results = await this.messenger.call( + 'SnapsRegistryController:getSnap', + { + [snapId]: snapInfo, + }, + ); const result = results[snapId]; if (result.status === SnapsRegistryStatus.Blocked) { @@ -3137,7 +3140,7 @@ export class SnapController extends BaseController< versionRange: SemVerRange, ): Promise { return await this.messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', snapId, versionRange, ); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts new file mode 100644 index 0000000000..1d222487c9 --- /dev/null +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts @@ -0,0 +1,55 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { SnapsRegistryController } from './SnapsRegistryController'; + +/** + * Triggers an update of the registry database. + * + * If an existing update is in progress this function will await that update. + */ +export type SnapsRegistryControllerUpdateRegistryAction = { + type: `SnapsRegistryController:updateRegistry`; + handler: SnapsRegistryController['updateRegistry']; +}; + +export type SnapsRegistryControllerGetSnapAction = { + type: `SnapsRegistryController:getSnap`; + handler: SnapsRegistryController['getSnap']; +}; + +/** + * Find an allowlisted version within a specified version range. Otherwise return the version range itself. + * + * @param snapId - The ID of the snap we are trying to resolve a version for. + * @param versionRange - The version range. + * @param refetch - An optional flag used to determine if we are refetching the registry. + * @returns An allowlisted version within the specified version range if available otherwise returns the input version range. + */ +export type SnapsRegistryControllerResolveSnapVersionAction = { + type: `SnapsRegistryController:resolveSnapVersion`; + handler: SnapsRegistryController['resolveSnapVersion']; +}; + +/** + * Get metadata for the given snap ID, if available, without updating registry. + * + * @param snapId - The ID of the snap to get metadata for. + * @returns The metadata for the given snap ID, or `null` if the snap is not + * verified. + */ +export type SnapsRegistryControllerGetSnapMetadataAction = { + type: `SnapsRegistryController:getSnapMetadata`; + handler: SnapsRegistryController['getSnapMetadata']; +}; + +/** + * Union of all SnapsRegistryController action types. + */ +export type SnapsRegistryControllerMethodActions = + | SnapsRegistryControllerUpdateRegistryAction + | SnapsRegistryControllerGetSnapAction + | SnapsRegistryControllerResolveSnapVersionAction + | SnapsRegistryControllerGetSnapMetadataAction; diff --git a/packages/snaps-controllers/src/snaps/registry/json.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts similarity index 87% rename from packages/snaps-controllers/src/snaps/registry/json.test.ts rename to packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts index 3aaada161b..4e742ca6cd 100644 --- a/packages/snaps-controllers/src/snaps/registry/json.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts @@ -7,9 +7,9 @@ import { import type { SemVerRange, SemVerVersion } from '@metamask/utils'; import fetchMock from 'jest-fetch-mock'; -import type { JsonSnapsRegistryArgs } from './json'; -import { JsonSnapsRegistry } from './json'; import { SnapsRegistryStatus } from './registry'; +import type { SnapsRegistryControllerArgs } from './SnapsRegistryController'; +import { SnapsRegistryController } from './SnapsRegistryController'; import { getRestrictedSnapsRegistryControllerMessenger } from '../../test-utils'; // Public key for the private key: @@ -17,10 +17,10 @@ import { getRestrictedSnapsRegistryControllerMessenger } from '../../test-utils' const MOCK_PUBLIC_KEY = '0x03a885324b8520fba54a173999629952cfa1f97930c20902ec389f9c32c6ffbc40'; -const getRegistry = (args?: Partial) => { +const getRegistry = (args?: Partial) => { const messenger = getRestrictedSnapsRegistryControllerMessenger(); return { - registry: new JsonSnapsRegistry({ + registry: new SnapsRegistryController({ messenger, publicKey: MOCK_PUBLIC_KEY, clientConfig: { @@ -125,7 +125,7 @@ const MOCK_COMPATIBILITY_SIGNATURE_FILE = { format: 'DER', }; -describe('JsonSnapsRegistry', () => { +describe('SnapsRegistryController', () => { fetchMock.enableMocks(); afterEach(() => { @@ -138,7 +138,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -159,7 +159,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_EMPTY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -179,7 +179,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -199,7 +199,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'bar', @@ -219,7 +219,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'foo', @@ -240,7 +240,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { 'npm:@consensys/starknet-snap': { version: '0.1.10' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -267,7 +267,7 @@ describe('JsonSnapsRegistry', () => { database: { verifiedSnaps: {}, blockedSnaps: [] }, }, }); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -287,7 +287,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -307,7 +307,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.1.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -332,7 +332,7 @@ describe('JsonSnapsRegistry', () => { }, }); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -357,7 +357,7 @@ describe('JsonSnapsRegistry', () => { }, }); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -376,7 +376,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -399,7 +399,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -423,7 +423,7 @@ describe('JsonSnapsRegistry', () => { '0x034ca27b046507d1a9997bddc991b56d96b93d4adac3a96dfe01ce450bfb661455', }); - const result = await messenger.call('SnapsRegistry:get', { + const result = await messenger.call('SnapsRegistryController:getSnap', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -445,7 +445,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -460,7 +460,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -477,7 +477,7 @@ describe('JsonSnapsRegistry', () => { clientConfig: { type: 'extension', version: '15.0.0' as SemVerVersion }, }); const result = await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -496,7 +496,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, range, ), @@ -512,7 +512,7 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, range, ), @@ -532,7 +532,7 @@ describe('JsonSnapsRegistry', () => { }, }); const result = await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -568,7 +568,7 @@ describe('JsonSnapsRegistry', () => { }, }); const result = await messenger.call( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -584,8 +584,11 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistry:update'); - const result = messenger.call('SnapsRegistry:getMetadata', MOCK_SNAP_ID); + await messenger.call('SnapsRegistryController:updateRegistry'); + const result = messenger.call( + 'SnapsRegistryController:getSnapMetadata', + MOCK_SNAP_ID, + ); expect(result).toStrictEqual({ name: 'Mock Snap', @@ -598,8 +601,11 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistry:update'); - const result = messenger.call('SnapsRegistry:getMetadata', 'foo'); + await messenger.call('SnapsRegistryController:updateRegistry'); + const result = messenger.call( + 'SnapsRegistryController:getSnapMetadata', + 'foo', + ); expect(result).toBeNull(); }); @@ -612,7 +618,7 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistry:update'); + await messenger.call('SnapsRegistryController:updateRegistry'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -632,7 +638,7 @@ describe('JsonSnapsRegistry', () => { databaseUnavailable: false, }, }); - await messenger.call('SnapsRegistry:update'); + await messenger.call('SnapsRegistryController:updateRegistry'); expect(fetchMock).toHaveBeenCalledTimes(2); expect(spy).not.toHaveBeenCalled(); @@ -644,8 +650,8 @@ describe('JsonSnapsRegistry', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistry:update'); - await messenger.call('SnapsRegistry:update'); + await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:updateRegistry'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -657,8 +663,8 @@ describe('JsonSnapsRegistry', () => { const { messenger } = getRegistry(); await Promise.all([ - messenger.call('SnapsRegistry:update'), - messenger.call('SnapsRegistry:update'), + messenger.call('SnapsRegistryController:updateRegistry'), + messenger.call('SnapsRegistryController:updateRegistry'), ]); expect(fetchMock).toHaveBeenCalledTimes(2); @@ -670,7 +676,11 @@ describe('JsonSnapsRegistry', () => { const { registry } = getRegistry(); expect( - deriveStateFromMetadata(registry.state, registry.metadata, 'anonymous'), + deriveStateFromMetadata( + registry.state, + registry.metadata, + 'includeInDebugSnapshot', + ), ).toMatchInlineSnapshot(`{}`); }); diff --git a/packages/snaps-controllers/src/snaps/registry/json.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts similarity index 87% rename from packages/snaps-controllers/src/snaps/registry/json.ts rename to packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts index 3c5310f5a5..e7e993e05c 100644 --- a/packages/snaps-controllers/src/snaps/registry/json.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts @@ -21,13 +21,13 @@ import { } from '@metamask/utils'; import type { - SnapsRegistry, SnapsRegistryInfo, SnapsRegistryMetadata, SnapsRegistryRequest, SnapsRegistryResult, } from './registry'; import { SnapsRegistryStatus } from './registry'; +import type { SnapsRegistryControllerMethodActions } from './SnapsRegistryController-method-action-types'; const SNAP_REGISTRY_URL = 'https://acl.execution.metamask.io/latest/registry.json'; @@ -48,7 +48,7 @@ export type ClientConfig = { version: SemVerVersion; }; -export type JsonSnapsRegistryArgs = { +export type SnapsRegistryControllerArgs = { messenger: SnapsRegistryMessenger; state?: SnapsRegistryState; fetchFunction?: typeof fetch; @@ -59,26 +59,6 @@ export type JsonSnapsRegistryArgs = { clientConfig: ClientConfig; }; -export type GetResult = { - type: `${typeof controllerName}:get`; - handler: SnapsRegistry['get']; -}; - -export type ResolveVersion = { - type: `${typeof controllerName}:resolveVersion`; - handler: SnapsRegistry['resolveVersion']; -}; - -export type GetMetadata = { - type: `${typeof controllerName}:getMetadata`; - handler: SnapsRegistry['getMetadata']; -}; - -export type Update = { - type: `${typeof controllerName}:update`; - handler: SnapsRegistry['update']; -}; - export type SnapsRegistryGetStateAction = ControllerGetStateAction< typeof controllerName, SnapsRegistryState @@ -86,10 +66,7 @@ export type SnapsRegistryGetStateAction = ControllerGetStateAction< export type SnapsRegistryActions = | SnapsRegistryGetStateAction - | GetResult - | GetMetadata - | Update - | ResolveVersion; + | SnapsRegistryControllerMethodActions; export type SnapsRegistryStateChangeEvent = ControllerStateChangeEvent< typeof controllerName, @@ -99,7 +76,7 @@ export type SnapsRegistryStateChangeEvent = ControllerStateChangeEvent< export type SnapsRegistryEvents = SnapsRegistryStateChangeEvent; export type SnapsRegistryMessenger = Messenger< - 'SnapsRegistry', + typeof controllerName, SnapsRegistryActions, SnapsRegistryEvents >; @@ -111,7 +88,14 @@ export type SnapsRegistryState = { databaseUnavailable: boolean; }; -const controllerName = 'SnapsRegistry'; +const controllerName = 'SnapsRegistryController'; + +const MESSENGER_EXPOSED_METHODS = [ + 'getSnap', + 'getSnapMetadata', + 'resolveSnapVersion', + 'updateRegistry', +] as const; const defaultState = { database: null, @@ -120,7 +104,7 @@ const defaultState = { databaseUnavailable: false, }; -export class JsonSnapsRegistry extends BaseController< +export class SnapsRegistryController extends BaseController< typeof controllerName, SnapsRegistryState, SnapsRegistryMessenger @@ -151,7 +135,7 @@ export class JsonSnapsRegistry extends BaseController< fetchFunction = globalThis.fetch.bind(undefined), recentFetchThreshold = inMilliseconds(5, Duration.Minute), refetchOnAllowlistMiss = true, - }: JsonSnapsRegistryArgs) { + }: SnapsRegistryControllerArgs) { super({ messenger, metadata: { @@ -194,22 +178,9 @@ export class JsonSnapsRegistry extends BaseController< this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss; this.#currentUpdate = null; - this.messenger.registerActionHandler('SnapsRegistry:get', async (...args) => - this.#get(...args), - ); - - this.messenger.registerActionHandler( - 'SnapsRegistry:getMetadata', - (...args) => this.#getMetadata(...args), - ); - - this.messenger.registerActionHandler( - 'SnapsRegistry:resolveVersion', - async (...args) => this.#resolveVersion(...args), - ); - - this.messenger.registerActionHandler('SnapsRegistry:update', async () => - this.#triggerUpdate(), + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, ); } @@ -225,7 +196,7 @@ export class JsonSnapsRegistry extends BaseController< * * If an existing update is in progress this function will await that update. */ - async #triggerUpdate() { + async updateRegistry() { // If an update is ongoing, wait for that. if (this.#currentUpdate) { await this.#currentUpdate; @@ -285,7 +256,7 @@ export class JsonSnapsRegistry extends BaseController< async #getDatabase(): Promise { if (this.state.database === null) { - await this.#triggerUpdate(); + await this.updateRegistry(); } return this.state.database; @@ -327,7 +298,7 @@ export class JsonSnapsRegistry extends BaseController< } // For now, if we have an allowlist miss, we can refetch once and try again. if (this.#refetchOnAllowlistMiss && !refetch) { - await this.#triggerUpdate(); + await this.updateRegistry(); return this.#getSingle(snapId, snapInfo, true); } return { @@ -337,7 +308,7 @@ export class JsonSnapsRegistry extends BaseController< }; } - async #get( + async getSnap( snaps: SnapsRegistryRequest, ): Promise> { return Object.entries(snaps).reduce< @@ -358,7 +329,7 @@ export class JsonSnapsRegistry extends BaseController< * @param refetch - An optional flag used to determine if we are refetching the registry. * @returns An allowlisted version within the specified version range if available otherwise returns the input version range. */ - async #resolveVersion( + async resolveSnapVersion( snapId: string, versionRange: SemVerRange, refetch = false, @@ -367,8 +338,8 @@ export class JsonSnapsRegistry extends BaseController< const versions = database?.verifiedSnaps[snapId]?.versions ?? null; if (!versions && this.#refetchOnAllowlistMiss && !refetch) { - await this.#triggerUpdate(); - return this.#resolveVersion(snapId, versionRange, true); + await this.updateRegistry(); + return this.resolveSnapVersion(snapId, versionRange, true); } // If we cannot narrow down the version range we return the unaltered version range. @@ -394,8 +365,8 @@ export class JsonSnapsRegistry extends BaseController< const targetVersion = getTargetVersion(compatibleVersions, versionRange); if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) { - await this.#triggerUpdate(); - return this.#resolveVersion(snapId, versionRange, true); + await this.updateRegistry(); + return this.resolveSnapVersion(snapId, versionRange, true); } // If we cannot narrow down the version range we return the unaltered version range. @@ -415,7 +386,7 @@ export class JsonSnapsRegistry extends BaseController< * @returns The metadata for the given snap ID, or `null` if the snap is not * verified. */ - #getMetadata(snapId: string): SnapsRegistryMetadata | null { + getSnapMetadata(snapId: string): SnapsRegistryMetadata | null { return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null; } diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index e1865b60d5..6658ef0c99 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -1,2 +1,22 @@ -export * from './registry'; -export * from './json'; +export type { + SnapsRegistryInfo, + SnapsRegistryMetadata, + SnapsRegistryRequest, + SnapsRegistryResult, +} from './registry'; +export { SnapsRegistryStatus } from './registry'; +export type { + SnapsRegistryActions, + SnapsRegistryControllerArgs, + SnapsRegistryGetStateAction, + SnapsRegistryMessenger, + SnapsRegistryState, + SnapsRegistryStateChangeEvent, +} from './SnapsRegistryController'; +export { SnapsRegistryController } from './SnapsRegistryController'; +export type { + SnapsRegistryControllerGetSnapAction, + SnapsRegistryControllerGetSnapMetadataAction, + SnapsRegistryControllerResolveSnapVersionAction, + SnapsRegistryControllerUpdateRegistryAction, +} from './SnapsRegistryController-method-action-types'; diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index 7211352855..dbddaa9465 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -496,10 +496,10 @@ export const getSnapControllerMessenger = ( 'PermissionController:getSubjectNames', 'SubjectMetadataController:getSubjectMetadata', 'SubjectMetadataController:addSubjectMetadata', - 'SnapsRegistry:get', - 'SnapsRegistry:getMetadata', - 'SnapsRegistry:update', - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:getSnap', + 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:updateRegistry', + 'SnapsRegistryController:resolveSnapVersion', 'SnapInterfaceController:createInterface', 'SnapInterfaceController:setInterfaceDisplayed', 'SnapInterfaceController:getInterface', @@ -513,7 +513,7 @@ export const getSnapControllerMessenger = ( 'ExecutionService:outboundRequest', 'ExecutionService:outboundResponse', 'KeyringController:lock', - 'SnapsRegistry:stateChange', + 'SnapsRegistryController:stateChange', ], messenger: snapControllerMessenger, }); diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index ef44f797ff..cf6f0d0a8e 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -9,22 +9,22 @@ export class MockSnapsRegistry implements SnapsRegistry { this.#messenger = messenger; this.#messenger.registerActionHandler( - 'SnapsRegistry:get', + 'SnapsRegistryController:getSnap', this.get.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistry:getMetadata', + 'SnapsRegistryController:getSnapMetadata', this.getMetadata.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistry:resolveVersion', + 'SnapsRegistryController:resolveSnapVersion', this.resolveVersion.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistry:update', + 'SnapsRegistryController:updateRegistry', this.update.bind(this), ); } @@ -49,7 +49,7 @@ export class MockSnapsRegistry implements SnapsRegistry { update = jest.fn().mockImplementation(() => { this.#messenger.publish( - 'SnapsRegistry:stateChange', + 'SnapsRegistryController:stateChange', { database: { verifiedSnaps: {}, blockedSnaps: [] }, lastUpdated: Date.now(), From bdde4c96d8927a9cd0766875b34c546b14c51d13 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 24 Mar 2026 16:26:39 +0100 Subject: [PATCH 02/11] Rename more types --- packages/snaps-controllers/CHANGELOG.md | 5 +-- .../src/snaps/SnapController.ts | 4 +-- .../snaps/registry/SnapsRegistryController.ts | 36 ++++++++++--------- .../src/snaps/registry/index.ts | 10 +++--- .../src/test-utils/controller.tsx | 16 +++++---- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index bc03e1666e..30571cd212 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** All action types were renamed from `DoSomething` to `ControllerNameDoSomethingAction` ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3911](https://github.com/MetaMask/snaps/pull/3911), [#3912](https://github.com/MetaMask/snaps/pull/3912), [#3916](https://github.com/MetaMask/snaps/pull/3916)) +- **BREAKING:** All action types were renamed from `DoSomething` to `ControllerNameDoSomethingAction` ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3911](https://github.com/MetaMask/snaps/pull/3911), [#3912](https://github.com/MetaMask/snaps/pull/3912), [#3916](https://github.com/MetaMask/snaps/pull/3916), [#3918](https://github.com/MetaMask/snaps/pull/3918)) - `SnapController` actions: - `GetSnap` is now `SnapControllerGetSnapAction`. - Note: The method is now called `getSnap` instead of `get`. @@ -85,8 +85,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `OutboundResponse` is now `ExecutionServiceOutboundResponseEvent`. - **BREAKING:**: Rename `MultichainRouter` to `MultichainRoutingService` and update action types accordingly ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - This is consistent with the naming of other services. -- **BREAKING:** Rename `JsonSnapsRegistry` to `SnapsRegistryController` and update action types accordingly ([#3917](https://github.com/MetaMask/snaps/pull/3917)) +- **BREAKING:** Rename `JsonSnapsRegistry` to `SnapsRegistryController` and update action types accordingly ([#3918](https://github.com/MetaMask/snaps/pull/3918)) - This is consistent with the naming of other controllers. + - The controller name is now `SnapsRegistryController` instead of `SnapsRegistry` as well. - **BREAKING:** `MultichainRoutingService` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - **BREAKING:** `SnapInsightsController` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3915](https://github.com/MetaMask/snaps/pull/3915)) - **RREAKING:** Replace `ExecutionService` interface with abstract class ([#3916](https://github.com/MetaMask/snaps/pull/3916)) diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 1f7cefa79d..ad61cc554f 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -167,7 +167,7 @@ import type { SnapsRegistryControllerUpdateRegistryAction, SnapsRegistryInfo, SnapsRegistryRequest, - SnapsRegistryStateChangeEvent, + SnapsRegistryControllerStateChangeEvent, } from './registry'; import { SnapsRegistryStatus } from './registry'; import { getRunnableSnaps } from './selectors'; @@ -552,7 +552,7 @@ export type AllowedEvents = | SnapControllerSnapInstalledEvent | SnapControllerSnapUpdatedEvent | KeyringControllerLockEvent - | SnapsRegistryStateChangeEvent; + | SnapsRegistryControllerStateChangeEvent; export type SnapControllerMessenger = Messenger< typeof controllerName, diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts index e7e993e05c..0125f7f778 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts @@ -49,8 +49,8 @@ export type ClientConfig = { }; export type SnapsRegistryControllerArgs = { - messenger: SnapsRegistryMessenger; - state?: SnapsRegistryState; + messenger: SnapsRegistryControllerMessenger; + state?: SnapsRegistryControllerState; fetchFunction?: typeof fetch; url?: JsonSnapsRegistryUrl; recentFetchThreshold?: number; @@ -59,29 +59,31 @@ export type SnapsRegistryControllerArgs = { clientConfig: ClientConfig; }; -export type SnapsRegistryGetStateAction = ControllerGetStateAction< +export type SnapsRegistryControllerGetStateAction = ControllerGetStateAction< typeof controllerName, - SnapsRegistryState + SnapsRegistryControllerState >; -export type SnapsRegistryActions = - | SnapsRegistryGetStateAction +export type SnapsRegistryControllerActions = + | SnapsRegistryControllerGetStateAction | SnapsRegistryControllerMethodActions; -export type SnapsRegistryStateChangeEvent = ControllerStateChangeEvent< - typeof controllerName, - SnapsRegistryState ->; +export type SnapsRegistryControllerStateChangeEvent = + ControllerStateChangeEvent< + typeof controllerName, + SnapsRegistryControllerState + >; -export type SnapsRegistryEvents = SnapsRegistryStateChangeEvent; +export type SnapsRegistryControllerEvents = + SnapsRegistryControllerStateChangeEvent; -export type SnapsRegistryMessenger = Messenger< +export type SnapsRegistryControllerMessenger = Messenger< typeof controllerName, - SnapsRegistryActions, - SnapsRegistryEvents + SnapsRegistryControllerActions, + SnapsRegistryControllerEvents >; -export type SnapsRegistryState = { +export type SnapsRegistryControllerState = { database: SnapsRegistryDatabase | null; signature: string | null; lastUpdated: number | null; @@ -106,8 +108,8 @@ const defaultState = { export class SnapsRegistryController extends BaseController< typeof controllerName, - SnapsRegistryState, - SnapsRegistryMessenger + SnapsRegistryControllerState, + SnapsRegistryControllerMessenger > { readonly #url: JsonSnapsRegistryUrl; diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index 6658ef0c99..d972966015 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -6,12 +6,12 @@ export type { } from './registry'; export { SnapsRegistryStatus } from './registry'; export type { - SnapsRegistryActions, + SnapsRegistryControllerActions, SnapsRegistryControllerArgs, - SnapsRegistryGetStateAction, - SnapsRegistryMessenger, - SnapsRegistryState, - SnapsRegistryStateChangeEvent, + SnapsRegistryControllerGetStateAction, + SnapsRegistryControllerMessenger, + SnapsRegistryControllerState, + SnapsRegistryControllerStateChangeEvent, } from './SnapsRegistryController'; export { SnapsRegistryController } from './SnapsRegistryController'; export type { diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index dbddaa9465..d9b838724b 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -63,9 +63,9 @@ import type { import type { MultichainRoutingServiceMessenger } from '../multichain/MultichainRoutingService'; import type { ExecutionService, ExecutionServiceMessenger } from '../services'; import type { - SnapsRegistryActions, + SnapsRegistryControllerActions, SnapsRegistryEvents, - SnapsRegistryMessenger, + SnapsRegistryControllerMessenger, } from '../snaps'; import { SnapController } from '../snaps'; import type { @@ -329,10 +329,14 @@ export const MOCK_INSIGHTS_PERMISSIONS_NO_ORIGINS: Record< export type RootMessenger = Messenger< MockAnyNamespace, MessengerActions< - SnapControllerMessenger | SnapsRegistryMessenger | ExecutionServiceMessenger + | SnapControllerMessenger + | SnapsRegistryControllerMessenger + | ExecutionServiceMessenger >, MessengerEvents< - SnapControllerMessenger | SnapsRegistryMessenger | ExecutionServiceMessenger + | SnapControllerMessenger + | SnapsRegistryControllerMessenger + | ExecutionServiceMessenger > >; @@ -792,7 +796,7 @@ export const getRestrictedCronjobControllerMessenger = ( // Mock controller messenger for registry export const getRootSnapsRegistryControllerMessenger = () => { const messenger = new MockControllerMessenger< - SnapsRegistryActions, + SnapsRegistryControllerActions, SnapsRegistryEvents >(); @@ -808,7 +812,7 @@ export const getRestrictedSnapsRegistryControllerMessenger = ( ) => { return new Messenger< 'SnapsRegistry', - SnapsRegistryActions, + SnapsRegistryControllerActions, SnapsRegistryEvents, any >({ namespace: 'SnapsRegistry', parent: messenger }); From 6fd489b49536295b904c2a27c11735ac4366fbaf Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 10:25:27 +0100 Subject: [PATCH 03/11] Fix tests --- .../src/snaps/registry/SnapsRegistryController.test.ts | 8 +++++++- packages/snaps-controllers/src/test-utils/controller.tsx | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts index 4e742ca6cd..e7cde552d6 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts @@ -681,7 +681,13 @@ describe('SnapsRegistryController', () => { registry.metadata, 'includeInDebugSnapshot', ), - ).toMatchInlineSnapshot(`{}`); + ).toMatchInlineSnapshot(` + { + "databaseUnavailable": false, + "lastUpdated": null, + "signature": null, + } + `); }); it('includes expected state in state logs', () => { diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index d9b838724b..fa883c69af 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -811,11 +811,11 @@ export const getRestrictedSnapsRegistryControllerMessenger = ( > = getRootSnapsRegistryControllerMessenger(), ) => { return new Messenger< - 'SnapsRegistry', + 'SnapsRegistryController', SnapsRegistryControllerActions, SnapsRegistryEvents, any - >({ namespace: 'SnapsRegistry', parent: messenger }); + >({ namespace: 'SnapsRegistryController', parent: messenger }); }; /** From 315bbf059ed561509215545af700a6dee156039e Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 10:32:06 +0100 Subject: [PATCH 04/11] Update coverage --- packages/snaps-controllers/coverage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/snaps-controllers/coverage.json b/packages/snaps-controllers/coverage.json index b63ccf012e..428f6713f9 100644 --- a/packages/snaps-controllers/coverage.json +++ b/packages/snaps-controllers/coverage.json @@ -2,5 +2,5 @@ "branches": 94.97, "functions": 98.78, "lines": 98.63, - "statements": 98.43 + "statements": 98.32 } From cbb2b01bb345d1138bf848338c178a3f8c081918 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 11:47:10 +0100 Subject: [PATCH 05/11] Remove unused `SnapsRegistry` interface --- .../registry/SnapsRegistryController.test.ts | 2 +- .../snaps/registry/SnapsRegistryController.ts | 6 +-- .../src/snaps/registry/index.ts | 14 ++--- .../src/snaps/registry/registry.ts | 53 ------------------- .../src/snaps/registry/types.ts | 23 ++++++++ 5 files changed, 34 insertions(+), 64 deletions(-) delete mode 100644 packages/snaps-controllers/src/snaps/registry/registry.ts create mode 100644 packages/snaps-controllers/src/snaps/registry/types.ts diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts index e7cde552d6..0643108935 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts @@ -7,9 +7,9 @@ import { import type { SemVerRange, SemVerVersion } from '@metamask/utils'; import fetchMock from 'jest-fetch-mock'; -import { SnapsRegistryStatus } from './registry'; import type { SnapsRegistryControllerArgs } from './SnapsRegistryController'; import { SnapsRegistryController } from './SnapsRegistryController'; +import { SnapsRegistryStatus } from './types'; import { getRestrictedSnapsRegistryControllerMessenger } from '../../test-utils'; // Public key for the private key: diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts index 0125f7f778..659e97104d 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts @@ -20,14 +20,14 @@ import { satisfiesVersionRange, } from '@metamask/utils'; +import type { SnapsRegistryControllerMethodActions } from './SnapsRegistryController-method-action-types'; import type { SnapsRegistryInfo, SnapsRegistryMetadata, SnapsRegistryRequest, SnapsRegistryResult, -} from './registry'; -import { SnapsRegistryStatus } from './registry'; -import type { SnapsRegistryControllerMethodActions } from './SnapsRegistryController-method-action-types'; +} from './types'; +import { SnapsRegistryStatus } from './types'; const SNAP_REGISTRY_URL = 'https://acl.execution.metamask.io/latest/registry.json'; diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index d972966015..066a95ed40 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -1,10 +1,3 @@ -export type { - SnapsRegistryInfo, - SnapsRegistryMetadata, - SnapsRegistryRequest, - SnapsRegistryResult, -} from './registry'; -export { SnapsRegistryStatus } from './registry'; export type { SnapsRegistryControllerActions, SnapsRegistryControllerArgs, @@ -20,3 +13,10 @@ export type { SnapsRegistryControllerResolveSnapVersionAction, SnapsRegistryControllerUpdateRegistryAction, } from './SnapsRegistryController-method-action-types'; +export type { + SnapsRegistryInfo, + SnapsRegistryMetadata, + SnapsRegistryRequest, + SnapsRegistryResult, +} from './types'; +export { SnapsRegistryStatus } from './types'; diff --git a/packages/snaps-controllers/src/snaps/registry/registry.ts b/packages/snaps-controllers/src/snaps/registry/registry.ts deleted file mode 100644 index 07c5009677..0000000000 --- a/packages/snaps-controllers/src/snaps/registry/registry.ts +++ /dev/null @@ -1,53 +0,0 @@ -import type { - BlockReason, - SnapsRegistryDatabase, -} from '@metamask/snaps-registry'; -import type { SnapId } from '@metamask/snaps-sdk'; -import type { SemVerRange, SemVerVersion } from '@metamask/utils'; - -export type SnapsRegistryInfo = { version: SemVerVersion; checksum: string }; -export type SnapsRegistryRequest = Record; -export type SnapsRegistryMetadata = - SnapsRegistryDatabase['verifiedSnaps'][SnapId]['metadata']; - -export enum SnapsRegistryStatus { - Unverified = 0, - Blocked = 1, - Verified = 2, - Unavailable = 3, -} - -export type SnapsRegistryResult = { - status: SnapsRegistryStatus; - reason?: BlockReason; -}; - -export type SnapsRegistry = { - get( - snaps: SnapsRegistryRequest, - ): Promise>; - - update(): Promise; - - /** - * Find an allowlisted version within a specified version range. - * - * @param snapId - The ID of the snap we are trying to resolve a version for. - * @param versionRange - The version range. - * @returns An allowlisted version within the specified version range. - * @throws If an allowlisted version does not exist within the version range. - */ - resolveVersion( - snapId: SnapId, - versionRange: SemVerRange, - ): Promise; - - /** - * Get metadata for the given snap ID. - * - * @param snapId - The ID of the snap to get metadata for. - * @returns The metadata for the given snap ID, or `null` if the snap is not - * verified. - */ - getMetadata(snapId: SnapId): SnapsRegistryMetadata | null; -}; diff --git a/packages/snaps-controllers/src/snaps/registry/types.ts b/packages/snaps-controllers/src/snaps/registry/types.ts new file mode 100644 index 0000000000..50c6959931 --- /dev/null +++ b/packages/snaps-controllers/src/snaps/registry/types.ts @@ -0,0 +1,23 @@ +import type { + BlockReason, + SnapsRegistryDatabase, +} from '@metamask/snaps-registry'; +import type { SnapId } from '@metamask/snaps-sdk'; +import type { SemVerVersion } from '@metamask/utils'; + +export type SnapsRegistryInfo = { version: SemVerVersion; checksum: string }; +export type SnapsRegistryRequest = Record; +export type SnapsRegistryMetadata = + SnapsRegistryDatabase['verifiedSnaps'][SnapId]['metadata']; + +export enum SnapsRegistryStatus { + Unverified = 0, + Blocked = 1, + Verified = 2, + Unavailable = 3, +} + +export type SnapsRegistryResult = { + status: SnapsRegistryStatus; + reason?: BlockReason; +}; From 40fcf6d688562be4c9c9e0be5d308d76382e5602 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:11:18 +0100 Subject: [PATCH 06/11] Update `updateRegistry` to `requestUpdate` --- .../src/snaps/SnapController.ts | 6 +++--- ...napsRegistryController-method-action-types.ts | 8 ++++---- .../registry/SnapsRegistryController.test.ts | 16 ++++++++-------- .../snaps/registry/SnapsRegistryController.ts | 12 ++++++------ .../src/snaps/registry/index.ts | 2 +- .../src/test-utils/controller.tsx | 2 +- .../snaps-controllers/src/test-utils/registry.ts | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index ad61cc554f..6f7deca643 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -164,7 +164,7 @@ import type { SnapsRegistryControllerGetSnapAction, SnapsRegistryControllerGetSnapMetadataAction, SnapsRegistryControllerResolveSnapVersionAction, - SnapsRegistryControllerUpdateRegistryAction, + SnapsRegistryControllerRequestUpdateAction, SnapsRegistryInfo, SnapsRegistryRequest, SnapsRegistryControllerStateChangeEvent, @@ -537,8 +537,8 @@ export type AllowedActions = | ApprovalControllerUpdateRequestStateAction | SnapsRegistryControllerGetSnapAction | SnapsRegistryControllerGetSnapMetadataAction - | SnapsRegistryControllerUpdateRegistryAction | SnapsRegistryControllerResolveSnapVersionAction + | SnapsRegistryControllerRequestUpdateAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction | SnapInterfaceControllerSetInterfaceDisplayedAction @@ -1457,7 +1457,7 @@ export class SnapController extends BaseController< */ async updateRegistry(): Promise { await this.#ensureCanUsePlatform(); - await this.messenger.call('SnapsRegistryController:updateRegistry'); + await this.messenger.call('SnapsRegistryController:requestUpdate'); } /** diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts index 1d222487c9..49a9ab9f95 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts @@ -10,9 +10,9 @@ import type { SnapsRegistryController } from './SnapsRegistryController'; * * If an existing update is in progress this function will await that update. */ -export type SnapsRegistryControllerUpdateRegistryAction = { - type: `SnapsRegistryController:updateRegistry`; - handler: SnapsRegistryController['updateRegistry']; +export type SnapsRegistryControllerRequestUpdateAction = { + type: `SnapsRegistryController:requestUpdate`; + handler: SnapsRegistryController['requestUpdate']; }; export type SnapsRegistryControllerGetSnapAction = { @@ -49,7 +49,7 @@ export type SnapsRegistryControllerGetSnapMetadataAction = { * Union of all SnapsRegistryController action types. */ export type SnapsRegistryControllerMethodActions = - | SnapsRegistryControllerUpdateRegistryAction + | SnapsRegistryControllerRequestUpdateAction | SnapsRegistryControllerGetSnapAction | SnapsRegistryControllerResolveSnapVersionAction | SnapsRegistryControllerGetSnapMetadataAction; diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts index 0643108935..6ebe00ab4b 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts @@ -584,7 +584,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:requestUpdate'); const result = messenger.call( 'SnapsRegistryController:getSnapMetadata', MOCK_SNAP_ID, @@ -601,7 +601,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:requestUpdate'); const result = messenger.call( 'SnapsRegistryController:getSnapMetadata', 'foo', @@ -618,7 +618,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -638,7 +638,7 @@ describe('SnapsRegistryController', () => { databaseUnavailable: false, }, }); - await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); expect(spy).not.toHaveBeenCalled(); @@ -650,8 +650,8 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:updateRegistry'); - await messenger.call('SnapsRegistryController:updateRegistry'); + await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapsRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -663,8 +663,8 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); await Promise.all([ - messenger.call('SnapsRegistryController:updateRegistry'), - messenger.call('SnapsRegistryController:updateRegistry'), + messenger.call('SnapsRegistryController:requestUpdate'), + messenger.call('SnapsRegistryController:requestUpdate'), ]); expect(fetchMock).toHaveBeenCalledTimes(2); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts index 659e97104d..b4c3fc4149 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts @@ -96,7 +96,7 @@ const MESSENGER_EXPOSED_METHODS = [ 'getSnap', 'getSnapMetadata', 'resolveSnapVersion', - 'updateRegistry', + 'requestUpdate', ] as const; const defaultState = { @@ -198,7 +198,7 @@ export class SnapsRegistryController extends BaseController< * * If an existing update is in progress this function will await that update. */ - async updateRegistry() { + async requestUpdate() { // If an update is ongoing, wait for that. if (this.#currentUpdate) { await this.#currentUpdate; @@ -258,7 +258,7 @@ export class SnapsRegistryController extends BaseController< async #getDatabase(): Promise { if (this.state.database === null) { - await this.updateRegistry(); + await this.requestUpdate(); } return this.state.database; @@ -300,7 +300,7 @@ export class SnapsRegistryController extends BaseController< } // For now, if we have an allowlist miss, we can refetch once and try again. if (this.#refetchOnAllowlistMiss && !refetch) { - await this.updateRegistry(); + await this.requestUpdate(); return this.#getSingle(snapId, snapInfo, true); } return { @@ -340,7 +340,7 @@ export class SnapsRegistryController extends BaseController< const versions = database?.verifiedSnaps[snapId]?.versions ?? null; if (!versions && this.#refetchOnAllowlistMiss && !refetch) { - await this.updateRegistry(); + await this.requestUpdate(); return this.resolveSnapVersion(snapId, versionRange, true); } @@ -367,7 +367,7 @@ export class SnapsRegistryController extends BaseController< const targetVersion = getTargetVersion(compatibleVersions, versionRange); if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) { - await this.updateRegistry(); + await this.requestUpdate(); return this.resolveSnapVersion(snapId, versionRange, true); } diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index 066a95ed40..a4f1ab963d 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -11,7 +11,7 @@ export type { SnapsRegistryControllerGetSnapAction, SnapsRegistryControllerGetSnapMetadataAction, SnapsRegistryControllerResolveSnapVersionAction, - SnapsRegistryControllerUpdateRegistryAction, + SnapsRegistryControllerRequestUpdateAction, } from './SnapsRegistryController-method-action-types'; export type { SnapsRegistryInfo, diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index fa883c69af..b024bf4ea5 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -502,7 +502,7 @@ export const getSnapControllerMessenger = ( 'SubjectMetadataController:addSubjectMetadata', 'SnapsRegistryController:getSnap', 'SnapsRegistryController:getSnapMetadata', - 'SnapsRegistryController:updateRegistry', + 'SnapsRegistryController:requestUpdate', 'SnapsRegistryController:resolveSnapVersion', 'SnapInterfaceController:createInterface', 'SnapInterfaceController:setInterfaceDisplayed', diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index cf6f0d0a8e..f7bba39556 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -24,7 +24,7 @@ export class MockSnapsRegistry implements SnapsRegistry { ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:updateRegistry', + 'SnapsRegistryController:requestUpdate', this.update.bind(this), ); } From ed2bd3949a58e6f6f45ebb40f97b72aef85c2a6b Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:19:33 +0100 Subject: [PATCH 07/11] Remove "Snap" from methods again --- packages/snaps-controllers/CHANGELOG.md | 13 ++---- .../src/snaps/SnapController.test.tsx | 2 +- .../src/snaps/SnapController.ts | 27 +++++------ ...sRegistryController-method-action-types.ts | 24 +++++----- .../registry/SnapsRegistryController.test.ts | 46 +++++++++---------- .../snaps/registry/SnapsRegistryController.ts | 16 +++---- .../src/snaps/registry/index.ts | 7 +-- .../src/test-utils/controller.tsx | 6 +-- .../src/test-utils/registry.ts | 6 +-- 9 files changed, 71 insertions(+), 76 deletions(-) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index 30571cd212..31b3c5e6e6 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -57,14 +57,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `TerminateSnap` is now `ExecutionServiceTerminateSnapAction`. - `GetExecutionStatus` is now `ExecutionServiceGetExecutionStatusAction`. - `SnapsRegistryController` actions: - - `GetResult` is now `SnapsRegistryControllerGetSnapAction`. - - Note: The method is now called `getSnap` instead of `get`. - - `GetMetadata` is now `SnapsRegistryControllerGetSnapMetadataAction`. - - Note: The method is now called `getSnapMetadata` instead of `getMetadata`. - - `ResolveVersion` is now `SnapsRegistryControllerResolveSnapVersionAction`. - - Note: The method is now called `resolveSnapVersion` instead of `resolveVersion`. - - `Update` is now `SnapsRegistryControllerUpdateRegistryAction`. - - Note: The method is now called `updateRegistry` instead of `update`. + - `GetResult` is now `SnapsRegistryControllerGetAction`. + - `GetMetadata` is now `SnapsRegistryControllerGetMetadataAction`. + - `ResolveVersion` is now `SnapsRegistryControllerResolveVersionAction`. + - `Update` is now `SnapsRegistryControllerRequestUpdateAction`. + - Note: The method is now called `requestUpdate` instead of `update`. - **BREAKING:** All event types were renamed from `OnSomething` to `ControllerOnSomethingEvent` ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3916](https://github.com/MetaMask/snaps/pull/3916)) - `SnapController` events: - `SnapStateChange` was removed in favour of `SnapControllerStateChangeEvent`. diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index 02116ce1b6..40ff6ce8f7 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -817,7 +817,7 @@ describe('SnapController', () => { expect(options.messenger.call).toHaveBeenNthCalledWith( 2, - 'SnapsRegistryController:getSnap', + 'SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0', diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 6f7deca643..33b257ad01 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -161,9 +161,9 @@ import { import type { SnapLocation } from './location'; import { detectSnapLocation } from './location'; import type { - SnapsRegistryControllerGetSnapAction, - SnapsRegistryControllerGetSnapMetadataAction, - SnapsRegistryControllerResolveSnapVersionAction, + SnapsRegistryControllerGetAction, + SnapsRegistryControllerGetMetadataAction, + SnapsRegistryControllerResolveVersionAction, SnapsRegistryControllerRequestUpdateAction, SnapsRegistryInfo, SnapsRegistryRequest, @@ -535,9 +535,9 @@ export type AllowedActions = | ExecutionServiceTerminateSnapAction | UpdateCaveat | ApprovalControllerUpdateRequestStateAction - | SnapsRegistryControllerGetSnapAction - | SnapsRegistryControllerGetSnapMetadataAction - | SnapsRegistryControllerResolveSnapVersionAction + | SnapsRegistryControllerGetAction + | SnapsRegistryControllerGetMetadataAction + | SnapsRegistryControllerResolveVersionAction | SnapsRegistryControllerRequestUpdateAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction @@ -1003,7 +1003,7 @@ export class SnapController extends BaseController< this.#trackSnapExport = throttleTracking( (snapId: SnapId, handler: string, success: boolean, origin: string) => { const snapMetadata = this.messenger.call( - 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:getMetadata', snapId, ); this.#trackEvent({ @@ -1469,7 +1469,7 @@ export class SnapController extends BaseController< */ async #handleRegistryUpdate() { const blockedSnaps = await this.messenger.call( - 'SnapsRegistryController:getSnap', + 'SnapsRegistryController:get', Object.values(this.state.snaps).reduce( (blockListArg, snap) => { blockListArg[snap.id] = { @@ -1596,12 +1596,9 @@ export class SnapController extends BaseController< platformVersion: string | undefined; }, ) { - const results = await this.messenger.call( - 'SnapsRegistryController:getSnap', - { - [snapId]: snapInfo, - }, - ); + const results = await this.messenger.call('SnapsRegistryController:get', { + [snapId]: snapInfo, + }); const result = results[snapId]; if (result.status === SnapsRegistryStatus.Blocked) { @@ -3140,7 +3137,7 @@ export class SnapController extends BaseController< versionRange: SemVerRange, ): Promise { return await this.messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', snapId, versionRange, ); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts index 49a9ab9f95..df6d4a2ef1 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts @@ -15,9 +15,9 @@ export type SnapsRegistryControllerRequestUpdateAction = { handler: SnapsRegistryController['requestUpdate']; }; -export type SnapsRegistryControllerGetSnapAction = { - type: `SnapsRegistryController:getSnap`; - handler: SnapsRegistryController['getSnap']; +export type SnapsRegistryControllerGetAction = { + type: `SnapsRegistryController:get`; + handler: SnapsRegistryController['get']; }; /** @@ -28,9 +28,9 @@ export type SnapsRegistryControllerGetSnapAction = { * @param refetch - An optional flag used to determine if we are refetching the registry. * @returns An allowlisted version within the specified version range if available otherwise returns the input version range. */ -export type SnapsRegistryControllerResolveSnapVersionAction = { - type: `SnapsRegistryController:resolveSnapVersion`; - handler: SnapsRegistryController['resolveSnapVersion']; +export type SnapsRegistryControllerResolveVersionAction = { + type: `SnapsRegistryController:resolveVersion`; + handler: SnapsRegistryController['resolveVersion']; }; /** @@ -40,9 +40,9 @@ export type SnapsRegistryControllerResolveSnapVersionAction = { * @returns The metadata for the given snap ID, or `null` if the snap is not * verified. */ -export type SnapsRegistryControllerGetSnapMetadataAction = { - type: `SnapsRegistryController:getSnapMetadata`; - handler: SnapsRegistryController['getSnapMetadata']; +export type SnapsRegistryControllerGetMetadataAction = { + type: `SnapsRegistryController:getMetadata`; + handler: SnapsRegistryController['getMetadata']; }; /** @@ -50,6 +50,6 @@ export type SnapsRegistryControllerGetSnapMetadataAction = { */ export type SnapsRegistryControllerMethodActions = | SnapsRegistryControllerRequestUpdateAction - | SnapsRegistryControllerGetSnapAction - | SnapsRegistryControllerResolveSnapVersionAction - | SnapsRegistryControllerGetSnapMetadataAction; + | SnapsRegistryControllerGetAction + | SnapsRegistryControllerResolveVersionAction + | SnapsRegistryControllerGetMetadataAction; diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts index 6ebe00ab4b..a3e4d467f3 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts @@ -138,7 +138,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -159,7 +159,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_EMPTY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -179,7 +179,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -199,7 +199,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'bar', @@ -219,7 +219,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'foo', @@ -240,7 +240,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { 'npm:@consensys/starknet-snap': { version: '0.1.10' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -267,7 +267,7 @@ describe('SnapsRegistryController', () => { database: { verifiedSnaps: {}, blockedSnaps: [] }, }, }); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -287,7 +287,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -307,7 +307,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.1.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -332,7 +332,7 @@ describe('SnapsRegistryController', () => { }, }); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -357,7 +357,7 @@ describe('SnapsRegistryController', () => { }, }); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -376,7 +376,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -399,7 +399,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -423,7 +423,7 @@ describe('SnapsRegistryController', () => { '0x034ca27b046507d1a9997bddc991b56d96b93d4adac3a96dfe01ce450bfb661455', }); - const result = await messenger.call('SnapsRegistryController:getSnap', { + const result = await messenger.call('SnapsRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -445,7 +445,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -460,7 +460,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -477,7 +477,7 @@ describe('SnapsRegistryController', () => { clientConfig: { type: 'extension', version: '15.0.0' as SemVerVersion }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -496,7 +496,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, range, ), @@ -512,7 +512,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, range, ), @@ -532,7 +532,7 @@ describe('SnapsRegistryController', () => { }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -568,7 +568,7 @@ describe('SnapsRegistryController', () => { }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -586,7 +586,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); await messenger.call('SnapsRegistryController:requestUpdate'); const result = messenger.call( - 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:getMetadata', MOCK_SNAP_ID, ); @@ -603,7 +603,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); await messenger.call('SnapsRegistryController:requestUpdate'); const result = messenger.call( - 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:getMetadata', 'foo', ); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts index b4c3fc4149..8b0034db2c 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts @@ -93,9 +93,9 @@ export type SnapsRegistryControllerState = { const controllerName = 'SnapsRegistryController'; const MESSENGER_EXPOSED_METHODS = [ - 'getSnap', - 'getSnapMetadata', - 'resolveSnapVersion', + 'get', + 'getMetadata', + 'resolveVersion', 'requestUpdate', ] as const; @@ -310,7 +310,7 @@ export class SnapsRegistryController extends BaseController< }; } - async getSnap( + async get( snaps: SnapsRegistryRequest, ): Promise> { return Object.entries(snaps).reduce< @@ -331,7 +331,7 @@ export class SnapsRegistryController extends BaseController< * @param refetch - An optional flag used to determine if we are refetching the registry. * @returns An allowlisted version within the specified version range if available otherwise returns the input version range. */ - async resolveSnapVersion( + async resolveVersion( snapId: string, versionRange: SemVerRange, refetch = false, @@ -341,7 +341,7 @@ export class SnapsRegistryController extends BaseController< if (!versions && this.#refetchOnAllowlistMiss && !refetch) { await this.requestUpdate(); - return this.resolveSnapVersion(snapId, versionRange, true); + return this.resolveVersion(snapId, versionRange, true); } // If we cannot narrow down the version range we return the unaltered version range. @@ -368,7 +368,7 @@ export class SnapsRegistryController extends BaseController< if (!targetVersion && this.#refetchOnAllowlistMiss && !refetch) { await this.requestUpdate(); - return this.resolveSnapVersion(snapId, versionRange, true); + return this.resolveVersion(snapId, versionRange, true); } // If we cannot narrow down the version range we return the unaltered version range. @@ -388,7 +388,7 @@ export class SnapsRegistryController extends BaseController< * @returns The metadata for the given snap ID, or `null` if the snap is not * verified. */ - getSnapMetadata(snapId: string): SnapsRegistryMetadata | null { + getMetadata(snapId: string): SnapsRegistryMetadata | null { return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null; } diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index a4f1ab963d..6661414e82 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -8,10 +8,11 @@ export type { } from './SnapsRegistryController'; export { SnapsRegistryController } from './SnapsRegistryController'; export type { - SnapsRegistryControllerGetSnapAction, - SnapsRegistryControllerGetSnapMetadataAction, - SnapsRegistryControllerResolveSnapVersionAction, + SnapsRegistryControllerGetAction, + SnapsRegistryControllerGetMetadataAction, + SnapsRegistryControllerMethodActions, SnapsRegistryControllerRequestUpdateAction, + SnapsRegistryControllerResolveVersionAction, } from './SnapsRegistryController-method-action-types'; export type { SnapsRegistryInfo, diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index b024bf4ea5..44a64b500f 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -500,10 +500,10 @@ export const getSnapControllerMessenger = ( 'PermissionController:getSubjectNames', 'SubjectMetadataController:getSubjectMetadata', 'SubjectMetadataController:addSubjectMetadata', - 'SnapsRegistryController:getSnap', - 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:get', + 'SnapsRegistryController:getMetadata', 'SnapsRegistryController:requestUpdate', - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', 'SnapInterfaceController:createInterface', 'SnapInterfaceController:setInterfaceDisplayed', 'SnapInterfaceController:getInterface', diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index f7bba39556..ad03c17784 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -9,17 +9,17 @@ export class MockSnapsRegistry implements SnapsRegistry { this.#messenger = messenger; this.#messenger.registerActionHandler( - 'SnapsRegistryController:getSnap', + 'SnapsRegistryController:get', this.get.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:getSnapMetadata', + 'SnapsRegistryController:getMetadata', this.getMetadata.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:resolveSnapVersion', + 'SnapsRegistryController:resolveVersion', this.resolveVersion.bind(this), ); From bf64a59cb6f35f73e2a8c4efeba27d48c7cbf560 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:27:34 +0100 Subject: [PATCH 08/11] Fix type errors --- .../src/snaps/registry/index.ts | 1 + .../src/test-utils/controller.tsx | 62 +++++++++---------- .../src/test-utils/registry.ts | 3 +- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index 6661414e82..19fce93147 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -1,5 +1,6 @@ export type { SnapsRegistryControllerActions, + SnapsRegistryControllerEvents, SnapsRegistryControllerArgs, SnapsRegistryControllerGetStateAction, SnapsRegistryControllerMessenger, diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index 44a64b500f..a0defcba40 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -62,11 +62,7 @@ import type { } from '../interface/SnapInterfaceController'; import type { MultichainRoutingServiceMessenger } from '../multichain/MultichainRoutingService'; import type { ExecutionService, ExecutionServiceMessenger } from '../services'; -import type { - SnapsRegistryControllerActions, - SnapsRegistryEvents, - SnapsRegistryControllerMessenger, -} from '../snaps'; +import type { SnapsRegistryControllerMessenger } from '../snaps'; import { SnapController } from '../snaps'; import type { PersistedSnapControllerState, @@ -74,11 +70,7 @@ import type { SnapControllerStateChangeEvent, } from '../snaps/SnapController'; import type { KeyDerivationOptions } from '../types'; -import type { - WebSocketServiceActions, - WebSocketServiceAllowedActions, - WebSocketServiceEvents, -} from '../websocket'; +import type { WebSocketServiceMessenger } from '../websocket'; const asyncNoOp = async () => Promise.resolve(); @@ -793,12 +785,15 @@ export const getRestrictedCronjobControllerMessenger = ( return cronjobControllerMessenger; }; -// Mock controller messenger for registry +type SnapsRegistryControllerRootMessenger = Messenger< + MockAnyNamespace, + MessengerActions, + MessengerEvents +>; + export const getRootSnapsRegistryControllerMessenger = () => { - const messenger = new MockControllerMessenger< - SnapsRegistryControllerActions, - SnapsRegistryEvents - >(); + const messenger: SnapsRegistryControllerRootMessenger = + new MockControllerMessenger(); jest.spyOn(messenger, 'call'); @@ -806,16 +801,16 @@ export const getRootSnapsRegistryControllerMessenger = () => { }; export const getRestrictedSnapsRegistryControllerMessenger = ( - messenger: ReturnType< + rootMessenger: ReturnType< typeof getRootSnapsRegistryControllerMessenger > = getRootSnapsRegistryControllerMessenger(), ) => { - return new Messenger< - 'SnapsRegistryController', - SnapsRegistryControllerActions, - SnapsRegistryEvents, - any - >({ namespace: 'SnapsRegistryController', parent: messenger }); + const messenger: SnapsRegistryControllerMessenger = new Messenger({ + namespace: 'SnapsRegistryController', + parent: rootMessenger, + }); + + return messenger; }; /** @@ -1028,12 +1023,15 @@ export const getRestrictedMultichainRoutingServiceMessenger = ( return controllerMessenger; }; -// Mock controller messenger for WebSocketService +type WebSocketServiceRootMessenger = Messenger< + MockAnyNamespace, + MessengerActions, + MessengerEvents +>; + export const getRootWebSocketServiceMessenger = () => { - const messenger = new MockControllerMessenger< - WebSocketServiceActions | WebSocketServiceAllowedActions, - WebSocketServiceEvents - >(); + const messenger: WebSocketServiceRootMessenger = + new MockControllerMessenger(); jest.spyOn(messenger, 'call'); @@ -1045,12 +1043,10 @@ export const getRestrictedWebSocketServiceMessenger = ( typeof getRootWebSocketServiceMessenger > = getRootWebSocketServiceMessenger(), ) => { - const controllerMessenger = new Messenger< - 'WebSocketService', - WebSocketServiceActions | WebSocketServiceAllowedActions, - WebSocketServiceEvents, - any - >({ namespace: 'WebSocketService', parent: messenger }); + const controllerMessenger: WebSocketServiceMessenger = new Messenger({ + namespace: 'WebSocketService', + parent: messenger, + }); messenger.delegate({ actions: ['SnapController:handleRequest'], diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index ad03c17784..5b56c29512 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -1,8 +1,7 @@ import type { RootMessenger } from './controller'; -import type { SnapsRegistry } from '../snaps'; import { SnapsRegistryStatus } from '../snaps'; -export class MockSnapsRegistry implements SnapsRegistry { +export class MockSnapsRegistry { readonly #messenger; constructor(messenger: RootMessenger) { From 391e78f0b115794bb6559b42eab04e502ff61b65 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:34:11 +0100 Subject: [PATCH 09/11] Rename controller to `SnapRegistryController` --- packages/snaps-controllers/CHANGELOG.md | 14 +-- .../src/snaps/SnapController.test.tsx | 22 ++-- .../src/snaps/SnapController.ts | 50 ++++----- ...RegistryController-method-action-types.ts} | 38 +++---- ...test.ts => SnapRegistryController.test.ts} | 106 +++++++++--------- ...ontroller.ts => SnapRegistryController.ts} | 79 +++++++------ .../src/snaps/registry/index.ts | 39 ++++--- .../src/snaps/registry/types.ts | 12 +- .../src/test-utils/controller.tsx | 36 +++--- .../src/test-utils/registry.ts | 14 +-- 10 files changed, 204 insertions(+), 206 deletions(-) rename packages/snaps-controllers/src/snaps/registry/{SnapsRegistryController-method-action-types.ts => SnapRegistryController-method-action-types.ts} (50%) rename packages/snaps-controllers/src/snaps/registry/{SnapsRegistryController.test.ts => SnapRegistryController.test.ts} (85%) rename packages/snaps-controllers/src/snaps/registry/{SnapsRegistryController.ts => SnapRegistryController.ts} (86%) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index 31b3c5e6e6..bf8ed73804 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -56,11 +56,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `HandleRequest` is now `ExecutionServiceHandleRequestAction`. - `TerminateSnap` is now `ExecutionServiceTerminateSnapAction`. - `GetExecutionStatus` is now `ExecutionServiceGetExecutionStatusAction`. - - `SnapsRegistryController` actions: - - `GetResult` is now `SnapsRegistryControllerGetAction`. - - `GetMetadata` is now `SnapsRegistryControllerGetMetadataAction`. - - `ResolveVersion` is now `SnapsRegistryControllerResolveVersionAction`. - - `Update` is now `SnapsRegistryControllerRequestUpdateAction`. + - `SnapRegistryController` actions: + - `GetResult` is now `SnapRegistryControllerGetAction`. + - `GetMetadata` is now `SnapRegistryControllerGetMetadataAction`. + - `ResolveVersion` is now `SnapRegistryControllerResolveVersionAction`. + - `Update` is now `SnapRegistryControllerRequestUpdateAction`. - Note: The method is now called `requestUpdate` instead of `update`. - **BREAKING:** All event types were renamed from `OnSomething` to `ControllerOnSomethingEvent` ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3916](https://github.com/MetaMask/snaps/pull/3916)) - `SnapController` events: @@ -82,9 +82,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `OutboundResponse` is now `ExecutionServiceOutboundResponseEvent`. - **BREAKING:**: Rename `MultichainRouter` to `MultichainRoutingService` and update action types accordingly ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - This is consistent with the naming of other services. -- **BREAKING:** Rename `JsonSnapsRegistry` to `SnapsRegistryController` and update action types accordingly ([#3918](https://github.com/MetaMask/snaps/pull/3918)) +- **BREAKING:** Rename `JsonSnapsRegistry` to `SnapRegistryController` and update action types accordingly ([#3918](https://github.com/MetaMask/snaps/pull/3918)) - This is consistent with the naming of other controllers. - - The controller name is now `SnapsRegistryController` instead of `SnapsRegistry` as well. + - The controller name is now `SnapRegistryController` instead of `SnapsRegistry` as well. - **BREAKING:** `MultichainRoutingService` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3913](https://github.com/MetaMask/snaps/pull/3913)) - **BREAKING:** `SnapInsightsController` now requires `SnapController:getRunnableSnaps` instead of `SnapController:getAllSnaps` ([#3915](https://github.com/MetaMask/snaps/pull/3915)) - **RREAKING:** Replace `ExecutionService` interface with abstract class ([#3916](https://github.com/MetaMask/snaps/pull/3916)) diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index 40ff6ce8f7..6818caf298 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -87,7 +87,7 @@ import { METAMASK_ORIGIN, STATE_DEBOUNCE_TIMEOUT, } from './constants'; -import { SnapsRegistryStatus } from './registry'; +import { SnapRegistryStatus } from './registry'; import type { SnapControllerState } from './SnapController'; import { controllerName, @@ -817,7 +817,7 @@ describe('SnapController', () => { expect(options.messenger.call).toHaveBeenNthCalledWith( 2, - 'SnapsRegistryController:get', + 'SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0', @@ -1091,7 +1091,7 @@ describe('SnapController', () => { // Mock resolve to succeed, but registry.get() will fail later registry.resolveVersion.mockReturnValue('1.0.0'); registry.get.mockReturnValue({ - [MOCK_SNAP_ID]: { status: SnapsRegistryStatus.Unavailable }, + [MOCK_SNAP_ID]: { status: SnapRegistryStatus.Unavailable }, }); await expect( @@ -1151,7 +1151,7 @@ describe('SnapController', () => { }); registry.get.mockResolvedValueOnce({ - [MOCK_SNAP_ID]: { status: SnapsRegistryStatus.Verified }, + [MOCK_SNAP_ID]: { status: SnapRegistryStatus.Verified }, }); registry.resolveVersion.mockReturnValue('1.1.0'); @@ -8940,7 +8940,7 @@ describe('SnapController', () => { ); registry.get.mockResolvedValueOnce({ - [MOCK_SNAP_ID]: { status: SnapsRegistryStatus.Blocked }, + [MOCK_SNAP_ID]: { status: SnapRegistryStatus.Blocked }, }); await expect( @@ -10569,7 +10569,7 @@ describe('SnapController', () => { // Block snap A, ignore B. registry.get.mockResolvedValueOnce({ [mockSnapA.id]: { - status: SnapsRegistryStatus.Blocked, + status: SnapRegistryStatus.Blocked, reason: { explanation, infoUrl }, }, }); @@ -10629,7 +10629,7 @@ describe('SnapController', () => { // Block the snap registry.get.mockResolvedValueOnce({ - [mockSnap.id]: { status: SnapsRegistryStatus.Blocked }, + [mockSnap.id]: { status: SnapRegistryStatus.Blocked }, }); await snapController.updateRegistry(); await waitForStateChange(options.messenger); @@ -10683,8 +10683,8 @@ describe('SnapController', () => { // Indicate that both snaps A and B are unblocked, and update blocked // states. registry.get.mockResolvedValueOnce({ - [mockSnapA.id]: { status: SnapsRegistryStatus.Unverified }, - [mockSnapB.id]: { status: SnapsRegistryStatus.Unverified }, + [mockSnapA.id]: { status: SnapRegistryStatus.Unverified }, + [mockSnapB.id]: { status: SnapRegistryStatus.Unverified }, }); await snapController.updateRegistry(); @@ -10736,7 +10736,7 @@ describe('SnapController', () => { // Resolve the blocklist and wait for the call to complete resolveBlockListPromise({ - [mockSnap.id]: { status: SnapsRegistryStatus.Blocked }, + [mockSnap.id]: { status: SnapRegistryStatus.Blocked }, }); await updateBlockList; @@ -10774,7 +10774,7 @@ describe('SnapController', () => { // Block the snap registry.get.mockResolvedValueOnce({ - [mockSnap.id]: { status: SnapsRegistryStatus.Blocked }, + [mockSnap.id]: { status: SnapRegistryStatus.Blocked }, }); await snapController.updateRegistry(); diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 33b257ad01..3257562723 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -161,15 +161,15 @@ import { import type { SnapLocation } from './location'; import { detectSnapLocation } from './location'; import type { - SnapsRegistryControllerGetAction, - SnapsRegistryControllerGetMetadataAction, - SnapsRegistryControllerResolveVersionAction, - SnapsRegistryControllerRequestUpdateAction, - SnapsRegistryInfo, - SnapsRegistryRequest, - SnapsRegistryControllerStateChangeEvent, + SnapRegistryControllerGetAction, + SnapRegistryControllerGetMetadataAction, + SnapRegistryControllerResolveVersionAction, + SnapRegistryControllerRequestUpdateAction, + SnapRegistryInfo, + SnapRegistryRequest, + SnapRegistryControllerStateChangeEvent, } from './registry'; -import { SnapsRegistryStatus } from './registry'; +import { SnapRegistryStatus } from './registry'; import { getRunnableSnaps } from './selectors'; import type { SnapControllerMethodActions } from './SnapController-method-action-types'; import { Timer } from './Timer'; @@ -535,10 +535,10 @@ export type AllowedActions = | ExecutionServiceTerminateSnapAction | UpdateCaveat | ApprovalControllerUpdateRequestStateAction - | SnapsRegistryControllerGetAction - | SnapsRegistryControllerGetMetadataAction - | SnapsRegistryControllerResolveVersionAction - | SnapsRegistryControllerRequestUpdateAction + | SnapRegistryControllerGetAction + | SnapRegistryControllerGetMetadataAction + | SnapRegistryControllerResolveVersionAction + | SnapRegistryControllerRequestUpdateAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction | SnapInterfaceControllerSetInterfaceDisplayedAction @@ -552,7 +552,7 @@ export type AllowedEvents = | SnapControllerSnapInstalledEvent | SnapControllerSnapUpdatedEvent | KeyringControllerLockEvent - | SnapsRegistryControllerStateChangeEvent; + | SnapRegistryControllerStateChangeEvent; export type SnapControllerMessenger = Messenger< typeof controllerName, @@ -980,7 +980,7 @@ export class SnapController extends BaseController< ); this.messenger.subscribe( - 'SnapsRegistryController:stateChange', + 'SnapRegistryController:stateChange', () => { this.#handleRegistryUpdate().catch((error) => { logError( @@ -1003,7 +1003,7 @@ export class SnapController extends BaseController< this.#trackSnapExport = throttleTracking( (snapId: SnapId, handler: string, success: boolean, origin: string) => { const snapMetadata = this.messenger.call( - 'SnapsRegistryController:getMetadata', + 'SnapRegistryController:getMetadata', snapId, ); this.#trackEvent({ @@ -1457,7 +1457,7 @@ export class SnapController extends BaseController< */ async updateRegistry(): Promise { await this.#ensureCanUsePlatform(); - await this.messenger.call('SnapsRegistryController:requestUpdate'); + await this.messenger.call('SnapRegistryController:requestUpdate'); } /** @@ -1469,8 +1469,8 @@ export class SnapController extends BaseController< */ async #handleRegistryUpdate() { const blockedSnaps = await this.messenger.call( - 'SnapsRegistryController:get', - Object.values(this.state.snaps).reduce( + 'SnapRegistryController:get', + Object.values(this.state.snaps).reduce( (blockListArg, snap) => { blockListArg[snap.id] = { version: snap.version, @@ -1484,7 +1484,7 @@ export class SnapController extends BaseController< await Promise.all( Object.entries(blockedSnaps).map(async ([snapId, { status, reason }]) => { - if (status === SnapsRegistryStatus.Blocked) { + if (status === SnapRegistryStatus.Blocked) { return this.#blockSnap(snapId as SnapId, reason); } @@ -1591,17 +1591,17 @@ export class SnapController extends BaseController< { platformVersion, ...snapInfo - }: SnapsRegistryInfo & { + }: SnapRegistryInfo & { permissions: SnapPermissions; platformVersion: string | undefined; }, ) { - const results = await this.messenger.call('SnapsRegistryController:get', { + const results = await this.messenger.call('SnapRegistryController:get', { [snapId]: snapInfo, }); const result = results[snapId]; - if (result.status === SnapsRegistryStatus.Blocked) { + if (result.status === SnapRegistryStatus.Blocked) { throw new Error( `Cannot install version "${ snapInfo.version @@ -1618,11 +1618,11 @@ export class SnapController extends BaseController< if ( this.#featureFlags.requireAllowlist && isAllowlistingRequired && - result.status !== SnapsRegistryStatus.Verified + result.status !== SnapRegistryStatus.Verified ) { throw new Error( `Cannot install version "${snapInfo.version}" of snap "${snapId}": ${ - result.status === SnapsRegistryStatus.Unavailable + result.status === SnapRegistryStatus.Unavailable ? 'The registry is temporarily unavailable.' : 'The snap is not on the allowlist.' }`, @@ -3137,7 +3137,7 @@ export class SnapController extends BaseController< versionRange: SemVerRange, ): Promise { return await this.messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', snapId, versionRange, ); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController-method-action-types.ts similarity index 50% rename from packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts rename to packages/snaps-controllers/src/snaps/registry/SnapRegistryController-method-action-types.ts index df6d4a2ef1..5fcac09d6e 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController-method-action-types.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController-method-action-types.ts @@ -3,21 +3,21 @@ * Do not edit manually. */ -import type { SnapsRegistryController } from './SnapsRegistryController'; +import type { SnapRegistryController } from './SnapRegistryController'; /** * Triggers an update of the registry database. * * If an existing update is in progress this function will await that update. */ -export type SnapsRegistryControllerRequestUpdateAction = { - type: `SnapsRegistryController:requestUpdate`; - handler: SnapsRegistryController['requestUpdate']; +export type SnapRegistryControllerRequestUpdateAction = { + type: `SnapRegistryController:requestUpdate`; + handler: SnapRegistryController['requestUpdate']; }; -export type SnapsRegistryControllerGetAction = { - type: `SnapsRegistryController:get`; - handler: SnapsRegistryController['get']; +export type SnapRegistryControllerGetAction = { + type: `SnapRegistryController:get`; + handler: SnapRegistryController['get']; }; /** @@ -28,9 +28,9 @@ export type SnapsRegistryControllerGetAction = { * @param refetch - An optional flag used to determine if we are refetching the registry. * @returns An allowlisted version within the specified version range if available otherwise returns the input version range. */ -export type SnapsRegistryControllerResolveVersionAction = { - type: `SnapsRegistryController:resolveVersion`; - handler: SnapsRegistryController['resolveVersion']; +export type SnapRegistryControllerResolveVersionAction = { + type: `SnapRegistryController:resolveVersion`; + handler: SnapRegistryController['resolveVersion']; }; /** @@ -40,16 +40,16 @@ export type SnapsRegistryControllerResolveVersionAction = { * @returns The metadata for the given snap ID, or `null` if the snap is not * verified. */ -export type SnapsRegistryControllerGetMetadataAction = { - type: `SnapsRegistryController:getMetadata`; - handler: SnapsRegistryController['getMetadata']; +export type SnapRegistryControllerGetMetadataAction = { + type: `SnapRegistryController:getMetadata`; + handler: SnapRegistryController['getMetadata']; }; /** - * Union of all SnapsRegistryController action types. + * Union of all SnapRegistryController action types. */ -export type SnapsRegistryControllerMethodActions = - | SnapsRegistryControllerRequestUpdateAction - | SnapsRegistryControllerGetAction - | SnapsRegistryControllerResolveVersionAction - | SnapsRegistryControllerGetMetadataAction; +export type SnapRegistryControllerMethodActions = + | SnapRegistryControllerRequestUpdateAction + | SnapRegistryControllerGetAction + | SnapRegistryControllerResolveVersionAction + | SnapRegistryControllerGetMetadataAction; diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController.test.ts similarity index 85% rename from packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts rename to packages/snaps-controllers/src/snaps/registry/SnapRegistryController.test.ts index a3e4d467f3..fb77965395 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.test.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController.test.ts @@ -7,20 +7,20 @@ import { import type { SemVerRange, SemVerVersion } from '@metamask/utils'; import fetchMock from 'jest-fetch-mock'; -import type { SnapsRegistryControllerArgs } from './SnapsRegistryController'; -import { SnapsRegistryController } from './SnapsRegistryController'; -import { SnapsRegistryStatus } from './types'; -import { getRestrictedSnapsRegistryControllerMessenger } from '../../test-utils'; +import type { SnapRegistryControllerArgs } from './SnapRegistryController'; +import { SnapRegistryController } from './SnapRegistryController'; +import { SnapRegistryStatus } from './types'; +import { getRestrictedSnapRegistryControllerMessenger } from '../../test-utils'; // Public key for the private key: // `0x541c6759fd86c69eceb8d792d7174623db139d81a5b560aa026afcb2dd1bb21c`. const MOCK_PUBLIC_KEY = '0x03a885324b8520fba54a173999629952cfa1f97930c20902ec389f9c32c6ffbc40'; -const getRegistry = (args?: Partial) => { - const messenger = getRestrictedSnapsRegistryControllerMessenger(); +const getRegistry = (args?: Partial) => { + const messenger = getRestrictedSnapRegistryControllerMessenger(); return { - registry: new SnapsRegistryController({ + registry: new SnapRegistryController({ messenger, publicKey: MOCK_PUBLIC_KEY, clientConfig: { @@ -125,7 +125,7 @@ const MOCK_COMPATIBILITY_SIGNATURE_FILE = { format: 'DER', }; -describe('SnapsRegistryController', () => { +describe('SnapRegistryController', () => { fetchMock.enableMocks(); afterEach(() => { @@ -138,7 +138,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -147,7 +147,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Verified, + status: SnapRegistryStatus.Verified, }, }); }); @@ -159,7 +159,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_EMPTY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -168,7 +168,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unverified, + status: SnapRegistryStatus.Unverified, }, }); }); @@ -179,7 +179,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -188,7 +188,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unverified, + status: SnapRegistryStatus.Unverified, }, }); }); @@ -199,7 +199,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'bar', @@ -208,7 +208,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unverified, + status: SnapRegistryStatus.Unverified, }, }); }); @@ -219,7 +219,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: 'foo', @@ -228,7 +228,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Blocked, + status: SnapRegistryStatus.Blocked, reason: { explanation: 'malicious' }, }, }); @@ -240,7 +240,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { 'npm:@consensys/starknet-snap': { version: '0.1.10' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -249,7 +249,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ 'npm:@consensys/starknet-snap': { - status: SnapsRegistryStatus.Blocked, + status: SnapRegistryStatus.Blocked, reason: { explanation: 'vuln' }, }, }); @@ -267,7 +267,7 @@ describe('SnapsRegistryController', () => { database: { verifiedSnaps: {}, blockedSnaps: [] }, }, }); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -276,7 +276,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Verified, + status: SnapRegistryStatus.Verified, }, }); }); @@ -287,7 +287,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -296,7 +296,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Verified, + status: SnapRegistryStatus.Verified, }, }); }); @@ -307,7 +307,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_COMPATIBILITY_SIGNATURE_FILE)); const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.1.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -316,7 +316,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unverified, + status: SnapRegistryStatus.Unverified, }, }); }); @@ -332,7 +332,7 @@ describe('SnapsRegistryController', () => { }, }); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -341,7 +341,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Verified, + status: SnapRegistryStatus.Verified, }, }); }); @@ -357,7 +357,7 @@ describe('SnapsRegistryController', () => { }, }); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.1' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -366,7 +366,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unavailable, + status: SnapRegistryStatus.Unavailable, }, }); }); @@ -376,7 +376,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -385,7 +385,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unavailable, + status: SnapRegistryStatus.Unavailable, }, }); }); @@ -399,7 +399,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -408,7 +408,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unavailable, + status: SnapRegistryStatus.Unavailable, }, }); }); @@ -423,7 +423,7 @@ describe('SnapsRegistryController', () => { '0x034ca27b046507d1a9997bddc991b56d96b93d4adac3a96dfe01ce450bfb661455', }); - const result = await messenger.call('SnapsRegistryController:get', { + const result = await messenger.call('SnapRegistryController:get', { [MOCK_SNAP_ID]: { version: '1.0.0' as SemVerVersion, checksum: DEFAULT_SNAP_SHASUM, @@ -432,7 +432,7 @@ describe('SnapsRegistryController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: { - status: SnapsRegistryStatus.Unavailable, + status: SnapRegistryStatus.Unavailable, }, }); }); @@ -445,7 +445,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -460,7 +460,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); const result = await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -477,7 +477,7 @@ describe('SnapsRegistryController', () => { clientConfig: { type: 'extension', version: '15.0.0' as SemVerVersion }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -496,7 +496,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, range, ), @@ -512,7 +512,7 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); expect( await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, range, ), @@ -532,7 +532,7 @@ describe('SnapsRegistryController', () => { }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -568,7 +568,7 @@ describe('SnapsRegistryController', () => { }, }); const result = await messenger.call( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', MOCK_SNAP_ID, '^1.0.0' as SemVerRange, ); @@ -584,9 +584,9 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); const result = messenger.call( - 'SnapsRegistryController:getMetadata', + 'SnapRegistryController:getMetadata', MOCK_SNAP_ID, ); @@ -601,9 +601,9 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); const result = messenger.call( - 'SnapsRegistryController:getMetadata', + 'SnapRegistryController:getMetadata', 'foo', ); @@ -618,7 +618,7 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -638,7 +638,7 @@ describe('SnapsRegistryController', () => { databaseUnavailable: false, }, }); - await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); expect(spy).not.toHaveBeenCalled(); @@ -650,8 +650,8 @@ describe('SnapsRegistryController', () => { .mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE)); const { messenger } = getRegistry(); - await messenger.call('SnapsRegistryController:requestUpdate'); - await messenger.call('SnapsRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); + await messenger.call('SnapRegistryController:requestUpdate'); expect(fetchMock).toHaveBeenCalledTimes(2); }); @@ -663,8 +663,8 @@ describe('SnapsRegistryController', () => { const { messenger } = getRegistry(); await Promise.all([ - messenger.call('SnapsRegistryController:requestUpdate'), - messenger.call('SnapsRegistryController:requestUpdate'), + messenger.call('SnapRegistryController:requestUpdate'), + messenger.call('SnapRegistryController:requestUpdate'), ]); expect(fetchMock).toHaveBeenCalledTimes(2); diff --git a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController.ts similarity index 86% rename from packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts rename to packages/snaps-controllers/src/snaps/registry/SnapRegistryController.ts index 8b0034db2c..4944f3789b 100644 --- a/packages/snaps-controllers/src/snaps/registry/SnapsRegistryController.ts +++ b/packages/snaps-controllers/src/snaps/registry/SnapRegistryController.ts @@ -20,14 +20,14 @@ import { satisfiesVersionRange, } from '@metamask/utils'; -import type { SnapsRegistryControllerMethodActions } from './SnapsRegistryController-method-action-types'; +import type { SnapRegistryControllerMethodActions } from './SnapRegistryController-method-action-types'; import type { - SnapsRegistryInfo, - SnapsRegistryMetadata, - SnapsRegistryRequest, - SnapsRegistryResult, + SnapRegistryInfo, + SnapRegistryMetadata, + SnapRegistryRequest, + SnapRegistryResult, } from './types'; -import { SnapsRegistryStatus } from './types'; +import { SnapRegistryStatus } from './types'; const SNAP_REGISTRY_URL = 'https://acl.execution.metamask.io/latest/registry.json'; @@ -48,9 +48,9 @@ export type ClientConfig = { version: SemVerVersion; }; -export type SnapsRegistryControllerArgs = { - messenger: SnapsRegistryControllerMessenger; - state?: SnapsRegistryControllerState; +export type SnapRegistryControllerArgs = { + messenger: SnapRegistryControllerMessenger; + state?: SnapRegistryControllerState; fetchFunction?: typeof fetch; url?: JsonSnapsRegistryUrl; recentFetchThreshold?: number; @@ -59,38 +59,37 @@ export type SnapsRegistryControllerArgs = { clientConfig: ClientConfig; }; -export type SnapsRegistryControllerGetStateAction = ControllerGetStateAction< +export type SnapRegistryControllerGetStateAction = ControllerGetStateAction< typeof controllerName, - SnapsRegistryControllerState + SnapRegistryControllerState >; -export type SnapsRegistryControllerActions = - | SnapsRegistryControllerGetStateAction - | SnapsRegistryControllerMethodActions; +export type SnapRegistryControllerActions = + | SnapRegistryControllerGetStateAction + | SnapRegistryControllerMethodActions; -export type SnapsRegistryControllerStateChangeEvent = - ControllerStateChangeEvent< - typeof controllerName, - SnapsRegistryControllerState - >; +export type SnapRegistryControllerStateChangeEvent = ControllerStateChangeEvent< + typeof controllerName, + SnapRegistryControllerState +>; -export type SnapsRegistryControllerEvents = - SnapsRegistryControllerStateChangeEvent; +export type SnapRegistryControllerEvents = + SnapRegistryControllerStateChangeEvent; -export type SnapsRegistryControllerMessenger = Messenger< +export type SnapRegistryControllerMessenger = Messenger< typeof controllerName, - SnapsRegistryControllerActions, - SnapsRegistryControllerEvents + SnapRegistryControllerActions, + SnapRegistryControllerEvents >; -export type SnapsRegistryControllerState = { +export type SnapRegistryControllerState = { database: SnapsRegistryDatabase | null; signature: string | null; lastUpdated: number | null; databaseUnavailable: boolean; }; -const controllerName = 'SnapsRegistryController'; +const controllerName = 'SnapRegistryController'; const MESSENGER_EXPOSED_METHODS = [ 'get', @@ -106,10 +105,10 @@ const defaultState = { databaseUnavailable: false, }; -export class SnapsRegistryController extends BaseController< +export class SnapRegistryController extends BaseController< typeof controllerName, - SnapsRegistryControllerState, - SnapsRegistryControllerMessenger + SnapRegistryControllerState, + SnapRegistryControllerMessenger > { readonly #url: JsonSnapsRegistryUrl; @@ -137,7 +136,7 @@ export class SnapsRegistryController extends BaseController< fetchFunction = globalThis.fetch.bind(undefined), recentFetchThreshold = inMilliseconds(5, Duration.Minute), refetchOnAllowlistMiss = true, - }: SnapsRegistryControllerArgs) { + }: SnapRegistryControllerArgs) { super({ messenger, metadata: { @@ -266,9 +265,9 @@ export class SnapsRegistryController extends BaseController< async #getSingle( snapId: string, - snapInfo: SnapsRegistryInfo, + snapInfo: SnapRegistryInfo, refetch = false, - ): Promise { + ): Promise { const database = await this.#getDatabase(); const blockedEntry = database?.blockedSnaps.find((blocked) => { @@ -284,7 +283,7 @@ export class SnapsRegistryController extends BaseController< if (blockedEntry) { return { - status: SnapsRegistryStatus.Blocked, + status: SnapRegistryStatus.Blocked, reason: blockedEntry.reason, }; } @@ -296,7 +295,7 @@ export class SnapsRegistryController extends BaseController< !clientRange || satisfiesVersionRange(this.#clientConfig.version, clientRange); if (version && version.checksum === snapInfo.checksum && isCompatible) { - return { status: SnapsRegistryStatus.Verified }; + return { status: SnapRegistryStatus.Verified }; } // For now, if we have an allowlist miss, we can refetch once and try again. if (this.#refetchOnAllowlistMiss && !refetch) { @@ -305,16 +304,16 @@ export class SnapsRegistryController extends BaseController< } return { status: this.state.databaseUnavailable - ? SnapsRegistryStatus.Unavailable - : SnapsRegistryStatus.Unverified, + ? SnapRegistryStatus.Unavailable + : SnapRegistryStatus.Unverified, }; } async get( - snaps: SnapsRegistryRequest, - ): Promise> { + snaps: SnapRegistryRequest, + ): Promise> { return Object.entries(snaps).reduce< - Promise> + Promise> >(async (previousPromise, [snapId, snapInfo]) => { const result = await this.#getSingle(snapId, snapInfo); const acc = await previousPromise; @@ -388,7 +387,7 @@ export class SnapsRegistryController extends BaseController< * @returns The metadata for the given snap ID, or `null` if the snap is not * verified. */ - getMetadata(snapId: string): SnapsRegistryMetadata | null { + getMetadata(snapId: string): SnapRegistryMetadata | null { return this.state?.database?.verifiedSnaps[snapId]?.metadata ?? null; } diff --git a/packages/snaps-controllers/src/snaps/registry/index.ts b/packages/snaps-controllers/src/snaps/registry/index.ts index 19fce93147..a4c0875fa5 100644 --- a/packages/snaps-controllers/src/snaps/registry/index.ts +++ b/packages/snaps-controllers/src/snaps/registry/index.ts @@ -1,24 +1,23 @@ export type { - SnapsRegistryControllerActions, - SnapsRegistryControllerEvents, - SnapsRegistryControllerArgs, - SnapsRegistryControllerGetStateAction, - SnapsRegistryControllerMessenger, - SnapsRegistryControllerState, - SnapsRegistryControllerStateChangeEvent, -} from './SnapsRegistryController'; -export { SnapsRegistryController } from './SnapsRegistryController'; + SnapRegistryControllerActions, + SnapRegistryControllerEvents, + SnapRegistryControllerArgs, + SnapRegistryControllerGetStateAction, + SnapRegistryControllerMessenger, + SnapRegistryControllerState, + SnapRegistryControllerStateChangeEvent, +} from './SnapRegistryController'; +export { SnapRegistryController } from './SnapRegistryController'; export type { - SnapsRegistryControllerGetAction, - SnapsRegistryControllerGetMetadataAction, - SnapsRegistryControllerMethodActions, - SnapsRegistryControllerRequestUpdateAction, - SnapsRegistryControllerResolveVersionAction, -} from './SnapsRegistryController-method-action-types'; + SnapRegistryControllerGetAction, + SnapRegistryControllerGetMetadataAction, + SnapRegistryControllerRequestUpdateAction, + SnapRegistryControllerResolveVersionAction, +} from './SnapRegistryController-method-action-types'; export type { - SnapsRegistryInfo, - SnapsRegistryMetadata, - SnapsRegistryRequest, - SnapsRegistryResult, + SnapRegistryInfo, + SnapRegistryMetadata, + SnapRegistryRequest, + SnapRegistryResult, } from './types'; -export { SnapsRegistryStatus } from './types'; +export { SnapRegistryStatus } from './types'; diff --git a/packages/snaps-controllers/src/snaps/registry/types.ts b/packages/snaps-controllers/src/snaps/registry/types.ts index 50c6959931..bbdcb82163 100644 --- a/packages/snaps-controllers/src/snaps/registry/types.ts +++ b/packages/snaps-controllers/src/snaps/registry/types.ts @@ -5,19 +5,19 @@ import type { import type { SnapId } from '@metamask/snaps-sdk'; import type { SemVerVersion } from '@metamask/utils'; -export type SnapsRegistryInfo = { version: SemVerVersion; checksum: string }; -export type SnapsRegistryRequest = Record; -export type SnapsRegistryMetadata = +export type SnapRegistryInfo = { version: SemVerVersion; checksum: string }; +export type SnapRegistryRequest = Record; +export type SnapRegistryMetadata = SnapsRegistryDatabase['verifiedSnaps'][SnapId]['metadata']; -export enum SnapsRegistryStatus { +export enum SnapRegistryStatus { Unverified = 0, Blocked = 1, Verified = 2, Unavailable = 3, } -export type SnapsRegistryResult = { - status: SnapsRegistryStatus; +export type SnapRegistryResult = { + status: SnapRegistryStatus; reason?: BlockReason; }; diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index a0defcba40..5087ab18d4 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -62,7 +62,7 @@ import type { } from '../interface/SnapInterfaceController'; import type { MultichainRoutingServiceMessenger } from '../multichain/MultichainRoutingService'; import type { ExecutionService, ExecutionServiceMessenger } from '../services'; -import type { SnapsRegistryControllerMessenger } from '../snaps'; +import type { SnapRegistryControllerMessenger } from '../snaps'; import { SnapController } from '../snaps'; import type { PersistedSnapControllerState, @@ -322,12 +322,12 @@ export type RootMessenger = Messenger< MockAnyNamespace, MessengerActions< | SnapControllerMessenger - | SnapsRegistryControllerMessenger + | SnapRegistryControllerMessenger | ExecutionServiceMessenger >, MessengerEvents< | SnapControllerMessenger - | SnapsRegistryControllerMessenger + | SnapRegistryControllerMessenger | ExecutionServiceMessenger > >; @@ -492,10 +492,10 @@ export const getSnapControllerMessenger = ( 'PermissionController:getSubjectNames', 'SubjectMetadataController:getSubjectMetadata', 'SubjectMetadataController:addSubjectMetadata', - 'SnapsRegistryController:get', - 'SnapsRegistryController:getMetadata', - 'SnapsRegistryController:requestUpdate', - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:get', + 'SnapRegistryController:getMetadata', + 'SnapRegistryController:requestUpdate', + 'SnapRegistryController:resolveVersion', 'SnapInterfaceController:createInterface', 'SnapInterfaceController:setInterfaceDisplayed', 'SnapInterfaceController:getInterface', @@ -509,7 +509,7 @@ export const getSnapControllerMessenger = ( 'ExecutionService:outboundRequest', 'ExecutionService:outboundResponse', 'KeyringController:lock', - 'SnapsRegistryController:stateChange', + 'SnapRegistryController:stateChange', ], messenger: snapControllerMessenger, }); @@ -785,14 +785,14 @@ export const getRestrictedCronjobControllerMessenger = ( return cronjobControllerMessenger; }; -type SnapsRegistryControllerRootMessenger = Messenger< +type SnapRegistryControllerRootMessenger = Messenger< MockAnyNamespace, - MessengerActions, - MessengerEvents + MessengerActions, + MessengerEvents >; -export const getRootSnapsRegistryControllerMessenger = () => { - const messenger: SnapsRegistryControllerRootMessenger = +export const getRootSnapRegistryControllerMessenger = () => { + const messenger: SnapRegistryControllerRootMessenger = new MockControllerMessenger(); jest.spyOn(messenger, 'call'); @@ -800,13 +800,13 @@ export const getRootSnapsRegistryControllerMessenger = () => { return messenger; }; -export const getRestrictedSnapsRegistryControllerMessenger = ( +export const getRestrictedSnapRegistryControllerMessenger = ( rootMessenger: ReturnType< - typeof getRootSnapsRegistryControllerMessenger - > = getRootSnapsRegistryControllerMessenger(), + typeof getRootSnapRegistryControllerMessenger + > = getRootSnapRegistryControllerMessenger(), ) => { - const messenger: SnapsRegistryControllerMessenger = new Messenger({ - namespace: 'SnapsRegistryController', + const messenger: SnapRegistryControllerMessenger = new Messenger({ + namespace: 'SnapRegistryController', parent: rootMessenger, }); diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index 5b56c29512..61a1839680 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -1,5 +1,5 @@ import type { RootMessenger } from './controller'; -import { SnapsRegistryStatus } from '../snaps'; +import { SnapRegistryStatus } from '../snaps'; export class MockSnapsRegistry { readonly #messenger; @@ -8,22 +8,22 @@ export class MockSnapsRegistry { this.#messenger = messenger; this.#messenger.registerActionHandler( - 'SnapsRegistryController:get', + 'SnapRegistryController:get', this.get.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:getMetadata', + 'SnapRegistryController:getMetadata', this.getMetadata.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:resolveVersion', + 'SnapRegistryController:resolveVersion', this.resolveVersion.bind(this), ); this.#messenger.registerActionHandler( - 'SnapsRegistryController:requestUpdate', + 'SnapRegistryController:requestUpdate', this.update.bind(this), ); } @@ -33,7 +33,7 @@ export class MockSnapsRegistry { Object.keys(snaps).reduce( (acc, snapId) => ({ ...acc, - [snapId]: { status: SnapsRegistryStatus.Unverified }, + [snapId]: { status: SnapRegistryStatus.Unverified }, }), {}, ), @@ -48,7 +48,7 @@ export class MockSnapsRegistry { update = jest.fn().mockImplementation(() => { this.#messenger.publish( - 'SnapsRegistryController:stateChange', + 'SnapRegistryController:stateChange', { database: { verifiedSnaps: {}, blockedSnaps: [] }, lastUpdated: Date.now(), From 0200b2e56d8f91222eedb176f066a66db3137d58 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:58:03 +0100 Subject: [PATCH 10/11] Fix mock name --- .../src/snaps/SnapController.test.tsx | 28 +++++++++---------- .../src/test-utils/controller.tsx | 4 +-- .../src/test-utils/registry.ts | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index 6818caf298..66ebf09a79 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -127,7 +127,7 @@ import { MOCK_SNAP_PERMISSIONS, MOCK_SNAP_SUBJECT_METADATA, MOCK_WALLET_SNAP_PERMISSION, - MockSnapsRegistry, + MockSnapRegistryController, sleep, waitForStateChange, } from '../test-utils'; @@ -1048,7 +1048,7 @@ describe('SnapController', () => { it('throws an error if snap is not on allowlist and allowlisting is required but resolve succeeds', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const controller = await getSnapController( getSnapControllerOptions({ @@ -1077,7 +1077,7 @@ describe('SnapController', () => { it('throws an error if the registry is unavailable and allowlisting is required but resolve succeeds', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const controller = await getSnapController( getSnapControllerOptions({ @@ -1141,7 +1141,7 @@ describe('SnapController', () => { it('resolves to allowlisted version when allowlisting is required', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const { manifest, sourceCode, svgIcon } = await getMockSnapFilesWithUpdatedChecksum({ @@ -1181,7 +1181,7 @@ describe('SnapController', () => { it('does not use registry resolving when allowlist is not required', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const controller = await getSnapController( getSnapControllerOptions({ @@ -8918,7 +8918,7 @@ describe('SnapController', () => { it('throws an error if the new version of the snap is blocked', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const { manifest } = await getMockSnapFilesWithUpdatedChecksum({ manifest: getSnapManifest({ @@ -10519,7 +10519,7 @@ describe('SnapController', () => { describe('updateRegistry', () => { it('updates the registry database', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const snapController = await getSnapController( getSnapControllerOptions({ @@ -10538,7 +10538,7 @@ describe('SnapController', () => { it('blocks snaps as expected', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const mockSnapA = getMockSnapData({ id: 'npm:exampleA' as SnapId, @@ -10609,7 +10609,7 @@ describe('SnapController', () => { it('stops running snaps when they are blocked', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const mockSnap = getMockSnapData({ id: 'npm:example' as SnapId, @@ -10644,7 +10644,7 @@ describe('SnapController', () => { it('unblocks snaps as expected', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const mockSnapA = getMockSnapData({ id: 'npm:exampleA' as SnapId, @@ -10707,7 +10707,7 @@ describe('SnapController', () => { it('updating blocked snaps does not throw if a snap is removed while fetching the blocklist', async () => { const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const mockSnap = getMockSnapData({ id: 'npm:example' as SnapId, @@ -10750,7 +10750,7 @@ describe('SnapController', () => { it('logs but does not throw unexpected errors while blocking', async () => { const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const mockSnap = getMockSnapData({ id: 'npm:example' as SnapId, @@ -10793,7 +10793,7 @@ describe('SnapController', () => { it('updates preinstalled Snaps', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); // Simulate previous permissions, some of which will be removed rootMessenger.registerActionHandler( @@ -10889,7 +10889,7 @@ describe('SnapController', () => { it('does not update preinstalled Snaps when the feature flag is off', async () => { const rootMessenger = getRootMessenger(); - const registry = new MockSnapsRegistry(rootMessenger); + const registry = new MockSnapRegistryController(rootMessenger); const snapId = 'npm:@metamask/jsx-example-snap' as SnapId; diff --git a/packages/snaps-controllers/src/test-utils/controller.tsx b/packages/snaps-controllers/src/test-utils/controller.tsx index 5087ab18d4..0fd143a10f 100644 --- a/packages/snaps-controllers/src/test-utils/controller.tsx +++ b/packages/snaps-controllers/src/test-utils/controller.tsx @@ -53,7 +53,7 @@ import type { Json } from '@metamask/utils'; import { MOCK_CRONJOB_PERMISSION } from './cronjob'; import { getNodeEES, getNodeEESMessenger } from './execution-environment'; -import { MockSnapsRegistry } from './registry'; +import { MockSnapRegistryController } from './registry'; import type { CronjobControllerMessenger } from '../cronjob/CronjobController'; import type { SnapInsightsControllerMessenger } from '../insights'; import type { @@ -430,7 +430,7 @@ export const getRootMessenger = () => { messenger.registerActionHandler('ExecutionService:terminateSnap', asyncNoOp); // eslint-disable-next-line no-new - new MockSnapsRegistry(messenger); + new MockSnapRegistryController(messenger); messenger.registerActionHandler( 'SnapInterfaceController:createInterface', diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index 61a1839680..ae50b854cc 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -1,7 +1,7 @@ import type { RootMessenger } from './controller'; import { SnapRegistryStatus } from '../snaps'; -export class MockSnapsRegistry { +export class MockSnapRegistryController { readonly #messenger; constructor(messenger: RootMessenger) { From 7a64b389a7d67cf38f81a173cc1b4942a145341b Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 13:04:46 +0100 Subject: [PATCH 11/11] Update mock update method --- packages/snaps-controllers/src/snaps/SnapController.test.tsx | 2 +- packages/snaps-controllers/src/test-utils/registry.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index 66ebf09a79..13a438111d 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -10531,7 +10531,7 @@ describe('SnapController', () => { ); await snapController.updateRegistry(); - expect(registry.update).toHaveBeenCalled(); + expect(registry.requestUpdate).toHaveBeenCalled(); snapController.destroy(); }); diff --git a/packages/snaps-controllers/src/test-utils/registry.ts b/packages/snaps-controllers/src/test-utils/registry.ts index ae50b854cc..34bacae94a 100644 --- a/packages/snaps-controllers/src/test-utils/registry.ts +++ b/packages/snaps-controllers/src/test-utils/registry.ts @@ -24,7 +24,7 @@ export class MockSnapRegistryController { this.#messenger.registerActionHandler( 'SnapRegistryController:requestUpdate', - this.update.bind(this), + this.requestUpdate.bind(this), ); } @@ -46,7 +46,7 @@ export class MockSnapRegistryController { getMetadata = jest.fn().mockReturnValue(null); - update = jest.fn().mockImplementation(() => { + requestUpdate = jest.fn().mockImplementation(() => { this.#messenger.publish( 'SnapRegistryController:stateChange', {