Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
c6fec94
wallet: add option to avoid script path spends
Sjors Jul 4, 2025
317b8f2
doc: add release note for keypath_only
Sjors Jun 16, 2026
5d0e71d
test: check unused xprv descriptor pubkeys
Sjors May 14, 2026
6d668f0
wallet: reject duplicate addhdkey xprvs
Sjors May 14, 2026
ef71fb5
rpc: make createwalletdescriptor smarter
Sjors Jul 3, 2025
2a567f8
doc: use a blank wallet in the multisig tutorial
Sjors Aug 25, 2026
bf0af8a
doc: add release note for #32861
Sjors Aug 25, 2026
48628a9
wallet: don't import external keys at creation if blank
Sjors Aug 1, 2025
762a32e
wallet: avoid signing via createTransaction() with external signer
Sjors Aug 1, 2025
91c0e44
wallet: make watch-only optional for external signer
Sjors Aug 1, 2025
fd0f9f1
wallet: make external_signer flag mutable
Sjors Aug 1, 2025
e66095d
wallet: extract load and unload wallet RPC helpers
Sjors Aug 26, 2026
aa632dd
wallet: report whether flag changes require reload
Sjors Aug 26, 2026
9e441bb
wallet: reload wallet when external signer flag changes
Sjors Aug 26, 2026
398b1f2
test: move mock signer path helper to the test framework
Sjors May 6, 2026
89185fe
wallet: upgrade to ExternalSignerScriptPubKeyMan in AddWalletDescriptor
Sjors Apr 29, 2026
df99c3a
wallet: sign with own keys before using the external signer
Sjors Aug 28, 2026
92cd45b
test: reuse create_outpoints in wallet_signer
Sjors Sep 28, 2026
b94d560
test: have external signer mock use a wallet
Sjors Aug 28, 2026
d95f9f4
test: add external signer mock sign modes
Sjors Sep 28, 2026
12fa81f
external_signer: require matching PSBT versions
Sjors Sep 28, 2026
4110fbd
external_signer: reject unsafe sighash types
Sjors Oct 24, 2026
4229879
iwyu: Fix warnings in `src/external_signer.cpp` and treat them as errors
Sjors Sep 28, 2026
2b801fc
external_signer: merge PSBT response instead of replacing
Sjors Oct 25, 2026
2796180
external_signer: reject finalized PSBT inputs
Sjors Sep 28, 2026
0df1a17
descriptor: Implement SubstituteMasterExtPubs
achow101 May 25, 2026
895b244
wallet: Substitute known keys when importing a descriptor
achow101 May 25, 2026
ac614dc
descriptor, musig: Return participants in GetPubKeys
achow101 Jul 31, 2026
44a26c1
test: Test importdescriptors with descriptors without privkeys
achow101 May 25, 2026
c4d69b2
rpc: add keypath_only to walletprocesspsbt
Sjors Nov 6, 2026
3335523
test: cover keypath_only in wallet_taproot.py
Sjors Jul 3, 2025
f978eb2
rpc: add keypath_only to descriptorprocesspsbt
Sjors Nov 6, 2026
8ea7ca4
test: cover keypath_only in wallet_musig.py
Sjors Jun 9, 2026
45ee976
rpc: add keypath_only to send and sendall
Sjors Nov 6, 2026
0949b3c
rpc: add keypath_only to walletcreatefundedpsbt
Sjors Nov 6, 2026
2f727b3
util: Make KeyPathElement class with private members
achow101 Sep 16, 2026
7fac137
util: Change all key path operations to operate with std::vector<KeyP…
achow101 Sep 16, 2026
e3a747c
util: Make KeyPath a subclass of std::vector and not only a typedef
achow101 Sep 21, 2026
b220521
util: Store hardened character in KeyPathElement
achow101 Sep 17, 2026
13d56f3
util: Make KeyPathElement handle multipaths
achow101 Sep 16, 2026
68fda85
descriptor: Get the multipath expansion from a multipath descriptor
achow101 Sep 21, 2026
6c4ff42
descriptor: Produce multipath descriptor in ParseScript
achow101 Sep 21, 2026
0f2dc37
descriptor: Return multipath descriptor from Parse
achow101 Sep 22, 2026
91ac9aa
descriptor: Implement multipath reconstruction
achow101 Sep 28, 2026
a7910c7
test: Add multipath reconstruction round trip checks
achow101 Sep 28, 2026
d8005a1
fuzz: Check multipath descriptor reconstruction
achow101 Sep 28, 2026
09d019a
test: Invalid multipath reconstruction tests
achow101 Sep 28, 2026
b5c4e04
wallet: Store multipath relative spkm ids in WalletDescriptor
achow101 Sep 28, 2026
3b0b34b
wallet, rpc: Store multipath relative ids on import
achow101 Sep 28, 2026
78e4619
wallet, export: Export multipath relative ids for exportwatchonly
achow101 Sep 28, 2026
ce22333
wallet, export, rpc: also list original multipath descriptors
achow101 Sep 28, 2026
81b6a29
wallet: Store automatically created descriptors as multipath
achow101 Sep 29, 2026
f57989d
test: Check for multipath descriptors in listdescriptors
achow101 Oct 5, 2026
b2c7f25
test: spend an existing output in TestBasicMining double spend case
yuvicc Nov 7, 2026
44901d8
Merge bitcoin/bitcoin#36798: test: spend an existing output in `TestB…
fanquake Nov 9, 2026
e17967d
Merge bitcoin/bitcoin 32861: wallet: smarter createwalletdescriptor
Sjors Nov 9, 2026
4e72627
Merge bitcoin/bitcoin 32857: wallet: allow skipping script paths
Sjors Nov 9, 2026
9fa1089
Merge bitcoin/bitcoin 33112: wallet: relax external signer constraints
Sjors Nov 9, 2026
f8417ee
Merge bitcoin/bitcoin 36114: wallet: harden external signer PSBT proc…
Sjors Nov 9, 2026
67dbe0c
Merge bitcoin/bitcoin 35377: wallet: substitute known keys when impor…
Sjors Nov 9, 2026
f5e1d50
Merge bitcoin/bitcoin 36442: descriptor: represent multipath descript…
Sjors Nov 9, 2026
dc260d4
Merge bitcoin/bitcoin 36443: descriptor: reconstruct multipath descri…
Sjors Nov 9, 2026
c137781
Merge bitcoin/bitcoin 36444: wallet: store multipath descriptor relat…
Sjors Nov 9, 2026
40253a7
test: configure mock signer display address
Sjors Sep 3, 2026
1c0697d
wallet: store external signer descriptor registrations
Sjors Jul 21, 2025
615c68b
external signer: add descriptor registration command
Sjors Jul 21, 2025
27e3dfa
wallet: add descriptor registration to external signer SPKM
Sjors Jul 21, 2025
b4ae3a7
wallet: register reconstructed multipath descriptors
Sjors Oct 20, 2026
f03ec84
rpc: add registerdescriptor
Sjors Jul 21, 2025
9e9ec39
external signer: display registered descriptor addresses
Sjors Apr 28, 2026
c4be584
wallet: add registered descriptor display helpers
Sjors Apr 28, 2026
354cf9c
wallet: display registered descriptor addresses
Sjors Apr 28, 2026
5d341c5
test: cover registered MuSig2 displayaddress with mock signer
Sjors Apr 29, 2026
038fe6d
external signer: sign with registered descriptors
Sjors Apr 28, 2026
640e502
wallet: add registered descriptor PSBT signer
Sjors Apr 28, 2026
61d26c3
wallet: route PSBT signing through registered descriptors
Sjors Apr 28, 2026
13e8cbe
wallet: retry FillPSBT for MuSig2 round 2
Sjors Apr 28, 2026
fd9bb93
test: cover registered MuSig2 signing dance with mock signer
Sjors Apr 29, 2026
8e470ed
external signer: surface registered signing crash as signer error
Sjors Apr 29, 2026
507a532
wallet: preserve local MuSig2 contribution when external signer fails
Sjors Apr 29, 2026
b7c6b7f
wallet: support multiple registered external signers
Sjors Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/test/03_test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ if [[ "${RUN_IWYU}" == true ]]; then
mv "${BASE_BUILD_DIR}/compile_commands_no_subtrees.json" "${BASE_BUILD_DIR}/compile_commands.json"

# TODO: Consider enforcing IWYU across the entire codebase.
FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|rpc|script|univalue/(lib|test)|util|zmq)/.*|node/(block_template_manager|blockstorage|interfaces|miner|mining_args|utxo_snapshot)|test/fuzz/(kitchen_sink|minisketch|parse_univalue)|clientversion|core_io|rest|signet|init)\.cpp'
FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|rpc|script|univalue/(lib|test)|util|zmq)/.*|node/(block_template_manager|blockstorage|interfaces|miner|mining_args|utxo_snapshot)|test/fuzz/(kitchen_sink|minisketch|parse_univalue)|clientversion|core_io|external_signer|rest|signet|init)\.cpp'
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"

Expand Down
4 changes: 4 additions & 0 deletions doc/external-signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ A future extension could add an optional return field `reachable`, in case `<cmd

This command reads request `<base64-encoded psbt>` and MUST return a JSON object. On success, it MUST contain `{"psbt": "<base64-encoded psbt>"}` updated to include any new signatures. On failure, it SHOULD contain `{"error": "<message>"}`. Presence of a key `error` with value `null` is not considered an error.

The returned PSBT MUST use the same PSBT version as the request.

The returned PSBT MUST NOT contain finalized inputs (`PSBT_IN_FINAL_SCRIPTSIG` or `PSBT_IN_FINAL_SCRIPTWITNESS`). Signatures MUST remain in the partial signature or Taproot signature fields so Bitcoin Core can check their sighash types.

PSBT SHOULD include BIP32 derivations. The command SHOULD fail if none of the BIP32 derivations match a key owned by the device.

The command SHOULD fail if the user cancels.
Expand Down
21 changes: 17 additions & 4 deletions doc/multisig-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ This tutorial also uses the default PKH derivation path to get the xpubs and doe

For a 2-of-3 multisig, create 3 wallets. These wallets contain HD seed and private keys, which will be used to sign the PSBTs and derive the xpub.

These three wallets should not be used directly for privacy reasons (public key reuse). They should only be used to sign transactions for the (watch-only) multisig wallet.
These three wallets should not be used directly for privacy reasons (public key reuse). They should only be used to sign transactions for the (watch-only) multisig wallet. To make that less likely to happen by accident, participant wallets only have singlesig legacy addresses, and no singlesig Bech32 addresses.

`addhdkey` adds an HD key to the blank wallet, which `createwalletdescriptor` then uses:

```bash
for ((n=1;n<=3;n++))
do
./build/bin/bitcoin rpc -signet createwallet "participant_${n}"
./build/bin/bitcoin rpc -signet -named createwallet wallet_name="participant_${n}" blank=true
./build/bin/bitcoin rpc -signet -rpcwallet="participant_${n}" addhdkey
./build/bin/bitcoin rpc -signet -rpcwallet="participant_${n}" createwalletdescriptor legacy
done
```

The `legacy` descriptor is only there to hold the private keys: it derives from `m/44h/1h/0h/<0;1>/*`, the same paths as the multisig descriptor defined below, and a wallet can only sign for a derivation path that one of its descriptors uses.

A later step spends from the multisig wallet, so create one more wallet to receive that payment. This one is an ordinary singlesig wallet, standing in for whoever is being paid:

```bash
./build/bin/bitcoin rpc -signet createwallet "recipient"
```

Extract the xpub of each wallet. To do this, the `derivehdkey` RPC is used.

Note that previously at least two descriptors were usually used, one for external derivation paths and one for internal ones. Since https://github.com/bitcoin/bitcoin/pull/22838 this redundancy has been eliminated by a multipath descriptor with <code><0;1></code> at the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change) change level expanding to external and internal descriptors when imported.
Expand Down Expand Up @@ -100,6 +112,7 @@ Once the wallets have already been created and this tutorial needs to be repeate
```bash
for ((n=1;n<=3;n++)); do ./build/bin/bitcoin rpc -signet loadwallet "participant_${n}"; done
./build/bin/bitcoin rpc -signet loadwallet "multisig_wallet_01"
./build/bin/bitcoin rpc -signet loadwallet "recipient"
```

### 1.4 Fund the wallet
Expand Down Expand Up @@ -138,7 +151,7 @@ PSBT is a data format that allows wallets and other tools to exchange informatio

The current PSBT version (v0) is defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki).

For simplicity, the destination address is taken from the `participant_1` wallet in the code above, but it can be any valid bitcoin address.
The destination address is taken from the `recipient` wallet.

The `walletcreatefundedpsbt` RPC is used to create and fund a transaction in the PSBT format. It is the first step in creating the PSBT.

Expand All @@ -147,7 +160,7 @@ balance=$(./build/bin/bitcoin rpc -signet -rpcwallet="multisig_wallet_01" getbal

amount=$(echo "$balance * 0.8" | bc -l | sed -e 's/^\./0./' -e 's/^-\./-0./')

destination_addr=$(./build/bin/bitcoin rpc -signet -rpcwallet="participant_1" getnewaddress)
destination_addr=$(./build/bin/bitcoin rpc -signet -rpcwallet="recipient" getnewaddress "" bech32m)

funded_psbt=$(./build/bin/bitcoin rpc -signet -rpcwallet="multisig_wallet_01" walletcreatefundedpsbt outputs="{\"$destination_addr\": $amount}" | jq -r '.psbt')
```
Expand Down
8 changes: 8 additions & 0 deletions doc/release-notes-32857.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Updated RPCs
------------

- The `send`, `sendall`, `walletprocesspsbt`, `walletcreatefundedpsbt`, and
`descriptorprocesspsbt` RPCs now accept a `keypath_only` option. When enabled,
they do not add new Taproot script-path data, sign script paths, or finalize
script-path spends. Existing script-path data and signatures remain in a
supplied PSBT. (#32857)
9 changes: 9 additions & 0 deletions doc/release-notes-32861.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Updated RPCs
------------

- `createwalletdescriptor` no longer requires the `hdkey` argument when the
wallet has no active descriptors but does have exactly one HD key added with
`addhdkey`. Previously the user had to look the key up with `listdescriptors`
and pass it in. This makes it easier to set up a blank wallet that only has
the descriptors it actually needs, which `doc/multisig-tutorial.md` now
demonstrates. (#32861)
4 changes: 2 additions & 2 deletions src/bench/descriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ static void ExpandDescriptor(benchmark::Bench& bench)
const std::pair<int64_t, int64_t> range = {0, 1000};
FlatSigningProvider provider;
std::string error;
auto descs = Parse(desc_str, provider, error);
auto desc = Parse(desc_str, provider, error);

bench.run([&] {
for (int i = range.first; i <= range.second; ++i) {
std::vector<CScript> scripts;
bool success = descs[0]->Expand(i, provider, scripts, provider);
bool success = desc->Expand(i, provider, scripts, provider);
assert(success);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/bench/wallet_encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)
CKey key = GenerateRandomKey();
FlatSigningProvider keys;
std::string error;
std::vector<std::unique_ptr<Descriptor>> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);
WalletDescriptor w_desc(std::move(desc.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);
WalletDescriptor w_desc(std::move(desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
descs.emplace_back(w_desc, keys);
}

Expand Down
5 changes: 2 additions & 3 deletions src/bench/wallet_ismine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace wallet {
static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)
Expand All @@ -49,8 +48,8 @@ static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)
key.MakeNewKey(/*fCompressed=*/true);
FlatSigningProvider keys;
std::string error;
std::vector<std::unique_ptr<Descriptor>> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);
WalletDescriptor w_desc(std::move(desc.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);
WalletDescriptor w_desc(std::move(desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
Assert(wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", /*internal=*/false));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct PSBTFillOptions {
* Whether to fill in bip32 derivation information if available.
*/
bool bip32_derivs{true};

/**
* Only add new Taproot key-path data, and only sign and finalize Taproot
* inputs using the key path. Existing script-path data is left intact.
*/
bool taproot_keypath_only{false};
};

} // namespace common
Expand Down
115 changes: 113 additions & 2 deletions src/external_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@

#include <external_signer.h>

#include <chainparams.h>
#include <common/run_command.h>
#include <core_io.h>
#include <psbt.h>
#include <pubkey.h>
#include <script/interpreter.h>
#include <script/keyorigin.h>
#include <streams.h>
#include <tinyformat.h>
#include <uint256.h>
#include <util/result.h>
#include <util/strencodings.h>
#include <util/subprocess.h>
#include <util/translation.h>
#include <util/vector.h>

#include <algorithm>
#include <cstdint>
#include <map>
#include <optional>
#include <set>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

ExternalSigner::ExternalSigner(std::vector<std::string> command, std::string chain, std::string fingerprint, std::string name)
Expand Down Expand Up @@ -77,6 +90,49 @@ UniValue ExternalSigner::GetDescriptors(const int account)
return RunCommandParseJSON(Cat(m_command, Cat(Cat({"--fingerprint", m_fingerprint}, NetworkArg()), {"getdescriptors", "--account", strprintf("%d", account)})), "");
}

UniValue ExternalSigner::RegisterDescriptor(const std::string& name, const std::string& descriptor) const
{
return RunCommandParseJSON(Cat(m_command, Cat(Cat({"--fingerprint", m_fingerprint}, NetworkArg()), {"registerdescriptor", name, descriptor})), "");
}

UniValue ExternalSigner::DisplayAddressRegistered(const std::string& registration, bool change, uint32_t index) const
{
// The registration descriptor combines the chains as <receive;change>,
// so the change chain is multipath index 1.
return RunCommandParseJSON(Cat(m_command, Cat(Cat({"--fingerprint", m_fingerprint}, NetworkArg()),
{"displayaddress",
"--registration", registration,
"--index", strprintf("%u", index),
"--multipath-index", change ? "1" : "0"})), "");
}

//! Find a sighash type used by the signer that doesn't commit to all outputs;
//! a signature with SIGHASH_NONE or SIGHASH_SINGLE would let anyone alter
//! them. SIGHASH_ANYONECANPAY is acceptable, since it only permits adding
//! inputs, which does not affect us.
static std::optional<int32_t> FindUnsafeSighashType(const PartiallySignedTransaction& psbtx)
{
std::vector<int32_t> sighash_types;
for (const PSBTInput& input : psbtx.inputs) {
if (input.sighash_type) sighash_types.push_back(*input.sighash_type);
for (const auto& [_, sig] : input.partial_sigs) {
if (!sig.second.empty()) sighash_types.push_back(sig.second.back());
}
// A 64 byte taproot signature implies SIGHASH_DEFAULT, 65 bytes
// carries an explicit sighash type in the last byte
if (input.m_tap_key_sig.size() == 65) sighash_types.push_back(input.m_tap_key_sig.back());
for (const auto& [_, sig] : input.m_tap_script_sigs) {
if (sig.size() == 65) sighash_types.push_back(sig.back());
}
}

for (const int32_t sighash_type : sighash_types) {
const int32_t base_sighash_type{sighash_type & ~SIGHASH_ANYONECANPAY};
if (base_sighash_type != SIGHASH_DEFAULT && base_sighash_type != SIGHASH_ALL) return sighash_type;
}
return std::nullopt;
}

bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error)
{
// Serialize the PSBT
Expand Down Expand Up @@ -121,7 +177,62 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
return false;
}

psbtx = *signer_psbtx;
if (signer_psbtx->GetVersion() != psbtx.GetVersion()) {
error = strprintf("Signer returned PSBT version %u, expected %u", signer_psbtx->GetVersion(), psbtx.GetVersion());
return false;
}

// Finalized inputs hide the signatures from the sighash checks below.
if (std::ranges::any_of(signer_psbtx->inputs, PSBTInputSigned)) {
error = "Signer returned a PSBT with finalized inputs";
return false;
}

if (const std::optional<int32_t> sighash{FindUnsafeSighashType(*signer_psbtx)}) {
const std::string sighash_str{SighashToStr(*sighash)};
error = strprintf("Signer used an unsafe sighash type: %s", sighash_str.empty() ? "unknown" : sighash_str);
return false;
}

if (!psbtx.Merge(*signer_psbtx)) {
error = "Signer returned a PSBT for a different transaction";
return false;
}

return true;
}

bool ExternalSigner::SignTransactionRegistered(PartiallySignedTransaction& psbtx,
const std::string& registration,
std::string& error)
{
// Serialize the PSBT
DataStream ssTx{};
ssTx << psbtx;

const std::vector<std::string> command = Cat(m_command, Cat({"--stdin", "--fingerprint", m_fingerprint}, NetworkArg()));

// The registration is base64 encoded by HWI and therefore contains no
// whitespace for shlex to split when the command is read from stdin.
const std::string stdinStr = "signtx " + EncodeBase64(ssTx.str()) + " --registration " + registration;

const UniValue signer_result = RunCommandParseJSON(command, stdinStr);

if (signer_result.find_value("error").isStr()) {
error = signer_result.find_value("error").get_str();
return false;
}
if (!signer_result.find_value("psbt").isStr()) {
error = "Unexpected result from signer";
return false;
}

util::Result<PartiallySignedTransaction> signer_psbtx = DecodeBase64PSBT(signer_result.find_value("psbt").get_str());
if (!signer_psbtx) {
error = strprintf("TX decode failed %s", util::ErrorString(signer_psbtx).original);
return false;
}

psbtx = *signer_psbtx;
return true;
}
32 changes: 31 additions & 1 deletion src/external_signer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef BITCOIN_EXTERNAL_SIGNER_H
#define BITCOIN_EXTERNAL_SIGNER_H

#include <common/system.h>
#include <univalue.h>

#include <cstdint>
#include <string>
#include <vector>

Expand Down Expand Up @@ -52,18 +52,48 @@ class ExternalSigner
//! Must include a public key or xpub, as well as key origin.
UniValue DisplayAddress(const std::string& descriptor) const;

//! Display an address from a previously registered descriptor.
//! Calls `<command> displayaddress --registration <registration>
//! --index <index> --multipath-index <0|1>`.
//! @param[in] registration opaque value returned by `registerdescriptor`
//! @param[in] change whether to show the change-chain address
//! @param[in] index address index within the chain
//! @returns signer reply, expected to contain `address`
UniValue DisplayAddressRegistered(const std::string& registration, bool change, uint32_t index) const;

//! Get receive and change Descriptor(s) from device for a given account.
//! Calls `<command> --fingerprint <fingerprint> --chain <chain> getdescriptors
//! --account <account>`.
//! @param[in] account which BIP32 account to use (e.g. `m/44'/0'/account'`)
//! @returns see doc/external-signer.md
UniValue GetDescriptors(int account);

//! Register a descriptor on the device.
//! Calls `<command> registerdescriptor <name> <descriptor>`.
//! @param[in] name descriptor name to display on the signer
//! @param[in] descriptor combined multipath descriptor
//! @returns opaque registration provided by the signer
UniValue RegisterDescriptor(const std::string& name, const std::string& descriptor) const;

//! Sign PartiallySignedTransaction on the device.
//! Calls `<command> --stdin --fingerprint <fingerprint> --chain <chain>` and passes the
//! `signtx` command and PSBT via stdin.
//! @param[in,out] psbt PartiallySignedTransaction to be signed
bool SignTransaction(PartiallySignedTransaction& psbt, std::string& error);

//! Sign a PartiallySignedTransaction using a previously registered
//! descriptor. Used for descriptors (e.g. MuSig2) that require
//! on-device registration before signing.
//!
//! Pipes `signtx <base64> --registration <registration>` to the
//! signer's stdin.
//!
//! @param[in,out] psbt PSBT to be signed
//! @param[in] registration opaque value returned by `registerdescriptor`
//! @param[out] error populated on failure
bool SignTransactionRegistered(PartiallySignedTransaction& psbt,
const std::string& registration,
std::string& error);
};

#endif // BITCOIN_EXTERNAL_SIGNER_H
7 changes: 4 additions & 3 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <crypto/hmac_sha512.h>
#include <hash.h>
#include <random.h>
#include <util/bip32.h>

#include <secp256k1.h>
#include <secp256k1_ellswift.h>
Expand Down Expand Up @@ -366,14 +367,14 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
}

std::optional<std::pair<CExtKey, KeyOriginInfo>> DeriveExtKey(const CExtKey& ext_key, const std::vector<uint32_t>& path)
std::optional<std::pair<CExtKey, KeyOriginInfo>> DeriveExtKey(const CExtKey& ext_key, const KeyPath& path)
{
CExtKey descendant = ext_key;
KeyOriginInfo origin;
origin.fingerprint = ext_key.id_key_fingerprint();
origin.path = path;
for (uint32_t i : path) {
if (!descendant.Derive(descendant, i)) return std::nullopt;
for (const KeyPathElement& i : path) {
if (!descendant.Derive(descendant, i.ChildNumber())) return std::nullopt;
}
return std::make_pair(descendant, origin);
}
Expand Down
Loading
Loading