Bitcoin ABC 0.30.5
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
15struct KeyOriginInfo;
16
21public:
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
42private:
43 const bool m_hide_secret;
44 const bool m_hide_origin;
46
47public:
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
58struct 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
77protected:
78 using KeyMap = std::map<CKeyID, CKey>;
79 using ScriptMap = std::map<CScriptID, CScript>;
80
87
105
106public:
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
An encapsulated secp256k1 private key.
Definition: key.h:28
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:210
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
An encapsulated public key.
Definition: pubkey.h:31
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:24
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override
virtual bool AddCScript(const CScript &redeemScript)
std::map< CScriptID, CScript > ScriptMap
KeyMap mapKeys GUARDED_BY(cs_KeyStore)
Map of key id to unencrypted private keys known by the signing provider.
ScriptMap mapScripts GUARDED_BY(cs_KeyStore)
(This comment has been elided for clarity since most of it detailed Core SegWit implementation detail...
virtual std::set< CKeyID > GetKeys() const
std::map< CKeyID, CKey > KeyMap
virtual std::set< CScriptID > GetCScripts() const
virtual bool HaveCScript(const CScriptID &hash) const override
virtual bool AddKey(const CKey &key)
RecursiveMutex cs_KeyStore
virtual bool HaveKey(const CKeyID &address) const override
bool GetKey(const CKeyID &keyid, CKey &key) const override
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
const SigningProvider * m_provider
bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override
HidingSigningProvider(const SigningProvider *provider, bool hide_secret, bool hide_origin)
bool GetCScript(const CScriptID &scriptid, CScript &script) const override
An interface to be implemented by keystores that support signing.
virtual ~SigningProvider()
virtual bool HaveKey(const CKeyID &address) const
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool HaveCScript(const CScriptID &scriptid) const
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
const SigningProvider & DUMMY_SIGNING_PROVIDER
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > origins
bool GetKey(const CKeyID &keyid, CKey &key) const override
std::map< CKeyID, CPubKey > pubkeys
std::map< CKeyID, CKey > keys
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
std::map< CScriptID, CScript > scripts
bool GetCScript(const CScriptID &scriptid, CScript &script) const override