I am confused about child HD public keys. Is this scenario correct?

  1. I am using bx (libbitcoin) for all action below.
  2. Generate a seed (bx seed).
  3. create master private key using seed (bx hd-new)
  4. create master public key from private key (bx hd-to-public)
  5. generate several child BIP32 public key using random indexes (bx hd-public)
  6. use generated child keys and generate several addresses
  7. now using generated addresses

will all addresses connected to master private key? or because I used random indexes (step 5), it is disconnected from master private and public key? In simple word, is it enough to use private key (step 3) in bitcoin clients such as electrum to access to all addresses that generated using child pub keys (not master key)?

  • It will depend on the wallet, so you should make that explicit in your question. – Pieter Wuille Dec 5 '16 at 19:47
  • especialy bitcoin client and electrum. but also if I don't want to use any wallet, what will be needed? is master private key enough or should I generate and store child private key too? – max Dec 6 '16 at 8:29

Use incremental indexes instead of random

First of all, you should generate child addressess incrementally instead of randomly, as wallets will re-generate them starting from the index 0, incrementing the indexes until they start finding empty addresses.

From the BIP44 Account Discovery chapter:

When the master seed is imported from an external source the software should start to discover the accounts in the following manner:

  1. derive the first account's node (index = 0)
  2. derive the external chain node of this account
  3. scan addresses of the external chain; respect the gap limit described below
  4. if no transactions are found on the external chain, stop discovery
  5. if there are some transactions, increase the account index and go to step 1

Address gap limit

Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. We scan just the external chains, because internal chains receive only coins that come from the associated external chains. Wallet software should warn when the user is trying to exceed the gap limit on an external chain by generating a new address.

If you generate your child keys at random indexes, most likely the first 20 indexes will be empty, so the wallet will stop the discovery and show you an empty wallet.

Standard derivation paths

The standard derivation path (defined in the aforementioned BIP44 standard) is the following (M denotes the master private key):

m / purpose' / coin_type' / account' / change / address_index

Most wallet implementations (Electrum being a notable exception) follow this standard. That means for a given receiving address, you should use a derivation path like this:

m / 44' / 0' / 0' / 0 / 0

Which translates to bx commands like this:

cat m | bx hd-private --index 44 --hard \ | bx hd-private --index 0 --hard \ | bx hd-private --index 0 --hard \ | bx hd-private --index 0 \ | bx hd-private --index 0 Since the first three levels involve hardened derivation, you have to use the master private key. The master public key can only be used for non-hardened derivation paths.

Electrum doesn't implement the full BIP44 standard as it only supports single-account wallets. In Electrum, the derivation path looks like the following:

m / change / address_index

Since there is no hardened derivation on the account level, you can also import the master public key into Electrum. This is similar to the chain you described but there is an extra "change" level still.

Electrum can also import a BIP44 master private key (there's a checkbox in the import dialog), by making you select an account index at import time.

I suggest to stick to the BIP44 standard as it will be can be imported by other wallets (like Mycelium) as a HD-wallet, and will also work in Electrum if you remember to import it as a BIP44 key.

However, if you need to work exclusively with master public keys, you can still use the 2-level derivation and import them to Electrum. I'm not sure if other wallets support importing them.

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.