This will add basic bip32 support for the current wallet. I testes the PR in serval environments, but, still needs more testing. Feedback of any type is highly welcome.
Concept
- At the moment, all HD operations are independent/separated from the existing normal single key operations (allows better testing and a smother transition to HD wallets).
- The wallet is still capable of using and producing single keys.
- The user can define his desired chainpath like
m/44'/0'/0'/corm/0'/c- "m" stands for master, "c" for switch between internal (1) and external (0) chain
- HD private keys are not stored in the database. If they are required, they get derived via the stored master seed and the available metadata (child index, chain path).
- When creating a new hd chain of keys (
hdaddchain add <chainpath> <masterseed>), the rpc command will add the generated master seed as hex to the response (user can store it and use it as backup). - Bip39 is not supported (and I don't plan to support it).
Instead of bip39 i'd like to use @maaku base-32 error correction encoding (https://gist.github.com/maaku/8996338). Users could write down the used master seed (or print if we would add a such option to the GUI).(not sure about that but i think users should create a print of the seeds 32byte hex representation. Brainwallets tend to have weak security and are social-conceptual a bad idea). - There is one new wallet state variable (
activeHDChain) which is somehow unavoidable (change addresses, etc.).
Persistance
- HD pub keys are stored within a new object CHDPubKey. Additional to the raw pub key there is also information about the chain, depth, etc.
- HD master seeds are stored as a 32byte raw data blob (encrypted with the given masterkey if wallet is/gets encrypted)
RPC
This adds 5 new rpc commands
hdaddchainallows to add a new hd chain of keyshdgetaddressget next available external keyhdsetchainset the active chain of keys (enables basic chain rotation)hdsendtoaddresscopy of sendtoaddress but uses a hd pub key for the change addresshdgetinfolist the available chains of keys
GUI
The UI still uses normal key operation. Switch to HD would be trivial, but, i'd like to extend the "first start wizard" to allow selecting a chain and encrypt before writing unencrypted data to the database.
What's next
- The rpc test is a little bit mininalistic and I have plans to extend the test
- Support for pub key only wallets (basically this is trivial, it only needs to allow master pub key or extended int./ext. chain pub keys as input for
hdaddchainRPC. Signing would fail in a such case. - Support for HDM (allow one or two additional master pub keys per chain of keys to allow creating of multisigaddresses with standard
hdgetaddresscall [as well as change output keys]).