Skip to content

Commit

Permalink
bump bitbox-api with bitcoin 0.32 as a duplicate dep
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Sep 19, 2024
1 parent 1f9a287 commit c77fb2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ regex = ["dep:regex"]
[dependencies]
async-trait = "0.1.52"
futures = "0.3"
bitcoin = { version = "0.31", default-features = false, features = ["base64", "serde", "std"] }
bitcoin = { package = "bitcoin", version = "0.31", default-features = false, features = ["base64", "serde", "std"] }
bitcoin_32 = { package = "bitcoin", version = "0.32", default-features = false, features = ["base64", "serde", "std"] }

# specter & jade
tokio-serial = { version = "5.4.1", optional = true }
Expand All @@ -43,7 +44,7 @@ serde_cbor = { version = "0.11", optional = true }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] , optional = true}

# bitbox
bitbox-api = { version = "0.2.3", default-features = false, features = ["usb", "tokio", "multithreaded"], optional = true }
bitbox-api = { version = "0.5.0", default-features = false, features = ["usb", "tokio", "multithreaded"], optional = true }

# coldcard
coldcard = { version = "0.12.2", optional = true }
Expand Down
30 changes: 22 additions & 8 deletions src/bitbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bitcoin::{
};
use regex::Regex;
use std::{
convert::TryFrom,
str::FromStr,
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -197,7 +198,8 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
} else {
pb::BtcCoin::Tbtc
},
&Keypath::from(path),
&Keypath::try_from(path.to_string().as_str())
.expect("Must be a bip32 derivation path"),
if self.network == bitcoin::Network::Bitcoin {
pb::btc_pub_request::XPubType::Xpub
} else {
Expand All @@ -220,7 +222,8 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
} else {
pb::BtcCoin::Tbtc
},
&Keypath::from(path),
&Keypath::try_from(path.to_string().as_str())
.expect("Must be a bip32 derivation path"),
&make_script_config_simple(pb::btc_script_config::SimpleType::P2tr),
true,
)
Expand Down Expand Up @@ -268,7 +271,8 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
} else {
pb::BtcCoin::Tbtc
},
&Keypath::from(&path),
&Keypath::try_from(path.to_string().as_str())
.expect("Must be a bip32 derivation path"),
&policy.into(),
true,
)
Expand Down Expand Up @@ -332,21 +336,26 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
}
Some(pb::BtcScriptConfigWithKeypath {
script_config: Some(policy.into()),
keypath: Keypath::from(&path).to_vec(),
keypath: path.to_u32_vec(),
})
} else {
None
};

let mut psbt_32 =
bitcoin_32::Psbt::from_str(&psbt.to_string()).expect("Must be a correct psbt");

self.client
.btc_sign_psbt(
coin_from_network(self.network),
psbt,
&mut psbt_32,
policy,
pb::btc_sign_init_request::FormatUnit::Default,
)
.await?;

*psbt = Psbt::from_str(&psbt_32.to_string()).expect("Must be a correct psbt");

Ok(())
}
}
Expand Down Expand Up @@ -497,9 +506,14 @@ pub struct KeyInfo {
impl From<KeyInfo> for KeyOriginInfo {
fn from(info: KeyInfo) -> KeyOriginInfo {
KeyOriginInfo {
root_fingerprint: info.master_fingerprint,
keypath: info.path.as_ref().map(Keypath::from),
xpub: info.xpub,
root_fingerprint: info
.master_fingerprint
.map(|fg| bitcoin_32::bip32::Fingerprint::from(fg.to_bytes())),
keypath: info.path.as_ref().map(|path| {
Keypath::try_from(path.to_string().as_str())
.expect("Must be a bip32 derivation path")
}),
xpub: bitcoin_32::bip32::Xpub::from_str(&info.xpub.to_string()).expect("Correct xpub"),
}
}
}
Expand Down

0 comments on commit c77fb2c

Please sign in to comment.