Skip to content

Commit

Permalink
refactor: apply @Gudahtt suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Sep 18, 2023
1 parent 8b201dd commit 6cb3831
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/scripts/controllers/decrypt-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { ApprovalType, ORIGIN_METAMASK } from '@metamask/controller-utils';
import { Patch } from 'immer';
import type { KeyringControllerDecryptMessageAction } from '@metamask/keyring-controller';
import { Eip1024EncryptedData, hasProperty } from '@metamask/utils';
import { Eip1024EncryptedData, hasProperty, isObject } from '@metamask/utils';
import { MetaMetricsEventCategory } from '../../../shared/constants/metametrics';
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';

Expand All @@ -36,6 +36,17 @@ const stateMetadata = {
unapprovedDecryptMsgCount: { persist: false, anonymous: false },
};

/**
* Type guard that checks for the presence of the required properties
* for EIP-1024 encrypted data.
*
* See: https://eips.ethereum.org/EIPS/eip-1024
*
* @param message - The message to check.
* @param message.from - The sender of the message.
* @param message.data - The EIP-1024 encrypted data.
* @returns Whether the message is an EIP-1024 encrypted message.
*/
export const isEIP1024EncryptedMessage = (message: {
from: string;
data: unknown;
Expand All @@ -44,8 +55,7 @@ export const isEIP1024EncryptedMessage = (message: {
data: Eip1024EncryptedData;
} => {
if (
message.data &&
typeof message.data === 'object' &&
isObject(message.data) &&
hasProperty(message.data, 'version') &&
hasProperty(message.data, 'nonce') &&
hasProperty(message.data, 'ephemPublicKey') &&
Expand Down

0 comments on commit 6cb3831

Please sign in to comment.