Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump bitbox-api with bitcoin 0.32 as a duplicate dep #98

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = { git = "https://github.com/BitBoxSwiss/bitbox-api-rs", branch = "taproot-policies", 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
Loading