Skip to content
Closed
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
741 changes: 455 additions & 286 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ default = ["ledger", "specter", "coldcard", "bitbox", "jade", "service"]
bitbox = ["tokio", "hidapi", "bitbox-api", "regex"]
coldcard = ["dep:coldcard", "regex"]
specter = ["tokio", "tokio-serial", "serialport"]
jade = ["tokio", "tokio-serial", "serde", "serde_bytes", "serde_cbor", "serialport", "reqwest"]
jade = ["tokio", "tokio-serial", "serde", "serde_bytes", "serde_cbor", "serialport", "ureq"]
ledger = ["regex", "tokio", "ledger_bitcoin_client", "ledger-transport-hidapi", "ledger-apdu", "hidapi"]
regex = ["dep:regex"]
service = ["bitbox", "coldcard", "jade", "ledger", "specter", "tracing", "hex", "crossbeam"]
Expand All @@ -41,7 +41,7 @@ serialport = { version = "4.3", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_bytes = { version = "0.11.14", optional = true }
serde_cbor = { version = "0.11", optional = true }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] , optional = true}
ureq = { version = "3", features = ["json"], optional = true }

# bitbox
bitbox-api = { version = "0.9.0", default-features = false, features = ["usb", "tokio", "multithreaded", "simulator"], optional = true }
Expand Down
6 changes: 3 additions & 3 deletions cli/src/bin/hwi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
eprint!("{}", device.get_master_fingerprint().await?);
eprint!(" {}", device.device_kind());
if let Ok(version) = device.get_version().await.map(|v| v.to_string()) {
eprint!(" {}", version);
eprint!(" {version}");
}
eprintln!();
}
Expand Down Expand Up @@ -194,7 +194,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
_ => ("".into(), policy.clone()),
};
let res = device.is_wallet_registered(&name, &policy).await?;
eprintln!("{}", res);
eprintln!("{res}");
}
}
Commands::Psbt(PsbtCommands::Sign {
Expand All @@ -219,7 +219,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}
device.sign_tx(&mut psbt).await?;
eprintln!("{}", psbt);
eprintln!("{psbt}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ pub mod command {
}

match Jade::enumerate().await {
Err(e) => println!("{:?}", e),
Err(e) => println!("{e:?}"),
Ok(devices) => {
for device in devices {
let device = device.with_network(network);
if let Ok(info) = device.get_info().await {
if info.jade_state == jade::api::JadeState::Locked {
if let Err(e) = device.auth().await {
eprintln!("auth {:?}", e);
eprintln!("auth {e:?}");
continue;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bitbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub fn extract_script_config_policy(policy: &str) -> Result<Policy, HWIError> {

let mut pubkeys: Vec<KeyInfo> = Vec::new();
for (i, key_str) in pubkeys_str.iter().enumerate() {
descriptor_template = descriptor_template.replace(key_str, &format!("@{}", i));
descriptor_template = descriptor_template.replace(key_str, &format!("@{i}"));
let pubkey = if let Ok(key) = Xpub::from_str(key_str) {
KeyInfo {
path: None,
Expand All @@ -428,7 +428,7 @@ pub fn extract_script_config_policy(policy: &str) -> Result<Policy, HWIError> {
let derivation_path = if path_str.is_empty() {
DerivationPath::master()
} else {
DerivationPath::from_str(&format!("m/{}", path_str))
DerivationPath::from_str(&format!("m/{path_str}"))
.map_err(|e| HWIError::InvalidParameter("policy", e.to_string()))?
};

Expand Down Expand Up @@ -462,7 +462,7 @@ pub fn extract_first_appended_derivation_with_some_wildcard(
) -> Result<(Vec<DerivationPath>, bip389::Wildcard), HWIError> {
let re = Regex::new(r"@\d+/[^,)]+").unwrap();
for capture in re.find_iter(template) {
if capture.as_str().contains(&format!("@{}", key_index)) {
if capture.as_str().contains(&format!("@{key_index}")) {
if let Some((_, appended)) = capture.as_str().split_once('/') {
let (derivations, wildcard) = bip389::parse_xkey_deriv(appended)?;
if wildcard != bip389::Wildcard::None {
Expand Down
6 changes: 3 additions & 3 deletions src/coldcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ impl HWI for Coldcard {
let path = if path.starts_with("m/") {
path
} else {
format!("m/{}", path)
format!("m/{path}")
};
let path = coldcard::protocol::DerivationPath::new(&path)
.map_err(|e| HWIError::InvalidParameter("path", format!("{:?}", e)))?;
.map_err(|e| HWIError::InvalidParameter("path", format!("{e:?}")))?;
let s = self.device()?.xpub(Some(path))?;
Xpub::from_str(&s).map_err(|e| HWIError::Device(e.to_string()))
}
Expand All @@ -98,7 +98,7 @@ impl HWI for Coldcard {
name: &str,
policy: &str,
) -> Result<Option<[u8; 32]>, HWIError> {
let payload = format!("{{\"name\":\"{}\",\"desc\":\"{}\"}}", name, policy);
let payload = format!("{{\"name\":\"{name}\",\"desc\":\"{policy}\"}}");
let _ = self.device()?.miniscript_enroll(payload.as_bytes())?;
Ok(None)
}
Expand Down
22 changes: 11 additions & 11 deletions src/jade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T: Transport + Sync + Send> Jade<T> {

if let api::AuthUserResponse::PinServerRequired { http_request } = res {
let client = pinserver::PinServerClient::new();
let pin_params: api::PinParams = client.request(http_request.params).await?;
let pin_params: api::PinParams = client.request(http_request.params)?;
let handshake_completed: bool = self
.transport
.request("pin", Some(pin_params))
Expand Down Expand Up @@ -219,7 +219,7 @@ impl<T: Transport + Sync + Send> HWI for Jade<T> {
datavalues: keys
.into_iter()
.enumerate()
.map(|(i, key)| (format!("@{}", i), key))
.map(|(i, key)| (format!("@{i}"), key))
.collect(),
}),
)
Expand All @@ -244,7 +244,7 @@ impl<T: Transport + Sync + Send> HWI for Jade<T> {
let datavalues: BTreeMap<String, String> = keys
.into_iter()
.enumerate()
.map(|(i, key)| (format!("@{}", i), key))
.map(|(i, key)| (format!("@{i}"), key))
.collect();

Ok(registered.descriptor_name == name
Expand Down Expand Up @@ -501,11 +501,11 @@ impl From<serialport::Error> for TransportError {
impl std::fmt::Display for TransportError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Serialize(e) => write!(f, "{}", e),
Self::Serialize(e) => write!(f, "{e}"),
Self::NoErrorOrResult => write!(f, "No Error or Result"),
Self::NonceMismatch => write!(f, "Nonce mismatched"),
Self::Io(e) => write!(f, "{}", e),
Self::Serial(e) => write!(f, "{}", e),
Self::Io(e) => write!(f, "{e}"),
Self::Serial(e) => write!(f, "{e}"),
}
}
}
Expand Down Expand Up @@ -533,9 +533,9 @@ impl From<pinserver::Error> for JadeError {
impl std::fmt::Display for JadeError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Transport(e) => write!(f, "{}", e),
Self::Rpc(e) => write!(f, "{:?}", e),
Self::PinServer(e) => write!(f, "{:?}", e),
Self::Transport(e) => write!(f, "{e}"),
Self::Rpc(e) => write!(f, "{e:?}"),
Self::PinServer(e) => write!(f, "{e:?}"),
Self::HandShakeRefused => write!(f, "Handshake with pinserver refused"),
}
}
Expand All @@ -551,10 +551,10 @@ impl From<JadeError> for HWIError {
} else if e.code == api::ErrorCode::NetworkMismatch as i32 {
HWIError::NetworkMismatch
} else {
HWIError::Device(format!("{:?}", e))
HWIError::Device(format!("{e:?}"))
}
}
JadeError::PinServer(e) => HWIError::Device(format!("{:?}", e)),
JadeError::PinServer(e) => HWIError::Device(format!("{e:?}")),
JadeError::HandShakeRefused => {
HWIError::Device("Handshake with pinserver refused".to_string())
}
Expand Down
21 changes: 8 additions & 13 deletions src/jade/pinserver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::api;

pub struct PinServerClient {
pub client: reqwest::Client,
pub client: ureq::Agent,
}

impl Default for PinServerClient {
Expand All @@ -13,11 +13,11 @@ impl Default for PinServerClient {
impl PinServerClient {
pub fn new() -> Self {
Self {
client: reqwest::Client::new(),
client: ureq::Agent::new_with_defaults(),
}
}

pub async fn request<D>(&self, req: api::PinServerRequestParams) -> Result<D, Error>
pub fn request<D>(&self, req: api::PinServerRequestParams) -> Result<D, Error>
where
D: serde::de::DeserializeOwned,
{
Expand All @@ -26,25 +26,20 @@ impl PinServerClient {
api::PinServerUrls::Object { url, .. } => url,
};

let res = self.client.post(url).json(&req.data).send().await?;

if res.status().is_success() {
res.json().await.map_err(Error::from)
} else {
Err(Error::Server(format!("{:?}", res)))
}
let mut res = self.client.post(url).send_json(&req.data)?;
res.body_mut().read_json().map_err(Error::from)
}
}

#[derive(Debug)]
pub enum Error {
NoUrlProvided,
Client(reqwest::Error),
Client(ureq::Error),
Server(String),
}

impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
impl From<ureq::Error> for Error {
fn from(e: ureq::Error) -> Self {
Self::Client(e)
}
}
2 changes: 1 addition & 1 deletion src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<T: core::fmt::Debug> From<BitcoinClientError<T>> for HWIError {
return HWIError::UserRefused;
}
};
HWIError::Device(format!("{:#?}", e))
HWIError::Device(format!("{e:#?}"))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ pub enum Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::ParsingPolicy(e) => write!(f, "{}", e),
Error::ParsingPolicy(e) => write!(f, "{e}"),
Error::MissingPolicy => write!(f, "Missing policy"),
Error::UnsupportedVersion => write!(f, "Unsupported version"),
Error::UnsupportedInput => write!(f, "Unsupported input"),
Error::UnimplementedMethod => write!(f, "Unimplemented method"),
Error::DeviceDisconnected => write!(f, "Device disconnected"),
Error::DeviceNotFound => write!(f, "Device not found"),
Error::DeviceDidNotSign => write!(f, "Device did not sign"),
Error::Device(e) => write!(f, "{}", e),
Error::InvalidParameter(param, e) => write!(f, "Invalid parameter {}: {}", param, e),
Error::Unexpected(e) => write!(f, "{}", e),
Error::Device(e) => write!(f, "{e}"),
Error::InvalidParameter(param, e) => write!(f, "Invalid parameter {param}: {e}"),
Error::Unexpected(e) => write!(f, "{e}"),
Error::UserRefused => write!(f, "User refused operation"),
Error::NetworkMismatch => write!(f, "Device network is different"),
Error::Bip86ChangeIndex => {
Expand Down
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ fn handle_bitbox02<Message, Id>(
/// Prefer serial number for stable ID across USB ports; fall back to path.
fn bitbox_id(device_info: &ledger::DeviceInfo) -> String {
let id = if let Some(sn) = device_info.serial_number() {
format!("bitbox-{}", sn)
format!("bitbox-{sn}")
} else {
format!(
"bitbox-{:?}-{}-{}",
Expand Down
9 changes: 4 additions & 5 deletions src/specter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<T: Transport> Specter<T> {

pub async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result<Xpub, SpecterError> {
self.transport
.request(&format!("\r\n\r\nxpub {}\r\n", path))
.request(&format!("\r\n\r\nxpub {path}\r\n"))
.await
.and_then(|resp| Xpub::from_str(&resp).map_err(|e| SpecterError::Device(e.to_string())))
}
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<T: Transport> Specter<T> {

pub async fn sign(&self, psbt: &Psbt) -> Result<Psbt, SpecterError> {
self.transport
.request(&format!("\r\n\r\nsign {}\r\n", psbt))
.request(&format!("\r\n\r\nsign {psbt}\r\n"))
.await
.and_then(|resp| {
if resp == "error: User cancelled" {
Expand Down Expand Up @@ -300,8 +300,7 @@ impl SerialTransport {
})
.collect()),
Err(e) => Err(SpecterError::Device(format!(
"Error listing serial ports: {}",
e
"Error listing serial ports: {e}"
))),
}
}
Expand Down Expand Up @@ -332,7 +331,7 @@ impl std::fmt::Display for SpecterError {
match self {
Self::DeviceNotFound => write!(f, "Specter not found"),
Self::DeviceDidNotSign => write!(f, "Specter did not sign the psbt"),
Self::Device(e) => write!(f, "Specter error: {}", e),
Self::Device(e) => write!(f, "Specter error: {e}"),
Self::UserCancelled => write!(f, "User cancelled operation"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn extract_keys_and_template<T: FromStr>(policy: &str) -> Result<(String, Ve

let mut pubkeys: Vec<T> = Vec::new();
for (i, key_str) in pubkeys_str.iter().enumerate() {
descriptor_template = descriptor_template.replace(key_str, &format!("@{}", i));
descriptor_template = descriptor_template.replace(key_str, &format!("@{i}"));
let pubkey = T::from_str(key_str).map_err(|_| Error::UnsupportedInput)?;
pubkeys.push(pubkey);
}
Expand Down
Loading