-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7747b3f refactor(signer)!: add `signer` behind a non-default feature (Leonardo Lima) b25168a feat: add `HWISigner`, moved from `bdk_hwi` (Leonardo Lima) Pull request description: partially addresses bitcoindevkit/bdk#1516 ## Description - adds a new `signer.rs` that contains the previous implementation of `HWISigner`, which implements `bdk_wallet::signer::{SignerCommon, TransactionSigner}` traits. - expose the new `signer::HWISigner` as public. - updates the crate documentation. - TODO: re-add test that relies on `bdk_wallet::tests::common::get_funded_wallet` helper methods. ## Notes for Reviewers I'm unsure if the documentation covers everything needed, please let me know if I'm missing something. ACKs for top commit: notmandatory: ACK 7747b3f Tree-SHA512: 8be7d681454eba31b5495dcf6cb9b399e2d992760f92f4ffc1d553908872b1272bb2e792ca608b679caf95b66126846bbb4dff37eb6f067a8e28d14454554098
- Loading branch information
Showing
4 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bdk_wallet::bitcoin::bip32::Fingerprint; | ||
use bdk_wallet::bitcoin::secp256k1::{All, Secp256k1}; | ||
use bdk_wallet::bitcoin::Psbt; | ||
|
||
use crate::error::Error; | ||
use crate::types::{HWIChain, HWIDevice}; | ||
use crate::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 an instance from the specified device and chain | ||
pub fn from_device(device: &HWIDevice, chain: HWIChain) -> Result<HWISigner, Error> { | ||
let client = HWIClient::get_client(device, false, chain)?; | ||
Ok(HWISigner { | ||
fingerprint: device.fingerprint, | ||
client, | ||
}) | ||
} | ||
} | ||
|
||
impl SignerCommon for HWISigner { | ||
fn id(&self, _secp: &Secp256k1<All>) -> SignerId { | ||
SignerId::Fingerprint(self.fingerprint) | ||
} | ||
} | ||
|
||
impl TransactionSigner for HWISigner { | ||
fn sign_transaction( | ||
&self, | ||
psbt: &mut Psbt, | ||
_sign_options: &bdk_wallet::SignOptions, | ||
_secp: &Secp256k1<All>, | ||
) -> 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(()) | ||
} | ||
} |