1

I woud like to obtain an extended public key of a derivation path (m/84'/0'/0'). I'm using btclib, and I have the xpub of the root account.

When I try to use bip32.derive("xpub...","m/84'/0'/0'")

I get btclib.exceptions.BTClibValueError: invalid hardened derivation from public key

What am I doing wrong ?

1

Review BIP32:

The fact that they are equivalent is what makes non-hardened keys useful (one can derive child public keys of a given parent key without knowing any private key), and also what distinguishes them from hardened keys. The reason for not always using non-hardened keys (which are more useful) is security; see further for more information.

That little apostrophe ' means that branch of the key derivation tree is "hardened" -- and THAT means that you must have the private key to derive its child keys.

So if you have the PRIVATE key for m/84'/0'/0' you can generate child keys for example m/84'/0'/0'/0 or m/84'/0'/0'/0' (these are two different keys, one is hardened the other is not).

If you were to derive the non-hardened key at m/84'/0'/0'/0 then you could use an xpub FROM THIS KEY (not any of the parent keys) to derive public child keys, without any private keys. Examples would be m/84'/0'/0'/0/0 and m/84'/0'/0'/0/1

4
  • Thanks a lot for your answer. Just another precision: If I have ONLY the xpub key of the top account (the xpub key than can be exported from a Ledger wallet for instance), it is not possible to get the xpub key at m/84'/0'/0' with btclib derive function so. But can I get the xpub key at m/84'/0'/0'/0 (or m/84'/0'/0'/1) ? – Guillaume07 Dec 19 '20 at 13:33
  • 1
    See github.com/bitcoin/bips/blob/master/… The xpub you get from a Ledger is (I'm pretty sure) at the account level. Meaning from there you can derive change and receive addresses like m/84'/0'/0'/0/0. What you should try with your library is to take the xpub and just derive the last two levels: xpub/0/0 – pinhead Dec 20 '20 at 3:10
  • It is exactly what you said, thanks for your help – Guillaume07 Dec 20 '20 at 9:02
  • More precisely bip32.derive("xpub...","/0") for receive addresses – Guillaume07 Dec 20 '20 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.