Add SaplingIncomingViewingKeys map, SaplingFullViewingKey methods
This commit is contained in:
@@ -99,7 +99,19 @@ bool CBasicKeyStore::AddSaplingSpendingKey(const libzcash::SaplingSpendingKey &s
|
|||||||
LOCK(cs_SpendingKeyStore);
|
LOCK(cs_SpendingKeyStore);
|
||||||
auto fvk = sk.full_viewing_key();
|
auto fvk = sk.full_viewing_key();
|
||||||
mapSaplingSpendingKeys[fvk] = sk;
|
mapSaplingSpendingKeys[fvk] = sk;
|
||||||
//! TODO: Note decryptors for Sapling
|
|
||||||
|
// if SaplingFullViewingKey is not in SaplingFullViewingKeyMap, add it
|
||||||
|
AddSaplingFullViewingKey(fvk);
|
||||||
|
|
||||||
|
// Add addr -> SaplingIncomingViewing to SaplingIncomingViewingKeyMap
|
||||||
|
auto ivk = fvk.in_viewing_key();
|
||||||
|
auto addrOpt = sk.default_address();
|
||||||
|
if (addrOpt){
|
||||||
|
auto addr = addrOpt.value();
|
||||||
|
mapSaplingIncomingViewingKeys[addr] = ivk;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +124,16 @@ bool CBasicKeyStore::AddViewingKey(const libzcash::SproutViewingKey &vk)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::AddSaplingFullViewingKey(const libzcash::SaplingFullViewingKey &fvk)
|
||||||
|
{
|
||||||
|
LOCK(cs_SpendingKeyStore);
|
||||||
|
auto ivk = fvk.in_viewing_key();
|
||||||
|
mapSaplingFullViewingKeys[ivk] = fvk;
|
||||||
|
//! TODO: Note decryptors for Sapling
|
||||||
|
// mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(vk.sk_enc)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CBasicKeyStore::RemoveViewingKey(const libzcash::SproutViewingKey &vk)
|
bool CBasicKeyStore::RemoveViewingKey(const libzcash::SproutViewingKey &vk)
|
||||||
{
|
{
|
||||||
LOCK(cs_SpendingKeyStore);
|
LOCK(cs_SpendingKeyStore);
|
||||||
@@ -125,6 +147,18 @@ bool CBasicKeyStore::HaveViewingKey(const libzcash::SproutPaymentAddress &addres
|
|||||||
return mapViewingKeys.count(address) > 0;
|
return mapViewingKeys.count(address) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::HaveSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk) const
|
||||||
|
{
|
||||||
|
LOCK(cs_SpendingKeyStore);
|
||||||
|
return mapSaplingFullViewingKeys.count(ivk) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::HaveSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr) const
|
||||||
|
{
|
||||||
|
LOCK(cs_SpendingKeyStore);
|
||||||
|
return mapSaplingIncomingViewingKeys.count(addr) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool CBasicKeyStore::GetViewingKey(const libzcash::SproutPaymentAddress &address,
|
bool CBasicKeyStore::GetViewingKey(const libzcash::SproutPaymentAddress &address,
|
||||||
libzcash::SproutViewingKey &vkOut) const
|
libzcash::SproutViewingKey &vkOut) const
|
||||||
{
|
{
|
||||||
@@ -136,3 +170,27 @@ bool CBasicKeyStore::GetViewingKey(const libzcash::SproutPaymentAddress &address
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::GetSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk,
|
||||||
|
libzcash::SaplingFullViewingKey &fvkOut) const
|
||||||
|
{
|
||||||
|
LOCK(cs_SpendingKeyStore);
|
||||||
|
SaplingFullViewingKeyMap::const_iterator mi = mapSaplingFullViewingKeys.find(ivk);
|
||||||
|
if (mi != mapSaplingFullViewingKeys.end()) {
|
||||||
|
fvkOut = mi->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::GetSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr,
|
||||||
|
libzcash::SaplingIncomingViewingKey &ivkOut) const
|
||||||
|
{
|
||||||
|
LOCK(cs_SpendingKeyStore);
|
||||||
|
SaplingIncomingViewingKeyMap::const_iterator mi = mapSaplingIncomingViewingKeys.find(addr);
|
||||||
|
if (mi != mapSaplingIncomingViewingKeys.end()) {
|
||||||
|
ivkOut = mi->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,6 +62,19 @@ public:
|
|||||||
//! Check whether a Sapling spending key corresponding to a given Sapling viewing key is present in the store.
|
//! Check whether a Sapling spending key corresponding to a given Sapling viewing key is present in the store.
|
||||||
virtual bool HaveSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk) const =0;
|
virtual bool HaveSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk) const =0;
|
||||||
virtual bool GetSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk, libzcash::SaplingSpendingKey& skOut) const =0;
|
virtual bool GetSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk, libzcash::SaplingSpendingKey& skOut) const =0;
|
||||||
|
|
||||||
|
//! Support for Sapling full viewing keys
|
||||||
|
virtual bool AddSaplingFullViewingKey(const libzcash::SaplingFullViewingKey &fvk) =0;
|
||||||
|
virtual bool HaveSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk) const =0;
|
||||||
|
virtual bool GetSaplingFullViewingKey(
|
||||||
|
const libzcash::SaplingIncomingViewingKey &ivk,
|
||||||
|
libzcash::SaplingFullViewingKey& fvkOut) const =0;
|
||||||
|
|
||||||
|
//! Sapling incoming viewing keys
|
||||||
|
virtual bool HaveSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr) const =0;
|
||||||
|
virtual bool GetSaplingIncomingViewingKey(
|
||||||
|
const libzcash::SaplingPaymentAddress &addr,
|
||||||
|
libzcash::SaplingIncomingViewingKey& ivkOut) const =0;
|
||||||
|
|
||||||
//! Support for viewing keys
|
//! Support for viewing keys
|
||||||
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk) =0;
|
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk) =0;
|
||||||
@@ -77,8 +90,12 @@ typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutSpendingKey> Sp
|
|||||||
typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutViewingKey> ViewingKeyMap;
|
typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutViewingKey> ViewingKeyMap;
|
||||||
typedef std::map<libzcash::SproutPaymentAddress, ZCNoteDecryption> NoteDecryptorMap;
|
typedef std::map<libzcash::SproutPaymentAddress, ZCNoteDecryption> NoteDecryptorMap;
|
||||||
|
|
||||||
|
// Full viewing key has equivalent functionality to a transparent address
|
||||||
|
// When encrypting wallet, encrypt SaplingSpendingKeyMap, while leaving SaplingFullViewingKeyMap unencrypted
|
||||||
typedef std::map<libzcash::SaplingFullViewingKey, libzcash::SaplingSpendingKey> SaplingSpendingKeyMap;
|
typedef std::map<libzcash::SaplingFullViewingKey, libzcash::SaplingSpendingKey> SaplingSpendingKeyMap;
|
||||||
typedef std::map<libzcash::SaplingIncomingViewingKey, libzcash::SaplingFullViewingKey> SaplingFullViewingKeyMap;
|
typedef std::map<libzcash::SaplingIncomingViewingKey, libzcash::SaplingFullViewingKey> SaplingFullViewingKeyMap;
|
||||||
|
// Only maps from default addresses to ivk, may need to be reworked when adding diversified addresses.
|
||||||
|
typedef std::map<libzcash::SaplingPaymentAddress, libzcash::SaplingIncomingViewingKey> SaplingIncomingViewingKeyMap;
|
||||||
|
|
||||||
/** Basic key store, that keeps keys in an address->secret map */
|
/** Basic key store, that keeps keys in an address->secret map */
|
||||||
class CBasicKeyStore : public CKeyStore
|
class CBasicKeyStore : public CKeyStore
|
||||||
@@ -92,6 +109,8 @@ protected:
|
|||||||
NoteDecryptorMap mapNoteDecryptors;
|
NoteDecryptorMap mapNoteDecryptors;
|
||||||
|
|
||||||
SaplingSpendingKeyMap mapSaplingSpendingKeys;
|
SaplingSpendingKeyMap mapSaplingSpendingKeys;
|
||||||
|
SaplingFullViewingKeyMap mapSaplingFullViewingKeys;
|
||||||
|
SaplingIncomingViewingKeyMap mapSaplingIncomingViewingKeys;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
|
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
|
||||||
@@ -220,6 +239,17 @@ public:
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool AddSaplingFullViewingKey(const libzcash::SaplingFullViewingKey &fvk);
|
||||||
|
virtual bool HaveSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk) const;
|
||||||
|
virtual bool GetSaplingFullViewingKey(
|
||||||
|
const libzcash::SaplingIncomingViewingKey &ivk,
|
||||||
|
libzcash::SaplingFullViewingKey& fvkOut) const;
|
||||||
|
|
||||||
|
virtual bool HaveSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr) const;
|
||||||
|
virtual bool GetSaplingIncomingViewingKey(
|
||||||
|
const libzcash::SaplingPaymentAddress &addr,
|
||||||
|
libzcash::SaplingIncomingViewingKey& ivkOut) const;
|
||||||
|
|
||||||
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk);
|
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk);
|
||||||
virtual bool RemoveViewingKey(const libzcash::SproutViewingKey &vk);
|
virtual bool RemoveViewingKey(const libzcash::SproutViewingKey &vk);
|
||||||
|
|||||||
@@ -138,16 +138,12 @@ bool CWallet::AddSaplingZKey(const libzcash::SaplingSpendingKey &sk)
|
|||||||
if (!CCryptoKeyStore::AddSaplingSpendingKey(sk)) {
|
if (!CCryptoKeyStore::AddSaplingSpendingKey(sk)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fFileBacked) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// // check if we need to remove from viewing keys
|
// TODO: Persist to disk
|
||||||
// if (HaveViewingKey(addr)) {
|
|
||||||
// RemoveViewingKey(key.viewing_key());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!fFileBacked) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!IsCrypted()) {
|
// if (!IsCrypted()) {
|
||||||
// return CWalletDB(strWalletFile).WriteSaplingZKey(addr,
|
// return CWalletDB(strWalletFile).WriteSaplingZKey(addr,
|
||||||
// sk,
|
// sk,
|
||||||
|
|||||||
Reference in New Issue
Block a user