29 throw std::runtime_error(
strprintf(
"'%s' received invalid response, expected array of signers",
command));
34 if (!
error.isNull()) {
42 if (fingerprint.
isNull()) {
43 throw std::runtime_error(
strprintf(
"'%s' received invalid response, missing signer fingerprint",
command));
45 const std::string fingerprintStr = fingerprint.
get_str();
47 bool duplicate =
false;
49 if (signer.m_fingerprint.compare(fingerprintStr) == 0) duplicate =
true;
80 auto matches_signer_fingerprint = [&](
const PSBTInput& input) {
81 for (
const auto& entry : input.hd_keypaths) {
82 if (parsed_m_fingerprint ==
MakeUCharSpan(entry.second.fingerprint))
return true;
84 for (
const auto& entry : input.m_tap_bip32_paths) {
85 if (parsed_m_fingerprint ==
MakeUCharSpan(entry.second.second.fingerprint))
return true;
90 if (!std::any_of(psbtx.
inputs.begin(), psbtx.
inputs.end(), matches_signer_fingerprint)) {
96 const std::string stdinStr =
"signtx \"" +
EncodeBase64(ssTx.
str()) +
"\"";
100 if (
find_value(signer_result,
"error").isStr()) {
105 if (!
find_value(signer_result,
"psbt").isStr()) {
106 error =
"Unexpected result from signer";
111 std::string signer_psbt_error;
117 psbtx = signer_psbtx;
Enables interaction with an external signing device or service, such as a hardware wallet.
std::string m_chain
Bitcoin mainnet, testnet, etc.
const std::string NetworkArg() const
UniValue DisplayAddress(const std::string &descriptor) const
Display address on the device.
UniValue GetDescriptors(const int account)
Get receive and change Descriptor(s) from device for a given account.
bool SignTransaction(PartiallySignedTransaction &psbt, std::string &error)
Sign PartiallySignedTransaction on the device.
std::string m_fingerprint
Master key fingerprint of the signer.
std::string m_command
The command which handles interaction with the external signer.
static bool Enumerate(const std::string &command, std::vector< ExternalSigner > &signers, const std::string chain)
Obtain a list of signers.
ExternalSigner(const std::string &command, const std::string chain, const std::string &fingerprint, const std::string name)
const std::string & get_str() const
const std::string & getValStr() const
const std::vector< UniValue > & getValues() const
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in)
Execute a command which returns JSON, and parse the result.
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) unsigned char member types only.
A version of CTransaction with the PSBT format.
std::vector< PSBTInput > inputs
bool error(const char *fmt, const Args &... args)
const UniValue & find_value(const UniValue &obj, const std::string &name)
std::vector< Byte > ParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
std::string EncodeBase64(Span< const unsigned char > input)
static const int PROTOCOL_VERSION
network protocol versioning