Skip to content

Commit

Permalink
Adjust latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OGPoyraz committed Jan 7, 2025
1 parent e976dd0 commit e31bfb6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
24 changes: 11 additions & 13 deletions app/scripts/controllers/decrypt-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type {
DecryptMessageManagerMessenger,
DecryptMessageManagerState,
DecryptMessageManagerUnapprovedMessageAddedEvent,
} from '@metamask/message-manager';
import {
BaseController,
Expand All @@ -37,6 +38,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.
Expand Down Expand Up @@ -115,7 +118,9 @@ type DecryptMessageManagerStateChangeEvent = {
payload: [DecryptMessageManagerState, Patch[]];
};

type AllowedEvents = DecryptMessageManagerStateChangeEvent;
type AllowedEvents =
| DecryptMessageManagerStateChangeEvent
| DecryptMessageManagerUnapprovedMessageAddedEvent

Check failure on line 123 in app/scripts/controllers/decrypt-message.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Insert `;`

export type DecryptMessageControllerMessenger = RestrictedControllerMessenger<
typeof controllerName,
Expand Down Expand Up @@ -183,20 +188,13 @@ export default class DecryptMessageController extends BaseController<
this.hub = new EventEmitter();

this._decryptMessageManager = new DecryptMessageManager({
messenger: managerMessenger,
name: 'DecryptMessageManager',
additionalFinishStatuses: ['decrypted'],
messenger: managerMessenger,
});

this._decryptMessageManager.hub.on('updateBadge', () => {
this.hub.emit('updateBadge');
});

this._decryptMessageManager.hub.on(
'unapprovedMessage',
(messageParams: AbstractMessageParamsMetamask) => {
this._requestApproval(messageParams);
},
messenger.subscribe(
`${managerName}:unapprovedMessage`,
this._requestApproval,
);

this._subscribeToMessageState(
Expand Down Expand Up @@ -370,7 +368,7 @@ export default class DecryptMessageController extends BaseController<
) => void,
) {
controllerMessenger.subscribe(
'DecryptMessageManager:stateChange',
`${managerName}:stateChange`,
(state: MessageManagerState<AbstractMessage>) => {
const newMessages = this._migrateMessages(
// TODO: Replace `any` with type
Expand Down
32 changes: 13 additions & 19 deletions app/scripts/controllers/encryption-public-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import type {
EncryptionPublicKeyManagerMessenger,
EncryptionPublicKeyManagerState,
EncryptionPublicKeyManagerUnapprovedMessageAddedEvent,
} from '@metamask/message-manager';
import {
BaseController,
Expand All @@ -28,6 +29,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 = {
Expand Down Expand Up @@ -58,7 +60,7 @@ export type EncryptionPublicKeyControllerState = {
unapprovedEncryptionPublicKeyMsgCount: number;
};

export type GetEncryptionPublicKeyControllerState = {
export type EncryptionPublicKeyControllerGetState = {
type: `${typeof controllerName}:getState`;
handler: () => EncryptionPublicKeyControllerState;
};
Expand All @@ -69,7 +71,7 @@ export type EncryptionPublicKeyControllerStateChange = {
};

export type EncryptionPublicKeyControllerActions =
GetEncryptionPublicKeyControllerState;
EncryptionPublicKeyControllerGetState;

export type EncryptionPublicKeyControllerEvents =
EncryptionPublicKeyControllerStateChange;
Expand All @@ -81,7 +83,9 @@ type EncryptionPublicKeyManagerStateChange = {

type AllowedActions = AddApprovalRequest | AcceptRequest | RejectRequest;

type AllowedEvents = EncryptionPublicKeyManagerStateChange;
type AllowedEvents =
| EncryptionPublicKeyManagerStateChange
| EncryptionPublicKeyManagerUnapprovedMessageAddedEvent;

export type EncryptionPublicKeyControllerMessenger =
RestrictedControllerMessenger<
Expand Down Expand Up @@ -164,18 +168,11 @@ export default class EncryptionPublicKeyController extends BaseController<
this._encryptionPublicKeyManager = new EncryptionPublicKeyManager({
additionalFinishStatuses: ['received'],
messenger: managerMessenger,
name: 'EncryptionPublicKeyManager',
});

this._encryptionPublicKeyManager.hub.on('updateBadge', () => {
this.hub.emit('updateBadge');
});

this._encryptionPublicKeyManager.hub.on(
'unapprovedMessage',
(msgParams: AbstractMessageParamsMetamask) => {
this._requestApproval(msgParams, methodNameGetEncryptionPublicKey);
},
this.messagingSystem.subscribe(
`${managerName}:unapprovedMessage`,
this._requestApproval,
);

this._subscribeToMessageState(
Expand Down Expand Up @@ -359,7 +356,7 @@ export default class EncryptionPublicKeyController extends BaseController<
) => void,
) {
controllerMessenger.subscribe(
'EncryptionPublicKeyManager:stateChange',
`${managerName}:stateChange`,
(state: MessageManagerState<AbstractMessage>) => {
const newMessages = this._migrateMessages(
// TODO: Replace `any` with type
Expand Down Expand Up @@ -401,10 +398,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;

Expand All @@ -414,7 +408,7 @@ export default class EncryptionPublicKeyController extends BaseController<
{
id,
origin,
type,
type: methodNameGetEncryptionPublicKey,
},
true,
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
"secp256k1@npm:^4.0.1": "4.0.4",
"secp256k1@npm:4.0.2": "4.0.4",
"secp256k1@npm:4.0.3": "4.0.4",
"@metamask/message-manager@npm:^11.0.0": "npm:@metamask-previews/[email protected]544f13b4"
"@metamask/message-manager@npm:^11.0.0": "npm:@metamask-previews/[email protected]e5e6db48"
},
"dependencies": {
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5793,9 +5793,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/message-manager@npm:@metamask-previews/[email protected]544f13b4":
version: 11.0.3-preview-544f13b4
resolution: "@metamask-previews/message-manager@npm:11.0.3-preview-544f13b4"
"@metamask/message-manager@npm:@metamask-previews/[email protected]e5e6db48":
version: 11.0.3-preview-e5e6db48
resolution: "@metamask-previews/message-manager@npm:11.0.3-preview-e5e6db48"
dependencies:
"@metamask/base-controller": "npm:^7.1.0"
"@metamask/controller-utils": "npm:^11.4.4"
Expand All @@ -5804,7 +5804,7 @@ __metadata:
"@types/uuid": "npm:^8.3.0"
jsonschema: "npm:^1.4.1"
uuid: "npm:^8.3.2"
checksum: 10/956bfc3053cf67fc6c53b1303fde9601b6e6b876cabd9007141c6f5237a9040431b41993c2bd74e344bf0b1c5a67f111a799fa8f041563af1beb6623e2c0fcf3
checksum: 10/77903c6339534ddb7b794479707546b986576aa08ae7f77460027a2ddd5ec3136cd63ca59b775d5fab629408327cabfb6c28d024cbd0cc51671deb4ddaf12e43
languageName: node
linkType: hard

Expand Down

0 comments on commit e31bfb6

Please sign in to comment.