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