Skip to content

Commit

Permalink
wip: update bicoin-0.30
Browse files Browse the repository at this point in the history
close #38
  • Loading branch information
edouardparis committed Jul 12, 2023
1 parent 035a39d commit 99a1b14
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
17 changes: 14 additions & 3 deletions src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,9 +123,19 @@ impl<T: Transport + Sync + Send> HWI for Ledger<T> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
9 changes: 4 additions & 5 deletions src/specter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -70,12 +69,12 @@ impl<T: Transport> Specter<T> {
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()))
})
}
}
Expand Down

0 comments on commit 99a1b14

Please sign in to comment.