Skip to content

Commit cad5dd2

Browse files
committed
Pass HD path data through SignatureData
1 parent 03a9958 commit cad5dd2

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

src/script/sign.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ static bool GetCScript(const SigningProvider& provider, const SignatureData& sig
5050

5151
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
5252
{
53-
if (provider.GetPubKey(address, pubkey)) {
54-
sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey);
55-
return true;
56-
}
5753
// Look for pubkey in all partial sigs
5854
const auto it = sigdata.signatures.find(address);
5955
if (it != sigdata.signatures.end()) {
@@ -63,7 +59,15 @@ static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, c
6359
// Look for pubkey in pubkey list
6460
const auto& pk_it = sigdata.misc_pubkeys.find(address);
6561
if (pk_it != sigdata.misc_pubkeys.end()) {
66-
pubkey = pk_it->second;
62+
pubkey = pk_it->second.first;
63+
return true;
64+
}
65+
// Query the underlying provider
66+
if (provider.GetPubKey(address, pubkey)) {
67+
KeyOriginInfo info;
68+
if (provider.GetKeyOrigin(address, info)) {
69+
sigdata.misc_pubkeys.emplace(address, std::make_pair(pubkey, std::move(info)));
70+
}
6771
return true;
6872
}
6973
return false;
@@ -543,7 +547,7 @@ void PSBTInput::FillSignatureData(SignatureData& sigdata) const
543547
sigdata.witness_script = witness_script;
544548
}
545549
for (const auto& key_pair : hd_keypaths) {
546-
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
550+
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
547551
}
548552
}
549553

@@ -571,6 +575,9 @@ void PSBTInput::FromSignatureData(const SignatureData& sigdata)
571575
if (witness_script.empty() && !sigdata.witness_script.empty()) {
572576
witness_script = sigdata.witness_script;
573577
}
578+
for (const auto& entry : sigdata.misc_pubkeys) {
579+
hd_keypaths.emplace(entry.second);
580+
}
574581
}
575582

576583
void PSBTInput::Merge(const PSBTInput& input)
@@ -612,7 +619,7 @@ void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
612619
sigdata.witness_script = witness_script;
613620
}
614621
for (const auto& key_pair : hd_keypaths) {
615-
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
622+
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
616623
}
617624
}
618625

@@ -624,6 +631,9 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
624631
if (witness_script.empty() && !sigdata.witness_script.empty()) {
625632
witness_script = sigdata.witness_script;
626633
}
634+
for (const auto& entry : sigdata.misc_pubkeys) {
635+
hd_keypaths.emplace(entry.second);
636+
}
627637
}
628638

629639
bool PSBTOutput::IsNull() const

src/script/sign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct SignatureData {
109109
CScript witness_script; ///< The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
110110
CScriptWitness scriptWitness; ///< The scriptWitness of an input. Contains complete signatures or the traditional partial signatures format. scriptWitness is part of a transaction input per BIP 144.
111111
std::map<CKeyID, SigPair> signatures; ///< BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a final scriptSig or scriptWitness.
112-
std::map<CKeyID, CPubKey> misc_pubkeys;
112+
std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> misc_pubkeys;
113113

114114
SignatureData() {}
115115
explicit SignatureData(const CScript& script) : scriptSig(script) {}

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,7 +4462,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
44624462
}
44634463

44644464
SignatureData sigdata;
4465-
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, false), *psbtx.tx, input, sigdata, i, sighash_type);
4465+
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, sigdata, i, sighash_type);
44664466

44674467
if (it != pwallet->mapWallet.end()) {
44684468
// Drop the unnecessary UTXO if we added both from the wallet.
@@ -4472,13 +4472,6 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
44724472
input.witness_utxo.SetNull();
44734473
}
44744474
}
4475-
4476-
// Get public key paths
4477-
if (bip32derivs) {
4478-
for (const auto& pubkey_it : sigdata.misc_pubkeys) {
4479-
AddKeypathToMap(pwallet, pubkey_it.first, input.hd_keypaths);
4480-
}
4481-
}
44824475
}
44834476

44844477
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
@@ -4496,15 +4489,8 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
44964489
psbt_out.FillSignatureData(sigdata);
44974490

44984491
MutableTransactionSignatureCreator creator(psbtx.tx.get_ptr(), 0, out.nValue, 1);
4499-
ProduceSignature(*pwallet, creator, out.scriptPubKey, sigdata);
4492+
ProduceSignature(HidingSigningProvider(pwallet, true, !bip32derivs), creator, out.scriptPubKey, sigdata);
45004493
psbt_out.FromSignatureData(sigdata);
4501-
4502-
// Get public key paths
4503-
if (bip32derivs) {
4504-
for (const auto& pubkey_it : sigdata.misc_pubkeys) {
4505-
AddKeypathToMap(pwallet, pubkey_it.first, psbt_out.hd_keypaths);
4506-
}
4507-
}
45084494
}
45094495
return complete;
45104496
}

0 commit comments

Comments
 (0)