Store HDSeed in CBasicKeyStore
This commit is contained in:
parent
7614198f9d
commit
70c8c25e4b
|
@ -8,11 +8,39 @@
|
|||
#include "wallet/crypter.h"
|
||||
#endif
|
||||
#include "zcash/Address.hpp"
|
||||
#include "zcash/zip32.h"
|
||||
|
||||
#include "json_test_vectors.h"
|
||||
|
||||
#define MAKE_STRING(x) std::string((x), (x)+sizeof(x))
|
||||
|
||||
TEST(keystore_tests, StoreAndRetrieveHDSeed) {
|
||||
CBasicKeyStore keyStore;
|
||||
HDSeed seedOut;
|
||||
|
||||
// When we haven't set a seed, we shouldn't get one
|
||||
EXPECT_FALSE(keyStore.HaveHDSeed());
|
||||
EXPECT_FALSE(keyStore.GetHDSeed(seedOut));
|
||||
|
||||
// Generate a random seed
|
||||
auto seed = HDSeed::Random();
|
||||
|
||||
// We should be able to set and retrieve the seed
|
||||
ASSERT_TRUE(keyStore.SetHDSeed(seed));
|
||||
EXPECT_TRUE(keyStore.HaveHDSeed());
|
||||
ASSERT_TRUE(keyStore.GetHDSeed(seedOut));
|
||||
EXPECT_EQ(seed, seedOut);
|
||||
|
||||
// Generate another random seed
|
||||
auto seed2 = HDSeed::Random();
|
||||
EXPECT_NE(seed, seed2);
|
||||
|
||||
// We should be able to set and retrieve a different seed
|
||||
ASSERT_TRUE(keyStore.SetHDSeed(seed2));
|
||||
ASSERT_TRUE(keyStore.GetHDSeed(seedOut));
|
||||
EXPECT_EQ(seed2, seedOut);
|
||||
}
|
||||
|
||||
TEST(keystore_tests, sapling_keys) {
|
||||
// ["sk, ask, nsk, ovk, ak, nk, ivk, default_d, default_pk_d, note_v, note_r, note_cm, note_pos, note_nf"],
|
||||
UniValue sapling_keys = read_json(MAKE_STRING(json_tests::sapling_key_components));
|
||||
|
|
|
@ -23,6 +23,30 @@ bool CKeyStore::AddKey(const CKey &key) {
|
|||
return AddKeyPubKey(key, key.GetPubKey());
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::SetHDSeed(const HDSeed& seed)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
hdSeed = seed;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::HaveHDSeed() const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
return !hdSeed.IsNull();
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::GetHDSeed(HDSeed& seedOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
if (hdSeed.IsNull()) {
|
||||
return false;
|
||||
} else {
|
||||
seedOut = hdSeed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "sync.h"
|
||||
#include "zcash/Address.hpp"
|
||||
#include "zcash/NoteEncryption.hpp"
|
||||
#include "zcash/zip32.h"
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
|
@ -27,6 +28,12 @@ protected:
|
|||
public:
|
||||
virtual ~CKeyStore() {}
|
||||
|
||||
//! Set the HD seed for this keystore
|
||||
virtual bool SetHDSeed(const HDSeed& seed) =0;
|
||||
virtual bool HaveHDSeed() const =0;
|
||||
//! Get the HD seed for this keystore
|
||||
virtual bool GetHDSeed(HDSeed& seedOut) const =0;
|
||||
|
||||
//! Add a key to the store.
|
||||
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
|
||||
virtual bool AddKey(const CKey &key);
|
||||
|
@ -109,6 +116,7 @@ typedef std::map<libzcash::SaplingPaymentAddress, libzcash::SaplingIncomingViewi
|
|||
class CBasicKeyStore : public CKeyStore
|
||||
{
|
||||
protected:
|
||||
HDSeed hdSeed;
|
||||
KeyMap mapKeys;
|
||||
ScriptMap mapScripts;
|
||||
WatchOnlySet setWatchOnly;
|
||||
|
@ -121,6 +129,10 @@ protected:
|
|||
SaplingIncomingViewingKeyMap mapSaplingIncomingViewingKeys;
|
||||
|
||||
public:
|
||||
bool SetHDSeed(const HDSeed& seed);
|
||||
bool HaveHDSeed() const;
|
||||
bool GetHDSeed(HDSeed& seedOut) const;
|
||||
|
||||
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
|
||||
bool HaveKey(const CKeyID &address) const
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue