Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

keystore.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_KEYSTORE_H
7 #define BITCOIN_KEYSTORE_H
8 
9 #include <hdchain.h>
10 #include <key.h>
11 #include <pubkey.h>
12 #include <script/script.h>
13 #include <script/standard.h>
14 #include <sync.h>
15 
16 #include <boost/signals2/signal.hpp>
17 
19 class CKeyStore
20 {
21 protected:
23 
24 public:
25  virtual ~CKeyStore() {}
26 
28  virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
29  virtual bool AddKey(const CKey &key);
30 
32  virtual bool HaveKey(const CKeyID &address) const =0;
33  virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0;
34  virtual std::set<CKeyID> GetKeys() const =0;
35  virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const =0;
36 
38  virtual bool AddCScript(const CScript& redeemScript) =0;
39  virtual bool HaveCScript(const CScriptID &hash) const =0;
40  virtual std::set<CScriptID> GetCScripts() const =0;
41  virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const =0;
42 
44  virtual bool AddWatchOnly(const CScript &dest) =0;
45  virtual bool RemoveWatchOnly(const CScript &dest) =0;
46  virtual bool HaveWatchOnly(const CScript &dest) const =0;
47  virtual bool HaveWatchOnly() const =0;
48 };
49 
50 typedef std::map<CKeyID, CKey> KeyMap;
51 typedef std::map<CKeyID, CPubKey> WatchKeyMap;
52 typedef std::map<CScriptID, CScript > ScriptMap;
53 typedef std::set<CScript> WatchOnlySet;
54 
56 class CBasicKeyStore : public CKeyStore
57 {
58 protected:
63  /* the HD chain data model*/
65 
66 public:
67  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
68  bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
69  bool HaveKey(const CKeyID &address) const override;
70  std::set<CKeyID> GetKeys() const override;
71  bool GetKey(const CKeyID &address, CKey &keyOut) const override;
72  bool AddCScript(const CScript& redeemScript) override;
73  bool HaveCScript(const CScriptID &hash) const override;
74  std::set<CScriptID> GetCScripts() const override;
75  bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
76 
77  bool AddWatchOnly(const CScript &dest) override;
78  bool RemoveWatchOnly(const CScript &dest) override;
79  bool HaveWatchOnly(const CScript &dest) const override;
80  bool HaveWatchOnly() const override;
81 
82  virtual bool GetHDChain(CHDChain& hdChainRet) const;
83 };
84 
85 typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
86 typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
87 
88 #endif // BITCOIN_KEYSTORE_H
CCriticalSection cs_KeyStore
Definition: keystore.h:22
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)=0
Add a key to the store.
std::map< CScriptID, CScript > ScriptMap
Definition: keystore.h:52
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: keystore.cpp:14
bool HaveCScript(const CScriptID &hash) const override
Definition: keystore.cpp:74
std::set< CScriptID > GetCScripts() const override
Definition: keystore.cpp:80
bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
Definition: keystore.cpp:90
std::set< CKeyID > GetKeys() const override
Definition: keystore.cpp:43
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: keystore.h:85
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: keystore.cpp:64
std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > > > CryptedKeyMap
Definition: keystore.h:86
virtual bool AddWatchOnly(const CScript &dest)=0
Support for Watch-only addresses.
std::set< CScript > WatchOnlySet
Definition: keystore.h:53
virtual std::set< CScriptID > GetCScripts() const =0
virtual bool AddCScript(const CScript &redeemScript)=0
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
CHDChain hdChain
Definition: keystore.h:64
virtual bool HaveCScript(const CScriptID &hash) const =0
WatchKeyMap mapWatchKeys
Definition: keystore.h:60
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
An encapsulated public key.
Definition: pubkey.h:30
virtual bool RemoveWatchOnly(const CScript &dest)=0
ScriptMap mapScripts
Definition: keystore.h:61
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: keystore.cpp:30
std::map< CKeyID, CPubKey > WatchKeyMap
Definition: keystore.h:51
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const =0
WatchOnlySet setWatchOnly
Definition: keystore.h:62
bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: keystore.cpp:53
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:10
bool RemoveWatchOnly(const CScript &dest) override
Definition: keystore.cpp:128
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const =0
KeyMap mapKeys
Definition: keystore.h:59
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
virtual bool HaveWatchOnly() const =0
A virtual base class for key stores.
Definition: keystore.h:19
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
virtual ~CKeyStore()
Definition: keystore.h:25
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
An encapsulated private key.
Definition: key.h:27
bool HaveWatchOnly() const override
Definition: keystore.cpp:144
virtual std::set< CKeyID > GetKeys() const =0
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
Definition: keystore.cpp:37
std::map< CKeyID, CKey > KeyMap
Definition: keystore.h:50
Basic key store, that keeps keys in an address->secret map.
Definition: keystore.h:56
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
bool AddWatchOnly(const CScript &dest) override
Support for Watch-only addresses.
Definition: keystore.cpp:118
virtual bool GetHDChain(CHDChain &hdChainRet) const
Definition: keystore.cpp:150
Released under the MIT license