diff --git a/packages/snaps-controllers/src/multichain/MultichainRoutingController.test.ts b/packages/snaps-controllers/src/multichain/MultichainRoutingController.test.ts index 19883e7926..77fd54e787 100644 --- a/packages/snaps-controllers/src/multichain/MultichainRoutingController.test.ts +++ b/packages/snaps-controllers/src/multichain/MultichainRoutingController.test.ts @@ -11,7 +11,6 @@ import { SOLANA_CAIP2, MOCK_SOLANA_ACCOUNTS, MOCK_BTC_ACCOUNTS, - getMockSnapKeyring, } from '../test-utils'; import { MultichainRoutingController } from './MultichainRoutingController'; @@ -24,11 +23,6 @@ describe('MultichainRoutingController', () => { /* eslint-disable-next-line no-new */ new MultichainRoutingController({ messenger, - getSnapKeyring: getMockSnapKeyring( - jest.fn().mockResolvedValue({ - txid: '53de51e2fa75c3cfa51132865f7d430138b1cd92a8f5267ec836ec565b422969', - }), - ), }); rootMessenger.registerActionHandler( @@ -36,6 +30,13 @@ describe('MultichainRoutingController', () => { () => MOCK_BTC_ACCOUNTS, ); + rootMessenger.registerActionHandler( + 'KeyringController:submitNonEvmRequest', + async () => ({ + txid: '53de51e2fa75c3cfa51132865f7d430138b1cd92a8f5267ec836ec565b422969', + }), + ); + rootMessenger.registerActionHandler( 'SnapController:handleRequest', async ({ handler }) => { @@ -74,9 +75,6 @@ describe('MultichainRoutingController', () => { /* eslint-disable-next-line no-new */ new MultichainRoutingController({ messenger, - getSnapKeyring: getMockSnapKeyring( - jest.fn().mockResolvedValue({ signature: '0x' }), - ), }); rootMessenger.registerActionHandler( @@ -84,6 +82,13 @@ describe('MultichainRoutingController', () => { () => MOCK_SOLANA_ACCOUNTS, ); + rootMessenger.registerActionHandler( + 'KeyringController:submitNonEvmRequest', + async () => ({ + signature: '0x', + }), + ); + rootMessenger.registerActionHandler( 'PermissionController:getPermissions', () => MOCK_SOLANA_SNAP_PERMISSIONS, @@ -125,7 +130,6 @@ describe('MultichainRoutingController', () => { /* eslint-disable-next-line no-new */ new MultichainRoutingController({ messenger, - getSnapKeyring: getMockSnapKeyring(), }); rootMessenger.registerActionHandler( @@ -175,7 +179,6 @@ describe('MultichainRoutingController', () => { /* eslint-disable-next-line no-new */ new MultichainRoutingController({ messenger, - getSnapKeyring: getMockSnapKeyring(), }); rootMessenger.registerActionHandler( diff --git a/packages/snaps-controllers/src/multichain/MultichainRoutingController.ts b/packages/snaps-controllers/src/multichain/MultichainRoutingController.ts index 9d13fa1f86..0e3205a1be 100644 --- a/packages/snaps-controllers/src/multichain/MultichainRoutingController.ts +++ b/packages/snaps-controllers/src/multichain/MultichainRoutingController.ts @@ -58,6 +58,16 @@ export type AccountsControllerListMultichainAccountsAction = { handler: (chainId?: CaipChainId) => InternalAccount[]; }; +export type KeyringControllerSubmitNonEvmRequestAction = { + type: `KeyringController:submitNonEvmRequest`; + handler: (args: { + address: string; + method: string; + params?: Json[] | Record; + chainId: CaipChainId; + }) => Promise; +}; + export type MultichainRoutingControllerActions = | MultichainRoutingControllerGetStateAction | MultichainRoutingControllerHandleRequestAction; @@ -66,7 +76,8 @@ export type MultichainRoutingControllerAllowedActions = | GetAllSnaps | HandleSnapRequest | GetPermissions - | AccountsControllerListMultichainAccountsAction; + | AccountsControllerListMultichainAccountsAction + | KeyringControllerSubmitNonEvmRequestAction; export type MultichainRoutingControllerEvents = MultichainRoutingControllerStateChangeEvent; @@ -81,19 +92,9 @@ export type MultichainRoutingControllerMessenger = MultichainRoutingControllerEvents['type'] >; -export type SnapKeyring = { - submitNonEvmRequest: (args: { - address: string; - method: string; - params?: Json[] | Record; - chainId: CaipChainId; - }) => Promise; -}; - export type MultichainRoutingControllerArgs = { messenger: MultichainRoutingControllerMessenger; state?: MultichainRoutingControllerState; - getSnapKeyring: () => Promise; }; export type MultichainRoutingControllerState = EmptyObject; @@ -110,13 +111,7 @@ export class MultichainRoutingController extends BaseController< MultichainRoutingControllerState, MultichainRoutingControllerMessenger > { - #getSnapKeyring: () => Promise; - - constructor({ - messenger, - state, - getSnapKeyring, - }: MultichainRoutingControllerArgs) { + constructor({ messenger, state }: MultichainRoutingControllerArgs) { super({ messenger, metadata: {}, @@ -126,8 +121,6 @@ export class MultichainRoutingController extends BaseController< }, }); - this.#getSnapKeyring = getSnapKeyring; - this.messagingSystem.registerActionHandler( `${controllerName}:handleRequest`, async (...args) => this.handleRequest(...args), @@ -258,13 +251,16 @@ export class MultichainRoutingController extends BaseController< request, ); if (accountSnap) { - const keyring = await this.#getSnapKeyring(); - return keyring.submitNonEvmRequest({ - address: accountSnap.address, - method, - params, - chainId: scope, - }); + // TODO: Decide on API for this. + return this.messagingSystem.call( + 'KeyringController:submitNonEvmRequest', + { + address: accountSnap.address, + method, + params, + chainId: scope, + }, + ); } // If the RPC request cannot be serviced by an account Snap, diff --git a/packages/snaps-controllers/src/test-utils/controller.ts b/packages/snaps-controllers/src/test-utils/controller.ts index aaf85c519a..9de3e200ae 100644 --- a/packages/snaps-controllers/src/test-utils/controller.ts +++ b/packages/snaps-controllers/src/test-utils/controller.ts @@ -857,6 +857,7 @@ export const getRestrictedMultichainRoutingControllerMessenger = ( 'SnapController:getAll', 'SnapController:handleRequest', 'AccountsController:listMultichainAccounts', + 'KeyringController:submitNonEvmRequest', ], }); diff --git a/packages/snaps-controllers/src/test-utils/multichain.ts b/packages/snaps-controllers/src/test-utils/multichain.ts index bd938fecfa..91c710bf28 100644 --- a/packages/snaps-controllers/src/test-utils/multichain.ts +++ b/packages/snaps-controllers/src/test-utils/multichain.ts @@ -87,10 +87,3 @@ export const MOCK_SOLANA_SNAP_PERMISSIONS: Record< parentCapability: SnapEndowments.Protocol, }, }; - -export const getMockSnapKeyring = (implementation = jest.fn()) => { - return async () => - Promise.resolve({ - submitNonEvmRequest: implementation, - }); -};