Skip to content

Commit f6763ce

Browse files
committed
feat(hwi): add hwi sign subcommand
- add signing psbt with hardware wallet
1 parent 0503d5f commit f6763ce

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/commands.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ pub enum HwiSubCommand {
474474
Register,
475475
/// Generate address
476476
Address,
477+
/// Sign PSBT with hardware wallet
478+
Sign {
479+
/// The base64-encoded PSBT to sign
480+
psbt: String,
481+
},
477482
}
478483

479484
/// Subcommands available in REPL mode.

src/handlers.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,26 @@ pub async fn handle_offline_wallet_subcommand(
379379
let address = wallet.next_unused_address(KeychainKind::External);
380380
Ok(json!({ "address": address.address }))
381381
}
382+
HwiSubCommand::Sign { psbt } => {
383+
let mut psbt = Psbt::from_str(&psbt)
384+
.map_err(|e| Error::Generic(format!("Failed to parse PSBT: {e}")))?;
385+
let device = crate::utils::connect_to_hardware_wallet(
386+
wallet.network(),
387+
wallet_opts,
388+
Some(wallet),
389+
)
390+
.await?;
391+
let signed_psbt = if let Some(device) = device {
392+
device
393+
.sign_tx(&mut psbt)
394+
.await
395+
.map_err(|e| Error::Generic(format!("Failed to sign PSBT: {e}")))?;
396+
Some(psbt.to_string())
397+
} else {
398+
None
399+
};
400+
Ok(json!({ "psbt": signed_psbt }))
401+
}
382402
},
383403
}
384404
}
@@ -837,7 +857,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
837857
wallet.persist(&mut persister)?;
838858
result
839859
};
840-
// #[cfg(not(any(feature = "sqlite")))]
860+
#[cfg(not(any(feature = "sqlite")))]
841861
let result = {
842862
let wallet = new_wallet(network, &wallet_opts)?;
843863
let blockchain_client =

0 commit comments

Comments
 (0)