20 :
m_command{std::move(
command)}, m_chain{std::move(chain)}, m_fingerprint{std::move(fingerprint)}, m_name{std::move(
name)} {}
34 throw std::runtime_error(
strprintf(
"'%s' received invalid response, expected array of signers",
command));
47 if (fingerprint.
isNull()) {
48 throw std::runtime_error(
strprintf(
"'%s' received invalid response, missing signer fingerprint",
command));
50 const std::string& fingerprintStr{fingerprint.
get_str()};
52 bool duplicate =
false;
54 if (
signer.m_fingerprint.compare(fingerprintStr) == 0) duplicate =
true;
85 auto matches_signer_fingerprint = [&](
const PSBTInput& input) {
86 for (
const auto& entry : input.hd_keypaths) {
87 if (std::ranges::equal(parsed_m_fingerprint, entry.second.fingerprint))
return true;
89 for (
const auto& entry : input.m_tap_bip32_paths) {
90 if (std::ranges::equal(parsed_m_fingerprint, entry.second.second.fingerprint))
return true;
95 if (!std::any_of(psbtx.inputs.begin(), psbtx.inputs.end(), matches_signer_fingerprint)) {
101 const std::string stdinStr =
"signtx " +
EncodeBase64(ssTx.str());
105 if (signer_result.find_value(
"error").isStr()) {
106 error = signer_result.find_value(
"error").get_str();
110 if (!signer_result.find_value(
"psbt").isStr()) {
111 error =
"Unexpected result from signer";
116 std::string signer_psbt_error;
117 if (!
DecodeBase64PSBT(signer_psbtx, signer_result.find_value(
"psbt").get_str(), signer_psbt_error)) {
118 error =
strprintf(
"TX decode failed %s", signer_psbt_error);
122 psbtx = signer_psbtx;
Enables interaction with an external signing device or service, such as a hardware wallet...
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
UniValue GetDescriptors(int account)
Get receive and change Descriptor(s) from device for a given account.
const std::string & get_str() const
A version of CTransaction with the PSBT format.
std::string EncodeBase64(std::span< const unsigned char > input)
std::string m_fingerprint
Master key fingerprint of the signer.
const std::string & getValStr() const
std::string m_chain
Bitcoin mainnet, testnet, etc.
std::vector< std::string > NetworkArg() const
UniValue DisplayAddress(const std::string &descriptor) const
Display address on the device.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Double ended buffer combining vector and stream-like interfaces.
ExternalSigner(std::vector< std::string > command, std::string chain, std::string fingerprint, std::string name)
UniValue RunCommandParseJSON(const std::vector< std::string > &cmd_args, const std::string &str_std_in)
Execute a command which returns JSON, and parse the result.
std::vector< std::string > m_command
The command which handles interaction with the external signer.
bool SignTransaction(PartiallySignedTransaction &psbt, std::string &error)
Sign PartiallySignedTransaction on the device.
static std::vector< std::string > split(const std::string &str, const std::string &delims=" \)
static bool Enumerate(const std::string &command, std::vector< ExternalSigner > &signers, const std::string &chain)
Obtain a list of signers.
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.