-
-
Notifications
You must be signed in to change notification settings - Fork 256
[keyring-controller] Add withKeyring method
#4197
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
Conversation
ec8c8dd to
3f59e75
Compare
81d5e29 to
6d13430
Compare
3760971 to
c7561d7
Compare
808ec49 to
871c5fe
Compare
784eee9 to
7109a5d
Compare
871c5fe to
6bc84be
Compare
e972d23 to
ecbdaf9
Compare
6bc84be to
c3e6a34
Compare
ecbdaf9 to
d58241e
Compare
36347ad to
20fd344
Compare
d58241e to
d023205
Compare
d023205 to
3854ee3
Compare
|
The As there are some issues when using action handlers with generic types, we can add the |
3854ee3 to
230bb61
Compare
230bb61 to
668b2b5
Compare
|
|
||
| const result = await fn(keyring); | ||
|
|
||
| if (Object.is(result, keyring)) { |
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.
Good idea 👍
Gudahtt
left a comment
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.
LGTM! Just a few nits left
d51ca05 to
404cf84
Compare
gantunesr
left a comment
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.
Great improvement!!
| | { | ||
| address: Hex; | ||
| }; |
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 comment is beyond the scope of the PR
How should we ensure the correct execution of an operation when we have multiple keyrings with the same address/account? @Gudahtt, and I believe others, have already pointed this particular issue regarding the removeAccount method
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.
Currently every time a new keyring is added (or deserialized from vault) this.#checkForDuplicates is called, but not when adding a new account on a keyring.
This means that a user would be able to add an account that is already on another keyring without issues, but it would then get errors when unlocking the wallet, because the keyrings would be added along with all the accounts already, and checkForDuplicates in #newKeyring would throw.
Perhaps we could check for duplicates also when adding new accounts? it would solve the root issue also regarding removeAccount as well
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.
Perhaps we could check for duplicates also when adding new accounts?
This sounds like a good solution for now, for as long as we're using the address as the unique identifier. Eventually we'll be moving away from that idea hopefully
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.
Perhaps we could check for duplicates also when adding new accounts? it would solve the root issue also regarding removeAccount as well
Hmm, I'm thinking that this could lead to interesting scenarios as well: if a user imports an account which can also be derived with e.g. index + 1 of the HD keyring, it would end up in a situation where no more HD accounts can be added until the imported one is removed, and the user would not receive clear errors or warnings about that.
Same applies for Snaps: I'm wondering if a Snap could potentially block account additions on other keyrings, or the other way around
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.
for as long as we're using the address as the unique identifier. Eventually we'll be moving away from that idea hopefully
The accounts-controller is introducing the concept of account ID (an UUID) in the clients, it would be good to also use this identifier inside the keyring-controller
I'm wondering if a Snap could potentially block account additions on other keyrings, or the other way around
Yes, this is a possible scenario, I think the long term solution is to use the regular IDs instead of addresses as the identifier. It's a good UX to be able to sign with different keyrings if the user wants to so I don't think we should block the account duplication at a keyring-controller but simplify it at a UI/UX level
404cf84 to
eeff1a2
Compare
Explanation
Part of
KeyringControllerresponsibilies is ensuring each operation is mutually exclusive and atomic, updating keyring instances and the vault (or rolling them back) in the same mutex lock.However, the ability of clients to have direct access to a keyring instance represents a loophole, as with the current implementation they don’t have to comply with the rules enforced by the controller: we should provide a way for clients to interact with a keyring instance through safeguards provided by KeyringController.
The current behavior is this one:
getKeyringForAccountpersistAllKeyringsWe should, instead, have something like this:
withKeyringmethod, passing a keyring selector and a callbackReferences
Changelog
@metamask/keyring-controllerwithKeyringmethodpersistAllKeyringsmethodwithKeyringinsteadChecklist