0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

external_signer: improve fingerprint matching logic (stop on first match)

This commit is contained in:
Sebastian Falbesoner 2021-08-24 11:19:43 +02:00
parent d3203a99d8
commit d047ed729f

View file

@ -9,6 +9,7 @@
#include <util/system.h>
#include <external_signer.h>
#include <algorithm>
#include <stdexcept>
#include <string>
#include <vector>
@ -75,15 +76,14 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
ssTx << psbtx;
// Check if signer fingerprint matches any input master key fingerprint
bool match = false;
for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
const PSBTInput& input = psbtx.inputs[i];
auto matches_signer_fingerprint = [&](const PSBTInput& input) {
for (const auto& entry : input.hd_keypaths) {
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true;
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) return true;
}
}
return false;
};
if (!match) {
if (!std::any_of(psbtx.inputs.begin(), psbtx.inputs.end(), matches_signer_fingerprint)) {
error = "Signer fingerprint " + m_fingerprint + " does not match any of the inputs:\n" + EncodeBase64(ssTx.str());
return false;
}