File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -238,11 +238,21 @@ impl LedgerStarknetApp {
238238 . await ?,
239239 ) ?;
240240
241+ // The Ledger app prior to version 2.0.0 expects the input to be left shifted by 4 bits:
242+ let app_version = self . get_version ( ) . await ?;
243+ let adjusted_bytes: [ u8 ; 32 ] = if app_version < Version :: new ( 2 , 0 , 0 ) {
244+ ( U256 :: from_be_slice ( & hash. to_bytes_be ( ) ) << 4 )
245+ . to_be_byte_array ( )
246+ . into ( )
247+ } else {
248+ hash. to_bytes_be ( )
249+ } ;
250+
241251 let response = self
242252 . transport
243253 . exchange (
244254 & SignHashCommand2 {
245- hash : hash . to_bytes_be ( ) ,
255+ hash : adjusted_bytes ,
246256 }
247257 . into ( ) ,
248258 )
@@ -326,17 +336,12 @@ impl From<SignHashCommand1> for APDUCommand {
326336
327337impl From < SignHashCommand2 > for APDUCommand {
328338 fn from ( value : SignHashCommand2 ) -> Self {
329- // For some reasons, the Ledger app expects the input to be left shifted by 4 bits...
330- let shifted_bytes: [ u8 ; 32 ] = ( U256 :: from_be_slice ( & value. hash ) << 4 )
331- . to_be_byte_array ( )
332- . into ( ) ;
333-
334339 Self {
335340 cla : CLA_STARKNET ,
336341 ins : 0x02 ,
337342 p1 : 0x01 ,
338343 p2 : 0x00 ,
339- data : APDUData :: new ( & shifted_bytes ) ,
344+ data : APDUData :: new ( & value . hash ) ,
340345 response_len : None ,
341346 }
342347 }
You can’t perform that action at this time.
0 commit comments