From 85beb9c9ca30a89b0c1aea973a4fd2f1ce16d38a Mon Sep 17 00:00:00 2001 From: Jay Graber Date: Tue, 17 Jul 2018 13:52:04 -0700 Subject: [PATCH] Add Sapling keys to CCryptoKeyStore::EncryptKeys --- src/wallet/crypter.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp index 5d1a31e14..af6bf3565 100644 --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -445,10 +445,12 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) CPubKey vchPubKey = key.GetPubKey(); CKeyingMaterial vchSecret(key.begin(), key.end()); std::vector vchCryptedSecret; - if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret)) + if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret)) { return false; - if (!AddCryptedKey(vchPubKey, vchCryptedSecret)) + } + if (!AddCryptedKey(vchPubKey, vchCryptedSecret)) { return false; + } } mapKeys.clear(); BOOST_FOREACH(SpendingKeyMap::value_type& mSpendingKey, mapSpendingKeys) @@ -459,12 +461,31 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) CKeyingMaterial vchSecret(ss.begin(), ss.end()); libzcash::SproutPaymentAddress address = sk.address(); std::vector vchCryptedSecret; - if (!EncryptSecret(vMasterKeyIn, vchSecret, address.GetHash(), vchCryptedSecret)) + if (!EncryptSecret(vMasterKeyIn, vchSecret, address.GetHash(), vchCryptedSecret)) { return false; - if (!AddCryptedSpendingKey(address, sk.receiving_key(), vchCryptedSecret)) + } + if (!AddCryptedSpendingKey(address, sk.receiving_key(), vchCryptedSecret)) { return false; + } } mapSpendingKeys.clear(); + //! Sapling key support + BOOST_FOREACH(SaplingSpendingKeyMap::value_type& mSaplingSpendingKey, mapSaplingSpendingKeys) + { + const libzcash::SaplingSpendingKey &sk = mSaplingSpendingKey.second; + CSecureDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << sk; + CKeyingMaterial vchSecret(ss.begin(), ss.end()); + libzcash::SaplingFullViewingKey fvk = sk.full_viewing_key(); + std::vector vchCryptedSecret; + if (!EncryptSecret(vMasterKeyIn, vchSecret, fvk.GetFingerprint(), vchCryptedSecret)) { + return false; + } + if (!AddCryptedSaplingSpendingKey(fvk, vchCryptedSecret)) { + return false; + } + } + mapSaplingSpendingKeys.clear(); } return true; }