child keys generated addresses reflect in wallet? I am confused about child HD public keys. Is this scenario correct?


I am using bx (libbitcoin) for all action below.
Generate a seed (bx seed).
create master private key using seed (bx hd-new)
create master public key from private key (bx hd-to-public)
generate several child BIP32 public key using random indexes (bx hd-public)
use generated child keys and generate several addresses
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)?
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:
  
  
  derive the first account's node (index = 0)
  derive the external chain node of this account
  scan addresses of the external chain; respect the gap limit described below
  if no transactions are found on the external chain, stop discovery
  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.