This commit adds the ability to backup and restore wallets using the
the HD Master Seed defined in BIP 32.
Please feel free to provide any feedback or comments. I always wanted
this functionality in the reference client and thought others would
find it useful as well. I tried to make this version a fully functional change that minimizes impact to the rest of the client, but if other approaches would be better, I tried to make this version a fully functional
change that minimizes impact to the rest of the client, but if other
approaches would be better,etc. please let me know.
This change enables wallets to be saved offline using a short key instead of requiring a prior wallet.dat file to restore. etc.The ability to backup and restore from a key is available in other clients, please let me knowbut not in Bitcoin core clients. I tested each
option on testnet and the recovery process functions as expectedBitcoin core exports the HD Master Extended Key in ‘dumpwallet’ and this key can be used to manually recover addresses, however the core client requires the HD Master Seed to function and this is only found in the wallet.dat file itself.
This change enables wallets to be saved offline using a short key
instead of requiring a prior wallet.dat file to restore. The ability
to backup and restore from a key is available in other clients, but
not in Bitcoin core clients. Bitcoin core exports the HD Master Extended
Key in ‘dumpwallet’ and this key can be used to manually recover
addresses, however the core client requires the HD Master Seed to
function and this is only found in the wallet.dat file itself.
To implement recovery this commit adds a new “Encrypt Wallet Advanced”
menu option and dialog window. Recovery during wallet encryption was
was the least disruptive method because normal wallet encryption already
generates a new HD Master Seed and inserts it into the wallet to use
use from that point forward. The recovery process implemented instead
inserts a manually entered HD Master Seed to use instead of the auto
generated seed. Once the recovered seed is added a simple ‘-rescan=1’
scans the blockchain and repopulates the wallet.
The Encrypted Wallet Advanced dialog offers three options:
1) Standard wallet encryption – This option encrypts the wallet with
a new auto generated seed, this is identical to normal wallet encryption.
2) Recover wallet – This option allows the user to enter a backup seed
to recover the wallet and then encrypts the wallet as normal
3) Manually generate seed2) Recover wallet – This option allows the user to roll dice toto enter a backup seed to recover the wallet and then encrypts the wallet as normal
3) Manually generate seed – This option allows the user to roll dice to create a new seed which guarantees full entropy and then encrypts
the wallet as normal
The dialog window provides user instructions depending on the options
selected. Keys are exported and imported in base58 format. The -rescan
command was also modified to optionally force rescanning from the
the genesis block. This was needed because by default -rescan only scans
from the time the wallet.dat file was created, which for newly created
wallet.dat files would skip all prior addresses trying to be recovered.
Below are files changed or added along with a description of the changes.
I also added comments in the code where I thought it would help.
Changes by file
New dialog window and methods
* A src/qt/encryptwalletadvanceddialog.cpp
* A src/qt/encryptwalletadvanceddialog.h
* A src/qt/forms/encryptwalletadvanceddialog.ui
Update wallet routines to encrypt using user entered backup seed
Update ‘-rescan’ to have ‘-rescan=1’ force a rescan from the genesis block
* M src/wallet/wallet.cpp
* M src/wallet/wallet.h
Export the HD Master Seed in ‘dumpwallet’
* M src/wallet/rpcdump.cpp
Add “Encrypt Wallet Advanced” menu option and associated plumbing
* M src/qt/bitcoingui.cpp
* M src/qt/bitcoingui.h
* M src/qt/walletframe.cpp
* M src/qt/walletframe.h
* M src/qt/walletview.cpp
* M src/qt/walletview.h
Pass recovery seed from dialog window to wallet encryption routines
* M src/qt/walletmodel.cpp
* M src/qt/walletmodel.h
New file additions to make
* M contrib/bitcoin-qt.pro
* M src/Makefile.qt.include
* M src/qt/CMakeLists.txt