Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/core/Encryptor/Encryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const isEncryptionKey = (key: unknown): key is EncryptionKey =>
* It supports generating a salt, deriving an encryption key from a
* password and salt, and performing the encryption and decryption processes.
*/
class Encryptor implements WithKeyEncryptor<EncryptionKey, Json> {
class Encryptor implements WithKeyEncryptor<EncryptionKey> {
/**
* The key derivation parameters used for encryption and decryption operations.
* These parameters include the algorithm and its specific parameters, for example, number of iterations for key derivation.
Expand Down Expand Up @@ -134,7 +134,6 @@ class Encryptor implements WithKeyEncryptor<EncryptionKey, Json> {
* @param data - The data to encrypt.
* @returns A promise that resolves to an object containing the cipher text and initialization vector (IV).
*/
//@ts-expect-error - TODO: will be implemented at the keyring controller the support for this key type
encryptWithKey = async (
key: EncryptionKey,
data: Json,
Expand All @@ -159,7 +158,6 @@ class Encryptor implements WithKeyEncryptor<EncryptionKey, Json> {
* @param payload - The encrypted payload to decrypt.
* @returns The decrypted object.
*/
//@ts-expect-error - TODO: will be implemented at the keyring controller the support for this key type
decryptWithKey = async (
key: EncryptionKey,
payload: EncryptionResult,
Expand Down
25 changes: 6 additions & 19 deletions app/core/Encryptor/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Json } from '@metamask/utils';
import type { KeyDerivationOptions } from '@metamask/browser-passworder';
import { ExportableKeyEncryptor } from '@metamask/keyring-controller';
import { Encryptor } from '@metamask/keyring-controller';

/** Key derivation function options. */
export type { KeyDerivationOptions };
Expand Down Expand Up @@ -124,21 +124,8 @@ export interface GenericEncryptor<Data = Json> {
* An encryptor interface that supports encrypting and decrypting
* serializable data with a password, and exporting and importing keys.
*/
export type WithKeyEncryptor<Key, Data> = ExportableKeyEncryptor & {
/**
* Encrypts the given object with the given encryption key.
*
* @param key - The encryption key to encrypt with.
* @param object - The object to encrypt.
* @returns The encryption result.
*/
encryptWithKey: (key: Key, data: Data) => Promise<EncryptionResult>;
/**
* Decrypts the given encrypted string with the given encryption key.
*
* @param key - The encryption key to decrypt with.
* @param encryptedString - The encrypted string to decrypt.
* @returns The decrypted object.
*/
decryptWithKey: (key: Key, payload: EncryptionResult) => Promise<unknown>;
};
export type WithKeyEncryptor<Key> = Encryptor<
Key,
KeyDerivationOptions,
EncryptionResult
>;
2 changes: 0 additions & 2 deletions app/core/Engine/controllers/keyring-controller-init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ describe('keyringControllerInit', () => {
expect(controllerMock).toHaveBeenCalledWith({
messenger: expect.any(Object),
state: undefined,
cacheEncryptionKey: true,
encryptor: expect.any(Encryptor),
keyringBuilders: expect.any(Array),
removeIdentity: expect.any(Function),
});
});
});
22 changes: 13 additions & 9 deletions app/core/Engine/controllers/keyring-controller-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ControllerInitFunction } from '../types';
import {
KeyringController,
KeyringControllerMessenger,
KeyringControllerOptions,
} from '@metamask/keyring-controller';
import { QrKeyring } from '@metamask/eth-qr-keyring';
import {
Expand All @@ -11,6 +12,11 @@ import {
} from '@metamask/eth-ledger-bridge-keyring';
import { HdKeyring } from '@metamask/eth-hd-keyring';
import { Encryptor, LEGACY_DERIVATION_OPTIONS, pbkdf2 } from '../../Encryptor';
import {
EncryptionKey,
EncryptionResult,
KeyDerivationOptions,
} from 'app/core/Encryptor/types';

const encryptor = new Encryptor({
keyDerivationOptions: LEGACY_DERIVATION_OPTIONS,
Expand All @@ -34,7 +40,7 @@ export const keyringControllerInit: ControllerInitFunction<
qrKeyringScanner,
getController,
}) => {
const additionalKeyrings = [];
const additionalKeyrings: KeyringControllerOptions['keyringBuilders'] = [];

const qrKeyringBuilder = () => {
const keyring = new QrKeyring({ bridge: qrKeyringScanner });
Expand Down Expand Up @@ -64,21 +70,19 @@ export const keyringControllerInit: ControllerInitFunction<

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const snapKeyringBuilder = getController('SnapKeyringBuilder');
// @ts-expect-error SnapKeyring is missing the `addAccounts` method
additionalKeyrings.push(snapKeyringBuilder);
///: END:ONLY_INCLUDE_IF

const preferencesController = getController('PreferencesController');

const controller = new KeyringController({
removeIdentity: (address: string) =>
preferencesController.removeIdentity(address),
const controller = new KeyringController<
EncryptionKey,
KeyDerivationOptions,
EncryptionResult
>({
encryptor,
messenger: controllerMessenger,
state: initialKeyringState || persistedState.KeyringController,
// @ts-expect-error: TODO: Update the type of QRHardwareKeyring to
// `Keyring<Json>`.
keyringBuilders: additionalKeyrings,
cacheEncryptionKey: true,
});

return {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
"@scure/bip32": "1.7.0",
"@metamask/snaps-sdk": "^10.0.0",
"react-native@0.76.9": "patch:react-native@npm%3A0.76.9#./.yarn/patches/react-native-npm-0.76.9-1c25352097.patch",
"@metamask/transaction-controller@npm:^61.1.0": "patch:@metamask/transaction-controller@npm%3A61.0.0#~/.yarn/patches/@metamask-transaction-controller-npm-61.0.0-cccac388c7.patch"
"@metamask/transaction-controller@npm:^61.1.0": "patch:@metamask/transaction-controller@npm%3A61.0.0#~/.yarn/patches/@metamask-transaction-controller-npm-61.0.0-cccac388c7.patch",
"@metamask/keyring-controller": "npm:@metamask-previews/keyring-controller@24.0.0-preview-20df3e99"
},
"dependencies": {
"@config-plugins/detox": "^9.0.0",
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7108,15 +7108,6 @@ __metadata:
languageName: node
linkType: hard

"@metamask/browser-passworder@npm:^4.3.0":
version: 4.3.0
resolution: "@metamask/browser-passworder@npm:4.3.0"
dependencies:
"@metamask/utils": "npm:^8.2.0"
checksum: 10/8ba5c50cd6274b0cc0f90a1ee16b960ee150f14c29083f3515f4abe018a28ead32c21f5f4a62a6e27a946b1228adc2ff1f195e71e38782fa39fa8fff116173e6
languageName: node
linkType: hard

"@metamask/browser-passworder@npm:^5.0.0":
version: 5.0.0
resolution: "@metamask/browser-passworder@npm:5.0.0"
Expand All @@ -7126,6 +7117,15 @@ __metadata:
languageName: node
linkType: hard

"@metamask/browser-passworder@npm:^6.0.0":
version: 6.0.0
resolution: "@metamask/browser-passworder@npm:6.0.0"
dependencies:
"@metamask/utils": "npm:^11.0.1"
checksum: 10/44b31729ccd52e62df27a948fbea2320a11861d6465128b1626a723fc47e25f9e3a8c3bdc09329f3f270b5d9e023107cb439cfb6961a3614c6daa58ea4524f00
languageName: node
linkType: hard

"@metamask/build-utils@npm:^3.0.0":
version: 3.0.4
resolution: "@metamask/build-utils@npm:3.0.4"
Expand Down Expand Up @@ -7755,13 +7755,13 @@ __metadata:
languageName: node
linkType: hard

"@metamask/keyring-controller@npm:^24.0.0":
version: 24.0.0
resolution: "@metamask/keyring-controller@npm:24.0.0"
"@metamask/keyring-controller@npm:@metamask-previews/keyring-controller@24.0.0-preview-20df3e99":
version: 24.0.0-preview-20df3e99
resolution: "@metamask-previews/keyring-controller@npm:24.0.0-preview-20df3e99"
dependencies:
"@ethereumjs/util": "npm:^9.1.0"
"@metamask/base-controller": "npm:^9.0.0"
"@metamask/browser-passworder": "npm:^4.3.0"
"@metamask/browser-passworder": "npm:^6.0.0"
"@metamask/eth-hd-keyring": "npm:^13.0.0"
"@metamask/eth-sig-util": "npm:^8.2.0"
"@metamask/eth-simple-keyring": "npm:^11.0.0"
Expand All @@ -7774,7 +7774,7 @@ __metadata:
immer: "npm:^9.0.6"
lodash: "npm:^4.17.21"
ulid: "npm:^2.3.0"
checksum: 10/35050ec779f364dab6dfa477cc3764b923277074769e2e7a5496ca82000493cf9292a56a048eaa1b361b2ca15369725ae8e2bb6a7f6d91b37ad1d86fab582c23
checksum: 10/f5332805b9ff74cefeae49b5b3b4cf9b6b1617535e78f30e052ccf79a8eaff9cef49527873b28f0249cd6528f3a823c4b9e1e4b3b1124854886eb8ace1540372
languageName: node
linkType: hard

Expand Down
Loading