-
-
Notifications
You must be signed in to change notification settings - Fork 220
fix: throw error when creating HD keyring with duplicate account #5675
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
base: main
Are you sure you want to change the base?
Conversation
f289dfe
to
3d7a30d
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
Co-authored-by: Charly Chevalier <[email protected]>
@@ -2587,7 +2587,8 @@ export class KeyringController extends BaseController< | |||
const accounts = await this.#getAccountsFromKeyrings(); | |||
|
|||
switch (type) { | |||
case KeyringTypes.simple: { | |||
case KeyringTypes.simple: | |||
case KeyringTypes.hd: { |
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.
Just for the record:
- Given that we only check for duplicates when creating new keyrings, this shouldn't impact the "manual" HD keyring account creation.
- For multi-SRP, this will prevent duplicated addresses when importing a new SRP (and thus, creating a new HD keyring).
@@ -2587,7 +2587,8 @@ export class KeyringController extends BaseController< | |||
const accounts = await this.#getAccountsFromKeyrings(); | |||
|
|||
switch (type) { | |||
case KeyringTypes.simple: { | |||
case KeyringTypes.simple: | |||
case KeyringTypes.hd: { |
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.
It looks like we are leaving account additions unchecked, which may be also problematic because if a user:
- Imports an SRP
- Imports a private key, part of the above SRP
- Adds an account until reaching the index of the imported private key
User will endup in the same faulty situation
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.
The reason I'm flagging this is that it is the fastest way to brick the wallet: #5701
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.
This can mitigate some issues for HD specifically. Is there a reason we are addressing those specifically instead of the account duplication for all types? I feel like we should find a solution that can work for all keyrings or we won't be able to really fix the underlying issues (i.e. hardware wallet accounts, snaps)
I opened an alternative PR that could avoid different cases of duplicates and fix users that are currently locked out: #5710 |
Explanation
Currently, we are not checking whether the HD keyring account being added by importing SRP is a duplicate. This creates the possibility of adding the same account first to the simple keyring and then again with import HD keyring.
This PR adds a duplicate account check when adding an HD keyring, preventing this situation.
References
Changelog
Checklist