Skip to content

Commit 52e3f2f

Browse files
committed
Fill PSBT Taproot input data to/from SignatureData
1 parent 05e2cc9 commit 52e3f2f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/psbt.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ void PSBTInput::FillSignatureData(SignatureData& sigdata) const
113113
for (const auto& key_pair : hd_keypaths) {
114114
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
115115
}
116+
if (!m_tap_key_sig.empty()) {
117+
sigdata.taproot_key_path_sig = m_tap_key_sig;
118+
}
119+
for (const auto& [pubkey_leaf, sig] : m_tap_script_sigs) {
120+
sigdata.taproot_script_sigs.emplace(pubkey_leaf, sig);
121+
}
122+
if (!m_tap_internal_key.IsNull()) {
123+
sigdata.tr_spenddata.internal_key = m_tap_internal_key;
124+
}
125+
if (!m_tap_merkle_root.IsNull()) {
126+
sigdata.tr_spenddata.merkle_root = m_tap_merkle_root;
127+
}
128+
for (const auto& [leaf_script, control_block] : m_tap_scripts) {
129+
sigdata.tr_spenddata.scripts.emplace(leaf_script, control_block);
130+
}
131+
for (const auto& [pubkey, leaf_origin] : m_tap_bip32_paths) {
132+
sigdata.taproot_misc_pubkeys.emplace(pubkey, leaf_origin);
133+
}
116134
}
117135

118136
void PSBTInput::FromSignatureData(const SignatureData& sigdata)
@@ -142,6 +160,24 @@ void PSBTInput::FromSignatureData(const SignatureData& sigdata)
142160
for (const auto& entry : sigdata.misc_pubkeys) {
143161
hd_keypaths.emplace(entry.second);
144162
}
163+
if (!sigdata.taproot_key_path_sig.empty()) {
164+
m_tap_key_sig = sigdata.taproot_key_path_sig;
165+
}
166+
for (const auto& [pubkey_leaf, sig] : sigdata.taproot_script_sigs) {
167+
m_tap_script_sigs.emplace(pubkey_leaf, sig);
168+
}
169+
if (!sigdata.tr_spenddata.internal_key.IsNull()) {
170+
m_tap_internal_key = sigdata.tr_spenddata.internal_key;
171+
}
172+
if (!sigdata.tr_spenddata.merkle_root.IsNull()) {
173+
m_tap_merkle_root = sigdata.tr_spenddata.merkle_root;
174+
}
175+
for (const auto& [leaf_script, control_block] : sigdata.tr_spenddata.scripts) {
176+
m_tap_scripts.emplace(leaf_script, control_block);
177+
}
178+
for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
179+
m_tap_bip32_paths.emplace(pubkey, leaf_origin);
180+
}
145181
}
146182

147183
void PSBTInput::Merge(const PSBTInput& input)

src/script/sign.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct SignatureData {
7474
std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> misc_pubkeys;
7575
std::vector<unsigned char> taproot_key_path_sig; /// Schnorr signature for key path spending
7676
std::map<std::pair<XOnlyPubKey, uint256>, std::vector<unsigned char>> taproot_script_sigs; ///< (Partial) schnorr signatures, indexed by XOnlyPubKey and leaf_hash.
77+
std::map<XOnlyPubKey, std::pair<std::set<uint256>, KeyOriginInfo>> taproot_misc_pubkeys; ///< Miscellaneous Taproot pubkeys involved in this input along with their leaf script hashes and key origin data. Also includes the Taproot internal key (may have no leaf script hashes).
7778
std::vector<CKeyID> missing_pubkeys; ///< KeyIDs of pubkeys which could not be found
7879
std::vector<CKeyID> missing_sigs; ///< KeyIDs of pubkeys for signatures which could not be found
7980
uint160 missing_redeem_script; ///< ScriptID of the missing redeemScript (if any)

0 commit comments

Comments
 (0)