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

handle hex in personal signing for HW #1035

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/entries/popup/handlers/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Address } from 'wagmi';

import { i18n } from '~/core/languages';
import { LEGACY_CHAINS_FOR_HW } from '~/core/references';
import { logger } from '~/logger';

import { walletAction } from './walletAction';

Expand Down Expand Up @@ -145,8 +146,12 @@ export async function signMessageByTypeFromLedger(
// Personal sign
if (messageType === 'personal_sign') {
if (typeof msgData === 'string') {
// eslint-disable-next-line no-param-reassign
msgData = toUtf8Bytes(msgData);
try {
// eslint-disable-next-line no-param-reassign
msgData = toUtf8Bytes(msgData);
} catch (e) {
logger.info('the message is not a utf8 string, will sign as hex');
}
}

const messageHex = hexlify(msgData).substring(2);
Expand Down
9 changes: 7 additions & 2 deletions src/entries/popup/handlers/trezor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Address } from 'wagmi';

import { LEGACY_CHAINS_FOR_HW } from '~/core/references';
import { addHexPrefix } from '~/core/utils/hex';
import { logger } from '~/logger';

import { walletAction } from './walletAction';

Expand Down Expand Up @@ -125,8 +126,12 @@ export async function signMessageByTypeFromTrezor(
// Personal sign
if (messageType === 'personal_sign') {
if (typeof msgData === 'string') {
// eslint-disable-next-line no-param-reassign
msgData = toUtf8Bytes(msgData);
try {
// eslint-disable-next-line no-param-reassign
msgData = toUtf8Bytes(msgData);
} catch (e) {
logger.info('the message is not a utf8 string, will sign as hex');
}
}

const messageHex = hexlify(msgData).substring(2);
Expand Down
Loading