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

Multi srp mvp #5112

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Multi srp mvp #5112

wants to merge 7 commits into from

Conversation

PatrykLucka
Copy link

@PatrykLucka PatrykLucka commented Jan 8, 2025

Explanation

Currently, we assume that the only HD Keyring is the Primary Keyring. Most methods related to adding accounts or displaying the SRP assume that it refers to the first keyring, which is the Primary Keyring. To enable having more than one SRP, and consequently more than one HD Keyring, this PR adds an array called keyringsMetadata, which contains an id that can be used to identify all keyrings and a proper place to keep other data we might want to add to each keyring such as name.

keyringsMetadata is a separate in order to minimize changes that we need to make to keyrings and the way we process them. We also can keep this data outside of the vault, as it's not storing any sensitive data.

References

Related to ADR 0002-keyring-id-and-name.md
Blocks Extension PR

Changelog

@metamask/keyring-controller

  • ADDED: { id: string } selector to withKeyring function
  • ADDED: optional keyringId param to addNewAccount function
  • ADDED: optional keyringId param to exportSeedPhrase function
  • ADDED: optional keyringId param to getAccounts function
  • ADDED: optional keyringId param to verifySeedPhrase function
  • ADDED: private #getKeyringById helper function
  • ADDED: optional keyringId param to #verifySeedPhrase function
  • ADDED: optional metadata param to #newKeyring function
  • ADDED: optional metadata param to #newKeyring function

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@PatrykLucka PatrykLucka self-assigned this Jan 8, 2025
@PatrykLucka
Copy link
Author

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.2-preview-e96ca40c",
  "@metamask-previews/address-book-controller": "6.0.2-preview-e96ca40c",
  "@metamask-previews/announcement-controller": "7.0.2-preview-e96ca40c",
  "@metamask-previews/approval-controller": "7.1.1-preview-e96ca40c",
  "@metamask-previews/assets-controllers": "45.1.2-preview-e96ca40c",
  "@metamask-previews/base-controller": "7.0.2-preview-e96ca40c",
  "@metamask-previews/build-utils": "3.0.2-preview-e96ca40c",
  "@metamask-previews/chain-controller": "0.2.2-preview-e96ca40c",
  "@metamask-previews/composable-controller": "10.0.0-preview-e96ca40c",
  "@metamask-previews/controller-utils": "11.4.4-preview-e96ca40c",
  "@metamask-previews/ens-controller": "15.0.1-preview-e96ca40c",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-e96ca40c",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-e96ca40c",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-e96ca40c",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-e96ca40c",
  "@metamask-previews/keyring-controller": "19.0.2-preview-e96ca40c",
  "@metamask-previews/logging-controller": "6.0.3-preview-e96ca40c",
  "@metamask-previews/message-manager": "11.0.3-preview-e96ca40c",
  "@metamask-previews/multichain": "1.1.2-preview-e96ca40c",
  "@metamask-previews/name-controller": "8.0.2-preview-e96ca40c",
  "@metamask-previews/network-controller": "22.1.1-preview-e96ca40c",
  "@metamask-previews/notification-services-controller": "0.15.0-preview-e96ca40c",
  "@metamask-previews/permission-controller": "11.0.4-preview-e96ca40c",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-e96ca40c",
  "@metamask-previews/phishing-controller": "12.3.1-preview-e96ca40c",
  "@metamask-previews/polling-controller": "12.0.2-preview-e96ca40c",
  "@metamask-previews/preferences-controller": "15.0.1-preview-e96ca40c",
  "@metamask-previews/profile-sync-controller": "3.1.1-preview-e96ca40c",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-e96ca40c",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-e96ca40c",
  "@metamask-previews/remote-feature-flag-controller": "1.2.0-preview-e96ca40c",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-e96ca40c",
  "@metamask-previews/signature-controller": "23.1.0-preview-e96ca40c",
  "@metamask-previews/transaction-controller": "42.0.0-preview-e96ca40c",
  "@metamask-previews/user-operation-controller": "21.0.0-preview-e96ca40c"
}

Copy link

socket-security bot commented Jan 13, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 23 kB alizain

View full report↗︎

@PatrykLucka
Copy link
Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.2-preview-407f96d",
  "@metamask-previews/address-book-controller": "6.0.2-preview-407f96d",
  "@metamask-previews/announcement-controller": "7.0.2-preview-407f96d",
  "@metamask-previews/approval-controller": "7.1.1-preview-407f96d",
  "@metamask-previews/assets-controllers": "45.1.2-preview-407f96d",
  "@metamask-previews/base-controller": "7.1.0-preview-407f96d",
  "@metamask-previews/build-utils": "3.0.2-preview-407f96d",
  "@metamask-previews/chain-controller": "0.2.2-preview-407f96d",
  "@metamask-previews/composable-controller": "10.0.0-preview-407f96d",
  "@metamask-previews/controller-utils": "11.4.4-preview-407f96d",
  "@metamask-previews/ens-controller": "15.0.1-preview-407f96d",
  "@metamask-previews/eth-json-rpc-provider": "4.1.7-preview-407f96d",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-407f96d",
  "@metamask-previews/json-rpc-engine": "10.0.2-preview-407f96d",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.6-preview-407f96d",
  "@metamask-previews/keyring-controller": "19.0.2-preview-407f96d",
  "@metamask-previews/logging-controller": "6.0.3-preview-407f96d",
  "@metamask-previews/message-manager": "11.0.3-preview-407f96d",
  "@metamask-previews/multichain": "2.0.0-preview-407f96d",
  "@metamask-previews/name-controller": "8.0.2-preview-407f96d",
  "@metamask-previews/network-controller": "22.1.1-preview-407f96d",
  "@metamask-previews/notification-services-controller": "0.15.0-preview-407f96d",
  "@metamask-previews/permission-controller": "11.0.4-preview-407f96d",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-407f96d",
  "@metamask-previews/phishing-controller": "12.3.1-preview-407f96d",
  "@metamask-previews/polling-controller": "12.0.2-preview-407f96d",
  "@metamask-previews/preferences-controller": "15.0.1-preview-407f96d",
  "@metamask-previews/profile-sync-controller": "3.3.0-preview-407f96d",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-407f96d",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-407f96d",
  "@metamask-previews/remote-feature-flag-controller": "1.3.0-preview-407f96d",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-407f96d",
  "@metamask-previews/signature-controller": "23.2.0-preview-407f96d",
  "@metamask-previews/transaction-controller": "42.1.0-preview-407f96d",
  "@metamask-previews/user-operation-controller": "21.0.0-preview-407f96d"
}

@PatrykLucka PatrykLucka force-pushed the multi-srp-mvp branch 2 times, most recently from bc69ea1 to b9ca305 Compare January 17, 2025 10:41
PatrykLucka and others added 7 commits January 17, 2025 11:44
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
The `KeyringController.verifySeedPhrase` method was not included in the
mutable methods that lock the controller mutex because it doesn't change
the state. Though, if another operation gets somehow overlapped (e.g. a
consumer calls `addNewAccount`), the call to `verifySeedPhrase` can
potentially fail.

To fix this, this PR is moving verifySeedPhrase behind
KeyringController's mutex. Since `addNewAccount` internally calls
`verifySeedPhrase`, and having a lock on both would create a deadlock,
the `verifySeedPhrase` implementation has been moved to an internal
method.

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

- **FIXED**:  `verifySeedPhrase` is now mutually exclusive

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@PatrykLucka
Copy link
Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "21.0.1-preview-83c8a21",
  "@metamask-previews/address-book-controller": "6.0.2-preview-83c8a21",
  "@metamask-previews/announcement-controller": "7.0.2-preview-83c8a21",
  "@metamask-previews/approval-controller": "7.1.2-preview-83c8a21",
  "@metamask-previews/assets-controllers": "46.0.0-preview-83c8a21",
  "@metamask-previews/base-controller": "7.1.1-preview-83c8a21",
  "@metamask-previews/build-utils": "3.0.2-preview-83c8a21",
  "@metamask-previews/composable-controller": "10.0.0-preview-83c8a21",
  "@metamask-previews/controller-utils": "11.4.5-preview-83c8a21",
  "@metamask-previews/ens-controller": "15.0.1-preview-83c8a21",
  "@metamask-previews/eth-json-rpc-provider": "4.1.7-preview-83c8a21",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-83c8a21",
  "@metamask-previews/json-rpc-engine": "10.0.2-preview-83c8a21",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.6-preview-83c8a21",
  "@metamask-previews/keyring-controller": "19.0.3-preview-83c8a21",
  "@metamask-previews/logging-controller": "6.0.3-preview-83c8a21",
  "@metamask-previews/message-manager": "12.0.0-preview-83c8a21",
  "@metamask-previews/multichain": "2.0.0-preview-83c8a21",
  "@metamask-previews/name-controller": "8.0.2-preview-83c8a21",
  "@metamask-previews/network-controller": "22.1.1-preview-83c8a21",
  "@metamask-previews/notification-services-controller": "0.16.0-preview-83c8a21",
  "@metamask-previews/permission-controller": "11.0.5-preview-83c8a21",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-83c8a21",
  "@metamask-previews/phishing-controller": "12.3.1-preview-83c8a21",
  "@metamask-previews/polling-controller": "12.0.2-preview-83c8a21",
  "@metamask-previews/preferences-controller": "15.0.1-preview-83c8a21",
  "@metamask-previews/profile-sync-controller": "4.1.0-preview-83c8a21",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-83c8a21",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-83c8a21",
  "@metamask-previews/remote-feature-flag-controller": "1.3.0-preview-83c8a21",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-83c8a21",
  "@metamask-previews/signature-controller": "23.2.0-preview-83c8a21",
  "@metamask-previews/transaction-controller": "43.0.0-preview-83c8a21",
  "@metamask-previews/user-operation-controller": "22.0.0-preview-83c8a21"
}

@PatrykLucka PatrykLucka marked this pull request as ready for review January 18, 2025 09:26
@PatrykLucka PatrykLucka requested review from a team as code owners January 18, 2025 09:26
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.

2 participants