Skip to content

Commit e650a8e

Browse files
committed
Add P2C tweaks and script paths to the signing provider
1 parent c815ddc commit e650a8e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/script/signingprovider.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ bool HidingSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& inf
4444
return m_provider->GetKeyOrigin(keyid, info);
4545
}
4646

47+
bool HidingSigningProvider::GetScriptPaths(const CKeyID &addressid, std::vector<ScriptPath>& paths) const
48+
{
49+
if (m_hide_origin) return false;
50+
return m_provider->GetScriptPaths(addressid, paths);
51+
}
52+
53+
bool HidingSigningProvider::GetP2CTweaks(const CKeyID &addressid, CPubKey& base, uint256& tweak) const
54+
{
55+
if (m_hide_origin) return false;
56+
return m_provider->GetP2CTweaks(addressid, base, tweak);
57+
}
58+
4759
bool FlatSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const { return LookupHelper(scripts, scriptid, script); }
4860
bool FlatSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const { return LookupHelper(pubkeys, keyid, pubkey); }
4961
bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const
@@ -55,6 +67,21 @@ bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info)
5567
}
5668
bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); }
5769

70+
71+
bool FlatSigningProvider::GetScriptPaths(const CKeyID &addressid, std::vector<ScriptPath>& paths) const { return LookupHelper(taproot_paths, addressid, paths); }
72+
73+
bool FlatSigningProvider::GetP2CTweaks(const CKeyID &addressid, CPubKey& base, uint256& tweak) const
74+
{
75+
std::pair<CPubKey, uint256> out;
76+
bool ret = LookupHelper(p2c_tweaks, addressid, out);
77+
if(ret) {
78+
base = out.first;
79+
tweak = out.second;
80+
}
81+
return ret;
82+
}
83+
84+
5885
FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b)
5986
{
6087
FlatSigningProvider ret;

src/script/signingprovider.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
struct KeyOriginInfo;
1616

17+
struct ScriptPath
18+
{
19+
uint8_t version = 0xc0;
20+
CScript leaf;
21+
std::vector<uint256> path;
22+
23+
void clear() {
24+
leaf.clear();
25+
path.clear();
26+
}
27+
};
28+
1729
/** An interface to be implemented by keystores that support signing. */
1830
class SigningProvider
1931
{
@@ -25,6 +37,14 @@ class SigningProvider
2537
virtual bool GetKey(const CKeyID &address, CKey& key) const { return false; }
2638
virtual bool HaveKey(const CKeyID &address) const { return false; }
2739
virtual bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const { return false; }
40+
virtual bool GetScriptPaths(const CKeyID &addressid, std::vector<ScriptPath>& paths) const { return false; }
41+
virtual bool GetP2CTweaks(const CKeyID &addressid, CPubKey& base, uint256& tweak) const { return false; }
42+
43+
SigningProvider() = default;
44+
protected:
45+
// This prevents accidental object slicing.
46+
SigningProvider(const SigningProvider&) = default;
47+
SigningProvider& operator=(const SigningProvider&) = default;
2848
};
2949

3050
extern const SigningProvider& DUMMY_SIGNING_PROVIDER;
@@ -42,6 +62,8 @@ class HidingSigningProvider : public SigningProvider
4262
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
4363
bool GetKey(const CKeyID& keyid, CKey& key) const override;
4464
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
65+
bool GetScriptPaths(const CKeyID &addressid, std::vector<ScriptPath>& paths) const override;
66+
bool GetP2CTweaks(const CKeyID &addressid, CPubKey& base, uint256& tweak) const override;
4567
};
4668

4769
struct FlatSigningProvider final : public SigningProvider
@@ -50,11 +72,16 @@ struct FlatSigningProvider final : public SigningProvider
5072
std::map<CKeyID, CPubKey> pubkeys;
5173
std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> origins;
5274
std::map<CKeyID, CKey> keys;
75+
std::map<CKeyID, std::vector<ScriptPath>> taproot_paths;
76+
std::map<CKeyID, std::pair<CPubKey, uint256>> p2c_tweaks;
5377

5478
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
5579
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
5680
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
5781
bool GetKey(const CKeyID& keyid, CKey& key) const override;
82+
bool GetScriptPaths(const CKeyID &addressid, std::vector<ScriptPath>& paths) const override;
83+
bool GetP2CTweaks(const CKeyID &addressid, CPubKey& base, uint256& tweak) const override;
84+
5885
};
5986

6087
FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b);

0 commit comments

Comments
 (0)