diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 4f159f9a1..eb144bd25 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -871,6 +871,10 @@ static bool IsKeyType(string strType) { return (strType == "key" || strType == "wkey" || strType == "hdseed" || strType == "chdseed" || + // The mnemonic entropy must survive a keys-only salvage: without it + // a recovered wallet keeps its seed (and stays fully spendable) but + // silently loses the ability to reprint its seed phrase. + strType == "mnementropy" || strType == "cmnementropy" || strType == "zkey" || strType == "czkey" || strType == "sapzkey" || strType == "csapzkey" || strType == "vkey" || @@ -1345,6 +1349,24 @@ bool CWalletDB::EraseHDSeed(const uint256& seedFp) return Erase(std::make_pair(std::string("hdseed"), seedFp)); } +bool CWalletDB::WriteMnemonicEntropy(const uint256& entropyFp, const RawHDSeed& entropy) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("mnementropy"), entropyFp), entropy); +} + +bool CWalletDB::WriteCryptedMnemonicEntropy(const uint256& entropyFp, const std::vector& vchCryptedSecret) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("cmnementropy"), entropyFp), vchCryptedSecret); +} + +bool CWalletDB::EraseMnemonicEntropy(const uint256& entropyFp) +{ + nWalletDBUpdated++; + return Erase(std::make_pair(std::string("mnementropy"), entropyFp)); +} + bool CWalletDB::WriteHDChain(const CHDChain& chain) { nWalletDBUpdated++; diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 6f08c6018..a219ec855 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -227,6 +227,12 @@ public: //! CWallet::EncryptWallet) copies whatever records still exist into the new //! file, so a leftover "hdseed" leaves the unencrypted seed on disk forever. bool EraseHDSeed(const uint256& seedFp); + //! BIP39 entropy for a phrase-recoverable wallet. Display-only: derivation + //! never reads it. Record names are deliberately distinct prefixes from + //! "hdseed"/"chdseed" so they cannot collide. + bool WriteMnemonicEntropy(const uint256& entropyFp, const RawHDSeed& entropy); + bool WriteCryptedMnemonicEntropy(const uint256& entropyFp, const std::vector& vchCryptedSecret); + bool EraseMnemonicEntropy(const uint256& entropyFp); //! write the hdchain model (external chain child index counter) bool WriteHDChain(const CHDChain& chain);