Skip to content

Commit 82831ec

Browse files
refactor!: remove cacheEncryptionKey flag from KeyringController (#7127)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR includes part of the changes originally proposed in [this PR](#5963) that were inflating its size: - Remove the `cacheEncryptionKey` flag from `KeyringController` constructor options and instance variables - All code paths that used this flag have been removed (effectively, the controller behaves as if the flag was always `true`) - `GenericEncryptor` and `ExportableKeyEncryptor` have been merged into a single `Encryptor` type. - The `Encryptor` type has also been fixed to be compatible with `@metamask/browser-passworder` and `Encryptor` from mobile - As `Encryptor` now accepts type parameters to specify encryption key and derivation params types, the `KeyringController` has been updated to accept these type parameters and pass them to the `Encryptor` instance. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Related to #6010 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Unifies the encryptor interface with a new generic `Encryptor`, removes `cacheEncryptionKey` and requires an `encryptor` for `KeyringController`, adds a derivation-options type param to `SeedlessOnboardingController`, and updates tests/types accordingly. > > - **Keyring Controller**: > - Replace `GenericEncryptor`/`ExportableKeyEncryptor` with a single generic `Encryptor` (supports key import/export, detailed encrypt/decrypt, custom result types). > - Add generic type params `EncryptionKey`, `SupportedKeyDerivationOptions`, and `EncryptionResult` to `KeyringController` and `KeyringControllerOptions`. > - BREAKING: `encryptor` is now required; remove `cacheEncryptionKey` and related paths/state handling. > - Fix `decryptWithKey` typing to accept encryption result object. > - **Seedless Onboarding Controller**: > - Add optional `SupportedKeyDerivationOptions` type parameter; update `VaultEncryptor` to use unified `Encryptor`. > - **Tests/Mocks**: > - Refactor tests to new encryptor API; remove branches for `cacheEncryptionKey`; add `createVault` helper and adjust mocks to new types. > - **Changelogs/Config**: > - Update package changelogs to document breaking changes and new generics. > - Slightly lower Jest coverage thresholds for `keyring-controller`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 16f68c7. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
1 parent 6ceb161 commit 82831ec

File tree

10 files changed

+942
-1166
lines changed

10 files changed

+942
-1166
lines changed

packages/keyring-controller/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added optional `EncryptionKey`, `SupportedKeyDerivationOptions` and `EncryptionResult` type parameters to the `KeyringController`, `ExportableKeyEncryptor` and `KeyringControllerOptions` types ([#7127](https://github.com/MetaMask/core/pull/7127))
13+
- This type parameter allows specifying the encryption key, key derivation options and encryption result types supported by the injected encryptor, defaulting to `@metamask/browser-passworder` types.
14+
15+
### Changed
16+
17+
- **BREAKING:** The `KeyringController` constructor options now require an encryptor ([#7127](https://github.com/MetaMask/core/pull/7127))
18+
- The `encryptor` constructor option was previously optional and defaulted to an instance of `@metamask/browser-passworder`.
19+
- **BREAKING:** The `GenericEncryptor` and `ExportableKeyEncryptor` types have been merged into a single `Encryptor` type ([#7127](https://github.com/MetaMask/core/pull/7127))
20+
21+
### Removed
22+
23+
- **BREAKING:** The `cacheEncryptionKey` parameter has been removed from the `KeyringController` constructor options ([#7127](https://github.com/MetaMask/core/pull/7127))
24+
- This parameter was previously used to enable encryption key in-memory caching, but it is no longer needed as the controller now always uses the latest encryption key.
25+
26+
### Fixed
27+
28+
- Fixed incorrect type for `decryptWithKey` method of `ExportableKeyEncryptor` (now `Encryptor`) ([#7127](https://github.com/MetaMask/core/pull/7127))
29+
1030
## [24.0.0]
1131

1232
### Changed

packages/keyring-controller/jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module.exports = merge(baseConfig, {
1717
// An object that configures minimum threshold enforcement for coverage results
1818
coverageThreshold: {
1919
global: {
20-
branches: 95.78,
20+
branches: 94.03,
2121
functions: 100,
22-
lines: 98.68,
23-
statements: 98.69,
22+
lines: 98.31,
23+
statements: 98.33,
2424
},
2525
},
2626

0 commit comments

Comments
 (0)