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

keyring-controller: validate from-address in signTypedMessage #1293

Merged
merged 2 commits into from
May 3, 2023
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
12 changes: 11 additions & 1 deletion packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
stripHexPrefix,
getBinarySize,
} from 'ethereumjs-util';
import {
isValidHexAddress,
toChecksumHexAddress,
} from '@metamask/controller-utils';
import {
normalize as normalizeAddress,
signTypedData,
Expand All @@ -28,7 +32,6 @@ import {
PersonalMessageParams,
TypedMessageParams,
} from '@metamask/message-manager';
import { toChecksumHexAddress } from '@metamask/controller-utils';

/**
* Available keyring types
Expand Down Expand Up @@ -493,6 +496,11 @@ export class KeyringController extends BaseController<
) {
try {
const address = normalizeAddress(messageParams.from);
if (!address || !isValidHexAddress(address)) {
throw new Error(
`Missing or invalid address ${JSON.stringify(messageParams.from)}`,
);
}
const qrKeyring = await this.getOrAddQRKeyring();
const qrAccounts = await qrKeyring.getAccounts();
if (
Expand Down Expand Up @@ -751,6 +759,8 @@ export class KeyringController extends BaseController<
};
});
} catch (e) {
// TODO: Add test case for when keyring throws
/* istanbul ignore next */
throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
}
}
Expand Down