diff --git a/Cargo.toml b/Cargo.toml index ef6d55e92..17d5c2e77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "crates/electrum", "crates/esplora", "crates/bitcoind_rpc", - "crates/hwi", "crates/testenv", "example-crates/example_cli", "example-crates/example_electrum", diff --git a/crates/hwi/README.md b/crates/hwi/README.md deleted file mode 100644 index f31601b97..000000000 --- a/crates/hwi/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# BDK HWI Signer - -This crate contains `HWISigner`, an implementation of a `TransactionSigner` to be used with hardware wallets. \ No newline at end of file diff --git a/crates/hwi/src/lib.rs b/crates/hwi/src/lib.rs deleted file mode 100644 index 7bb7e4caf..000000000 --- a/crates/hwi/src/lib.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! HWI Signer -//! -//! This crate contains HWISigner, an implementation of a [`TransactionSigner`] to be -//! used with hardware wallets. -//! ```no_run -//! # use bdk_wallet::bitcoin::Network; -//! # use bdk_wallet::descriptor::Descriptor; -//! # use bdk_wallet::signer::SignerOrdering; -//! # use bdk_hwi::HWISigner; -//! # use bdk_wallet::{KeychainKind, SignOptions, Wallet}; -//! # use hwi::HWIClient; -//! # use std::sync::Arc; -//! # use std::str::FromStr; -//! # -//! # fn main() -> Result<(), Box> { -//! let mut devices = HWIClient::enumerate()?; -//! if devices.is_empty() { -//! panic!("No devices found!"); -//! } -//! let first_device = devices.remove(0)?; -//! let custom_signer = HWISigner::from_device(&first_device, Network::Testnet.into())?; -//! -//! # let mut wallet = Wallet::create("", "").network(Network::Testnet).create_wallet_no_persist()?; -//! # -//! // Adding the hardware signer to the BDK wallet -//! wallet.add_signer( -//! KeychainKind::External, -//! SignerOrdering(200), -//! Arc::new(custom_signer), -//! ); -//! -//! # Ok(()) -//! # } -//! ``` -//! -//! [`TransactionSigner`]: bdk_wallet::signer::TransactionSigner - -mod signer; -pub use signer::*; diff --git a/crates/hwi/src/signer.rs b/crates/hwi/src/signer.rs deleted file mode 100644 index f1b569e35..000000000 --- a/crates/hwi/src/signer.rs +++ /dev/null @@ -1,94 +0,0 @@ -use bdk_wallet::bitcoin::bip32::Fingerprint; -use bdk_wallet::bitcoin::secp256k1::{All, Secp256k1}; -use bdk_wallet::bitcoin::Psbt; - -use hwi::error::Error; -use hwi::types::{HWIChain, HWIDevice}; -use hwi::HWIClient; - -use bdk_wallet::signer::{SignerCommon, SignerError, SignerId, TransactionSigner}; - -#[derive(Debug)] -/// Custom signer for Hardware Wallets -/// -/// This ignores `sign_options` and leaves the decisions up to the hardware wallet. -pub struct HWISigner { - fingerprint: Fingerprint, - client: HWIClient, -} - -impl HWISigner { - /// Create a instance from the specified device and chain - pub fn from_device(device: &HWIDevice, chain: HWIChain) -> Result { - let client = HWIClient::get_client(device, false, chain)?; - Ok(HWISigner { - fingerprint: device.fingerprint, - client, - }) - } -} - -impl SignerCommon for HWISigner { - fn id(&self, _secp: &Secp256k1) -> SignerId { - SignerId::Fingerprint(self.fingerprint) - } -} - -impl TransactionSigner for HWISigner { - fn sign_transaction( - &self, - psbt: &mut Psbt, - _sign_options: &bdk_wallet::SignOptions, - _secp: &Secp256k1, - ) -> Result<(), SignerError> { - psbt.combine( - self.client - .sign_tx(psbt) - .map_err(|e| { - SignerError::External(format!("While signing with hardware wallet: {}", e)) - })? - .psbt, - ) - .expect("Failed to combine HW signed psbt with passed PSBT"); - Ok(()) - } -} - -// TODO: re-enable this once we have the `get_funded_wallet` test util -// #[cfg(test)] -// mod tests { -// #[test] -// fn test_hardware_signer() { -// use std::sync::Arc; -// -// use bdk_wallet::tests::get_funded_wallet; -// use bdk_wallet::signer::SignerOrdering; -// use bdk_wallet::bitcoin::Network; -// use crate::HWISigner; -// use hwi::HWIClient; -// -// let mut devices = HWIClient::enumerate().unwrap(); -// if devices.is_empty() { -// panic!("No devices found!"); -// } -// let device = devices.remove(0).unwrap(); -// let client = HWIClient::get_client(&device, true, Network::Regtest.into()).unwrap(); -// let descriptors = client.get_descriptors::(None).unwrap(); -// let custom_signer = HWISigner::from_device(&device, Network::Regtest.into()).unwrap(); -// -// let (mut wallet, _) = get_funded_wallet(&descriptors.internal[0]); -// wallet.add_signer( -// bdk_wallet::KeychainKind::External, -// SignerOrdering(200), -// Arc::new(custom_signer), -// ); -// -// let addr = wallet.get_address(bdk_wallet::AddressIndex::LastUnused); -// let mut builder = wallet.build_tx(); -// builder.drain_to(addr.script_pubkey()).drain_wallet(); -// let (mut psbt, _) = builder.finish().unwrap(); -// -// let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); -// assert!(finalized); -// } -// }