@@ -247,33 +247,33 @@ def get_onekey_features() -> OnekeyFeatures:
247247async def handle_Initialize (
248248 ctx : wire .Context | wire .QRContext , msg : Initialize
249249) -> Features :
250- if hasattr (msg , "is_contains_attach" ) and msg .is_contains_attach is not None :
250+ has_attach = (
251+ hasattr (msg , "is_contains_attach" ) and msg .is_contains_attach is not None
252+ )
253+ if has_attach :
251254 storage .cache .set (storage .cache .APP_COMMON_CLIENT_CONTAINS_ATTACH , b"\x01 " )
252255 else :
253256 storage .cache .delete (storage .cache .APP_COMMON_CLIENT_CONTAINS_ATTACH )
257+ ps_raw = getattr (msg , "passphrase_state" , None )
258+ if isinstance (ps_raw , bytes ):
259+ passphrase_state = ps_raw .decode () if ps_raw else None
260+ elif isinstance (ps_raw , str ):
261+ passphrase_state = ps_raw
262+ else :
263+ passphrase_state = None
254264
255- prev_session_id = storage .cache .get_session_id ()
256-
257- from apps .common import passphrase
258-
259- passphrase_pin_enabled = passphrase .is_passphrase_pin_enabled ()
260- if (
261- device_is_unlocked ()
262- and prev_session_id != msg .session_id
263- and hasattr (msg , "passphrase_state" )
264- and msg .passphrase_state is not None
265- and passphrase_pin_enabled
266- and msg .passphrase_state != ""
267- and se_thd89 .check_passphrase_btc_test_address (
268- msg .passphrase_state
269- if isinstance (msg .passphrase_state , str )
270- else msg .passphrase_state .decode ()
271- )
265+ session_id_in_msg = getattr (msg , "session_id" , None )
266+ if passphrase_state and se_thd89 .check_passphrase_btc_test_address (
267+ passphrase_state
272268 ):
273269 session_id = storage .cache .start_session ()
270+ elif has_attach and session_id_in_msg is not None and passphrase_state is None :
271+ session_id = storage .cache .start_session ()
274272 else :
275- session_id = storage .cache .start_session (msg .session_id )
273+ session_id = storage .cache .start_session (session_id_in_msg )
274+
276275 if not utils .BITCOIN_ONLY :
276+
277277 if utils .USE_THD89 :
278278 if msg .derive_cardano is not None and msg .derive_cardano :
279279 state = se_thd89 .get_session_state ()
@@ -664,7 +664,6 @@ def get_pinlocked_handler(
664664
665665 async def wrapper (ctx : wire .Context , msg : wire .Msg ) -> protobuf .MessageType :
666666 await unlock_device (ctx )
667- storage .cache .start_session ()
668667 return await orig_handler (ctx , msg )
669668
670669 return wrapper
@@ -756,7 +755,6 @@ async def handle_UnLockDevice(
756755 """Handle UnLockDevice message to unlock the device if needed."""
757756 if not config .is_unlocked ():
758757 await unlock_device (ctx , pin_use_type = PinType .USER_AND_PASSPHRASE_PIN )
759- storage .cache .start_session ()
760758
761759 # Get current device state after unlock attempt
762760 from apps .common import passphrase
0 commit comments