pub mod api;
pub mod error;
pub mod interpreter;
pub mod proto;
use crate::device::DeviceId;
pub use error::TrezorError;
#[derive(Clone, Default, zeroize::Zeroize, zeroize_derive::ZeroizeOnDrop)]
pub struct HostPin(String);
impl HostPin {
pub fn new(positions: String) -> Result<Self, TrezorError> {
if positions.is_empty() || !positions.chars().all(|c| c.is_ascii_digit()) {
return Err(TrezorError::NonNumericPin);
}
Ok(Self(positions))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl core::fmt::Debug for HostPin {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("HostPin(<redacted>)")
}
}
pub use interpreter::{
TrezorCommand, TrezorDeviceInfo, TrezorInterpreter, TrezorMultisigAddress,
TrezorMultisigAddressType, TrezorResponse,
};
#[derive(Clone, Debug)]
pub enum ManagementContext {
Setup {
host_entropy: [u8; 32],
},
Restore {
u2f_counter: u32,
},
Pin(
HostPin,
),
}
pub const TREZOR_VID: u16 = 0x1209;
pub const TREZOR_PID: u16 = 0x53c1;
pub const TREZOR_BOOTLOADER_PID: u16 = 0x53c0;
pub const TREZOR_ONE_VID: u16 = 0x534c;
pub const TREZOR_ONE_PID: u16 = 0x0001;
pub const DEFAULT_TREZOR_EMULATOR: &str = "udp:127.0.0.1:21324";
pub const TREZOR_DEVICE_ID: DeviceId = DeviceId::new(TREZOR_VID)
.with_pid(TREZOR_PID)
.with_emulator_path(DEFAULT_TREZOR_EMULATOR);
pub const TREZOR_ONE_DEVICE_ID: DeviceId = DeviceId::new(TREZOR_ONE_VID)
.with_pid(TREZOR_ONE_PID)
.with_usage_page(0xff00);