Bitcoin ABC  0.22.13
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 
81  KeyMap mapKeys GUARDED_BY(cs_KeyStore);
82  ScriptMap mapScripts GUARDED_BY(cs_KeyStore);
83 
84 public:
86 
87  virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey);
88  virtual bool AddKey(const CKey &key) {
89  return AddKeyPubKey(key, key.GetPubKey());
90  }
91  virtual bool GetPubKey(const CKeyID &address,
92  CPubKey &vchPubKeyOut) const override;
93  virtual bool HaveKey(const CKeyID &address) const override;
94  virtual std::set<CKeyID> GetKeys() const;
95  virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override;
96  virtual bool AddCScript(const CScript &redeemScript);
97  virtual bool HaveCScript(const CScriptID &hash) const override;
98  virtual std::set<CScriptID> GetCScripts() const;
99  virtual bool GetCScript(const CScriptID &hash,
100  CScript &redeemScriptOut) const override;
101 };
102 
107  const CTxDestination &dest);
108 
109 #endif // BITCOIN_SCRIPT_SIGNINGPROVIDER_H
virtual ~SigningProvider()
std::map< CScriptID, CScript > ScriptMap
const SigningProvider & DUMMY_SIGNING_PROVIDER
const SigningProvider * m_provider
RecursiveMutex cs_KeyStore
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:210
virtual bool HaveCScript(const CScriptID &scriptid) const
std::map< CKeyID, CKey > keys
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > origins
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
std::map< CScriptID, CScript > scripts
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
An encapsulated public key.
Definition: pubkey.h:31
Fillable signing provider that keeps keys in an address->secret map.
std::map< CKeyID, CPubKey > pubkeys
virtual bool HaveKey(const CKeyID &address) const
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
An interface to be implemented by keystores that support signing.
std::map< CKeyID, CKey > KeyMap
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
#define GUARDED_BY(x)
Definition: threadsafety.h:45
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
HidingSigningProvider(const SigningProvider *provider, bool hide_secret, bool hide_origin)
An encapsulated secp256k1 private key.
Definition: key.h:25
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:87
virtual bool AddKey(const CKey &key)