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

Redesign Keyring Controller API #431

Closed
35 tasks done
Gudahtt opened this issue Mar 24, 2021 · 5 comments
Closed
35 tasks done

Redesign Keyring Controller API #431

Gudahtt opened this issue Mar 24, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request Epic

Comments

@Gudahtt
Copy link
Member

Gudahtt commented Mar 24, 2021

The keyring controller API is confusing and difficult to extend.

Today we have two "keyring controllers". The first is the original one, eth-keyring-controller, which is used by both projects. The second is @metamask/keyring-controller, which is used by mobile as a wrapper around eth-keyring-controller.

@metamask/keyring-controller mainly serves to coordinate changes between eth-keyring-controller and other controllers. It also handles some keyring-interaction related tasks that aren't handled by eth-keyring-controller, such as input parsing for imported accounts.

  • Side-note: In the extension, the closest equivalent to this wrapper class is a collection of keyring-related methods that are directly in metamask-controller.js. This collection of functions serves the same purpose that @metamask/keyring-controller does for mobile.

My questions are:

  • What is the KeyringController (eth-keyring-controller) responsible for exactly? Why are some keyring methods called through the KeyringController, while others are called directly on keyrings?
  • What is the wrapper KeyringController class responsible for? Can we avoid the need for a wrapper class altogether?
  • How can we extend the capabilities of keyrings and integrate keyrings with additional setup requirements without requiring custom methods in the keyring controller?

The outcome of this task should be a proposal in Notion.

Related issues:

Edit: Work towards this has begun, but there is a bunch of preparation required first. Here's a rough checklist of the work involved:

@Gudahtt Gudahtt added the enhancement New feature or request label Mar 24, 2021
@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 24, 2021

I'm not sure where I land yet on all of these questions. I have a draft answer for the first one though:

  • The KeyringController (eth-keyring-controller) holds references to all keyrings, and is responsible for locking/unlocking, but don't provide pass-through methods for interactiing with keyrings. The rest of the codebase interacts directly with keyrings when performing keyring-related operations.
  • The IdentityController holds the "identities" state currently in the PreferencesController, and handles most identity-related functionality that is currently provided by the KeyringController wrapper. Most of the rest of the codebase doesn't deal directly with keys or keyrings - they deal with this "identity" abstraction.
  • The AccountTrackerController remains basically as-is, responding to state updates from the IdentityController.

@Gudahtt
Copy link
Member Author

Gudahtt commented Jul 14, 2021

I've begun work to prepare for the new proposed Keyring APIs. It would have been challenging to move directly from what we have now to the new API because we've fallen behind in maintaining these repos and their dependencies. At the moment they're using JavaScript, they're full of inconsistencies and extra non-standard functions, they have outdated dependencies, they don't follow our standard lint rules, etc. So I'll be making an effort to clean them up and migrate them to TypeScript first. This will make more clear what their existing APIs are, so the proposed changes will be easier to understand, review, and implement.

I've added a rough checklist of the work involved to the issue description.

@mcmire
Copy link
Contributor

mcmire commented Mar 23, 2022

This may already be covered by the above, but linking this issue in case it gives us ideas: #35

@Gudahtt Gudahtt added the Epic label Jan 24, 2023
@Gudahtt Gudahtt changed the title Redesign Keyring Controller API and identity state management Redesign Keyring Controller API Feb 17, 2023
@Gudahtt
Copy link
Member Author

Gudahtt commented Feb 17, 2023

The scope of this issue was too broad. I split out the identity state management to a separate issue, as well as the consolidation of keyring code between extension and mobile.

@Gudahtt
Copy link
Member Author

Gudahtt commented Apr 22, 2024

Closing this in favour of the Keyring Controller API proposal from the accounts team: https://www.notion.so/metamask-consensys/KeyringController-API-b28018e6611940d5a57d5c5a0226902c

@Gudahtt Gudahtt closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Epic
Projects
None yet
Development

No branches or pull requests

3 participants