question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`fromMnemonic` returns a private key which shouldn't be used

See original GitHub issue

This isn’t a bug, but rather a way that an SDK user can easily misuse the PrivateKey::fromMnemonic function.

By default, calling fromMnemonic returns the key at derivation path m/44'/3030'/0'/0' (A in the figure below). If a programmer isn’t familiar with derivation paths, they will probably just use the resulting private key without a further thought. This behavior seems to be enforced by the online documentation, which shows simple usage of fromMnemonic

//Use the mnemonic to recover the private key
PrivateKey privateKey = PrivateKey.fromMnemonic(mnemonic);
PublicKey publicKey = privateKey.publicKey();

//v2.0.0

However, the private key created from fromMnemonic should not be used directly - the programmer ought to go one layer deeper in the derivation path, to m/44'/3030'/0'/0'/0', m/44'/3030'/0'/0'/1', etc… (B in the figure below). This requirement is documented, but only briefly, in the function documentation

     * @return the recovered key; use {@link #derive(int)} to get a key for an account index (0
     * for default account)

Screenshot 2022-11-29 at 10 49 44 AM

My understanding is that receiving to A is out of line with expected BIP44 behavior, and doing so might result in different wallets not finding existing funds. It seems worth it to me to make it harder for a wallet developer to mistakenly receive here.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
alittleycommented, Dec 2, 2022

I guess this means that if we were to change Ed25519 derivation to not infer all indices are hardened, that would be a breaking change 🤔 So we probably should continue inferring all Ed25519 indices are hardened. But to get a hardened ECDSA child, it must be explicitly chosen

1reaction
alittleycommented, Dec 1, 2022

One more consideration-

since Ed25519 supports only hardened derivation, we need to decide whether Ed25519PrivateKey::fromMnemonic(mnemonic, 0) interprets “0” to mean the 0th hardened child index (2147483648), or whether this should throw an error due to invalid child index

I think my preference would be that Ed25519PrivateKey::fromMnemonic(mnemonic, 0) kicks back an error, and the user would have to do something like Ed25519PrivateKey::fromMnemonic(mnemonic, toHardened(0)). But I can see this going either way, as long as there is consistency across SDKs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wallets and Signers — ethers.js 4.0.0 documentation
A Wallet manages a private/public key pair which is used to cryptographically sign transactions and prove ownership on the Ethereum network.
Read more >
How to generate key pairs from mnemonic? · Issue #113
slice(0, 32)) returns a PrivateKey object (yes, internally it's a pointer, but it shouldn't matter to you or me as consumers of the...
Read more >
How to set private key for Ethers Signer
... define a signer from a mnemonic instead of a private key, as follows: const account = utils.HDNode.fromMnemonic(your_mnemonic_string).
Read more >
Going from BIP39 (mnemonic) to BIP32 (public/private keys)
I'm looking to develop some code, that creates Bitcoin private and public keys from a mnemonic. My current ...
Read more >
Wallet class - ethers library - Dart API
createRandom(): Returns a new Wallet with a random private key, generated from ... impl → _WalletImpl: Internal JS Object, should not be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found