@@ -5,6 +5,7 @@ use coins_ledger::{
5
5
APDUAnswer , APDUCommand , Ledger ,
6
6
} ;
7
7
use crypto_bigint:: { ArrayEncoding , U256 } ;
8
+ use semver:: Version ;
8
9
use starknet_core:: { crypto:: Signature , types:: Felt } ;
9
10
10
11
use crate :: { Signer , VerifyingKey } ;
@@ -19,6 +20,7 @@ const EIP_2645_PURPOSE: u32 = 0x80000a55;
19
20
20
21
const EIP_2645_PATH_LENGTH : usize = 6 ;
21
22
23
+ const VERSION_SIZE : usize = 3 ;
22
24
const PUBLIC_KEY_SIZE : usize = 65 ;
23
25
const SIGNATURE_SIZE : usize = 65 ;
24
26
@@ -49,6 +51,9 @@ pub enum LedgerError {
49
51
UnexpectedResponseLength { expected : usize , actual : usize } ,
50
52
}
51
53
54
+ /// The `GetPubKey` Ledger command.
55
+ struct GetVersion ;
56
+
52
57
/// The `GetPubKey` Ledger command.
53
58
struct GetPubKeyCommand {
54
59
display : bool ,
@@ -126,6 +131,21 @@ impl LedgerStarknetApp {
126
131
Ok ( Self { transport } )
127
132
}
128
133
134
+ /// Gets the Ledger app version.
135
+ pub async fn get_version ( & self ) -> Result < Version , LedgerError > {
136
+ let response = self . transport . exchange ( & GetVersion . into ( ) ) . await ?;
137
+
138
+ let data = get_apdu_data ( & response) ?;
139
+ if data. len ( ) != VERSION_SIZE {
140
+ return Err ( LedgerError :: UnexpectedResponseLength {
141
+ expected : VERSION_SIZE ,
142
+ actual : data. len ( ) ,
143
+ } ) ;
144
+ }
145
+
146
+ Ok ( Version :: new ( data[ 0 ] as u64 , data[ 1 ] as u64 , data[ 2 ] as u64 ) )
147
+ }
148
+
129
149
/// Gets a public key from the app for a particular derivation path, with optional on-device
130
150
/// confirmation for extra security.
131
151
///
@@ -242,6 +262,19 @@ impl From<coins_ledger::LedgerError> for LedgerError {
242
262
}
243
263
}
244
264
265
+ impl From < GetVersion > for APDUCommand {
266
+ fn from ( _value : GetVersion ) -> Self {
267
+ Self {
268
+ cla : CLA_STARKNET ,
269
+ ins : 0x00 ,
270
+ p1 : 0x00 ,
271
+ p2 : 0x00 ,
272
+ data : APDUData :: new ( & [ ] ) ,
273
+ response_len : None ,
274
+ }
275
+ }
276
+ }
277
+
245
278
impl From < GetPubKeyCommand > for APDUCommand {
246
279
fn from ( value : GetPubKeyCommand ) -> Self {
247
280
let path = value
0 commit comments