Bitcoin ABC  0.24.7
P2P Digital Currency
signingprovider.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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_SCRIPT_SIGNINGPROVIDER_H
7 #define BITCOIN_SCRIPT_SIGNINGPROVIDER_H
8 
9 #include <key.h>
10 #include <pubkey.h>
11 #include <script/script.h>
12 #include <script/standard.h>
13 #include <sync.h>
14 
15 struct KeyOriginInfo;
16 
21 public:
22  virtual ~SigningProvider() {}
23  virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const {
24  return false;
25  }
26  virtual bool HaveCScript(const CScriptID &scriptid) const { return false; }
27  virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const {
28  return false;
29  }
30  virtual bool GetKey(const CKeyID &address, CKey &key) const {
31  return false;
32  }
33  virtual bool HaveKey(const CKeyID &address) const { return false; }
34  virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const {
35  return false;
36  }
37 };
38 
40 
42 private:
43  const bool m_hide_secret;
44  const bool m_hide_origin;
46 
47 public:
48  HidingSigningProvider(const SigningProvider *provider, bool hide_secret,
49  bool hide_origin)
50  : m_hide_secret(hide_secret), m_hide_origin(hide_origin),
51  m_provider(provider) {}
52  bool GetCScript(const CScriptID &scriptid, CScript &script) const override;
53  bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override;
54  bool GetKey(const CKeyID &keyid, CKey &key) const override;
55  bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override;
56 };
57 
58 struct FlatSigningProvider final : public SigningProvider {
59  std::map<CScriptID, CScript> scripts;
60  std::map<CKeyID, CPubKey> pubkeys;
61  std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> origins;
62  std::map<CKeyID, CKey> keys;
63 
64  bool GetCScript(const CScriptID &scriptid, CScript &script) const override;
65  bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override;
66  bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override;
67  bool GetKey(const CKeyID &keyid, CKey &key) const override;
68 };
69 
71  const FlatSigningProvider &b);
72 
77 protected:
78  using KeyMap = std::map<CKeyID, CKey>;
79  using ScriptMap = std::map<CScriptID, CScript>;
80 
86  KeyMap mapKeys GUARDED_BY(cs_KeyStore);
87 
104  ScriptMap mapScripts GUARDED_BY(cs_KeyStore);
105 
106 public:
108 
109  virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey);
110  virtual bool AddKey(const CKey &key) {
111  return AddKeyPubKey(key, key.GetPubKey());
112  }
113  virtual bool GetPubKey(const CKeyID &address,
114  CPubKey &vchPubKeyOut) const override;
115  virtual bool HaveKey(const CKeyID &address) const override;
116  virtual std::set<CKeyID> GetKeys() const;
117  virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override;
118  virtual bool AddCScript(const CScript &redeemScript);
119  virtual bool HaveCScript(const CScriptID &hash) const override;
120  virtual std::set<CScriptID> GetCScripts() const;
121  virtual bool GetCScript(const CScriptID &hash,
122  CScript &redeemScriptOut) const override;
123 };
124 
129  const CTxDestination &dest);
130 
131 #endif // BITCOIN_SCRIPT_SIGNINGPROVIDER_H
FillableSigningProvider::KeyMap
std::map< CKeyID, CKey > KeyMap
Definition: signingprovider.h:78
FillableSigningProvider::ScriptMap
std::map< CScriptID, CScript > ScriptMap
Definition: signingprovider.h:79
SigningProvider::~SigningProvider
virtual ~SigningProvider()
Definition: signingprovider.h:22
FillableSigningProvider::GetKeys
virtual std::set< CKeyID > GetKeys() const
Definition: signingprovider.cpp:105
HidingSigningProvider::m_provider
const SigningProvider * m_provider
Definition: signingprovider.h:45
SigningProvider::HaveCScript
virtual bool HaveCScript(const CScriptID &scriptid) const
Definition: signingprovider.h:26
sync.h
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:76
FlatSigningProvider::keys
std::map< CKeyID, CKey > keys
Definition: signingprovider.h:62
SigningProvider
An interface to be implemented by keystores that support signing.
Definition: signingprovider.h:20
HidingSigningProvider::HidingSigningProvider
HidingSigningProvider(const SigningProvider *provider, bool hide_secret, bool hide_origin)
Definition: signingprovider.h:48
AnnotatedMixin< std::recursive_mutex >
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
pubkey.h
SigningProvider::GetPubKey
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
Definition: signingprovider.h:27
FillableSigningProvider::AddKey
virtual bool AddKey(const CKey &key)
Definition: signingprovider.h:110
FlatSigningProvider::GetKeyOrigin
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
Definition: signingprovider.cpp:56
FillableSigningProvider::GetCScripts
virtual std::set< CScriptID > GetCScripts() const
Definition: signingprovider.cpp:143
FlatSigningProvider::scripts
std::map< CScriptID, CScript > scripts
Definition: signingprovider.h:59
SigningProvider::HaveKey
virtual bool HaveKey(const CKeyID &address) const
Definition: signingprovider.h:33
HidingSigningProvider::GetKeyOrigin
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
Definition: signingprovider.cpp:40
FlatSigningProvider::origins
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > origins
Definition: signingprovider.h:61
HidingSigningProvider::m_hide_secret
const bool m_hide_secret
Definition: signingprovider.h:43
FillableSigningProvider::GetPubKey
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: signingprovider.cpp:83
SigningProvider::GetKeyOrigin
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
Definition: signingprovider.h:34
Merge
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
Definition: signingprovider.cpp:69
DUMMY_SIGNING_PROVIDER
const SigningProvider & DUMMY_SIGNING_PROVIDER
Definition: signingprovider.cpp:11
standard.h
FillableSigningProvider::HaveCScript
virtual bool HaveCScript(const CScriptID &hash) const override
Definition: signingprovider.cpp:138
SigningProvider::GetCScript
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
Definition: signingprovider.h:23
FlatSigningProvider::pubkeys
std::map< CKeyID, CPubKey > pubkeys
Definition: signingprovider.h:60
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:210
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
key.h
FlatSigningProvider::GetKey
bool GetKey(const CKeyID &keyid, CKey &key) const override
Definition: signingprovider.cpp:65
CPubKey
An encapsulated public key.
Definition: pubkey.h:31
CKey
An encapsulated secp256k1 private key.
Definition: key.h:28
FillableSigningProvider::GetKey
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: signingprovider.cpp:114
HidingSigningProvider::GetPubKey
bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override
Definition: signingprovider.cpp:28
FillableSigningProvider::AddKeyPubKey
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Definition: signingprovider.cpp:93
HidingSigningProvider::m_hide_origin
const bool m_hide_origin
Definition: signingprovider.h:44
SigningProvider::GetKey
virtual bool GetKey(const CKeyID &address, CKey &key) const
Definition: signingprovider.h:30
FillableSigningProvider::GetCScript
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
Definition: signingprovider.cpp:152
FillableSigningProvider::AddCScript
virtual bool AddCScript(const CScript &redeemScript)
Definition: signingprovider.cpp:125
GetKeyForDestination
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
Definition: signingprovider.cpp:163
script.h
HidingSigningProvider::GetCScript
bool GetCScript(const CScriptID &scriptid, CScript &script) const override
Definition: signingprovider.cpp:23
FlatSigningProvider::GetCScript
bool GetCScript(const CScriptID &scriptid, CScript &script) const override
Definition: signingprovider.cpp:48
FillableSigningProvider::GUARDED_BY
KeyMap mapKeys GUARDED_BY(cs_KeyStore)
Map of key id to unencrypted private keys known by the signing provider.
FillableSigningProvider::HaveKey
virtual bool HaveKey(const CKeyID &address) const override
Definition: signingprovider.cpp:100
FillableSigningProvider::cs_KeyStore
RecursiveMutex cs_KeyStore
Definition: signingprovider.h:107
HidingSigningProvider
Definition: signingprovider.h:41
FlatSigningProvider::GetPubKey
bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override
Definition: signingprovider.cpp:52
HidingSigningProvider::GetKey
bool GetKey(const CKeyID &keyid, CKey &key) const override
Definition: signingprovider.cpp:33
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:65
CTxDestination
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:132
KeyOriginInfo
Definition: keyorigin.h:11
FlatSigningProvider
Definition: signingprovider.h:58