@@ -30,14 +30,15 @@ use crypto::key::{
3030} ;
3131use serialization:: { Decode , DecodeAll , Encode } ;
3232use utils:: ensure;
33+ use wallet_types:: hw_data:: LedgerFullInfo ;
3334
3435use ledger_lib:: Exchange ;
3536use mintlayer_ledger_messages:: {
3637 decode_all as ledger_decode_all, encode as ledger_encode, AddrType , Amount as LAmount ,
3738 Bip32Path as LedgerBip32Path , CoinType , InputAdditionalInfoReq , Ins ,
3839 OutputValue as LOutputValue , P1SignTx , PubKeyP1 , PublicKeyReq , SignMessageReq , SignTxReq ,
3940 TxInput as LTxInput , TxInputReq , TxMetadataReq , TxOutput as LTxOutput , TxOutputReq , APDU_CLASS ,
40- H256 as LH256 , P1_APP_NAME , P1_SIGN_NEXT , P1_SIGN_START , P2_DONE , P2_SIGN_MORE ,
41+ H256 as LH256 , P1_APP_NAME , P1_GET_VERSION , P1_SIGN_NEXT , P1_SIGN_START , P2_DONE , P2_SIGN_MORE ,
4142} ;
4243
4344const MAX_ADPU_LEN : usize = ( u8:: MAX - 5 ) as usize ; // 4 bytes for the header + 1 for len
@@ -136,11 +137,15 @@ pub async fn sign_challenge<L: Exchange>(
136137
137138pub async fn get_app_name < L : Exchange > ( ledger : & mut L ) -> Result < Vec < u8 > , ledger_lib:: Error > {
138139 let msg_buf = [ APDU_CLASS , Ins :: APP_NAME , P1_APP_NAME , P2_DONE ] ;
139- ledger. exchange ( & msg_buf, Duration :: from_millis ( 100 ) ) . await
140+ ledger. exchange ( & msg_buf, Duration :: from_millis ( 500 ) ) . await
140141}
141142
142- #[ allow( dead_code) ]
143- pub async fn check_current_app < L : Exchange > ( ledger : & mut L ) -> SignerResult < ( ) > {
143+ async fn get_app_version < L : Exchange > ( ledger : & mut L ) -> Result < Vec < u8 > , ledger_lib:: Error > {
144+ let msg_buf = [ APDU_CLASS , Ins :: GET_VERSION , P1_GET_VERSION , P2_DONE ] ;
145+ ledger. exchange ( & msg_buf, Duration :: from_millis ( 500 ) ) . await
146+ }
147+
148+ pub async fn check_current_app < L : Exchange > ( ledger : & mut L ) -> SignerResult < LedgerFullInfo > {
144149 let resp = get_app_name ( ledger)
145150 . await
146151 . map_err ( |err| LedgerError :: DeviceError ( err. to_string ( ) ) ) ?;
@@ -152,7 +157,20 @@ pub async fn check_current_app<L: Exchange>(ledger: &mut L) -> SignerResult<()>
152157 LedgerError :: DifferentActiveApp ( name)
153158 ) ;
154159
155- Ok ( ( ) )
160+ let resp = get_app_version ( ledger)
161+ . await
162+ . map_err ( |err| LedgerError :: DeviceError ( err. to_string ( ) ) ) ?;
163+ let ver = ok_response ( resp) ?;
164+ let app_version = match ver. as_slice ( ) {
165+ [ major, minor, patch] => common:: primitives:: semver:: SemVer {
166+ major : * major,
167+ minor : * minor,
168+ patch : * patch as u16 ,
169+ } ,
170+ _ => return Err ( SignerError :: LedgerError ( LedgerError :: InvalidResponse ) ) ,
171+ } ;
172+
173+ Ok ( LedgerFullInfo { app_version } )
156174}
157175
158176pub async fn get_extended_public_key < L : Exchange > (
0 commit comments