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

Add prompt_pin and send_pin HWI commands #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,36 @@ impl HWIClient {
})
}

/// Prompt PIN on a device
pub fn prompt_pin(&self) -> Result<(), Error> {
Python::with_gil(|py| {
let func_args = (&self.hw_client,);
let output = self
.hwilib
.commands
.getattr(py, "prompt_pin")?
.call1(py, func_args)?;
let output = self.hwilib.json_dumps.call1(py, (output,))?;
let status: HWIStatus = deserialize_obj!(&output.to_string())?;
status.into()
})
}

/// Send PIN to a device
pub fn send_pin(&self, pin: &str) -> Result<(), Error> {
Python::with_gil(|py| {
let func_args = (&self.hw_client, pin);
let output = self
.hwilib
.commands
.getattr(py, "send_pin")?
.call1(py, func_args)?;
let output = self.hwilib.json_dumps.call1(py, (output,))?;
let status: HWIStatus = deserialize_obj!(&output.to_string())?;
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| {
Expand Down
39 changes: 37 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ pub mod types;

#[cfg(test)]
mod tests {
use crate::types::{self, HWIDeviceType, TESTNET};
use crate::types::{self, HWIChain, HWIDevice, HWIDeviceType, TESTNET};
use crate::HWIClient;
use std::collections::BTreeMap;
use std::str::FromStr;

use bitcoin::bip32::{DerivationPath, KeySource};
use bitcoin::bip32::{DerivationPath, Fingerprint, KeySource};
use bitcoin::locktime::absolute;
use bitcoin::psbt::{Input, Output};
use bitcoin::{secp256k1, Transaction};
Expand Down Expand Up @@ -435,6 +435,41 @@ mod tests {
}
}

#[test]
#[serial]
#[ignore = "Needs a Trezor One device for the test"]
fn test_prompt_pin_to_trezor_device() {
let client = HWIClient::find_device(
None,
Some(HWIDeviceType::Trezor),
None,
false,
Network::Testnet,
)
.unwrap();
client.prompt_pin().unwrap();
}

#[test]
#[serial]
#[ignore = "Needs a Trezor One device for the test"]
fn test_send_pin_to_trezor_device() {
let client = HWIClient::get_client(
&HWIDevice {
device_type: HWIDeviceType::Trezor,
model: "trezor_1".to_string(),
path: "webusb:000:1:2".to_string(),
needs_pin_sent: true,
needs_passphrase_sent: false,
fingerprint: Fingerprint::from_str("00000000").unwrap(),
},
false,
HWIChain::from(Network::Testnet),
)
.unwrap();
client.send_pin("123456").unwrap();
}

#[test]
#[serial]
#[ignore]
Expand Down
Loading