From ea7043eade4d11e7855c69f6620e3db8f3d8311e Mon Sep 17 00:00:00 2001 From: Vihiga Tyonum Date: Mon, 3 Aug 2026 15:28:19 +0100 Subject: [PATCH] feat(hwi): Add hwi feature to dispatch and routing --- src/commands.rs | 9 +++++++++ src/handlers/mod.rs | 8 ++++---- src/handlers/offline.rs | 10 +++++++++- src/main.rs | 7 ++++++- src/utils/mod.rs | 4 ++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d921e7c..e4f9dce 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -60,6 +60,9 @@ use crate::handlers::dns::{CreateDnsTxCommand, ResolveDnsRecipientCommand}; #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] use crate::utils::parse_proxy_auth; +#[cfg(feature = "hwi")] +use crate::handlers::hwi::HwiCommand; + /// The BDK Command Line Wallet App /// /// bdk-cli is a lightweight command line bitcoin wallet, powered by BDK. @@ -207,6 +210,12 @@ pub enum CliSubCommand { /// Resolves BIP-353 DNS payment instructions for a human-readable name. #[cfg(feature = "dns_payment")] ResolveDnsRecipient(ResolveDnsRecipientCommand), + /// Hardware wallet (HWI) operations. + /// + /// List connected devices, register a wallet policy, display a receive + /// address for verification, or sign a PSBT with a hardware wallet. + #[cfg(feature = "hwi")] + Hwi(HwiCommand), } /// Wallet operation subcommands. diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 0dd871a..7d3d7f8 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -2,6 +2,8 @@ pub mod config; pub mod descriptor; #[cfg(feature = "dns_payment")] pub mod dns; +#[cfg(feature = "hwi")] +pub mod hwi; pub mod key; pub mod offline; pub mod online; @@ -13,9 +15,6 @@ pub mod online; ))] pub mod payjoin; pub mod repl; -#[cfg(feature = "hwi")] -pub mod hwi; - #[cfg(any( feature = "electrum", @@ -117,7 +116,8 @@ pub trait AppCommand { feature = "esplora", feature = "rpc", feature = "cbf", - feature = "dns_payment" + feature = "dns_payment", + feature = "hwi" ))] pub trait AsyncAppCommand { type Output: FormatOutput; diff --git a/src/handlers/offline.rs b/src/handlers/offline.rs index 15cdd26..6f86ca3 100644 --- a/src/handlers/offline.rs +++ b/src/handlers/offline.rs @@ -35,6 +35,14 @@ use { bdk_message_signer::{MessageProof, MessageSigner}, }; +/// When built with hardware wallet support, `create_tx` produces a +/// PSBT that offline signers and hardware wallets can consume. +#[cfg(feature = "hwi")] +const DEFAULT_OFFLINE_SIGNER: bool = true; +#[cfg(not(feature = "hwi"))] +const DEFAULT_OFFLINE_SIGNER: bool = false; + + impl OfflineWalletSubCommand { pub fn execute(&self, ctx: &mut AppContext>) -> Result<(), Error> { match self { @@ -543,7 +551,7 @@ pub struct BumpFeeCommand { pub shrink_address: Option
, /// Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `non_witness_utxo` and more details to let the signer identify the change output. - #[arg(long = "offline_signer")] + #[arg(long = "offline_signer", default_value_t = DEFAULT_OFFLINE_SIGNER))] pub offline_signer: bool, /// Selects which utxos *must* be added to the tx. Unconfirmed utxos cannot be used. diff --git a/src/main.rs b/src/main.rs index d13bf8a..b0b528d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use log::{debug, warn}; use crate::commands::{CliOpts, CliSubCommand, WalletSubCommand}; use crate::error::BDKCliError as Error; -#[cfg(feature = "dns_payment")] +#[cfg(any(feature = "dns_payment", feature = "hwi"))] use crate::handlers::AsyncAppCommand; use crate::handlers::{AppCommand, AppContext}; use crate::utils::output::FormatOutput; @@ -218,6 +218,11 @@ async fn run(cli_opts: CliOpts) -> Result<(), Error> { let mut ctx = AppContext::new(cli_opts.network, home_dir); cmd.execute(&mut ctx).await?.write_out(std::io::stdout())?; } + #[cfg(feature = "hwi")] + CliSubCommand::Hwi(cmd) => { + let mut ctx = AppContext::new(cli_opts.network, home_dir); + cmd.execute(&mut ctx).await?.write_out(std::io::stdout())?; + } } Ok(()) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 17a6dec..15138df 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,7 +2,7 @@ pub mod common; pub mod descriptors; pub mod output; pub use common::*; -pub mod runtime; -pub mod types; #[cfg(feature = "hwi")] pub mod hwi; +pub mod runtime; +pub mod types; -- 2.49.0