We have a couple of opportunities for optimizing the performance of vault encryption, specifically within the EthKeyringController and the KeyringController setup:
1. Improve Key Caching in EthKeyringController:
The EthKeyringController is currently set up to derive a new encryption key from the user's password for every keychain operation. This approach is inefficient as it unnecessarily repeats the key derivation process.
We should amend the EthKeyringController to prioritize the use of a cached encryption key rather than re-deriving it from the password. This would only apply in instances where the cached encryption key is still in memory, and it would significantly reduce the processing time by avoiding redundant derivations.
2. Initialize KeyringController with Caching Enabled (in the extension):
As a separate but related improvement, when initializing KeyringController in the extension, we should enable the cacheEncryptionKey option by default (instead of MV3-only). This adjustment would ensure that the KeyringController itself utilizes the performance benefits of key caching.
3. Replace updateVault with isVaultUpdated:
The EthKeyringController currently uses the updateVault function from browser-passworder for a simple comparison with the existing vault, which leads to needless re-encryption.
We should export isVaultUpdated from browser-passworder, and use it in the EthKeyringController. This function would allow us to check if the vault is updated by analyzing its metadata, which is far more efficient than performing a full derivation -> decryption -> derivation -> encryption operation.
We have a couple of opportunities for optimizing the performance of vault encryption, specifically within the
EthKeyringControllerand theKeyringControllersetup:1. Improve Key Caching in EthKeyringController:
The
EthKeyringControlleris currently set up to derive a new encryption key from the user's password for every keychain operation. This approach is inefficient as it unnecessarily repeats the key derivation process.We should amend the
EthKeyringControllerto prioritize the use of a cached encryption key rather than re-deriving it from the password. This would only apply in instances where the cached encryption key is still in memory, and it would significantly reduce the processing time by avoiding redundant derivations.2. Initialize
KeyringControllerwith Caching Enabled (in the extension):As a separate but related improvement, when initializing
KeyringControllerin the extension, we should enable thecacheEncryptionKeyoption by default (instead of MV3-only). This adjustment would ensure that theKeyringControlleritself utilizes the performance benefits of key caching.3. Replace
updateVaultwithisVaultUpdated:The
EthKeyringControllercurrently uses theupdateVaultfunction frombrowser-passworderfor a simple comparison with the existing vault, which leads to needless re-encryption.We should export
isVaultUpdatedfrombrowser-passworder, and use it in theEthKeyringController. This function would allow us to check if the vault is updated by analyzing its metadata, which is far more efficient than performing a fullderivation -> decryption -> derivation -> encryptionoperation.