2019-04-27 13:10:35 -04:00
|
|
|
// Copyright (c) 2018-2021 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2021-03-18 10:17:39 -03:00
|
|
|
#ifndef BITCOIN_EXTERNAL_SIGNER_H
|
|
|
|
#define BITCOIN_EXTERNAL_SIGNER_H
|
2019-04-27 13:10:35 -04:00
|
|
|
|
|
|
|
#include <univalue.h>
|
2019-02-15 08:54:29 -03:00
|
|
|
#include <util/system.h>
|
2019-04-27 13:10:35 -04:00
|
|
|
|
2021-04-13 03:02:10 -04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-08-04 17:26:01 -04:00
|
|
|
struct PartiallySignedTransaction;
|
|
|
|
|
2019-04-27 13:10:35 -04:00
|
|
|
//! Enables interaction with an external signing device or service, such as
|
|
|
|
//! a hardware wallet. See doc/external-signer.md
|
|
|
|
class ExternalSigner
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
//! The command which handles interaction with the external signer.
|
|
|
|
std::string m_command;
|
|
|
|
|
2021-06-15 10:58:55 -04:00
|
|
|
//! Bitcoin mainnet, testnet, etc
|
|
|
|
std::string m_chain;
|
|
|
|
|
|
|
|
const std::string NetworkArg() const;
|
|
|
|
|
2019-04-27 13:10:35 -04:00
|
|
|
public:
|
|
|
|
//! @param[in] command the command which handles interaction with the external signer
|
|
|
|
//! @param[in] fingerprint master key fingerprint of the signer
|
2019-02-15 08:54:29 -03:00
|
|
|
//! @param[in] chain "main", "test", "regtest" or "signet"
|
|
|
|
//! @param[in] name device name
|
2021-06-15 10:58:55 -04:00
|
|
|
ExternalSigner(const std::string& command, const std::string chain, const std::string& fingerprint, const std::string name);
|
2019-04-27 13:10:35 -04:00
|
|
|
|
|
|
|
//! Master key fingerprint of the signer
|
|
|
|
std::string m_fingerprint;
|
2019-02-15 08:54:29 -03:00
|
|
|
|
|
|
|
//! Name of signer
|
|
|
|
std::string m_name;
|
|
|
|
|
|
|
|
//! Obtain a list of signers. Calls `<command> enumerate`.
|
|
|
|
//! @param[in] command the command which handles interaction with the external signer
|
|
|
|
//! @param[in,out] signers vector to which new signers (with a unique master key fingerprint) are added
|
|
|
|
//! @param chain "main", "test", "regtest" or "signet"
|
2021-03-18 10:17:39 -03:00
|
|
|
//! @returns success
|
2021-04-13 07:41:50 -04:00
|
|
|
static bool Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain);
|
2019-02-15 08:54:29 -03:00
|
|
|
|
2020-02-19 10:33:37 -03:00
|
|
|
//! Display address on the device. Calls `<command> displayaddress --desc <descriptor>`.
|
|
|
|
//! @param[in] descriptor Descriptor specifying which address to display.
|
|
|
|
//! Must include a public key or xpub, as well as key origin.
|
|
|
|
UniValue DisplayAddress(const std::string& descriptor) const;
|
|
|
|
|
2019-10-31 06:27:47 -03:00
|
|
|
//! Get receive and change Descriptor(s) from device for a given account.
|
|
|
|
//! Calls `<command> getdescriptors --account <account>`
|
|
|
|
//! @param[in] account which BIP32 account to use (e.g. `m/44'/0'/account'`)
|
2021-03-18 10:17:39 -03:00
|
|
|
//! @returns see doc/external-signer.md
|
2021-04-13 07:41:50 -04:00
|
|
|
UniValue GetDescriptors(const int account);
|
2019-10-31 06:27:47 -03:00
|
|
|
|
2019-08-04 17:26:01 -04:00
|
|
|
//! Sign PartiallySignedTransaction on the device.
|
|
|
|
//! Calls `<command> signtransaction` and passes the PSBT via stdin.
|
|
|
|
//! @param[in,out] psbt PartiallySignedTransaction to be signed
|
|
|
|
bool SignTransaction(PartiallySignedTransaction& psbt, std::string& error);
|
2019-04-27 13:10:35 -04:00
|
|
|
};
|
|
|
|
|
2021-03-18 10:17:39 -03:00
|
|
|
#endif // BITCOIN_EXTERNAL_SIGNER_H
|