X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fkeystore.cpp;h=fdbecbabe873e281a89639f9c5731ab7a98b9341;hb=b7970580fe39d1148a92de290abf6ca7e63bbfe6;hp=b4783ec5b9258e774ea3041e86c08729155452c8;hpb=1c4fc9052a444c114d9c1501d2c6d1305de650d0;p=novacoin.git diff --git a/src/keystore.cpp b/src/keystore.cpp index b4783ec..fdbecba 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -29,8 +29,20 @@ bool CBasicKeyStore::AddKey(const CKey& key) return true; } +bool CBasicKeyStore::AddMalleableKey(const CMalleableKey& mKey) +{ + { + LOCK(cs_KeyStore); + mapMalleableKeys[CMalleableKeyView(mKey)] = mKey; + } + return true; +} + bool CBasicKeyStore::AddCScript(const CScript& redeemScript) { + if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) + return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE); + { LOCK(cs_KeyStore); mapScripts[redeemScript.GetID()] = redeemScript; @@ -79,12 +91,26 @@ bool CBasicKeyStore::AddWatchOnly(const CScript &dest) return true; } + +bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest) +{ + LOCK(cs_KeyStore); + setWatchOnly.erase(dest); + return true; +} + bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const { LOCK(cs_KeyStore); return setWatchOnly.count(dest) > 0; } +bool CBasicKeyStore::HaveWatchOnly() const +{ + LOCK(cs_KeyStore); + return (!setWatchOnly.empty()); +} + bool CCryptoKeyStore::SetCrypted() { { @@ -137,6 +163,7 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) break; return false; } + vMasterKey = vMasterKeyIn; } NotifyStatusChanged(this); @@ -252,3 +279,33 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) } return true; } + +bool CCryptoKeyStore::DecryptKeys(const CKeyingMaterial& vMasterKeyIn) +{ + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return false; + + CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); + for (; mi != mapCryptedKeys.end(); ++mi) + { + const CPubKey &vchPubKey = (*mi).second.first; + const std::vector &vchCryptedSecret = (*mi).second.second; + CSecret vchSecret; + if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) + return false; + if (vchSecret.size() != 32) + return false; + CKey key; + key.SetPubKey(vchPubKey); + key.SetSecret(vchSecret); + if (!CBasicKeyStore::AddKey(key)) + return false; + } + + mapCryptedKeys.clear(); + } + + return true; +}