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

Fix @metamask/eth-sig-util types #248

Merged
merged 1 commit into from
Jul 17, 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
16 changes: 12 additions & 4 deletions src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ class KeyringController extends EventEmitter {
return res.concat(arr);
}, []);

return addresses.map(normalizeToHex);
// Cast to `Hex[]` here is safe here because `addresses` has no nullish
// values, and `normalizeToHex` returns `Hex` unless given a nullish value
return addresses.map(normalizeToHex) as Hex[];
}

/**
Expand Down Expand Up @@ -515,7 +517,9 @@ class KeyringController extends EventEmitter {
},
opts: Record<string, unknown> = { version: 'V1' },
): Promise<Bytes> {
const address = normalizeToHex(msgParams.from);
// Cast to `Hex` here is safe here because `msgParams.from` is not nullish.
// `normalizeToHex` returns `Hex` unless given a nullish value.
const address = normalizeToHex(msgParams.from) as Hex;
const keyring = await this.getKeyringForAccount(address);
if (!keyring.signTypedData) {
throw new Error(KeyringControllerError.UnsupportedSignTypedMessage);
Expand Down Expand Up @@ -697,7 +701,9 @@ class KeyringController extends EventEmitter {
* @returns The keyring of the account, if it exists.
*/
async getKeyringForAccount(address: string): Promise<Keyring<Json>> {
const hexed = normalizeToHex(address);
// Cast to `Hex` here is safe here because `address` is not nullish.
// `normalizeToHex` returns `Hex` unless given a nullish value.
const hexed = normalizeToHex(address) as Hex;

const candidates = await Promise.all(
this.keyrings.map(async (keyring) => {
Expand Down Expand Up @@ -1086,7 +1092,9 @@ async function displayForKeyring(

return {
type: keyring.type,
accounts: accounts.map(normalizeToHex),
// Cast to `Hex[]` here is safe here because `addresses` has no nullish
// values, and `normalizeToHex` returns `Hex` unless given a nullish value
accounts: accounts.map(normalizeToHex) as Hex[],
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/types/@metamask/eth-sig-util.d.ts

This file was deleted.