ThomasV helped me import a private key into Electrum, so I'm putting it down in case anyone else would like to do it. Currently it's manual, but someday there might be an option inside GUI. It would be a killer feature, something that BitcoinJ based clients are not able to do as far as I know.
Here is how it's done:
- find your electrum.dat wallet file (~/.electrum/electrum.dat in linux, ~\AppData\Local\Electrum\electrum.dat in windows)
- backup the file, just in case
- run electrum, disable wallet encryption (at your own risk), create new address (temp address), close program
- prepare your private key to import (offline key) in sipa format (starts with a '5'), together with a matching address (offline address). If your private key is not in correct format, use bitaddress.org to convert it.
- open electrum.dat in text editor, find the temp address. It should be the last one in a list of addresses enclosed by []. After the list of addresses, there is a similar list of private keys, they match addresses by index. Last private key matches last address etc.. Use your text editor search/replace functionality to search for this newly generated temp address and replace all instances with your offline address. Next, replace matching temp private key with offline key. Save the file.
- run electrum, your offline key should show up as any other keys, with correct balance. Encrypt and backup the wallet.
Electrum has deterministic wallet. ThomasV warned me this could mess up new address generation, which would not be deterministic anymore. I tested it and looks like there is no problem. Use at your own risk.
Well, importing keys is not going to mess up new address generation, but it might interfer with the recovery from seed process.
First, exogenous addresses will obviously not be recovered from the seed (ok, you knew it). Second, since the added addresses
will occupy slots normally used by addresses generated by the seed, these addresses might create gaps (sequences of unused
addresses) in your list of addresses. If these gaps become larger than the gap limit set in your preferences, then you cannot rely
on this parameter to recover your wallet.