Skip to content

Commit

Permalink
feat: add decryptMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Aug 17, 2023
1 parent 0cb49fd commit 471f845
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ import type {
TypedMessageParams,
} from '@metamask/message-manager';
import type { PreferencesController } from '@metamask/preferences-controller';
import {
assertIsStrictHexString,
hasProperty,
type Hex,
type Keyring,
type Json,
} from '@metamask/utils';
import type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';
import { assertIsStrictHexString, hasProperty } from '@metamask/utils';
import { Mutex } from 'async-mutex';
import {
addHexPrefix,
Expand Down Expand Up @@ -442,6 +437,21 @@ export class KeyringController extends BaseControllerV2<
return this.#keyring.getEncryptionPublicKey(account, opts);
}

/**
* Attempts to decrypt the provided message parameters.
*
* @param messageParams - The decryption message parameters.
* @param messageParams.from - The address of the account you want to use to decrypt the message.
* @param messageParams.data - The encrypted data that you want to decrypt.
* @returns The raw decryption result.
*/
async decryptMessage(messageParams: {
from: string;
data: Eip1024EncryptedData;
}): Promise<string> {
return this.#keyring.decryptMessage(messageParams);
}

/**
* Returns the currently initialized keyring that manages
* the specified `address` if one exists.
Expand Down

0 comments on commit 471f845

Please sign in to comment.