Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit c3afc44

Browse files
authored
Fix @metamask/eth-sig-util types (#248)
The types for the package `@metamask/eth-sig-util` were being overwritten by a local type declaration. That has been removed, and all type errors have been resolved. All of the type errors were related to `normalize` returning `undefined` if given a nullish input. We never pass it a nullish input, but TypeScript wasn't able to infer that, so that issue was addressed with type casts. This isn't ideal, but it's temporary. Once we finish migrating all Keyrings to the new Keyring interface, we won't need to normalize addresses anymore at all.
1 parent 2adb432 commit c3afc44

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/KeyringController.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ class KeyringController extends EventEmitter {
334334
return res.concat(arr);
335335
}, []);
336336

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

340342
/**
@@ -515,7 +517,9 @@ class KeyringController extends EventEmitter {
515517
},
516518
opts: Record<string, unknown> = { version: 'V1' },
517519
): Promise<Bytes> {
518-
const address = normalizeToHex(msgParams.from);
520+
// Cast to `Hex` here is safe here because `msgParams.from` is not nullish.
521+
// `normalizeToHex` returns `Hex` unless given a nullish value.
522+
const address = normalizeToHex(msgParams.from) as Hex;
519523
const keyring = await this.getKeyringForAccount(address);
520524
if (!keyring.signTypedData) {
521525
throw new Error(KeyringControllerError.UnsupportedSignTypedMessage);
@@ -697,7 +701,9 @@ class KeyringController extends EventEmitter {
697701
* @returns The keyring of the account, if it exists.
698702
*/
699703
async getKeyringForAccount(address: string): Promise<Keyring<Json>> {
700-
const hexed = normalizeToHex(address);
704+
// Cast to `Hex` here is safe here because `address` is not nullish.
705+
// `normalizeToHex` returns `Hex` unless given a nullish value.
706+
const hexed = normalizeToHex(address) as Hex;
701707

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

10871093
return {
10881094
type: keyring.type,
1089-
accounts: accounts.map(normalizeToHex),
1095+
// Cast to `Hex[]` here is safe here because `addresses` has no nullish
1096+
// values, and `normalizeToHex` returns `Hex` unless given a nullish value
1097+
accounts: accounts.map(normalizeToHex) as Hex[],
10901098
};
10911099
}
10921100

src/types/@metamask/eth-sig-util.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)