remote-wallet: Expose Ledger app settings
This commit is contained in:
parent
4ab98fff02
commit
2dabcac0da
|
@ -67,6 +67,23 @@ mod commands {
|
|||
pub const SIGN_MESSAGE: u8 = 0x06;
|
||||
}
|
||||
|
||||
enum ConfigurationVersion {
|
||||
Deprecated(Vec<u8>),
|
||||
Current(Vec<u8>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PubkeyDisplayMode {
|
||||
Short,
|
||||
Long,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LedgerSettings {
|
||||
pub enable_blind_signing: bool,
|
||||
pub pubkey_display: PubkeyDisplayMode,
|
||||
}
|
||||
|
||||
/// Ledger Wallet device
|
||||
pub struct LedgerWallet {
|
||||
pub device: hidapi::HidDevice,
|
||||
|
@ -275,26 +292,50 @@ impl LedgerWallet {
|
|||
}
|
||||
|
||||
fn get_firmware_version(&self) -> Result<FirmwareVersion, RemoteWalletError> {
|
||||
if let Ok(version) = self._send_apdu(commands::GET_APP_CONFIGURATION, 0, 0, &[], false) {
|
||||
if version.len() != 5 {
|
||||
self.get_configuration_vector().map(|config| match config {
|
||||
ConfigurationVersion::Current(config) => {
|
||||
FirmwareVersion::new(config[2].into(), config[3].into(), config[4].into())
|
||||
}
|
||||
ConfigurationVersion::Deprecated(config) => {
|
||||
FirmwareVersion::new(config[1].into(), config[2].into(), config[3].into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_settings(&self) -> Result<LedgerSettings, RemoteWalletError> {
|
||||
self.get_configuration_vector().map(|config| match config {
|
||||
ConfigurationVersion::Current(config) => {
|
||||
let enable_blind_signing = config[0] != 0;
|
||||
let pubkey_display = if config[1] == 0 {
|
||||
PubkeyDisplayMode::Long
|
||||
} else {
|
||||
PubkeyDisplayMode::Short
|
||||
};
|
||||
LedgerSettings {
|
||||
enable_blind_signing,
|
||||
pubkey_display,
|
||||
}
|
||||
}
|
||||
ConfigurationVersion::Deprecated(_) => LedgerSettings {
|
||||
enable_blind_signing: false,
|
||||
pubkey_display: PubkeyDisplayMode::Short,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn get_configuration_vector(&self) -> Result<ConfigurationVersion, RemoteWalletError> {
|
||||
if let Ok(config) = self._send_apdu(commands::GET_APP_CONFIGURATION, 0, 0, &[], false) {
|
||||
if config.len() != 5 {
|
||||
return Err(RemoteWalletError::Protocol("Version packet size mismatch"));
|
||||
}
|
||||
Ok(FirmwareVersion::new(
|
||||
version[2].into(),
|
||||
version[3].into(),
|
||||
version[4].into(),
|
||||
))
|
||||
Ok(ConfigurationVersion::Current(config))
|
||||
} else {
|
||||
let version =
|
||||
let config =
|
||||
self._send_apdu(commands::DEPRECATED_GET_APP_CONFIGURATION, 0, 0, &[], true)?;
|
||||
if version.len() != 4 {
|
||||
if config.len() != 4 {
|
||||
return Err(RemoteWalletError::Protocol("Version packet size mismatch"));
|
||||
}
|
||||
Ok(FirmwareVersion::new(
|
||||
version[1].into(),
|
||||
version[2].into(),
|
||||
version[3].into(),
|
||||
))
|
||||
Ok(ConfigurationVersion::Deprecated(config))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue