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(keyring-eth-hd)!: move seed generation to deserialization #100

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

FrederikBolding
Copy link
Member

This PR refactors the eth-hd-keyring constructor to remove the deserialization step directly in the constructor. This lets us turn deserialize into a proper async function and use an async version of mnemonicToSeed (which should be swapped out for something faster in the future).

This is a breaking change and requires that all usage of eth-hd-keyring calls deserialize with the arguments previously passed into the constructor. This seems to already be the case in the KeyringController, but may deserve a more thorough look.

This PR also changes the function signature of generateRandomMnemonic, making this an async function as well.

Appreciate any feedback and/or sanity checks on this!

@danroc
Copy link
Contributor

danroc commented Nov 22, 2024

I haven't reviewed all the changes in detail, but the idea makes sense to me. I’d like to get @mikesposito’s opinion as well, as my main concern is the potential impact on the interface, other keyrings, and the KeyringController.

Copy link
Member

@mikesposito mikesposito left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this!

It looks like we may keep KeyringController as is, since these are the only lines of code that deal with this code under change.

FYI this HDKeyiring is constructed here, thus without constructor args already

packages/keyring-eth-hd/src/index.js Show resolved Hide resolved
@FrederikBolding
Copy link
Member Author

@mikesposito We will have to update the KeyringController to await keyring.generateRandomMnemonic at the very least.

@ccharly ccharly changed the title refactor(keyring-eth-hd)!: Move seed generation to deserialization refactor(keyring-eth-hd)!: move seed generation to deserialization Nov 25, 2024
@ccharly ccharly added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit 31746a4 Nov 25, 2024
24 checks passed
@ccharly ccharly deleted the fb/hd-keyring-constructor-refactor branch November 25, 2024 19:49
github-merge-queue bot pushed a commit that referenced this pull request Nov 26, 2024
…raphy (#102)

<!--
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 issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->

Uses the latest version of `@metamask/keytree`, which allows passing
`cryptographicFunctions` for derivation of the mnemonic seed. Also
reintroduces constructor arguments to allow passing of
`cryptographicFunctions` to `HdKeyring`.

Follow-up PR to #100

---------

Co-authored-by: Charly Chevalier <[email protected]>
mikesposito added a commit to MetaMask/utils that referenced this pull request Nov 26, 2024
<!--
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 issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->

Our HD keyring [has been
updated](MetaMask/accounts#100) to support
different kinds of cryptographic functions to randomly generate a
mnemonic, which may be an asynchronous operation in some cases.

This PR updates the `generateRandomMnemonic` on the `Keyring` type
accordingly, even though `eth-hd-keyring` does not implement the type
yet, because `KeyringController` uses it as keyring interface.
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.

4 participants