-
Notifications
You must be signed in to change notification settings - Fork 30
Add Ledger signer provider #1946
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
base: feature/ledger_signer
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ pub fn estimate_status_bar_height(wallet_info: &WalletExtraInfo) -> f32 { | |
// For some reason, the status bar gets a bit of additional height. | ||
+ 4. | ||
} | ||
WalletExtraInfo::LedgerWallet { .. } => { | ||
TEXT_SIZE + 2. * VERTICAL_PADDING | ||
// Same as Trezor | ||
+ 4. | ||
} | ||
} | ||
} | ||
|
||
|
@@ -67,6 +72,16 @@ pub fn view_status_bar(wallet_info: &WalletExtraInfo) -> Option<Element<'static, | |
.size(TEXT_SIZE), | ||
] | ||
} | ||
#[cfg(feature = "ledger")] | ||
WalletExtraInfo::LedgerWallet { firmware_version } => { | ||
use iced::widget::{rich_text, span}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this out of the function? (for the trezor case too). |
||
|
||
row![rich_text([ | ||
span("Firmware version: ").font(bold_font), | ||
span(firmware_version.clone()) | ||
]) | ||
.size(TEXT_SIZE),] | ||
Comment on lines
+79
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we should be able to obtain the device name for the ledger too (which will be the model name, not the label set in Ledger Live, but it's still better than nothing). As I've mentioned in the ledger app PR, it seems like the APDU 0xE0/0x01 is "get device info" (need to check if it works when an app is opened though). One of the returned values is targetId, from which the model name can be deduced. Ledger Live sometimes calls this endpoint - https://manager.api.live.ledger.com/api/devices - to get the device model name (by comparing obtained the device's targetId with And it also has a hardcoded array of device infos and this function obtains them by targetId - https://github.com/LedgerHQ/ledger-live/blob/2dddf3a308ec6bd9fa436c7bc5bc02bcb33593e6/libs/ledgerjs/packages/devices/src/index.ts#L176-L182 |
||
} | ||
}; | ||
|
||
let status_bar = Container::new( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ use crypto::key::{ | |
}; | ||
use serialization::{Decode, DecodeAll, Encode}; | ||
use utils::ensure; | ||
use wallet_types::hw_data::LedgerDataFullInfo; | ||
|
||
use ledger_lib::Exchange; | ||
|
||
|
@@ -57,6 +58,7 @@ impl From<LedgerAddrType> for u8 { | |
struct Ins {} | ||
|
||
impl Ins { | ||
const APP_VER: u8 = 0x03; | ||
const APP_NAME: u8 = 0x04; | ||
const PUB_KEY: u8 = 0x05; | ||
const SIGN_TX: u8 = 0x06; | ||
|
@@ -199,8 +201,13 @@ pub async fn get_app_name<L: Exchange>(ledger: &mut L) -> Result<Vec<u8>, ledger | |
ledger.exchange(&msg_buf, Duration::from_millis(100)).await | ||
} | ||
|
||
async fn get_app_version<L: Exchange>(ledger: &mut L) -> Result<Vec<u8>, ledger_lib::Error> { | ||
let msg_buf = [CLA, Ins::APP_VER, 0, P2::DONE]; | ||
ledger.exchange(&msg_buf, Duration::from_millis(100)).await | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub async fn check_current_app<L: Exchange>(ledger: &mut L) -> SignerResult<()> { | ||
pub async fn check_current_app<L: Exchange>(ledger: &mut L) -> SignerResult<LedgerDataFullInfo> { | ||
let resp = get_app_name(ledger) | ||
.await | ||
.map_err(|err| LedgerError::DeviceError(err.to_string()))?; | ||
|
@@ -212,7 +219,19 @@ pub async fn check_current_app<L: Exchange>(ledger: &mut L) -> SignerResult<()> | |
LedgerError::DifferentActiveApp(name) | ||
); | ||
|
||
Ok(()) | ||
let ver = get_app_version(ledger) | ||
.await | ||
.map_err(|err| LedgerError::DeviceError(err.to_string()))?; | ||
let firmware_version = match ver.as_slice() { | ||
[major, minor, patch] => common::primitives::semver::SemVer { | ||
major: *major, | ||
minor: *minor, | ||
patch: *patch as u16, | ||
}, | ||
_ => return Err(SignerError::LedgerError(LedgerError::InvalidResponse)), | ||
}; | ||
|
||
Ok(LedgerDataFullInfo { firmware_version }) | ||
Comment on lines
+225
to
+234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a mintlayer app version, not firmware version |
||
} | ||
|
||
pub async fn get_extended_public_key<L: Exchange>( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plz don't duplicate the value.