Skip to content
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

Add getKeyringsByType method #1376

Merged
merged 3 commits into from
May 25, 2023
Merged

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented May 16, 2023

Description

This PR adds the getKeyringsByType method to KeyringController.
This method can be used to get keyrings of a given type.

To support types from the extension that are not supported by mobile, this function accepts also a string in addition to KeyringTypes - an alternative to this would be to edit the KeyringTypes enum itself but in this controller we don't explicitly support all hardware keyrings.

Note: getKeyringsByType and getKeyringForAccount have been marked as deprecated as their usage is unsafe at the moment: actions executed directly on keyring instances are not being reflected on EthKeyringController and KeyringController states

Changes

  • ADDED: getKeyringsByType method to list keyrings for a given type
  • DEPRECATED: getKeyringsByType has been marked as deprecated as it is currently unsafe
  • DEPRECATED: getKeyringForAccount has been marked as deprecated as it is currently unsafe

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate (note: this will usually be JSDoc)
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@mikesposito mikesposito requested a review from a team as a code owner May 16, 2023 11:38
@mikesposito mikesposito marked this pull request as draft May 16, 2023 11:39
@mikesposito mikesposito changed the base branch from main to feat/1257-cache-encryption-key May 16, 2023 11:42
@mikesposito mikesposito force-pushed the feat/1255-get-keyrings-by-type branch from a9b8b2d to e49d428 Compare May 16, 2023 12:07
@mikesposito mikesposito changed the base branch from feat/1257-cache-encryption-key to main May 16, 2023 12:07
@mikesposito mikesposito marked this pull request as ready for review May 16, 2023 12:08
@mikesposito mikesposito force-pushed the feat/1255-get-keyrings-by-type branch from e49d428 to 87e8264 Compare May 18, 2023 08:57
@mikesposito
Copy link
Member Author

mikesposito commented May 23, 2023

@Gudahtt I think that we should somehow discourage the use of this method, along with any direct interaction with keyrings. If for example deserialize is called on a keyring, the update will not be propagated to the inner vault and the outer KeyringController, and we'll end up having a stale state.
This can be avoided by calling this.#keyring.persistAllKeyrings, it would be responsibility of the client but that method is inaccessible from the outside.

Do you think we should expose it with a method on KeyringController? This kind of interaction will be needed mainly by the extension

@mikesposito mikesposito force-pushed the feat/1255-get-keyrings-by-type branch from 837a473 to 835ad30 Compare May 24, 2023 11:23
@Gudahtt
Copy link
Member

Gudahtt commented May 24, 2023

Great point @mikesposito . Calling deserialize on a keyring would indeed be unsafe at the moment. The accounts team has a plan for solving that problem using events, so that the keyring controller can listen to the keyring for updates and always remain in-sync.

In the short term, perhaps we could just deprecate this method and explain why it's dangerous? Then we can be mindful of these dangers in the few places we need it in the extension until we can get rid of it completely.

I am unsure about exposing persistAllKeyrings. Ideally the client would never have a reason to call that, because they would avoid write operations on keyrings directly. If we find a situation like that we can certainly expose it though.

@mikesposito mikesposito force-pushed the feat/1255-get-keyrings-by-type branch from 835ad30 to 54e3bf1 Compare May 25, 2023 08:18
@mikesposito
Copy link
Member Author

mikesposito commented May 25, 2023

Makes sense, I added a deprecation notice for getKeyringsByType and getKeyringForAccount - added also a note on the PR description for visibility

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mikesposito mikesposito merged commit 992e968 into main May 25, 2023
@mikesposito mikesposito deleted the feat/1255-get-keyrings-by-type branch May 25, 2023 11:33
brad-decker pushed a commit to dragana8/core that referenced this pull request Jun 1, 2023
* feat: add getKeyringsByType method

* fix: use type unknown instead of Keyring

* chore: add deprecation tags
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* feat: add getKeyringsByType method

* fix: use type unknown instead of Keyring

* chore: add deprecation tags
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* feat: add getKeyringsByType method

* fix: use type unknown instead of Keyring

* chore: add deprecation tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyringController: Add getKeyringsByType method
3 participants