Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
hwi>=2.1.1,<3
protobuf==3.20.1
requests>=2.27.1
34 changes: 34 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops::Deref;
use std::process::Command;

use bitcoin::consensus::encode::serialize;
use bitcoin::util::bip32::DerivationPath;
Expand Down Expand Up @@ -362,4 +363,37 @@ impl HWIClient {
status.into()
})
}

/// Get the installed version of hwilib. Returns None if hwi is not installed.
pub fn get_version() -> Option<String> {
Python::with_gil(|py| {
Some(
PyModule::import(py, "hwilib")
.ok()?
.getattr("__version__")
.expect("Should have a __version__")
.to_string(),
)
})
}

/// Install hwi for the current user via pip. If no version is specified, the default version from pip will be installed.
pub fn install_hwilib(version: Option<&str>) -> Result<(), Error> {
let hwi_with_version = match version {
Some(ver) => "hwi==".to_owned() + ver,
None => "hwi".to_owned(),
};
let output = Command::new("pip")
.args(vec!["install", "--user", hwi_with_version.as_str()])
.output()?;
if output.status.success() {
Ok(())
} else {
Err(Error::HWIError(
std::str::from_utf8(&output.stderr)
.expect("Non UTF-8 error while installing")
.to_string(),
))
}
}
}
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ mod tests {
break;
}
}
#[test]
#[serial]
fn test_get_version() {
HWIClient::get_version().unwrap();
}

#[test]
#[serial]
Expand All @@ -322,4 +327,10 @@ mod tests {
client.wipe_device().unwrap();
}
}
#[test]
#[serial]
#[ignore]
fn test_install_hwi() {
HWIClient::install_hwilib(Some("2.1.1")).unwrap();
}
}