diff --git a/Cargo.toml b/Cargo.toml index 547dbe8..7328df6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ ledger = ["regex", "tokio", "ledger_bitcoin_client", "ledger-apdu", "ledger-tran base64 = "0.13.0" async-trait = "0.1.52" futures = "0.3" -bitcoin = { version = "0.29.1", features = ["base64", "serde"] } +bitcoin = { version = "0.30.0", default-features = false, features = ["base64", "serde", "no-std"] } # specter & ledger tokio = { version = "1.21.0", features = ["net", "time", "io-util", "sync"], optional = true } @@ -28,7 +28,7 @@ serialport = { version = "4.2", optional = true } # ledger regex = { version = "1.6.0", optional = true } -ledger_bitcoin_client = { version = "0.1.3", optional = true } +ledger_bitcoin_client = { git = "https://github.com/edouardparis/app-bitcoin-new", branch = "bitcoin-0.30", optional = true } ledger-apdu = { version = "0.10", optional = true } ledger-transport-hid = { version = "0.10", optional = true } hidapi = { version = "1.4.1", features = ["linux-static-hidraw"], default-features = false, optional = true } diff --git a/src/ledger.rs b/src/ledger.rs index 55beb9c..391a3a5 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -5,10 +5,11 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::str::FromStr; use async_trait::async_trait; -use bitcoin::util::{ +use bitcoin::{ bip32::{DerivationPath, ExtendedPubKey, Fingerprint}, psbt::Psbt, }; +use ledger_bitcoin_client::psbt::PartialSignature; use regex::Regex; use ledger_apdu::APDUAnswer; @@ -122,9 +123,19 @@ impl HWI for Ledger { async fn sign_tx(&self, psbt: &mut Psbt) -> Result<(), HWIError> { if let Some((policy, hmac)) = &self.options.wallet { let sigs = self.client.sign_psbt(psbt, policy, hmac.as_ref()).await?; - for (i, key, sig) in sigs { + for (i, sig) in sigs { let input = psbt.inputs.get_mut(i).ok_or(HWIError::DeviceDidNotSign)?; - input.partial_sigs.insert(key, sig); + match sig { + PartialSignature::Sig(key, sig) => { + input.partial_sigs.insert(key, sig); + } + PartialSignature::TapScriptSig(key, Some(tapleaf_hash), sig) => { + input.tap_script_sigs.insert((key, tapleaf_hash), sig); + } + PartialSignature::TapScriptSig(_, None, sig) => { + input.tap_key_sig = Some(sig); + } + } } Ok(()) } else { diff --git a/src/lib.rs b/src/lib.rs index 18864e6..0d3810d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub mod ledger; pub mod specter; use async_trait::async_trait; -use bitcoin::util::{ +use bitcoin::{ bip32::{DerivationPath, ExtendedPubKey, Fingerprint}, psbt::PartiallySignedTransaction as Psbt, }; diff --git a/src/specter.rs b/src/specter.rs index 17201a3..f5a802b 100644 --- a/src/specter.rs +++ b/src/specter.rs @@ -2,9 +2,8 @@ use std::fmt::Debug; use std::str::FromStr; use bitcoin::{ - consensus::encode, - util::bip32::{DerivationPath, ExtendedPubKey, Fingerprint}, - util::psbt::PartiallySignedTransaction as Psbt, + bip32::{DerivationPath, ExtendedPubKey, Fingerprint}, + psbt::PartiallySignedTransaction as Psbt, }; use serialport::{available_ports, SerialPortType}; @@ -70,12 +69,12 @@ impl Specter { self.transport .request(&format!( "\r\n\r\nsign {}\r\n", - base64::encode(encode::serialize(&psbt)) + base64::encode(psbt.serialize()) )) .await .and_then(|resp| base64::decode(resp).map_err(|e| SpecterError::Device(e.to_string()))) .and_then(|bytes| { - encode::deserialize(&bytes).map_err(|e| SpecterError::Device(e.to_string())) + Psbt::deserialize(&bytes).map_err(|e| SpecterError::Device(e.to_string())) }) } }