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

refactor!: addNewKeyring returns metadata instead of keyring #5372

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

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Feb 21, 2025

Explanation

This PR changes the return type of addNewKeyring to return a promise resolving in KeyringMetadata instead of the keyring instance. The reason is that accessing keyring instances outside of KeyringController safeguards is considered unsafe.

The withKeyring method signature has also been changed: the operation callback now will be called with {keyring: SelectedKeyring; metadata: KeyringMetadata } instead of SelectedKeyring

References

Changelog

@metamask/keyring-controller

  • BREAKING: addNewKeyring method now returns Promise<KeyringMetadata> instead of Promise<unknown> (#5372)
    • Consumers can use the returned KeyringMetadata.id to access the created keyring instance via withKeyring.
  • BREAKING: withKeyring method now requires a callback argument of type ({ keyring: SelectedKeyring; metadata: KeyringMetadata }) => Promise<CallbackResult> (#5372)

@metamask/profile-sync-controller

  • No consumer-facing changes

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

@mikesposito mikesposito marked this pull request as ready for review February 21, 2025 11:36
@mikesposito mikesposito requested review from a team as code owners February 21, 2025 11:36
mathieuartu
mathieuartu previously approved these changes Feb 21, 2025
Copy link
Contributor

@mathieuartu mathieuartu left a comment

Choose a reason for hiding this comment

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

Owned files LGTM, thanks!

* @param keyring - The keyring instance to get the metadata for.
* @returns The keyring metadata.
*/
#getKeyringMetadata(keyring: unknown): KeyringMetadata {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm keeping this method as internal because consumers are not supposed to carry keyring instances around

Comment on lines +1517 to +1518
keyring: SelectedKeyring;
metadata: KeyringMetadata;

This comment was marked as outdated.

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 addNewKeyring should not return the keyring instance
3 participants