diff --git a/app/scripts/background.js b/app/scripts/background.js index 700db8127a97..442efbbccfdd 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -1045,12 +1045,12 @@ export function setupController( // updateBadge(); - controller.decryptMessageController.hub.on( - METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE, + controller.controllerMessenger.subscribe( + METAMASK_CONTROLLER_EVENTS.DECRYPT_MESSAGE_MANAGER_UPDATE_BADGE, updateBadge, ); - controller.encryptionPublicKeyController.hub.on( - METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE, + controller.controllerMessenger.subscribe( + METAMASK_CONTROLLER_EVENTS.ENCRYPTION_PUBLIC_KEY_MANAGER_UPDATE_BADGE, updateBadge, ); controller.signatureController.hub.on( diff --git a/app/scripts/controllers/decrypt-message.test.ts b/app/scripts/controllers/decrypt-message.test.ts index 848fe3f9986d..46240f7c92fa 100644 --- a/app/scripts/controllers/decrypt-message.test.ts +++ b/app/scripts/controllers/decrypt-message.test.ts @@ -2,6 +2,7 @@ import { DecryptMessageManager, DecryptMessageParams, } from '@metamask/message-manager'; +import type { DecryptMessageManagerMessenger } from '@metamask/message-manager'; import { MetaMetricsEventCategory } from '../../../shared/constants/metametrics'; import DecryptMessageController, { DecryptMessageControllerMessenger, @@ -36,11 +37,15 @@ const createMessengerMock = () => ({ registerActionHandler: jest.fn(), registerInitialEventPayload: jest.fn(), + subscribe: jest.fn(), publish: jest.fn(), call: jest.fn(), - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any as jest.Mocked); + } as unknown as jest.Mocked); + +const createManagerMessengerMock = () => + ({ + subscribe: jest.fn(), + } as unknown as jest.Mocked); const createDecryptMessageManagerMock = () => ({ @@ -64,20 +69,14 @@ const createDecryptMessageManagerMock = () => } as any as jest.Mocked); describe('DecryptMessageController', () => { - class MockDecryptMessageController extends DecryptMessageController { - // update is protected, so we expose it for typechecking here - public update(callback: Parameters[0]) { - return super.update(callback); - } - } - - let decryptMessageController: MockDecryptMessageController; + let decryptMessageController: DecryptMessageController; const decryptMessageManagerConstructorMock = DecryptMessageManager as jest.MockedClass; const getStateMock = jest.fn(); const keyringControllerMock = createKeyringControllerMock(); const messengerMock = createMessengerMock(); + const managerMessengerMock = createManagerMessengerMock(); const metricsEventMock = jest.fn(); const decryptMessageManagerMock = @@ -105,7 +104,7 @@ describe('DecryptMessageController', () => { decryptMessageManagerMock, ); - decryptMessageController = new MockDecryptMessageController({ + decryptMessageController = new DecryptMessageController({ // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any getState: getStateMock as any, @@ -118,6 +117,7 @@ describe('DecryptMessageController', () => { // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any metricsEvent: metricsEventMock as any, + managerMessenger: managerMessengerMock, } as DecryptMessageControllerOptions); }); @@ -127,23 +127,10 @@ describe('DecryptMessageController', () => { }); it('should reset state', () => { - decryptMessageController.update(() => ({ - unapprovedDecryptMsgs: { - [messageIdMock]: messageMock, - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any, - unapprovedDecryptMsgCount: 1, - })); decryptMessageController.resetState(); expect(decryptMessageController.state).toStrictEqual(getDefaultState()); }); - it('should clear unapproved messages', () => { - decryptMessageController.clearUnapproved(); - expect(decryptMessageController.state).toStrictEqual(getDefaultState()); - expect(decryptMessageManagerMock.update).toBeCalledTimes(1); - }); it('should add unapproved messages', async () => { await decryptMessageController.newRequestDecryptMessage( messageMock, diff --git a/app/scripts/controllers/decrypt-message.ts b/app/scripts/controllers/decrypt-message.ts index 7a6fe1c31a3d..9cf14d4b9bbe 100644 --- a/app/scripts/controllers/decrypt-message.ts +++ b/app/scripts/controllers/decrypt-message.ts @@ -1,8 +1,6 @@ -import EventEmitter from 'events'; import log from 'loglevel'; import { AbstractMessage, - AbstractMessageManager, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, @@ -11,6 +9,11 @@ import { DecryptMessageParams, DecryptMessageParamsMetamask, } from '@metamask/message-manager'; +import type { + DecryptMessageManagerMessenger, + DecryptMessageManagerState, + DecryptMessageManagerUnapprovedMessageAddedEvent, +} from '@metamask/message-manager'; import { BaseController, RestrictedControllerMessenger, @@ -34,6 +37,8 @@ const stateMetadata = { unapprovedDecryptMsgCount: { persist: false, anonymous: false }, }; +export const managerName = 'DecryptMessageManager'; + /** * Type guard that checks for the presence of the required properties * for EIP-1024 encrypted data. @@ -86,19 +91,20 @@ export type DecryptMessageControllerState = { unapprovedDecryptMsgCount: number; }; -export type GetDecryptMessageState = { +export type GetDecryptMessageControllerState = { type: `${typeof controllerName}:getState`; handler: () => DecryptMessageControllerState; }; -export type DecryptMessageStateChange = { +export type DecryptMessageControllerStateChange = { type: `${typeof controllerName}:stateChange`; payload: [DecryptMessageControllerState, Patch[]]; }; -export type DecryptMessageControllerActions = GetDecryptMessageState; +export type DecryptMessageControllerActions = GetDecryptMessageControllerState; -export type DecryptMessageControllerEvents = DecryptMessageStateChange; +export type DecryptMessageControllerEvents = + DecryptMessageControllerStateChange; type AllowedActions = | AddApprovalRequest @@ -106,18 +112,28 @@ type AllowedActions = | RejectRequest | KeyringControllerDecryptMessageAction; +type DecryptMessageManagerStateChangeEvent = { + type: `DecryptMessageManager:stateChange`; + payload: [DecryptMessageManagerState, Patch[]]; +}; + +type AllowedEvents = + | DecryptMessageManagerStateChangeEvent + | DecryptMessageManagerUnapprovedMessageAddedEvent; + export type DecryptMessageControllerMessenger = RestrictedControllerMessenger< typeof controllerName, DecryptMessageControllerActions | AllowedActions, - DecryptMessageControllerEvents, + DecryptMessageControllerEvents | AllowedEvents, AllowedActions['type'], - never + AllowedEvents['type'] >; export type DecryptMessageControllerOptions = { // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any getState: () => any; + managerMessenger: DecryptMessageManagerMessenger; messenger: DecryptMessageControllerMessenger; // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -132,8 +148,6 @@ export default class DecryptMessageController extends BaseController< DecryptMessageControllerState, DecryptMessageControllerMessenger > { - hub: EventEmitter; - // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any private _getState: () => any; @@ -151,11 +165,13 @@ export default class DecryptMessageController extends BaseController< * @param options.getState - Callback to retrieve all user state. * @param options.messenger - A reference to the messaging system. * @param options.metricsEvent - A function for emitting a metric event. + * @param options.managerMessenger - A reference to the messenger need by the message manager. */ constructor({ getState, metricsEvent, messenger, + managerMessenger, }: DecryptMessageControllerOptions) { super({ metadata: stateMetadata, @@ -166,28 +182,18 @@ export default class DecryptMessageController extends BaseController< this._getState = getState; this._metricsEvent = metricsEvent; - this.hub = new EventEmitter(); - - this._decryptMessageManager = new DecryptMessageManager( - undefined, - undefined, - undefined, - ['decrypted'], - ); - - this._decryptMessageManager.hub.on('updateBadge', () => { - this.hub.emit('updateBadge'); + this._decryptMessageManager = new DecryptMessageManager({ + additionalFinishStatuses: ['decrypted'], + messenger: managerMessenger, }); - this._decryptMessageManager.hub.on( - 'unapprovedMessage', - (messageParams: AbstractMessageParamsMetamask) => { - this._requestApproval(messageParams); - }, + messenger.subscribe( + `${managerName}:unapprovedMessage`, + this._requestApproval.bind(this), ); this._subscribeToMessageState( - this._decryptMessageManager, + messenger, (state, newMessages, messageCount) => { state.unapprovedDecryptMsgs = newMessages; state.unapprovedDecryptMsgCount = messageCount; @@ -215,10 +221,7 @@ export default class DecryptMessageController extends BaseController< * Clears all unapproved messages from memory. */ clearUnapproved() { - this._decryptMessageManager.update({ - unapprovedMessages: {}, - unapprovedMessagesCount: 0, - }); + this._decryptMessageManager.clearUnapprovedMessages(); } /** @@ -331,11 +334,7 @@ export default class DecryptMessageController extends BaseController< } private _cancelAbstractMessage( - messageManager: AbstractMessageManager< - AbstractMessage, - AbstractMessageParams, - AbstractMessageParamsMetamask - >, + messageManager: DecryptMessageManager, messageId: string, reason?: string, ) { @@ -356,27 +355,26 @@ export default class DecryptMessageController extends BaseController< } private _subscribeToMessageState( - messageManager: AbstractMessageManager< - AbstractMessage, - AbstractMessageParams, - AbstractMessageParamsMetamask - >, + controllerMessenger: DecryptMessageControllerMessenger, updateState: ( state: DecryptMessageControllerState, newMessages: Record, messageCount: number, ) => void, ) { - messageManager.subscribe((state: MessageManagerState) => { - const newMessages = this._migrateMessages( - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - state.unapprovedMessages as any, - ); - this.update((draftState) => { - updateState(draftState, newMessages, state.unapprovedMessagesCount); - }); - }); + controllerMessenger.subscribe( + `${managerName}:stateChange`, + (state: MessageManagerState) => { + const newMessages = this._migrateMessages( + // TODO: Replace `any` with type + // eslint-disable-next-line @typescript-eslint/no-explicit-any + state.unapprovedMessages as any, + ); + this.update((draftState) => { + updateState(draftState, newMessages, state.unapprovedMessagesCount); + }); + }, + ); } private _migrateMessages( diff --git a/app/scripts/controllers/encryption-public-key.test.ts b/app/scripts/controllers/encryption-public-key.test.ts index 09b16dfb62a7..dc3550a891fb 100644 --- a/app/scripts/controllers/encryption-public-key.test.ts +++ b/app/scripts/controllers/encryption-public-key.test.ts @@ -2,6 +2,7 @@ import { EncryptionPublicKeyManager, AbstractMessage, OriginalRequest, + EncryptionPublicKeyManagerMessenger, } from '@metamask/message-manager'; import { KeyringType } from '../../../shared/constants/keyring'; import { MetaMetricsEventCategory } from '../../../shared/constants/metametrics'; @@ -34,20 +35,7 @@ const messageMock = { status: 'unapproved', type: 'testType', rawSig: undefined, - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any -} as any as AbstractMessage; - -const coreMessageMock = { - ...messageMock, - messageParams: messageParamsMock, -}; - -const stateMessageMock = { - ...messageMock, - msgParams: addressMock, - origin: messageParamsMock.origin, -}; +} as unknown as AbstractMessage; const requestMock = { origin: 'http://test2.com', @@ -57,11 +45,15 @@ const createMessengerMock = () => ({ registerActionHandler: jest.fn(), publish: jest.fn(), + subscribe: jest.fn(), call: jest.fn(), registerInitialEventPayload: jest.fn(), - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any as jest.Mocked); + } as unknown as jest.Mocked); + +const createManagerMessengerMock = () => + ({ + subscribe: jest.fn(), + } as unknown as jest.Mocked); const createEncryptionPublicKeyManagerMock = () => ({ @@ -76,9 +68,7 @@ const createEncryptionPublicKeyManagerMock = () => hub: { on: jest.fn(), }, - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any as jest.Mocked); + } as unknown as jest.Mocked); describe('EncryptionPublicKeyController', () => { let encryptionPublicKeyController: EncryptionPublicKeyController; @@ -90,6 +80,7 @@ describe('EncryptionPublicKeyController', () => { const encryptionPublicKeyManagerMock = createEncryptionPublicKeyManagerMock(); const messengerMock = createMessengerMock(); + const managerMessengerMock = createManagerMessengerMock(); const getEncryptionPublicKeyMock = jest.fn(); const getAccountKeyringTypeMock = jest.fn(); const getStateMock = jest.fn(); @@ -118,6 +109,7 @@ describe('EncryptionPublicKeyController', () => { // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any metricsEvent: metricsEventMock as any, + managerMessenger: managerMessengerMock, } as EncryptionPublicKeyControllerOptions); }); @@ -198,22 +190,6 @@ describe('EncryptionPublicKeyController', () => { }); }); - describe('clearUnapproved', () => { - it('resets state in all message managers', () => { - encryptionPublicKeyController.clearUnapproved(); - - const defaultState = { - unapprovedMessages: {}, - unapprovedMessagesCount: 0, - }; - - expect(encryptionPublicKeyManagerMock.update).toHaveBeenCalledTimes(1); - expect(encryptionPublicKeyManagerMock.update).toHaveBeenCalledWith( - defaultState, - ); - }); - }); - describe('newRequestEncryptionPublicKey', () => { // @ts-expect-error This function is missing from the Mocha type definitions it.each([ @@ -374,56 +350,4 @@ describe('EncryptionPublicKeyController', () => { ).toEqual(stateMock); }); }); - - describe('message manager events', () => { - it('bubbles update badge event from EncryptionPublicKeyManager', () => { - const mockListener = jest.fn(); - - encryptionPublicKeyController.hub.on('updateBadge', mockListener); - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (encryptionPublicKeyManagerMock.hub.on as any).mock.calls[0][1](); - - expect(mockListener).toHaveBeenCalledTimes(1); - }); - - it('requires approval on unapproved message event from EncryptionPublicKeyManager', () => { - messengerMock.call.mockResolvedValueOnce({}); - - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (encryptionPublicKeyManagerMock.hub.on as any).mock.calls[1][1]( - messageParamsMock, - ); - - expect(messengerMock.call).toHaveBeenCalledTimes(1); - expect(messengerMock.call).toHaveBeenCalledWith( - 'ApprovalController:addRequest', - { - id: messageIdMock, - origin: messageParamsMock.origin, - type: 'eth_getEncryptionPublicKey', - }, - true, - ); - }); - - it('updates state on EncryptionPublicKeyManager state change', async () => { - await encryptionPublicKeyManagerMock.subscribe.mock.calls[0][0]({ - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - unapprovedMessages: { [messageIdMock]: coreMessageMock as any }, - unapprovedMessagesCount: 3, - }); - - expect(encryptionPublicKeyController.state).toEqual({ - unapprovedEncryptionPublicKeyMsgs: { - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [messageIdMock]: stateMessageMock as any, - }, - unapprovedEncryptionPublicKeyMsgCount: 3, - }); - }); - }); }); diff --git a/app/scripts/controllers/encryption-public-key.ts b/app/scripts/controllers/encryption-public-key.ts index 5b07ee6144b7..ab13feb32199 100644 --- a/app/scripts/controllers/encryption-public-key.ts +++ b/app/scripts/controllers/encryption-public-key.ts @@ -1,15 +1,18 @@ -import EventEmitter from 'events'; import log from 'loglevel'; import { EncryptionPublicKeyManager, EncryptionPublicKeyParamsMetamask, - AbstractMessageManager, AbstractMessage, MessageManagerState, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest, } from '@metamask/message-manager'; +import type { + EncryptionPublicKeyManagerMessenger, + EncryptionPublicKeyManagerState, + EncryptionPublicKeyManagerUnapprovedMessageAddedEvent, +} from '@metamask/message-manager'; import { BaseController, RestrictedControllerMessenger, @@ -25,6 +28,7 @@ import { KeyringType } from '../../../shared/constants/keyring'; import { ORIGIN_METAMASK } from '../../../shared/constants/app'; const controllerName = 'EncryptionPublicKeyController'; +const managerName = 'EncryptionPublicKeyManager'; const methodNameGetEncryptionPublicKey = 'eth_getEncryptionPublicKey'; const stateMetadata = { @@ -55,30 +59,40 @@ export type EncryptionPublicKeyControllerState = { unapprovedEncryptionPublicKeyMsgCount: number; }; -export type GetEncryptionPublicKeyState = { +export type EncryptionPublicKeyControllerGetState = { type: `${typeof controllerName}:getState`; handler: () => EncryptionPublicKeyControllerState; }; -export type EncryptionPublicKeyStateChange = { +export type EncryptionPublicKeyControllerStateChange = { type: `${typeof controllerName}:stateChange`; payload: [EncryptionPublicKeyControllerState, Patch[]]; }; -export type EncryptionPublicKeyControllerActions = GetEncryptionPublicKeyState; +export type EncryptionPublicKeyControllerActions = + EncryptionPublicKeyControllerGetState; export type EncryptionPublicKeyControllerEvents = - EncryptionPublicKeyStateChange; + EncryptionPublicKeyControllerStateChange; + +type EncryptionPublicKeyManagerStateChange = { + type: `EncryptionPublicKeyManager:stateChange`; + payload: [EncryptionPublicKeyManagerState, Patch[]]; +}; type AllowedActions = AddApprovalRequest | AcceptRequest | RejectRequest; +type AllowedEvents = + | EncryptionPublicKeyManagerStateChange + | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent; + export type EncryptionPublicKeyControllerMessenger = RestrictedControllerMessenger< typeof controllerName, EncryptionPublicKeyControllerActions | AllowedActions, - EncryptionPublicKeyControllerEvents, + EncryptionPublicKeyControllerEvents | AllowedEvents, AllowedActions['type'], - never + AllowedEvents['type'] >; export type EncryptionPublicKeyControllerOptions = { @@ -91,6 +105,7 @@ export type EncryptionPublicKeyControllerOptions = { // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any metricsEvent: (payload: any, options?: any) => void; + managerMessenger: EncryptionPublicKeyManagerMessenger; }; /** @@ -101,8 +116,6 @@ export default class EncryptionPublicKeyController extends BaseController< EncryptionPublicKeyControllerState, EncryptionPublicKeyControllerMessenger > { - hub: EventEmitter; - private _getEncryptionPublicKey: (address: string) => Promise; private _getAccountKeyringType: (account: string) => Promise; @@ -126,9 +139,11 @@ export default class EncryptionPublicKeyController extends BaseController< * @param options.getAccountKeyringType - Callback to get the keyring type. * @param options.getState - Callback to retrieve all user state. * @param options.metricsEvent - A function for emitting a metric event. + * @param options.managerMessenger */ constructor({ messenger, + managerMessenger, getEncryptionPublicKey, getAccountKeyringType, getState, @@ -145,28 +160,18 @@ export default class EncryptionPublicKeyController extends BaseController< this._getAccountKeyringType = getAccountKeyringType; this._getState = getState; this._metricsEvent = metricsEvent; - - this.hub = new EventEmitter(); - this._encryptionPublicKeyManager = new EncryptionPublicKeyManager( - undefined, - undefined, - undefined, - ['received'], - ); - - this._encryptionPublicKeyManager.hub.on('updateBadge', () => { - this.hub.emit('updateBadge'); + this._encryptionPublicKeyManager = new EncryptionPublicKeyManager({ + additionalFinishStatuses: ['received'], + messenger: managerMessenger, }); - this._encryptionPublicKeyManager.hub.on( - 'unapprovedMessage', - (msgParams: AbstractMessageParamsMetamask) => { - this._requestApproval(msgParams, methodNameGetEncryptionPublicKey); - }, + this.messagingSystem.subscribe( + `${managerName}:unapprovedMessage`, + this._requestApproval.bind(this), ); this._subscribeToMessageState( - this._encryptionPublicKeyManager, + messenger, (state, newMessages, messageCount) => { state.unapprovedEncryptionPublicKeyMsgs = newMessages; state.unapprovedEncryptionPublicKeyMsgCount = messageCount; @@ -313,18 +318,11 @@ export default class EncryptionPublicKeyController extends BaseController< * Clears all unapproved messages from memory. */ clearUnapproved() { - this._encryptionPublicKeyManager.update({ - unapprovedMessages: {}, - unapprovedMessagesCount: 0, - }); + this._encryptionPublicKeyManager.clearUnapprovedMessages(); } private _cancelAbstractMessage( - messageManager: AbstractMessageManager< - AbstractMessage, - AbstractMessageParams, - AbstractMessageParamsMetamask - >, + messageManager: EncryptionPublicKeyManager, messageId: string, reason?: string, ) { @@ -345,27 +343,26 @@ export default class EncryptionPublicKeyController extends BaseController< } private _subscribeToMessageState( - messageManager: AbstractMessageManager< - AbstractMessage, - AbstractMessageParams, - AbstractMessageParamsMetamask - >, + controllerMessenger: EncryptionPublicKeyControllerMessenger, updateState: ( state: EncryptionPublicKeyControllerState, newMessages: Record, messageCount: number, ) => void, ) { - messageManager.subscribe((state: MessageManagerState) => { - const newMessages = this._migrateMessages( - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - state.unapprovedMessages as any, - ); - this.update((draftState) => { - updateState(draftState, newMessages, state.unapprovedMessagesCount); - }); - }); + controllerMessenger.subscribe( + `${managerName}:stateChange`, + (state: MessageManagerState) => { + const newMessages = this._migrateMessages( + // TODO: Replace `any` with type + // eslint-disable-next-line @typescript-eslint/no-explicit-any + state.unapprovedMessages as any, + ); + this.update((draftState) => { + updateState(draftState, newMessages, state.unapprovedMessagesCount); + }); + }, + ); } private _migrateMessages( @@ -396,10 +393,7 @@ export default class EncryptionPublicKeyController extends BaseController< return stateMessage; } - private _requestApproval( - msgParams: AbstractMessageParamsMetamask, - type: string, - ) { + private _requestApproval(msgParams: AbstractMessageParamsMetamask) { const id = msgParams.metamaskId as string; const origin = msgParams.origin || ORIGIN_METAMASK; @@ -409,7 +403,7 @@ export default class EncryptionPublicKeyController extends BaseController< { id, origin, - type, + type: methodNameGetEncryptionPublicKey, }, true, ) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 684f7b4ca32a..7c4fe1d2fd77 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -394,6 +394,9 @@ export const METAMASK_CONTROLLER_EVENTS = { // Fired after state changes that impact the extension badge (unapproved msg count) // The process of updating the badge happens in app/scripts/background.js. UPDATE_BADGE: 'updateBadge', + DECRYPT_MESSAGE_MANAGER_UPDATE_BADGE: 'DecryptMessageManager:updateBadge', + ENCRYPTION_PUBLIC_KEY_MANAGER_UPDATE_BADGE: + 'EncryptionPublicKeyManager:updateBadge', // TODO: Add this and similar enums to the `controllers` repo and export them APPROVAL_STATE_CHANGE: 'ApprovalController:stateChange', APP_STATE_UNLOCK_CHANGE: 'AppStateController:unlockChange', @@ -2064,6 +2067,13 @@ export default class MetamaskController extends EventEmitter { `${this.approvalController.name}:rejectRequest`, `${this.keyringController.name}:decryptMessage`, ], + allowedEvents: [ + 'DecryptMessageManager:stateChange', + 'DecryptMessageManager:unapprovedMessage', + ], + }), + managerMessenger: this.controllerMessenger.getRestricted({ + name: 'DecryptMessageManager', }), metricsEvent: this.metaMetricsController.trackEvent.bind( this.metaMetricsController, @@ -2078,6 +2088,13 @@ export default class MetamaskController extends EventEmitter { `${this.approvalController.name}:acceptRequest`, `${this.approvalController.name}:rejectRequest`, ], + allowedEvents: [ + 'EncryptionPublicKeyManager:stateChange', + 'EncryptionPublicKeyManager:unapprovedMessage', + ], + }), + managerMessenger: this.controllerMessenger.getRestricted({ + name: 'EncryptionPublicKeyManager', }), getEncryptionPublicKey: this.keyringController.getEncryptionPublicKey.bind( diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index cab7f02f635c..52b5ef08c823 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -1431,7 +1431,7 @@ "packages": { "@metamask/base-controller": true, "@metamask/controller-utils": true, - "@metamask/utils": true, + "@metamask/message-manager>@metamask/utils": true, "browserify>buffer": true, "webpack>events": true, "uuid": true @@ -2280,6 +2280,21 @@ "semver": true } }, + "@metamask/message-manager>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@noble/hashes": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true, + "nock>debug": true, + "@metamask/utils>pony-cause": true, + "semver": true + } + }, "@metamask/multichain>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 428035dbd0f8..f3039013abee 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -1431,7 +1431,7 @@ "packages": { "@metamask/base-controller": true, "@metamask/controller-utils": true, - "@metamask/utils": true, + "@metamask/message-manager>@metamask/utils": true, "browserify>buffer": true, "webpack>events": true, "uuid": true @@ -2293,6 +2293,21 @@ "semver": true } }, + "@metamask/message-manager>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@noble/hashes": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true, + "nock>debug": true, + "@metamask/utils>pony-cause": true, + "semver": true + } + }, "@metamask/multichain>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index cab7f02f635c..52b5ef08c823 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -1431,7 +1431,7 @@ "packages": { "@metamask/base-controller": true, "@metamask/controller-utils": true, - "@metamask/utils": true, + "@metamask/message-manager>@metamask/utils": true, "browserify>buffer": true, "webpack>events": true, "uuid": true @@ -2280,6 +2280,21 @@ "semver": true } }, + "@metamask/message-manager>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@noble/hashes": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true, + "nock>debug": true, + "@metamask/utils>pony-cause": true, + "semver": true + } + }, "@metamask/multichain>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 0602635a4079..d1e0987d7baa 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -1523,7 +1523,7 @@ "packages": { "@metamask/base-controller": true, "@metamask/controller-utils": true, - "@metamask/utils": true, + "@metamask/message-manager>@metamask/utils": true, "browserify>buffer": true, "webpack>events": true, "uuid": true @@ -2387,6 +2387,21 @@ "semver": true } }, + "@metamask/message-manager>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@noble/hashes": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true, + "nock>debug": true, + "@metamask/utils>pony-cause": true, + "semver": true + } + }, "@metamask/name-controller>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/package.json b/package.json index 44556e2b8caa..3c3c6adb15dc 100644 --- a/package.json +++ b/package.json @@ -316,7 +316,7 @@ "@metamask/keyring-snap-client": "^3.0.0", "@metamask/logging-controller": "^6.0.0", "@metamask/logo": "^3.1.2", - "@metamask/message-manager": "^11.0.0", + "@metamask/message-manager": "^12.0.0", "@metamask/message-signing-snap": "^0.6.0", "@metamask/metamask-eth-abis": "^3.1.1", "@metamask/multichain": "^2.1.0", diff --git a/yarn.lock b/yarn.lock index d65a3111d841..a159da980faa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5759,21 +5759,6 @@ __metadata: languageName: node linkType: hard -"@metamask/message-manager@npm:^11.0.0": - version: 11.0.3 - resolution: "@metamask/message-manager@npm:11.0.3" - dependencies: - "@metamask/base-controller": "npm:^7.0.2" - "@metamask/controller-utils": "npm:^11.4.4" - "@metamask/eth-sig-util": "npm:^8.0.0" - "@metamask/utils": "npm:^10.0.0" - "@types/uuid": "npm:^8.3.0" - jsonschema: "npm:^1.4.1" - uuid: "npm:^8.3.2" - checksum: 10/18f5b0091474fc45e854db9c91ad8f5f898017ba9a08b01c770904ad3929b004c65298fe246b989f3c92fd2f03b5932dfa31adadb95ca81ce6940cb28a2ec793 - languageName: node - linkType: hard - "@metamask/message-manager@npm:^12.0.0": version: 12.0.0 resolution: "@metamask/message-manager@npm:12.0.0" @@ -26718,7 +26703,7 @@ __metadata: "@metamask/keyring-snap-client": "npm:^3.0.0" "@metamask/logging-controller": "npm:^6.0.0" "@metamask/logo": "npm:^3.1.2" - "@metamask/message-manager": "npm:^11.0.0" + "@metamask/message-manager": "npm:^12.0.0" "@metamask/message-signing-snap": "npm:^0.6.0" "@metamask/metamask-eth-abis": "npm:^3.1.1" "@metamask/multichain": "npm:^2.1.0"