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

Commit 3e102b5

Browse files
authored
Narrow return type of signTypedMessage and encryption methods (#249)
* 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
1 parent c3afc44 commit 3e102b5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/KeyringController.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { remove0x, isValidHexAddress } from '@metamask/utils';
77
import type {
88
Hex,
99
Json,
10-
Bytes,
1110
Keyring,
1211
KeyringClass,
1312
Eip1024EncryptedData,
@@ -467,7 +466,7 @@ class KeyringController extends EventEmitter {
467466
async getEncryptionPublicKey(
468467
address: string,
469468
opts: Record<string, unknown> = {},
470-
): Promise<Bytes> {
469+
): Promise<string> {
471470
const normalizedAddress = normalizeToHex(address) as Hex;
472471
const keyring = await this.getKeyringForAccount(address);
473472
if (!keyring.getEncryptionPublicKey) {
@@ -490,7 +489,7 @@ class KeyringController extends EventEmitter {
490489
async decryptMessage(msgParams: {
491490
from: string;
492491
data: Eip1024EncryptedData;
493-
}): Promise<Bytes> {
492+
}): Promise<string> {
494493
const address = normalizeToHex(msgParams.from) as Hex;
495494
const keyring = await this.getKeyringForAccount(address);
496495
if (!keyring.decryptMessage) {
@@ -516,7 +515,7 @@ class KeyringController extends EventEmitter {
516515
data: Record<string, unknown>[];
517516
},
518517
opts: Record<string, unknown> = { version: 'V1' },
519-
): Promise<Bytes> {
518+
): Promise<string> {
520519
// Cast to `Hex` here is safe here because `msgParams.from` is not nullish.
521520
// `normalizeToHex` returns `Hex` unless given a nullish value.
522521
const address = normalizeToHex(msgParams.from) as Hex;

0 commit comments

Comments
 (0)