mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-12 21:52:38 +01:00
Merge #13723: PSBT key path cleanups
917353c8b0Make SignPSBTInput operate on a private SignatureData object (Pieter Wuille)cad5dd2368Pass HD path data through SignatureData (Pieter Wuille)03a99586a3Implement key origin lookup in CWallet (Pieter Wuille)3b01efa0d1[MOVEONLY] Move ParseHDKeypath to utilstrencodings (Pieter Wuille)81e1dd5ce1Generalize PublicOnlySigningProvider into HidingSigningProvider (Pieter Wuille)84f1f1bfdfMake SigningProvider expose key origin information (Pieter Wuille)611ab307fbIntroduce KeyOriginInfo for fingerprint + path (Pieter Wuille) Pull request description: This PR adds "key origin" (master fingeprint + key path) information to what is exposed from `SigningProvider`s, allowing this information to be used by the generic PSBT code instead of having the RPC pull it directly from the wallet. This is also a preparation to having PSBT interact with output descriptors, which can then directly expose key origin information for the scripts they generate. Tree-SHA512: c718382ba8ba2d6fc9a32c062bd4cff08b6f39b133838aa03115c39aeca0f654c7cc3ec72d87005bf8306e550824cd8eb9d60f0bd41784a3e22e17b2afcfe833
This commit is contained in:
@@ -50,10 +50,6 @@ static bool GetCScript(const SigningProvider& provider, const SignatureData& sig
|
||||
|
||||
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
|
||||
{
|
||||
if (provider.GetPubKey(address, pubkey)) {
|
||||
sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey);
|
||||
return true;
|
||||
}
|
||||
// Look for pubkey in all partial sigs
|
||||
const auto it = sigdata.signatures.find(address);
|
||||
if (it != sigdata.signatures.end()) {
|
||||
@@ -63,7 +59,15 @@ static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, c
|
||||
// Look for pubkey in pubkey list
|
||||
const auto& pk_it = sigdata.misc_pubkeys.find(address);
|
||||
if (pk_it != sigdata.misc_pubkeys.end()) {
|
||||
pubkey = pk_it->second;
|
||||
pubkey = pk_it->second.first;
|
||||
return true;
|
||||
}
|
||||
// Query the underlying provider
|
||||
if (provider.GetPubKey(address, pubkey)) {
|
||||
KeyOriginInfo info;
|
||||
if (provider.GetKeyOrigin(address, info)) {
|
||||
sigdata.misc_pubkeys.emplace(address, std::make_pair(pubkey, std::move(info)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -232,7 +236,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
|
||||
return sigdata.complete;
|
||||
}
|
||||
|
||||
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash)
|
||||
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
|
||||
{
|
||||
// if this input has a final scriptsig or scriptwitness, don't do anything with it
|
||||
if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) {
|
||||
@@ -240,6 +244,7 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
|
||||
}
|
||||
|
||||
// Fill SignatureData with input info
|
||||
SignatureData sigdata;
|
||||
input.FillSignatureData(sigdata);
|
||||
|
||||
// Get UTXO
|
||||
@@ -271,6 +276,16 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
|
||||
// Verify that a witness signature was produced in case one was required.
|
||||
if (require_witness_sig && !sigdata.witness) return false;
|
||||
input.FromSignatureData(sigdata);
|
||||
|
||||
// If both UTXO types are present, drop the unnecessary one.
|
||||
if (input.non_witness_utxo && !input.witness_utxo.IsNull()) {
|
||||
if (sigdata.witness) {
|
||||
input.non_witness_utxo = nullptr;
|
||||
} else {
|
||||
input.witness_utxo.SetNull();
|
||||
}
|
||||
}
|
||||
|
||||
return sig_complete;
|
||||
}
|
||||
|
||||
@@ -541,7 +556,7 @@ void PSBTInput::FillSignatureData(SignatureData& sigdata) const
|
||||
sigdata.witness_script = witness_script;
|
||||
}
|
||||
for (const auto& key_pair : hd_keypaths) {
|
||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
|
||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,6 +584,9 @@ void PSBTInput::FromSignatureData(const SignatureData& sigdata)
|
||||
if (witness_script.empty() && !sigdata.witness_script.empty()) {
|
||||
witness_script = sigdata.witness_script;
|
||||
}
|
||||
for (const auto& entry : sigdata.misc_pubkeys) {
|
||||
hd_keypaths.emplace(entry.second);
|
||||
}
|
||||
}
|
||||
|
||||
void PSBTInput::Merge(const PSBTInput& input)
|
||||
@@ -610,7 +628,7 @@ void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
|
||||
sigdata.witness_script = witness_script;
|
||||
}
|
||||
for (const auto& key_pair : hd_keypaths) {
|
||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
|
||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,6 +640,9 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
|
||||
if (witness_script.empty() && !sigdata.witness_script.empty()) {
|
||||
witness_script = sigdata.witness_script;
|
||||
}
|
||||
for (const auto& entry : sigdata.misc_pubkeys) {
|
||||
hd_keypaths.emplace(entry.second);
|
||||
}
|
||||
}
|
||||
|
||||
bool PSBTOutput::IsNull() const
|
||||
@@ -638,14 +659,26 @@ void PSBTOutput::Merge(const PSBTOutput& output)
|
||||
if (witness_script.empty() && !output.witness_script.empty()) witness_script = output.witness_script;
|
||||
}
|
||||
|
||||
bool PublicOnlySigningProvider::GetCScript(const CScriptID &scriptid, CScript& script) const
|
||||
bool HidingSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const
|
||||
{
|
||||
return m_provider->GetCScript(scriptid, script);
|
||||
}
|
||||
|
||||
bool PublicOnlySigningProvider::GetPubKey(const CKeyID &address, CPubKey& pubkey) const
|
||||
bool HidingSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const
|
||||
{
|
||||
return m_provider->GetPubKey(address, pubkey);
|
||||
return m_provider->GetPubKey(keyid, pubkey);
|
||||
}
|
||||
|
||||
bool HidingSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const
|
||||
{
|
||||
if (m_hide_secret) return false;
|
||||
return m_provider->GetKey(keyid, key);
|
||||
}
|
||||
|
||||
bool HidingSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const
|
||||
{
|
||||
if (m_hide_origin) return false;
|
||||
return m_provider->GetKeyOrigin(keyid, info);
|
||||
}
|
||||
|
||||
bool FlatSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const { return LookupHelper(scripts, scriptid, script); }
|
||||
|
||||
Reference in New Issue
Block a user