Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.81.0
toolchain: 1.88.0
components: rustfmt, clippy
override: true
- name: rustfmt
Expand All @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
toolchain:
- 1.81.0
- 1.85.0
- nightly
os:
- ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus
bitbox-api = { version = "0.9.0", default-features = false, features = ["usb", "tokio", "multithreaded", "simulator"], optional = true }

# coldcard
coldcard = { version = "0.12.2", optional = true }
coldcard = { version = "0.13.0", optional = true }

# ledger
ledger_bitcoin_client = { version = "0.5.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# async-hwi

Current **Minimum Supported Rust Version**: v1.81
Current **Minimum Supported Rust Version**: v1.81 (1.85 if coldcard feature enabled)

```rust
/// HWI is the common Hardware Wallet Interface.
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
18 changes: 14 additions & 4 deletions src/coldcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bitcoin::{
bip32::{DerivationPath, Fingerprint, Xpub},
psbt::Psbt,
};
use coldcard::protocol::DescriptorName;
use hidapi::DeviceInfo;

use crate::{parse_version, AddressScript, DeviceKind, Error as HWIError, Version, HWI};
Expand Down Expand Up @@ -69,10 +70,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 +99,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 All @@ -121,7 +122,16 @@ impl HWI for Coldcard {
async fn sign_tx(&self, psbt: &mut Psbt) -> Result<(), HWIError> {
let mut cc = self.device()?;

let _ = cc.sign_psbt(&psbt.serialize(), api::SignMode::Signed)?;
let wallet_name = if let Some(name) = self.wallet_name.clone() {
Some(
DescriptorName::new(name)
.map_err(|_| HWIError::Unexpected("Coldcard: Invalid wallet name"))?,
)
} else {
None
};

let _ = cc.sign_psbt_miniscript(&psbt.serialize(), api::SignMode::Signed, wallet_name)?;

let tx = loop {
if let Some(tx) = cc.get_signed_tx()? {
Expand Down
20 changes: 10 additions & 10 deletions src/jade/mod.rs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/jade/pinserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl PinServerClient {
if res.status().is_success() {
res.json().await.map_err(Error::from)
} else {
Err(Error::Server(format!("{:?}", res)))
Err(Error::Server(format!("{res:?}")))
}
}
}
Expand Down
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