-
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.
Merge branch 'master' into separate-python
- Loading branch information
Showing
4 changed files
with
114 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "hwi" | ||
version = "0.9.0" | ||
version = "0.10.0" | ||
authors = ["Daniela Brozzoni <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT" | ||
|
@@ -12,14 +12,17 @@ readme = "README.md" | |
|
||
[dependencies] | ||
bitcoin = { version = "0.32", features = ["serde", "base64"] } | ||
pyo3 = { version = "0.21.2", features = ["auto-initialize"] } | ||
serde = { version = "^1.0", features = ["derive"] } | ||
serde_json = { version = "^1.0" } | ||
pyo3 = { version = "0.21.2", features = ["auto-initialize"] } | ||
|
||
bdk_wallet = { version = "1.0.0-beta.3", optional = true } | ||
miniscript = { version = "12.0", features = ["serde"], optional = true } | ||
|
||
[dev-dependencies] | ||
serial_test = "0.6.0" | ||
|
||
[features] | ||
doctest = [] | ||
signer = ["dep:bdk_wallet"] | ||
miniscript = ["dep:miniscript"] |
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(()) | ||
} | ||
} |