-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Streamlining KeyringController API #3871
Comments
Hold KeyringsThe first responsibility listed is already effectively implemented: |
Locking and UnlockingThe second responsibility, /providing functionalities to lock and unlock the wallet/, is also already implemented, but we can probably do some refactoring to make it easier to use, and reduce the API coverage that it takes. Currently, we have these methods:
We could do a couple of small improvements here:
|
Keep in sync its state with the state of each keyringThis is were things become a little more tricky. Currently, every time one of the “keyring actions” provided by the This mechanism is our strategy to keep the vault, the state of the Unfortunately, as we’ll observe in the next paragraph “Route action calls for a specific account to the corresponding keyring”, not all possible “keyring actions” are supported by the This is where the KeyringController’s Including all possible supported methods in |
Route action calls for a specific account to the corresponding keyringAs already disclosed in the previous paragraphs, not all keyrings have the same features, and some of them present different APIs, in some cases very similar to each other, yet not identical. There's no clear distinction, as of now, about when such a difference in a specific Keyring should result in a new "special" method on Unfortunately, both of the alternatives have downsides:
A brilliant proposal from the accounts team aims to turn KeyringController into a router with a method like this: handleRequest({
account,
request,
origin,
opts?,
}: {
address: Hex,
request: Record<string, unknown>, // JSON-RPC request
opts?: Record<string, unknown>,
}): Promise<unknown> With this solution, we can route any request to any keyring, based on the targeted account, while also making sure that we keep everything in sync: this would solve the issue described. To make that an easier goal, we could cut off some of the Methods related to the QRKeyringSome of the methods related to the QRKeyring are included in the Looking at these methods:
They are there only to expose methods from the underlying QRKeyring instance. But, if the client can use Warning There’s a caveat that is worth noting: The Methods related to HDKeyring
To answer the question “Is there anything special in the actions executed on the primary (HD) keyring, compared to other keyrings?”, we should take a better look at these methods: The HDKeyring is, as we said, the primary keyring. It has this nickname because it is the keyring currently created on the first vault creation or restore, through the first two methods listed: This behaviour is being changed by the accounts team, so this will probably no longer be the case, but there's something probably worth noting. Currently, the Regarding Lastly, Given that, the answer to the question “Is there anything special in the actions executed on the primary (HD) keyring, compared to other keyrings?” is most likely No. Methods related to SimpleKeyringThe SimpleKeyring is the keyring type used for imported accounts. It can be seen as a keyring that holds a single private key, instead of a mnemonic.
|
Proposed solutionsLock / Unlock
State syncingPhase 1
Phase 2
Phase 3
KeyringController redundant methods removal
Remove redundant HDKeyring methods (and features) from KeyringController
Remove redundant SimpleKeyring methods from KeyringController
|
@mikesposito Good analysis! Some notes:
|
Thanks for taking a close look @mcmire!
Agreed!
True, they will also have to provide a way to unsubscribe
That is correct. I didn't mention
This issue is meant to be a step in that direction, aligning keyring features better so that it will be easier to apply that proposed API.
Ideally, all keyring-specific methods that consumers currently use on Keyrings object directly should be accessed through I do think that the
The idea is to simply remove them, as consumers can access them using other KeyringController methods: (await keyringController.getOrAddQRKeyring()).restoreQRKeyring
// or
keyringController.getKeyringsByType('qr')[0].restoreQRKeyring This is how also other hardware keyrings are accessed by consumers |
@mikesposito Thanks for the replies! Seems like a well-thought-out plan in total 👍🏻 |
This issue aims to provide a list of observations and possible proposals to simplify the
KeyringController
API, removing unnecessary, redundant, out-of-scope, and confusing methods.The
KeyringController
responsibilities should be the following (ideally, this is not written on any stone):The text was updated successfully, but these errors were encountered: