Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cherry-pick #8157 #8497

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/components/UI/PersonalSign/PersonalSign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { View, Text, InteractionManager } from 'react-native';
import Engine from '../../../core/Engine';
import SignatureRequest from '../SignatureRequest';
import ExpandedMessage from '../SignatureRequest/ExpandedMessage';
import { hexToText } from '@metamask/controller-utils';
import NotificationManager from '../../../core/NotificationManager';
import { strings } from '../../../../locales/i18n';
import { WALLET_CONNECT_ORIGIN } from '../../../util/walletconnect';
Expand All @@ -13,6 +12,7 @@ import AnalyticsV2 from '../../../util/analyticsV2';
import {
getAddressAccountType,
isExternalHardwareAccount,
stripHexPrefix,
} from '../../../util/address';
import sanitizeString from '../../../util/string';
import { KEYSTONE_TX_CANCELED } from '../../../constants/error';
Expand All @@ -28,6 +28,25 @@ import { store } from '../../../store';
import { getBlockaidMetricsParams } from '../../../util/blockaid';
import { SecurityAlertResponse } from '../BlockaidBanner/BlockaidBanner.types';
import { SigningModalSelectorsIDs } from '../../../../e2e/selectors/Modals/SigningModal.selectors';
import Logger from '../../../util/Logger';

/**
* Converts a hexadecimal string to a utf8 string.
* If the hexadecimal string is 32 bytes long, it is assumed to be a hash and returned as is.
*
* @param {string} hex - Hexadecimal string to convert
* @returns {string} - The utf8 equivalent or the original hexadecimal string.
*/
function msgHexToText(hex: string): string {
try {
const stripped = stripHexPrefix(hex);
const buff = Buffer.from(stripped, 'hex');
return buff.length === 32 ? hex : buff.toString('utf8');
} catch (e) {
Logger.log(e);
return hex;
}
}

/**
* Component that supports personal_sign
Expand Down Expand Up @@ -161,7 +180,7 @@ const PersonalSign = ({
};

const renderMessageText = () => {
const textChild = sanitizeString(hexToText(messageParams.data))
const textChild = sanitizeString(msgHexToText(messageParams.data))
.split('\n')
.map((line: string, i: number) => (
<Text
Expand Down
Loading