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

Commit

Permalink
Narrow return type of signTypedMessage and encryption methods (#249)
Browse files Browse the repository at this point in the history
* Narrow return type of `signTypedMessage`

The method `signTypedMessage` always returns a string, but the declared
return type was `Bytes` (which is a type union of `string` along with
other things). This made the method more difficult to use, as callers
had to handle the other `Bytes` types as return values as well.

The method has been updated to use `string` as the return type.

* Narrow return type for encryption methods as well
  • Loading branch information
Gudahtt authored Jul 17, 2023
1 parent c3afc44 commit 3e102b5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { remove0x, isValidHexAddress } from '@metamask/utils';
import type {
Hex,
Json,
Bytes,
Keyring,
KeyringClass,
Eip1024EncryptedData,
Expand Down Expand Up @@ -467,7 +466,7 @@ class KeyringController extends EventEmitter {
async getEncryptionPublicKey(
address: string,
opts: Record<string, unknown> = {},
): Promise<Bytes> {
): Promise<string> {
const normalizedAddress = normalizeToHex(address) as Hex;
const keyring = await this.getKeyringForAccount(address);
if (!keyring.getEncryptionPublicKey) {
Expand All @@ -490,7 +489,7 @@ class KeyringController extends EventEmitter {
async decryptMessage(msgParams: {
from: string;
data: Eip1024EncryptedData;
}): Promise<Bytes> {
}): Promise<string> {
const address = normalizeToHex(msgParams.from) as Hex;
const keyring = await this.getKeyringForAccount(address);
if (!keyring.decryptMessage) {
Expand All @@ -516,7 +515,7 @@ class KeyringController extends EventEmitter {
data: Record<string, unknown>[];
},
opts: Record<string, unknown> = { version: 'V1' },
): Promise<Bytes> {
): Promise<string> {
// 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;
Expand Down

0 comments on commit 3e102b5

Please sign in to comment.