@@ -110,58 +110,74 @@ STATIC mp_obj_t mod_trezorconfig_is_initialized(void) {
110110STATIC MP_DEFINE_CONST_FUN_OBJ_0 (mod_trezorconfig_is_initialized_obj ,
111111 mod_trezorconfig_is_initialized );
112112
113- /// def unlock(pin: str, ext_salt: bytes | None) -> bool:
113+ /// def unlock(pin: str, ext_salt: bytes | None, pin_use_type: int = 0)
114+ /// -> tuple[bool, int]:
114115/// """
115116/// Attempts to unlock the storage with the given PIN and external salt.
116117/// Returns True on success, False on failure.
117118/// """
118- STATIC mp_obj_t mod_trezorconfig_unlock (mp_obj_t pin , mp_obj_t ext_salt ) {
119+ STATIC mp_obj_t mod_trezorconfig_unlock (size_t n_args , const mp_obj_t * args ) {
119120 mp_buffer_info_t pin_b = {0 };
120- mp_get_buffer_raise (pin , & pin_b , MP_BUFFER_READ );
121+ mp_get_buffer_raise (args [ 0 ] , & pin_b , MP_BUFFER_READ );
121122
122123 mp_buffer_info_t ext_salt_b = {0 };
123124 ext_salt_b .buf = NULL ;
124- if (ext_salt != mp_const_none ) {
125- mp_get_buffer_raise (ext_salt , & ext_salt_b , MP_BUFFER_READ );
125+ if (n_args > 1 && args [ 1 ] != mp_const_none ) {
126+ mp_get_buffer_raise (args [ 1 ] , & ext_salt_b , MP_BUFFER_READ );
126127 if (ext_salt_b .len != EXTERNAL_SALT_SIZE )
127128 mp_raise_msg (& mp_type_ValueError , "Invalid length of external salt." );
128129 }
129130
131+ pin_type_t pin_use_type = PIN_TYPE_USER ;
132+
133+ if (n_args > 2 ) {
134+ pin_use_type = mp_obj_get_int (args [2 ]);
135+ }
136+
130137 // display_clear();
131138 // display_loader_ex(0, false, 0, 0xFFFF, 0x0000, NULL, 0, 0);
132139 secbool ret = secfalse ;
133140
134141 // verify se pin first when not in emulator
135- ret = se_verifyPin (pin_b .buf );
142+ ret = se_verifyPin (pin_b .buf , pin_use_type );
136143 if (ret != sectrue ) {
137144 if (!pin_state .pin_unlocked_initialized ) {
138145 pin_state .pin_unlocked = false;
139146 pin_state .pin_unlocked_initialized = true;
140147 }
141- return mp_const_false ;
148+ mp_obj_t tuple [2 ] = {mp_const_false , mp_obj_new_int (0 )};
149+ return mp_obj_new_tuple (2 , tuple );
142150 }
143151
152+ pin_result_t pin_type = se_get_pin_result_type ();
153+
144154 // fpsensor_data_init();
145155 fpsensor_data_init_start ();
146156 pin_state .pin_unlocked = true;
147157 pin_state .pin_unlocked_initialized = true;
148158 pin_state .fp_unlocked = true;
149159 pin_state .fp_unlocked_initialized = true;
150- return mp_const_true ;
160+
161+ mp_obj_tuple_t * tuple = MP_OBJ_TO_PTR (mp_obj_new_tuple (2 , NULL ));
162+ tuple -> items [0 ] = mp_const_true ;
163+ tuple -> items [1 ] = mp_obj_new_int (pin_type );
164+ return MP_OBJ_FROM_PTR (tuple );
151165}
152- STATIC MP_DEFINE_CONST_FUN_OBJ_2 (mod_trezorconfig_unlock_obj ,
153- mod_trezorconfig_unlock );
166+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mod_trezorconfig_unlock_obj , 2 , 3 ,
167+ mod_trezorconfig_unlock );
154168
155- /// def check_pin(pin: str, ext_salt: bytes | None) -> bool:
169+ /// def check_pin(pin: str, ext_salt: bytes | None, pin_use_type: int = 0) ->
170+ /// bool:
156171/// """
157172/// Check the given PIN with the given external salt.
158173/// Returns True on success, False on failure.
159174/// """
160- STATIC mp_obj_t mod_trezorconfig_check_pin (mp_obj_t pin , mp_obj_t ext_salt ) {
161- return mod_trezorconfig_unlock (pin , ext_salt );
175+ STATIC mp_obj_t mod_trezorconfig_check_pin (size_t n_args ,
176+ const mp_obj_t * args ) {
177+ return mod_trezorconfig_unlock (n_args , args );
162178}
163- STATIC MP_DEFINE_CONST_FUN_OBJ_2 (mod_trezorconfig_check_pin_obj ,
164- mod_trezorconfig_check_pin );
179+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mod_trezorconfig_check_pin_obj , 2 , 3 ,
180+ mod_trezorconfig_check_pin );
165181
166182/// def lock() -> None:
167183/// """
@@ -578,6 +594,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_wipe_obj,
578594 mod_trezorconfig_wipe );
579595
580596#ifndef TREZOR_EMULATOR
597+ /// def se_import_mnemonic(mnemonic: bytes) -> bool:
598+ /// """
599+ /// Import mnemonic to SE.
600+ /// """
581601STATIC mp_obj_t mod_trezorconfig_se_import_mnemonic (mp_obj_t mnemonic ) {
582602 mp_buffer_info_t mnemo = {0 };
583603 mp_get_buffer_raise (mnemonic , & mnemo , MP_BUFFER_READ );
@@ -592,6 +612,35 @@ STATIC mp_obj_t mod_trezorconfig_se_import_mnemonic(mp_obj_t mnemonic) {
592612STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mod_trezorconfig_se_import_mnemonic_obj ,
593613 mod_trezorconfig_se_import_mnemonic );
594614
615+ /// def se_import_slip39(mnemonic: bytes, backup_type: int, identifier: int |
616+ /// None, iteration_exponent: int | None) -> bool:
617+ /// """
618+ /// Import slip39 to SE.
619+ /// """
620+ STATIC mp_obj_t mod_trezorconfig_se_import_slip39 (size_t n_args ,
621+ const mp_obj_t * args ) {
622+ mp_buffer_info_t master_secret_info = {0 };
623+ mp_get_buffer_raise (args [0 ], & master_secret_info , MP_BUFFER_READ );
624+
625+ uint8_t backup_type = trezor_obj_get_uint8 (args [1 ]);
626+ uint16_t identifier = 0 ;
627+ if (args [2 ] != mp_const_none ) {
628+ identifier = trezor_obj_get_uint (args [2 ]);
629+ }
630+ uint8_t iteration_exponent = trezor_obj_get_uint8 (args [3 ]);
631+
632+ if (sectrue != se_import_slip39 (master_secret_info .buf ,
633+ master_secret_info .len , backup_type ,
634+ identifier , iteration_exponent )) {
635+ return mp_const_false ;
636+ }
637+ return mp_const_true ;
638+ }
639+
640+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (
641+ mod_trezorconfig_se_import_slip39_obj , 4 , 4 ,
642+ mod_trezorconfig_se_import_slip39 );
643+
595644/// def se_export_mnemonic() -> bytes:
596645/// """
597646/// Export mnemonic from SE.
@@ -777,6 +826,8 @@ STATIC const mp_rom_map_elem_t mp_module_trezorconfig_globals_table[] = {
777826#ifndef TREZOR_EMULATOR
778827 {MP_ROM_QSTR (MP_QSTR_se_import_mnemonic ),
779828 MP_ROM_PTR (& mod_trezorconfig_se_import_mnemonic_obj )},
829+ {MP_ROM_QSTR (MP_QSTR_se_import_slip39 ),
830+ MP_ROM_PTR (& mod_trezorconfig_se_import_slip39_obj )},
780831 {MP_ROM_QSTR (MP_QSTR_se_export_mnemonic ),
781832 MP_ROM_PTR (& mod_trezorconfig_se_export_mnemonic_obj )},
782833 {MP_ROM_QSTR (MP_QSTR_get_serial ),
0 commit comments