From 9064c9ffadc1883e4509a4a17e2253a66c14b9aa Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 17 Jul 2023 19:13:08 -0230 Subject: [PATCH 1/2] 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. --- src/KeyringController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KeyringController.ts b/src/KeyringController.ts index 195b045b..3bbd2f3b 100644 --- a/src/KeyringController.ts +++ b/src/KeyringController.ts @@ -516,7 +516,7 @@ class KeyringController extends EventEmitter { data: Record[]; }, opts: Record = { version: 'V1' }, - ): Promise { + ): Promise { // 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; From 2d07efceab818433015f599245672a7f4eee8291 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 17 Jul 2023 20:02:58 -0230 Subject: [PATCH 2/2] Narrow return type for encryption methods as well --- src/KeyringController.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/KeyringController.ts b/src/KeyringController.ts index 3bbd2f3b..45648544 100644 --- a/src/KeyringController.ts +++ b/src/KeyringController.ts @@ -7,7 +7,6 @@ import { remove0x, isValidHexAddress } from '@metamask/utils'; import type { Hex, Json, - Bytes, Keyring, KeyringClass, Eip1024EncryptedData, @@ -467,7 +466,7 @@ class KeyringController extends EventEmitter { async getEncryptionPublicKey( address: string, opts: Record = {}, - ): Promise { + ): Promise { const normalizedAddress = normalizeToHex(address) as Hex; const keyring = await this.getKeyringForAccount(address); if (!keyring.getEncryptionPublicKey) { @@ -490,7 +489,7 @@ class KeyringController extends EventEmitter { async decryptMessage(msgParams: { from: string; data: Eip1024EncryptedData; - }): Promise { + }): Promise { const address = normalizeToHex(msgParams.from) as Hex; const keyring = await this.getKeyringForAccount(address); if (!keyring.decryptMessage) {