-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate KeyringController to BaseControllerV2 #1378
Conversation
0ef1d78
to
40ebd18
Compare
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been removed or ignored. Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
77c7655
to
706b0e7
Compare
a0171f4
to
cc408fe
Compare
965a2f9
to
65d38ca
Compare
522e462
to
281d6ff
Compare
...rest, | ||
}); | ||
const initialState = await controller.createNewVaultAndKeychain(password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we removed vault
, encryptionKey
and encryptionSalt
from methods returns, we now need to take the initial state from controller.state
, which contains all state properties
e7e6e41
to
1caf12e
Compare
I audited the set of changes here and here are my notes for the changelog:
@mikesposito I believe this aligns with what you had written in your changelog. I just had a question about the behavior of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple of questions but I've looked this over and these changes make sense to me.
@@ -237,7 +280,7 @@ export class KeyringController extends BaseController< | |||
// we return the account already existing at index `accountCount` | |||
const primaryKeyringAccounts = await primaryKeyring.getAccounts(); | |||
return { | |||
keyringState: await this.fullUpdate(), | |||
keyringState: this.state, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it important to filter vault
, encryptionKey
and encryptionSalt
out of this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops! yes, it is. I forgot this occurrence, I just changed it to this.#getMemState()
7b2577b
to
a0d8096
Compare
@mcmire thanks for auditing this PR changes and writing down a nice changelog! I just updated the main description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Nice work 💪🏻
* feat: supp cacheEncryptionKey and submitEncryptionKey method * docs: update jsdoc * refactor: migrate KeyringController to BaseControllerV2 * fix: use immer v9 * rollback: controller parameters change * refactor: change KeyringConfig to KeyringControllerConfig * refactor: sync controller state with keyring state * refactor: no vault sync * refactor: use state value for isUnlocked * refactor: use controller state for test assertions * refactor: remove onLock and onUnlock in favor of events * refactor: sync mem and persistent store * refactor: apply review feedback * refactor: use option bag for constructor * fix: set immer as prod dependency * fix: add encryption key and salt to memstore * refactor: remove vault encryptionKey and encryptionSalt from returns * fix: remove forgotten state return
* feat: supp cacheEncryptionKey and submitEncryptionKey method * docs: update jsdoc * refactor: migrate KeyringController to BaseControllerV2 * fix: use immer v9 * rollback: controller parameters change * refactor: change KeyringConfig to KeyringControllerConfig * refactor: sync controller state with keyring state * refactor: no vault sync * refactor: use state value for isUnlocked * refactor: use controller state for test assertions * refactor: remove onLock and onUnlock in favor of events * refactor: sync mem and persistent store * refactor: apply review feedback * refactor: use option bag for constructor * fix: set immer as prod dependency * fix: add encryption key and salt to memstore * refactor: remove vault encryptionKey and encryptionSalt from returns * fix: remove forgotten state return
Description
This PR refactors
KeyringController
to extendBaseControllerV2
.This controller's state is completely non-persistent and is kept in sync with the inner
EthKeyringController
's memStore through event subscription. For this reason, thefullUpdate
method is now unnecessary and has been removed - Tests have been refactored to use controller state for assertions so that this mechanism is implicitly well covered.All the methods that returned
fullUpdate
, now return theKeyringController
's state withvault
,encryptionKey
andencryptionSalt
removed as sensitive data; these parameters can always be found withKeyringController.state
Changes
controller.state
instead ofcontroller.store.getState()
messenger
option (and corresponding type KeyringControllerMessenger is now available)KeyringController:getState
andKeyringController:stateChange
events (and corresponding types KeyringControllerGetStateAction and KeyringControllerStateChangeEvent are now available)vault
propertyimmer
as a dependencyindex
from the Keyring typekeyringState
property in the return value ofaddNewAccount
,addNewAccountWithoutUpdate
,createNewVaultAndRestore
,createNewVaultAndKeychain
,importAccountWithStrategy
,removeAccount
,setLocked
,submitEncryptionKey
, andsubmitPassword
is now a type of KeyringControllerMemState instead of KeyringMemState (and may omitvault
,encryptionKey
, andencryptionSalt
)subscribe
andunsubscribe
methodslock
andunlock
methodsKeyringController:lock
andKeyringController:unlock
may now be subscribed to via the messenger if necessary.fullUpdate
methodencryptionKey
orencryptionSalt
NetworkController:lock
andNetworkController:unlock
(and corresponding types KeyringControllerLockEvent and KeyringControllerUnlockEvent)NetworkController:lock
when the inner EthKeyringController instance publishes itslock
event andNetworkController:unlock
when it publishes itsunlock
eventReferences
BaseControllerV2
#1258Checklist