diff --git a/core/SConscript.firmware b/core/SConscript.firmware index f87288cb0fe..937deadfd91 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -314,24 +314,23 @@ SOURCE_MOD += [ # rust mods SOURCE_MOD += [ + 'embed/upymod/bindgen-static.c', 'embed/upymod/rustmods.c', ] -# modutime +# modutime, modtimeq SOURCE_MOD += [ + 'embed/upymod/modtimeq.c', 'embed/upymod/modutime.c', ] SOURCE_MICROPYTHON = [ - 'vendor/micropython/extmod/modubinascii.c', + 'vendor/micropython/extmod/modtime.c', 'vendor/micropython/extmod/moductypes.c', - 'vendor/micropython/extmod/moduheapq.c', - 'vendor/micropython/extmod/modutimeq.c', - 'vendor/micropython/extmod/utime_mphal.c', 'vendor/micropython/shared/libc/abort_.c', 'vendor/micropython/shared/libc/printf.c', - 'vendor/micropython/shared/runtime/gchelper_m3.s', 'vendor/micropython/shared/runtime/gchelper_native.c', + 'vendor/micropython/shared/runtime/gchelper_thumb.s' 'vendor/micropython/shared/runtime/interrupt_char.c', 'vendor/micropython/shared/runtime/pyexec.c', 'vendor/micropython/shared/runtime/stdout_helpers.c', @@ -350,6 +349,7 @@ SOURCE_MICROPYTHON = [ 'vendor/micropython/py/builtinhelp.c', 'vendor/micropython/py/builtinimport.c', 'vendor/micropython/py/compile.c', + 'vendor/micropython/py/cstack.c', 'vendor/micropython/py/emitbc.c', 'vendor/micropython/py/emitcommon.c', 'vendor/micropython/py/emitglue.c', @@ -378,6 +378,7 @@ SOURCE_MICROPYTHON = [ 'vendor/micropython/py/objboundmeth.c', 'vendor/micropython/py/objcell.c', 'vendor/micropython/py/objclosure.c', + 'vendor/micropython/py/objcode.c', 'vendor/micropython/py/objcomplex.c', 'vendor/micropython/py/objdict.c', 'vendor/micropython/py/objenumerate.c', @@ -560,9 +561,10 @@ env.Replace( MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py', MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py', MAKEMODULEDEFS='$PYTHON vendor/micropython/py/makemoduledefs.py', + MAKEROOTPOINTERS='$PYTHON vendor/micropython/py/make_root_pointers.py', MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py', MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py', - MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross -O' + BYTECODE_OPTIMIZATION, + MPY_CROSS='vendor/micropython/mpy-cross/build/mpy-cross -O' + BYTECODE_OPTIMIZATION, PB2PY='$PYTHON ../common/protob/pb2py', ) @@ -636,6 +638,18 @@ compressed_data = env.GenerateCompressed( env.Ignore(micropy_defines, compressed_data) +# +# Micropython root pointers +# + +rootpointers_collected = env.CollectRootPointers( + target='genhdr/root_pointers.collected', source=micropy_defines) + +rootpointers_data = env.GenerateRootPointers( + target='genhdr/root_pointers.h', source=rootpointers_collected) + +env.Ignore(micropy_defines, rootpointers_data) + # # Micropython version # diff --git a/core/SConscript.unix b/core/SConscript.unix index ac5ce199206..34e4597ceb3 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -96,7 +96,10 @@ CPPDEFINES_HAL = [] PATH_HAL = [] CPPDEFINES_MOD = [] SOURCE_MOD = [ + 'vendor/micropython/extmod/vfs.c', + 'vendor/micropython/extmod/vfs_posix.c', 'vendor/micropython/extmod/vfs_posix_file.c', + 'vendor/micropython/extmod/vfs_reader.c', ] SOURCE_MOD_CRYPTO = [] RUST_UI_FEATURES = [] @@ -296,21 +299,20 @@ SOURCE_MOD += [ # rust mods SOURCE_MOD += [ + 'embed/upymod/bindgen-static.c', 'embed/upymod/rustmods.c', ] -# modutime +# modutime, modtimeq SOURCE_MOD += [ + 'embed/upymod/modtimeq.c', 'embed/upymod/modutime.c', ] SOURCE_MICROPYTHON = [ - 'vendor/micropython/extmod/modubinascii.c', + 'vendor/micropython/extmod/modtime.c', 'vendor/micropython/extmod/moductypes.c', - 'vendor/micropython/extmod/moduheapq.c', - 'vendor/micropython/extmod/moduos.c', - 'vendor/micropython/extmod/modutimeq.c', - 'vendor/micropython/extmod/utime_mphal.c', + 'vendor/micropython/extmod/modos.c', 'vendor/micropython/shared/readline/readline.c', 'vendor/micropython/shared/timeutils/timeutils.c', 'vendor/micropython/py/argcheck.c', @@ -326,6 +328,7 @@ SOURCE_MICROPYTHON = [ 'vendor/micropython/py/builtinhelp.c', 'vendor/micropython/py/builtinimport.c', 'vendor/micropython/py/compile.c', + 'vendor/micropython/py/cstack.c', 'vendor/micropython/py/emitbc.c', 'vendor/micropython/py/emitcommon.c', 'vendor/micropython/py/emitglue.c', @@ -354,7 +357,7 @@ SOURCE_MICROPYTHON = [ 'vendor/micropython/py/modstruct.c', 'vendor/micropython/py/modsys.c', 'vendor/micropython/py/modthread.c', - 'vendor/micropython/py/moduerrno.c', + 'vendor/micropython/py/moderrno.c', 'vendor/micropython/py/mpprint.c', 'vendor/micropython/py/mpstate.c', 'vendor/micropython/py/mpz.c', @@ -372,6 +375,7 @@ SOURCE_MICROPYTHON = [ 'vendor/micropython/py/objbool.c', 'vendor/micropython/py/objboundmeth.c', 'vendor/micropython/py/objcell.c', + 'vendor/micropython/py/objcode.c', 'vendor/micropython/py/objclosure.c', 'vendor/micropython/py/objcomplex.c', 'vendor/micropython/py/objdeque.c', @@ -439,6 +443,7 @@ SOURCE_UNIX = [ 'vendor/micropython/ports/unix/input.c', 'vendor/micropython/ports/unix/unix_mphal.c', 'vendor/micropython/shared/runtime/gchelper_generic.c', + 'vendor/micropython/shared/runtime/pyexec.c', ] if "app_loading" in FEATURES_WANTED: @@ -575,9 +580,10 @@ env.Replace( MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py', MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py', MAKEMODULEDEFS='$PYTHON vendor/micropython/py/makemoduledefs.py', + MAKEROOTPOINTERS='$PYTHON vendor/micropython/py/make_root_pointers.py', MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py', MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py', - MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross -O' + BYTECODE_OPTIMIZATION, + MPY_CROSS='vendor/micropython/mpy-cross/build/mpy-cross -O' + BYTECODE_OPTIMIZATION, PB2PY='$PYTHON ../common/protob/pb2py', ) @@ -652,6 +658,18 @@ compressed_data = env.GenerateCompressed( env.Ignore(micropy_defines, compressed_data) +# +# Micropython root pointers +# + +rootpointers_collected = env.CollectRootPointers( + target='genhdr/root_pointers.collected', source=micropy_defines) + +rootpointers_data = env.GenerateRootPointers( + target='genhdr/root_pointers.h', source=rootpointers_collected) + +env.Ignore(micropy_defines, rootpointers_data) + # # Micropython version # diff --git a/core/embed/projects/firmware/main.c b/core/embed/projects/firmware/main.c index 01b59baf452..827b5d59350 100644 --- a/core/embed/projects/firmware/main.c +++ b/core/embed/projects/firmware/main.c @@ -147,13 +147,12 @@ int main_func(uint32_t cmd, void *arg) { // Interpreter init LOG_INF("Starting interpreter"); mp_init(); - mp_obj_list_init(mp_sys_argv, 0); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen)); // Execute the main script LOG_INF("Executing main script"); - pyexec_frozen_module("main.py"); + pyexec_frozen_module("main.py", false); // Clean up LOG_INF("Main script finished, cleaning up"); diff --git a/core/embed/projects/firmware/mpconfigport.h b/core/embed/projects/firmware/mpconfigport.h index 5928bc3b9b8..844e0236841 100644 --- a/core/embed/projects/firmware/mpconfigport.h +++ b/core/embed/projects/firmware/mpconfigport.h @@ -80,8 +80,8 @@ #define MICROPY_ENABLE_SOURCE_LINE (1) #endif #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) +#define MICROPY_TIME_SUPPORT_Y2100_AND_BEYOND (1) #define MICROPY_STREAMS_NON_BLOCK (1) -#define MICROPY_MODULE_WEAK_LINKS (0) #define MICROPY_CAN_OVERRIDE_BUILTINS (0) #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_ENABLE_SCHEDULER (0) @@ -92,6 +92,7 @@ #define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_DESCRIPTORS (0) #define MICROPY_PY_DELATTR_SETATTR (0) +#define MICROPY_PY_BUILTINS_BYTES_HEX (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_CENTER (0) #define MICROPY_PY_BUILTINS_STR_PARTITION (1) @@ -130,37 +131,36 @@ #define MICROPY_PY_SYS_STDFILES (0) #define MICROPY_PY_SYS_STDIO_BUFFER (0) #define MICROPY_PY_SYS_PLATFORM "trezor" -#define MICROPY_PY_UERRNO (0) +#define MICROPY_PY_SYS_ARGV (0) +#define MICROPY_PY_ERRNO (0) #define MICROPY_PY_THREAD (0) #define MICROPY_PY_FSTRINGS (1) // extended modules #define MICROPY_PY_UCTYPES (!BITCOIN_ONLY) // used in FIDO -#define MICROPY_PY_UZLIB (0) -#define MICROPY_PY_UJSON (0) -#define MICROPY_PY_UOS (0) -#define MICROPY_PY_URE (0) -#define MICROPY_PY_URE_SUB (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UHASHLIB (0) -#define MICROPY_PY_UHASHLIB_MD5 (0) -#define MICROPY_PY_UHASHLIB_SHA1 (0) -#define MICROPY_PY_UCRYPTOLIB (0) -#define MICROPY_PY_UBINASCII (1) -#define MICROPY_PY_UBINASCII_CRC32 (0) -#define MICROPY_PY_URANDOM (0) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) -#define MICROPY_PY_USELECT (0) -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIMEQ (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_DEFLATE (0) +#define MICROPY_PY_JSON (0) +#define MICROPY_PY_OS (0) +#define MICROPY_PY_RE (0) +#define MICROPY_PY_RE_SUB (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_HASHLIB (0) +#define MICROPY_PY_HASHLIB_MD5 (0) +#define MICROPY_PY_HASHLIB_SHA1 (0) +#define MICROPY_PY_CRYPTOLIB (0) +#define MICROPY_PY_BINASCII (0) +#define MICROPY_PY_BINASCII_CRC32 (0) +#define MICROPY_PY_RANDOM (0) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (0) +#define MICROPY_PY_SELECT (0) +#define MICROPY_PY_TIME (1) #define MICROPY_PY_OS_DUPTERM (0) #define MICROPY_PY_LWIP_SOCK_RAW (0) #define MICROPY_PY_MACHINE (0) -#define MICROPY_PY_UWEBSOCKET (0) +#define MICROPY_PY_WEBSOCKET (0) #define MICROPY_PY_WEBREPL (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) // allocate traceback data only on debug builds @@ -180,7 +180,8 @@ // by default contains nearest git tag, which may not be present in shallow // repo, breaking reproducibility -#define MICROPY_BANNER_NAME_AND_VERSION "" +#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython" +#define MICROPY_BANNER_MACHINE "Trezor" // ============= this ends common config section =================== @@ -197,15 +198,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned int mp_uint_t; // must be pointer size typedef long mp_off_t; -#define MICROPY_BEGIN_ATOMIC_SECTION() (0) -#define MICROPY_END_ATOMIC_SECTION(state) (void)(state) -#define MICROPY_EVENT_POLL_HOOK \ - do { \ - extern void mp_handle_pending(bool); \ - mp_handle_pending(true); \ - __WFI(); \ - } while (0); - #define MICROPY_HW_BOARD_NAME "TREZORv2" #define MICROPY_HW_MCU_NAME "STM32F427xx" #define MICROPY_HW_HAS_SDCARD 1 @@ -218,9 +210,6 @@ typedef long mp_off_t; #define free(p) m_free(p) #define realloc(p, n) m_realloc(p, n) -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_t trezorconfig_ui_wait_callback; \ - // We need to provide a declaration/definition of alloca() #include diff --git a/core/embed/projects/firmware/mphalport.c b/core/embed/projects/firmware/mphalport.c index 0b138cdedd0..2dbd063f3b1 100644 --- a/core/embed/projects/firmware/mphalport.c +++ b/core/embed/projects/firmware/mphalport.c @@ -37,9 +37,12 @@ int mp_hal_stdin_rx_chr(void) { #endif } -void mp_hal_stdout_tx_strn(const char *str, size_t len) { +mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) { #ifdef USE_DBG_CONSOLE - dbg_console_write(str, len); + ssize_t written = dbg_console_write(str, len); + return (written > 0 ? written : 0); +#else + return 0; #endif } diff --git a/core/embed/projects/firmware/nlrthumb.c b/core/embed/projects/firmware/nlrthumb.c index 4cf92ddb921..12d976c1179 100644 --- a/core/embed/projects/firmware/nlrthumb.c +++ b/core/embed/projects/firmware/nlrthumb.c @@ -115,6 +115,22 @@ void nlr_pop(void) { *top = (*top)->prev; } +void nlr_push_jump_callback(nlr_jump_callback_node_t *node, nlr_jump_callback_fun_t fun) { + nlr_jump_callback_node_t **top = &MP_STATE_THREAD(nlr_jump_callback_top); + node->prev = *top; + node->fun = fun; + *top = node; +} + +void nlr_pop_jump_callback(bool run_callback) { + nlr_jump_callback_node_t **top = &MP_STATE_THREAD(nlr_jump_callback_top); + nlr_jump_callback_node_t *cur = *top; + *top = (*top)->prev; + if (run_callback) { + cur->fun(cur); + } +} + NORETURN __attribute__((naked)) void nlr_jump(void *val) { nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top); nlr_buf_t *top = *top_ptr; diff --git a/core/embed/projects/unix/main.c b/core/embed/projects/unix/main.c index fabd3ae887c..da631eca61e 100644 --- a/core/embed/projects/unix/main.c +++ b/core/embed/projects/unix/main.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2014-2017 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,33 +33,43 @@ #include #endif +#include "version.h" + #include #include #include #include +#include +#include +#include #include +#include #include #include #include #include "extmod/misc.h" +#include "extmod/modplatform.h" +#include "extmod/vfs.h" #include "extmod/vfs_posix.h" #include "genhdr/mpversion.h" #include "input.h" - #include "py/builtin.h" #include "py/compile.h" +#include "py/cstack.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/mphal.h" #include "py/mpthread.h" +#include "py/objstr.h" #include "py/repl.h" #include "py/runtime.h" -#include "py/stackctrl.h" +#include "shared/runtime/pyexec.h" +#include "stack_size.h" // Command line options, with their defaults -STATIC bool compile_only = false; -STATIC uint emit_opt = MP_EMIT_OPT_NONE; +bool mp_compile_only = false; +static uint emit_opt = MP_EMIT_OPT_NONE; #if MICROPY_ENABLE_GC // Heap size of GC heap (if enabled) @@ -66,12 +77,25 @@ STATIC uint emit_opt = MP_EMIT_OPT_NONE; long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); #endif -STATIC void stderr_print_strn(void *env, const char *str, size_t len) { +// Number of heaps to assign by default if MICROPY_GC_SPLIT_HEAP=1 +#ifndef MICROPY_GC_SPLIT_HEAP_N_HEAPS +#define MICROPY_GC_SPLIT_HEAP_N_HEAPS (1) +#endif + +#if !MICROPY_PY_SYS_PATH +#error "The unix port requires MICROPY_PY_SYS_PATH=1" +#endif + +#if !MICROPY_PY_SYS_ARGV +#error "The unix port requires MICROPY_PY_SYS_ARGV=1" +#endif + +static void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; #ifdef USE_DBG_CONSOLE dbg_console_write(str, len); #endif - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; @@ -80,7 +104,7 @@ const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; // If exc is SystemExit, return value where FORCED_EXIT bit set, // and lower 8 bits are SystemExit value. For all other exceptions, // return 1. -STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { +static int handle_uncaught_exception(mp_obj_base_t *exc) { // check for SystemExit if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { @@ -99,14 +123,12 @@ STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { } #define LEX_SRC_STR (1) -#define LEX_SRC_VSTR (2) -#define LEX_SRC_FILENAME (3) #define LEX_SRC_STDIN (4) // Returns standard error codes: 0 for success, 1 for all other errors, // except if FORCED_EXIT bit is set then script raised SystemExit and the // value of the exit is in the lower 8 bits of the return value -STATIC int execute_from_lexer(int source_kind, const void *source, +static int execute_from_lexer(int source_kind, const void *source, mp_parse_input_kind_t input_kind, bool is_repl) { mp_hal_set_interrupt_char(CHAR_CTRL_C); @@ -118,19 +140,13 @@ STATIC int execute_from_lexer(int source_kind, const void *source, const char *line = source; lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line, strlen(line), false); - } else if (source_kind == LEX_SRC_VSTR) { - const vstr_t *vstr = source; - lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr->buf, - vstr->len, false); - } else if (source_kind == LEX_SRC_FILENAME) { - lex = mp_lexer_new_from_file((const char *)source); } else { // LEX_SRC_STDIN lex = mp_lexer_new_from_fd(MP_QSTR__lt_stdin_gt_, 0, false); } qstr source_name = lex->source_name; -#if MICROPY_PY___FILE__ +#if MICROPY_MODULE___FILE__ if (input_kind == MP_PARSE_FILE_INPUT) { mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); } @@ -138,26 +154,31 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); +#if defined(MICROPY_UNIX_COVERAGE) + // allow to print the parse tree in the coverage build + if (mp_verbose_flag >= 3) { + printf("----------------\n"); + mp_parse_node_print(&mp_plat_print, parse_tree.root, 0); + printf("----------------\n"); + } +#endif + mp_obj_t module_fun = mp_compile(&parse_tree, source_name, is_repl); - if (!compile_only) { + if (!mp_compile_only) { // execute it mp_call_function_0(module_fun); - // check for pending exception - if (MP_STATE_MAIN_THREAD(mp_pending_exception) != MP_OBJ_NULL) { - mp_obj_t obj = MP_STATE_MAIN_THREAD(mp_pending_exception); - MP_STATE_MAIN_THREAD(mp_pending_exception) = MP_OBJ_NULL; - nlr_raise(obj); - } } mp_hal_set_interrupt_char(-1); + mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); nlr_pop(); return 0; } else { // uncaught exception mp_hal_set_interrupt_char(-1); + mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_CLEAR_EXCEPTIONS); return handle_uncaught_exception(nlr.ret_val); } } @@ -165,7 +186,7 @@ STATIC int execute_from_lexer(int source_kind, const void *source, #if MICROPY_USE_READLINE == 1 #include "shared/readline/readline.h" #else -STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { +static char *strjoin(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); int l2 = strlen(s2); char *s = malloc(l1 + l2 + 2); @@ -180,102 +201,41 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } #endif -STATIC int do_repl(void) { - mp_hal_stdout_tx_str("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE - "; " MICROPY_PY_SYS_PLATFORM - " version\nUse Ctrl-D to exit, Ctrl-E for paste mode\n"); - +static int do_repl(void) { #if MICROPY_USE_READLINE == 1 - // use MicroPython supplied readline + // use MicroPython supplied readline-based REPL - vstr_t line; - vstr_init(&line, 16); + int ret = 0; for (;;) { - mp_hal_stdio_mode_raw(); - - input_restart: - vstr_reset(&line); - int ret = readline(&line, ">>> "); - mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT; - - if (ret == CHAR_CTRL_C) { - // cancel input - mp_hal_stdout_tx_str("\r\n"); - goto input_restart; - } else if (ret == CHAR_CTRL_D) { - // EOF - printf("\n"); - mp_hal_stdio_mode_orig(); - vstr_clear(&line); - return 0; - } else if (ret == CHAR_CTRL_E) { - // paste mode - mp_hal_stdout_tx_str( - "\npaste mode; Ctrl-C to cancel, Ctrl-D to finish\n=== "); - vstr_reset(&line); - for (;;) { - char c = mp_hal_stdin_rx_chr(); - if (c == CHAR_CTRL_C) { - // cancel everything - mp_hal_stdout_tx_str("\n"); - goto input_restart; - } else if (c == CHAR_CTRL_D) { - // end of input - mp_hal_stdout_tx_str("\n"); - break; - } else { - // add char to buffer and echo - vstr_add_byte(&line, c); - if (c == '\r') { - mp_hal_stdout_tx_str("\n=== "); - } else { - mp_hal_stdout_tx_strn(&c, 1); - } - } - } - parse_input_kind = MP_PARSE_FILE_INPUT; - } else if (line.len == 0) { - if (ret != 0) { - printf("\n"); + if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { + if ((ret = pyexec_raw_repl()) != 0) { + break; } - goto input_restart; } else { - // got a line with non-zero length, see if it needs continuing - while (mp_repl_continue_with_input(vstr_null_terminated_str(&line))) { - vstr_add_byte(&line, '\n'); - ret = readline(&line, "... "); - if (ret == CHAR_CTRL_C) { - // cancel everything - printf("\n"); - goto input_restart; - } else if (ret == CHAR_CTRL_D) { - // stop entering compound statement - break; - } + if ((ret = pyexec_friendly_repl()) != 0) { + break; } } - - mp_hal_stdio_mode_orig(); - - ret = execute_from_lexer(LEX_SRC_VSTR, &line, parse_input_kind, true); - if (ret & FORCED_EXIT) { - return ret; - } } + return ret; #else // use simple readline + mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION); + mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE); + mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n"); + for (;;) { - char *line = prompt(">>> "); + char *line = prompt((char *)mp_repl_get_ps1()); if (line == NULL) { // EOF return 0; } while (mp_repl_continue_with_input(line)) { - char *line2 = prompt("... "); + char *line2 = prompt((char *)mp_repl_get_ps2()); if (line2 == NULL) { break; } @@ -287,29 +247,65 @@ STATIC int do_repl(void) { int ret = execute_from_lexer(LEX_SRC_STR, line, MP_PARSE_SINGLE_INPUT, true); + free(line); if (ret & FORCED_EXIT) { return ret; } - free(line); } #endif } -STATIC int do_file(const char *file) { - return execute_from_lexer(LEX_SRC_FILENAME, file, MP_PARSE_FILE_INPUT, false); +static inline int convert_pyexec_result(int ret) { +#if MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING + // With exit code handling enabled: + // pyexec returns exit code with PYEXEC_FORCED_EXIT flag set for SystemExit + // Unix port expects: 0 for success, non-zero for error/exit + if (ret & PYEXEC_FORCED_EXIT) { + // SystemExit: extract exit code from lower bits + return ret & 0xFF; + } + // Normal execution or exception: return as-is (0 for success, 1 for + // exception) + return ret; +#else + // pyexec returns 1 for success, 0 for exception, PYEXEC_FORCED_EXIT for + // SystemExit Convert to unix port's expected codes: 0 for success, 1 for + // exception, FORCED_EXIT|val for SystemExit + if (ret == 1) { + return 0; // success + } else if (ret & PYEXEC_FORCED_EXIT) { + return ret; // SystemExit with exit value in lower 8 bits + } else { + return 1; // exception + } +#endif } -STATIC int do_str(const char *str) { - return execute_from_lexer(LEX_SRC_STR, str, MP_PARSE_FILE_INPUT, false); +static int do_file(const char *file) { + return convert_pyexec_result(pyexec_file(file)); } -STATIC int usage(char **argv) { +static int do_str(const char *str) { + vstr_t vstr; + vstr.buf = (char *)str; + vstr.len = strlen(str); + int ret = pyexec_vstr(&vstr, true); + return convert_pyexec_result(ret); +} + +static void print_help(char **argv) { printf( - "usage: %s [] [-X ] [-c ] []\n" + "usage: %s [] [-X ] [-i | -c | -m | " + "]\n" "Options:\n" "--emulator-properties : print basic emulator info and exit\n" + "--version : show version information\n" + "-h : print this help message\n" + "-i : enable REPL\n" +#if MICROPY_DEBUG_PRINTERS "-v : verbose (trace various operations); can be multiple\n" +#endif "-O[N] : apply bytecode optimizations of level N\n" "\n" "Implementation specific options (-X):\n", @@ -330,25 +326,42 @@ STATIC int usage(char **argv) { heap_size); impl_opts_cnt++; #endif +#if defined(__APPLE__) + printf(" realtime -- set thread priority to realtime\n"); + impl_opts_cnt++; +#endif if (impl_opts_cnt == 0) { printf(" (none)\n"); } +} +static int invalid_args(void) { + fprintf(stderr, "Invalid command line arguments. Use -h option for help.\n"); return 1; } // Process options which set interpreter init options -STATIC void pre_process_options(int argc, char **argv) { +static void pre_process_options(int argc, char **argv) { for (int a = 1; a < argc; a++) { if (argv[a][0] == '-') { + if (strcmp(argv[a], "-h") == 0) { + print_help(argv); + exit(0); + } + if (strcmp(argv[a], "--version") == 0) { + printf("%s (trezor-core %d.%d.%d.%d); %s\n", + MICROPY_BANNER_NAME_AND_VERSION, VERSION_MAJOR, VERSION_MINOR, + VERSION_PATCH, VERSION_BUILD, MICROPY_BANNER_MACHINE); + exit(0); + } if (strcmp(argv[a], "-X") == 0) { if (a + 1 >= argc) { - exit(usage(argv)); + exit(invalid_args()); } if (0) { } else if (strcmp(argv[a + 1], "compile-only") == 0) { - compile_only = true; + mp_compile_only = true; } else if (strcmp(argv[a + 1], "emit=bytecode") == 0) { emit_opt = MP_EMIT_OPT_BYTECODE; #if MICROPY_EMIT_NATIVE @@ -391,11 +404,19 @@ STATIC void pre_process_options(int argc, char **argv) { if (heap_size < 700) { goto invalid_arg; } +#endif +#if defined(__APPLE__) + } else if (strcmp(argv[a + 1], "realtime") == 0) { +#if MICROPY_PY_THREAD + mp_thread_is_realtime_enabled = true; +#endif + // main thread was already initialized before the option + // was parsed, so we have to enable realtime here. + mp_thread_set_realtime(); #endif } else { invalid_arg: - printf("Invalid option\n"); - exit(usage(argv)); + exit(invalid_args()); } a++; } @@ -403,12 +424,27 @@ STATIC void pre_process_options(int argc, char **argv) { } } -STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { +static void set_sys_argv(char *argv[], int argc, int start_arg) { for (int i = start_arg; i < argc; i++) { mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); } } +#if MICROPY_PY_SYS_EXECUTABLE +extern mp_obj_str_t mp_sys_executable_obj; +static char *executable_path = NULL; + +static void sys_set_excecutable(char *argv0) { + if (executable_path == NULL) { + executable_path = realpath(argv0, NULL); + } + if (executable_path != NULL) { + mp_obj_str_set_data(&mp_sys_executable_obj, (byte *)executable_path, + strlen(executable_path)); + } +} +#endif + #ifdef _WIN32 #define PATHLIST_SEP_CHAR ';' #else @@ -417,7 +453,7 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { static int do_import_module(const char *modname) { mp_obj_t import_args[4]; - import_args[0] = mp_obj_new_str(modname, strlen(modname)); + import_args[0] = mp_obj_new_str_from_cstr(modname); import_args[1] = import_args[2] = mp_const_none; // Ask __import__ to handle imported module specially - set its __name__ // to __main__, and also return this leaf module, not top-level package @@ -433,16 +469,22 @@ static int do_import_module(const char *modname) { bool subpkg_tried = false; reimport: + mp_hal_set_interrupt_char(CHAR_CTRL_C); if (nlr_push(&nlr) == 0) { mod = mp_builtin___import__(MP_ARRAY_SIZE(import_args), import_args); + mp_hal_set_interrupt_char(-1); + mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); nlr_pop(); } else { // uncaught exception + mp_hal_set_interrupt_char(-1); + mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_CLEAR_EXCEPTIONS); exit(handle_uncaught_exception(nlr.ret_val) & 0xff); } + // If this module is a package, see if it has a `__main__.py`. mp_obj_t dest[2]; - mp_load_method_maybe(mod, MP_QSTR___path__, dest); + mp_load_method_protected(mod, MP_QSTR___path__, dest, true); if (dest[0] != MP_OBJ_NULL && !subpkg_tried) { subpkg_tried = true; vstr_t vstr; @@ -450,7 +492,7 @@ static int do_import_module(const char *modname) { vstr_init(&vstr, len + sizeof(".__main__")); vstr_add_strn(&vstr, modname, len); vstr_add_strn(&vstr, ".__main__", sizeof(".__main__") - 1); - import_args[0] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + import_args[0] = mp_obj_new_str_from_vstr(&vstr); goto reimport; } @@ -482,13 +524,25 @@ MP_NOINLINE int main_(int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - mp_stack_set_limit(600000 * (sizeof(void *) / 4)); - pre_process_options(argc, argv); #if MICROPY_ENABLE_GC +#if !MICROPY_GC_SPLIT_HEAP char *heap = malloc(heap_size); gc_init(heap, heap + heap_size); +#else + assert(MICROPY_GC_SPLIT_HEAP_N_HEAPS > 0); + char *heaps[MICROPY_GC_SPLIT_HEAP_N_HEAPS]; + long multi_heap_size = heap_size / MICROPY_GC_SPLIT_HEAP_N_HEAPS; + for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) { + heaps[i] = malloc(multi_heap_size); + if (i == 0) { + gc_init(heaps[i], heaps[i] + multi_heap_size); + } else { + gc_add(heaps[i], heaps[i] + multi_heap_size); + } + } +#endif #endif #if MICROPY_ENABLE_PYSTACK @@ -498,72 +552,101 @@ MP_NOINLINE int main_(int argc, char **argv) { mp_init(); +#if MICROPY_EMIT_NATIVE + // Set default emitter options + MP_STATE_VM(default_emit_opt) = emit_opt; +#else + (void)emit_opt; +#endif + #if MICROPY_ENABLE_COMPILER && MICROPY_ENABLE_SOURCE_LINE // include source lines on non-frozen builds MP_STATE_VM(include_source_lines) = true; #endif - char *home = getenv("HOME"); - char *path = getenv("MICROPYPATH"); - if (path == NULL) { +// do not let frozen emulator import live files +#ifndef TREZOR_EMULATOR_FROZEN +#if MICROPY_VFS_POSIX + { + // Mount the host FS at the root of our internal VFS + mp_obj_t args[2] = { + MP_OBJ_TYPE_GET_SLOT(&mp_type_vfs_posix, make_new)(&mp_type_vfs_posix, + 0, 0, NULL), + MP_OBJ_NEW_QSTR(MP_QSTR__slash_), + }; + mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map); + + // Make sure the root that was just mounted is the current VFS (it's always + // at the end of the linked list). Can't use chdir('/') because that will + // change the current path within the VfsPosix object. + MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_mount_table); + while (MP_STATE_VM(vfs_cur)->next != NULL) { + MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_cur)->next; + } + } +#endif +#endif + + { + // sys.path starts as [""] + mp_sys_path = mp_obj_new_list(0, NULL); + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); + + // Add colon-separated entries from MICROPYPATH. + char *home = getenv("HOME"); + char *path = getenv("MICROPYPATH"); + if (path == NULL) { #ifdef MICROPY_PY_SYS_PATH_DEFAULT - path = MICROPY_PY_SYS_PATH_DEFAULT; + path = MICROPY_PY_SYS_PATH_DEFAULT; #else - path = ".frozen"; + path = ".frozen"; #endif - } - size_t path_num = 1; // [0] is for current dir (or base dir of the script) - if (*path == ':') { - path_num++; - } - for (char *p = path; p != NULL; p = strchr(p, PATHLIST_SEP_CHAR)) { - path_num++; - if (p != NULL) { - p++; } - } - mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), path_num); - mp_obj_t *path_items; - mp_obj_list_get(mp_sys_path, &path_num, &path_items); - path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_); - { - char *p = path; - for (mp_uint_t i = 1; i < path_num; i++) { - char *p1 = strchr(p, PATHLIST_SEP_CHAR); - if (p1 == NULL) { - p1 = p + strlen(p); + if (*path == PATHLIST_SEP_CHAR) { + // First entry is empty. We've already added an empty entry to sys.path, + // so skip it. + ++path; + } + // GCC targeting RISC-V 64 reports a warning about `path_remaining` being + // clobbered by either setjmp or vfork if that variable it is allocated on + // the stack. This may probably be a compiler error as it occurs on a few + // recent GCC releases (up to 14.1.0) but LLVM doesn't report any warnings. + static bool path_remaining; + path_remaining = *path; + while (path_remaining) { + char *path_entry_end = strchr(path, PATHLIST_SEP_CHAR); + if (path_entry_end == NULL) { + path_entry_end = path + strlen(path); + path_remaining = false; } - if (p[0] == '~' && p[1] == '/' && home != NULL) { + if (path[0] == '~' && path[1] == '/' && home != NULL) { // Expand standalone ~ to $HOME int home_l = strlen(home); vstr_t vstr; - vstr_init(&vstr, home_l + (p1 - p - 1) + 1); + vstr_init(&vstr, home_l + (path_entry_end - path - 1) + 1); vstr_add_strn(&vstr, home, home_l); - vstr_add_strn(&vstr, p + 1, p1 - p - 1); - path_items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + vstr_add_strn(&vstr, path + 1, path_entry_end - path - 1); + mp_obj_list_append(mp_sys_path, mp_obj_new_str_from_vstr(&vstr)); } else { - path_items[i] = mp_obj_new_str_via_qstr(p, p1 - p); + mp_obj_list_append( + mp_sys_path, mp_obj_new_str_via_qstr(path, path_entry_end - path)); } - p = p1 + 1; + path = path_entry_end + 1; } } mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0); - // Here is some example code to create a class and instance of that class. - // First is the Python, then the C code. - // - // class TestClass: - // pass - // test_obj = TestClass() - // test_obj.attr = 42 - // - // mp_obj_t test_class_type, test_class_instance; - // test_class_type = mp_obj_new_type(QSTR_FROM_STR_STATIC("TestClass"), - // mp_const_empty_tuple, mp_obj_new_dict(0)); - // mp_store_name(QSTR_FROM_STR_STATIC("test_obj"), test_class_instance = - // mp_call_function_0(test_class_type)); mp_store_attr(test_class_instance, - // QSTR_FROM_STR_STATIC("attr"), mp_obj_new_int(42)); +#if defined(MICROPY_UNIX_COVERAGE) + { + MP_DECLARE_CONST_FUN_OBJ_0(extra_coverage_obj); + MP_DECLARE_CONST_FUN_OBJ_0(extra_cpp_coverage_obj); + mp_store_global(MP_QSTR_extra_coverage, + MP_OBJ_FROM_PTR(&extra_coverage_obj)); + mp_store_global(MP_QSTR_extra_cpp_coverage, + MP_OBJ_FROM_PTR(&extra_cpp_coverage_obj)); + } +#endif /* printf("bytes:\n"); @@ -572,6 +655,10 @@ MP_NOINLINE int main_(int argc, char **argv) { printf(" peak %d\n", m_get_peak_bytes_allocated()); */ +#if MICROPY_PY_SYS_EXECUTABLE + sys_set_excecutable(argv[0]); +#endif + const int NOTHING_EXECUTED = -2; int ret = NOTHING_EXECUTED; bool inspect = false; @@ -583,7 +670,7 @@ MP_NOINLINE int main_(int argc, char **argv) { inspect = true; } else if (strcmp(argv[a], "-c") == 0) { if (a + 1 >= argc) { - return usage(argv); + return invalid_args(); } ret = do_str(argv[a + 1]); if (ret & FORCED_EXIT) { @@ -592,7 +679,7 @@ MP_NOINLINE int main_(int argc, char **argv) { a += 1; } else if (strcmp(argv[a], "-m") == 0) { if (a + 1 >= argc) { - return usage(argv); + return invalid_args(); } default_import = false; set_sys_argv(argv, argc, a + 1); @@ -613,24 +700,23 @@ MP_NOINLINE int main_(int argc, char **argv) { p++, MP_STATE_VM(mp_optimise_value)++); } } else { - return usage(argv); + return invalid_args(); } } else { - char *pathbuf = malloc(PATH_MAX); - char *basedir = realpath(argv[a], pathbuf); + char *basedir = realpath(argv[a], NULL); if (basedir == NULL) { mp_printf(&mp_stderr_print, "%s: can't open file '%s': [Errno %d] %s\n", argv[0], argv[a], errno, strerror(errno)); // CPython exits with 2 in such case ret = 2; - free(pathbuf); break; } - // Set base dir of the script as first entry in sys.path + // Set base dir of the script as first entry in sys.path. char *p = strrchr(basedir, '/'); - path_items[0] = mp_obj_new_str_via_qstr(basedir, p - basedir); - free(pathbuf); + mp_obj_list_store(mp_sys_path, MP_OBJ_NEW_SMALL_INT(0), + mp_obj_new_str_via_qstr(basedir, p - basedir)); + free(basedir); set_sys_argv(argv, argc, a); ret = do_file(argv[a]); @@ -642,8 +728,12 @@ MP_NOINLINE int main_(int argc, char **argv) { ret = do_import_module("main"); } + const char *inspect_env = getenv("MICROPYINSPECT"); + if (inspect_env && inspect_env[0] != '\0') { + inspect = true; + } if (ret == NOTHING_EXECUTED || inspect) { - if (isatty(0)) { + if (isatty(0) || inspect) { prompt_read_history(); ret = do_repl(); prompt_write_history(); @@ -674,12 +764,36 @@ MP_NOINLINE int main_(int argc, char **argv) { } #endif +#if MICROPY_PY_BLUETOOTH + int mp_bluetooth_deinit(void); + mp_bluetooth_deinit(); +#endif + +#if MICROPY_PY_THREAD + mp_thread_deinit(); +#endif + +#if defined(MICROPY_UNIX_COVERAGE) + gc_sweep_all(); +#endif + mp_deinit(); #if MICROPY_ENABLE_GC && !defined(NDEBUG) - // We don't really need to free memory since we are about to exit the - // process, but doing so helps to find memory leaks. +// We don't really need to free memory since we are about to exit the +// process, but doing so helps to find memory leaks. +#if !MICROPY_GC_SPLIT_HEAP free(heap); +#else + for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) { + free(heaps[i]); + } +#endif +#endif + +#if MICROPY_PY_SYS_EXECUTABLE && !defined(NDEBUG) + // Again, make memory leak detector happy + free(executable_path); #endif // printf("total bytes = %d\n", m_get_total_bytes_allocated()); @@ -690,61 +804,43 @@ int coreapp_emu(int argc, char **argv) { #if MICROPY_PY_THREAD mp_thread_init(); #endif + + // Define a reasonable stack limit to detect stack overflow. + mp_uint_t stack_size = 600000 * UNIX_STACK_MULTIPLIER; + // We should capture stack top ASAP after start, and it should be // captured guaranteedly before any other stack variables are allocated. // For this, actual main (renamed main_) should not be inlined into // this function. main_() itself may have other functions inlined (with // their own stack variables), that's why we need this main/main_ split. - mp_stack_ctrl_init(); + mp_cstack_init_with_sp_here(stack_size); return main_(argc, argv); } -#if !MICROPY_VFS - -#ifdef TREZOR_EMULATOR_FROZEN -mp_import_stat_t mp_import_stat(const char *path) { - return MP_IMPORT_STAT_NO_EXIST; -} -#else -mp_import_stat_t mp_import_stat(const char *path) { - struct stat st; - if (stat(path, &st) == 0) { - if (S_ISDIR(st.st_mode)) { - return MP_IMPORT_STAT_DIR; - } else if (S_ISREG(st.st_mode)) { - return MP_IMPORT_STAT_FILE; - } - } - return MP_IMPORT_STAT_NO_EXIST; -} +void nlr_jump_fail(void *val) { +#if MICROPY_USE_READLINE == 1 + mp_hal_stdio_mode_orig(); #endif - -#if MICROPY_PY_IO -// Factory function for I/O stream classes, only needed if generic VFS subsystem -// isn't used. Note: buffering and encoding are currently ignored. -mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *pos_args, - mp_map_t *kwargs) { - enum { ARG_file, ARG_mode }; - STATIC const mp_arg_t allowed_args[] = { - {MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE}}, - {MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_r)}}, - {MP_QSTR_buffering, MP_ARG_INT, {.u_int = -1}}, - {MP_QSTR_encoding, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}}, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kwargs, MP_ARRAY_SIZE(allowed_args), - allowed_args, args); - return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, - args[ARG_mode].u_obj); + fprintf(stderr, "FATAL: uncaught NLR %p\n", val); + exit(1); } -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); -#endif -#endif +#if MICROPY_VFS_ROM_IOCTL -void nlr_jump_fail(void *val) { - printf("FATAL: uncaught NLR %p\n", val); - exit(1); +static uint8_t romfs_buf[4] = {0xd2, 0xcd, 0x31, 0x00}; // empty ROMFS +static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, sizeof(romfs_buf), + romfs_buf); + +mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) { + switch (mp_obj_get_int(args[0])) { + case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS: + return MP_OBJ_NEW_SMALL_INT(1); + + case MP_VFS_ROM_IOCTL_GET_SEGMENT: + return MP_OBJ_FROM_PTR(&romfs_obj); + } + + return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL); } -MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos); +#endif diff --git a/core/embed/projects/unix/mpconfigport.h b/core/embed/projects/unix/mpconfigport.h index 18e5e9bd924..ff066ddfce8 100644 --- a/core/embed/projects/unix/mpconfigport.h +++ b/core/embed/projects/unix/mpconfigport.h @@ -71,7 +71,7 @@ #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) // Python internal features -#define MICROPY_READER_VFS (0) +#define MICROPY_READER_VFS (1) #define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_FINALISER (1) #define MICROPY_STACK_CHECK (1) @@ -88,19 +88,21 @@ #define MICROPY_ENABLE_SOURCE_LINE (1) #endif #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) +#define MICROPY_TIME_SUPPORT_Y2100_AND_BEYOND (1) #define MICROPY_STREAMS_NON_BLOCK (1) -#define MICROPY_MODULE_WEAK_LINKS (0) #define MICROPY_CAN_OVERRIDE_BUILTINS (0) -#define MICROPY_VFS_POSIX_FILE (1) +#define MICROPY_VFS_POSIX (1) #define MICROPY_USE_INTERNAL_ERRNO (0) +#define MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING (1) #define MICROPY_ENABLE_SCHEDULER (0) #define MICROPY_SCHEDULER_DEPTH (0) -#define MICROPY_VFS (0) +#define MICROPY_VFS (1) // control over Python builtins #define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_DESCRIPTORS (0) #define MICROPY_PY_DELATTR_SETATTR (0) +#define MICROPY_PY_BUILTINS_BYTES_HEX (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_CENTER (0) #define MICROPY_PY_BUILTINS_STR_PARTITION (1) @@ -139,43 +141,41 @@ #define MICROPY_PY_SYS_STDFILES (0) #define MICROPY_PY_SYS_STDIO_BUFFER (0) #define MICROPY_PY_SYS_PLATFORM "trezor-emulator" -#define MICROPY_PY_UERRNO (0) +#define MICROPY_PY_ERRNO (0) #define MICROPY_PY_THREAD (0) #define MICROPY_PY_FSTRINGS (1) // extended modules #define MICROPY_PY_UCTYPES (!BITCOIN_ONLY) // used in FIDO -#define MICROPY_PY_UZLIB (0) -#define MICROPY_PY_UJSON (0) -#define MICROPY_PY_UOS (1) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c" -#define MICROPY_PY_UOS_ERRNO (1) -#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1) -#define MICROPY_PY_UOS_SEP (1) -#define MICROPY_PY_UOS_SYSTEM (1) -#define MICROPY_PY_UOS_URANDOM (1) -#define MICROPY_PY_URE (0) -#define MICROPY_PY_URE_SUB (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UHASHLIB (0) -#define MICROPY_PY_UHASHLIB_MD5 (0) -#define MICROPY_PY_UHASHLIB_SHA1 (0) -#define MICROPY_PY_UCRYPTOLIB (0) -#define MICROPY_PY_UBINASCII (1) -#define MICROPY_PY_UBINASCII_CRC32 (0) -#define MICROPY_PY_URANDOM (0) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) -#define MICROPY_PY_USELECT (0) -#define MICROPY_PY_UTIMEQ (1) -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_DEFLATE (0) +#define MICROPY_PY_JSON (0) +#define MICROPY_PY_OS (1) +#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/modos.c" +#define MICROPY_PY_OS_ERRNO (1) +#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) +#define MICROPY_PY_OS_SEP (1) +#define MICROPY_PY_OS_SYSTEM (1) +#define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_RE (0) +#define MICROPY_PY_RE_SUB (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_HASHLIB (0) +#define MICROPY_PY_HASHLIB_MD5 (0) +#define MICROPY_PY_HASHLIB_SHA1 (0) +#define MICROPY_PY_CRYPTOLIB (0) +#define MICROPY_PY_BINASCII (0) +#define MICROPY_PY_BINASCII_CRC32 (0) +#define MICROPY_PY_RANDOM (0) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (0) +#define MICROPY_PY_SELECT (0) +#define MICROPY_PY_TIME (1) #define MICROPY_PY_OS_DUPTERM (0) #define MICROPY_PY_LWIP_SOCK_RAW (0) #define MICROPY_PY_MACHINE (0) -#define MICROPY_PY_UWEBSOCKET (0) +#define MICROPY_PY_WEBSOCKET (0) #define MICROPY_PY_WEBREPL (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) // allocate traceback data only on debug builds @@ -230,7 +230,8 @@ extern const struct _mp_print_t mp_stderr_print; // by default contains nearest git tag, which may not be present in shallow // repo, breaking reproducibility -#define MICROPY_BANNER_NAME_AND_VERSION "" +#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython" +#define MICROPY_BANNER_MACHINE "unix" // ============= this ends common config section =================== @@ -250,13 +251,6 @@ typedef unsigned int mp_uint_t; // must be pointer size #endif #endif -#define MICROPY_EVENT_POLL_HOOK \ - do { \ - extern void mp_handle_pending(bool); \ - mp_handle_pending(true); \ - mp_hal_delay_us(500); \ - } while (0); - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; @@ -284,11 +278,6 @@ void mp_unix_mark_exec(void); // with EINTR, updates remaining timeout value. #define MICROPY_SELECT_REMAINING_TIME (1) -#define MICROPY_PORT_ROOT_POINTERS \ - const char *readline_hist[50]; \ - void *mmap_region_head; \ - mp_obj_t trezorconfig_ui_wait_callback; \ - // We need to provide a declaration/definition of alloca() // unless support for it is disabled. #if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0 diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index d5b95ea75cf..e4479be472e 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -312,10 +312,19 @@ fn generate_micropython_bindings() { let bindings = prepare_bindings() .header("micropython.h") + // Needed to call header statics like mp_obj_list_set_len. See also upymod/build.rs. + .wrap_static_fns(true) + .wrap_static_fns_path(PathBuf::from(out_dir.clone()).join("bindgen-static")) // obj .new_type_alias("mp_obj_t") .allowlist_type("mp_obj_type_t") .allowlist_type("mp_obj_base_t") + .allowlist_type("mp_obj_full_type_t") + .allowlist_type("mp_attr_fun_t") + .allowlist_type("mp_call_fun_t") + .allowlist_type("mp_make_new_fun_t") + .allowlist_type("mp_print_fun_t") + .allowlist_type("mp_buffer_fun_t") .allowlist_function("mp_obj_new_int") .allowlist_function("mp_obj_new_int_from_ll") .allowlist_function("mp_obj_new_int_from_ull") @@ -330,6 +339,7 @@ fn generate_micropython_bindings() { .allowlist_function("mp_call_function_n_kw") .allowlist_function("trezor_obj_get_ll_checked") .allowlist_function("trezor_obj_str_from_rom_text") + .allowlist_var("MP_TYPE_FLAG_NONE") // buffer .allowlist_function("mp_obj_new_slice") .allowlist_function("mp_obj_subscr") @@ -495,6 +505,7 @@ fn generate_trezorhal_bindings() { .allowlist_function("gfx_mono8_blend_mono4") .allowlist_function("gfx_bitblt_wait") // uzlib + .allowlist_type("uzlib_uncomp_t") .allowlist_function("uzlib_uncompress_init") .allowlist_function("uzlib_uncompress") // bip39 diff --git a/core/embed/rust/librust.h b/core/embed/rust/librust.h index fb46c75aab8..706a2c06ad6 100644 --- a/core/embed/rust/librust.h +++ b/core/embed/rust/librust.h @@ -7,21 +7,21 @@ mp_obj_t protobuf_debug_msg_type(); mp_obj_t protobuf_debug_msg_def_type(); #endif -extern mp_obj_module_t mp_module_trezorproto; -extern mp_obj_module_t mp_module_trezorui_api; -extern mp_obj_module_t mp_module_trezortranslate; -extern mp_obj_module_t mp_module_trezorble; -extern mp_obj_module_t mp_module_trezorthp; +extern const mp_obj_module_t mp_module_trezorproto; +extern const mp_obj_module_t mp_module_trezorui_api; +extern const mp_obj_module_t mp_module_trezortranslate; +extern const mp_obj_module_t mp_module_trezorble; +extern const mp_obj_module_t mp_module_trezorthp; #ifdef USE_DBG_CONSOLE -extern mp_obj_module_t mp_module_trezorlog; +extern const mp_obj_module_t mp_module_trezorlog; #endif #if !PYOPT mp_obj_t ui_debug_layout_type(); #ifdef TREZOR_EMULATOR -extern mp_obj_module_t mp_module_coveragedata; +extern const mp_obj_module_t mp_module_coveragedata; #endif #endif diff --git a/core/embed/rust/micropython.h b/core/embed/rust/micropython.h index 8fe33f6b2f2..6951690d174 100644 --- a/core/embed/rust/micropython.h +++ b/core/embed/rust/micropython.h @@ -2,6 +2,7 @@ #include "py/mphal.h" #include "py/nlr.h" #include "py/obj.h" +#include "py/objlist.h" #include "py/objstr.h" #include "py/runtime.h" diff --git a/core/embed/rust/src/micropython/exception.rs b/core/embed/rust/src/micropython/exception.rs index ba5ce494732..02369708b27 100644 --- a/core/embed/rust/src/micropython/exception.rs +++ b/core/embed/rust/src/micropython/exception.rs @@ -3,7 +3,7 @@ use super::ffi; use super::obj::Obj; use super::qstr::Qstr; -use super::typ::Type; +use super::typ::{FullType, Type}; pub const AttributeError: &Type = unsafe { &ffi::mp_type_AttributeError }; pub const EOFError: &Type = unsafe { &ffi::mp_type_EOFError }; @@ -17,7 +17,7 @@ pub const RuntimeError: &Type = unsafe { &ffi::mp_type_RuntimeError }; pub const TypeError: &Type = unsafe { &ffi::mp_type_TypeError }; pub const ValueError: &Type = unsafe { &ffi::mp_type_ValueError }; -pub const fn define_exception(name: Qstr, parent: &Type) -> Type { +pub const fn define_exception(name: Qstr, parent: &Type) -> FullType { obj_type! { name: name, make_new_fn: ffi::mp_obj_exception_make_new, diff --git a/core/embed/rust/src/micropython/macros.rs b/core/embed/rust/src/micropython/macros.rs index a8415270275..75dde3627ed 100644 --- a/core/embed/rust/src/micropython/macros.rs +++ b/core/embed/rust/src/micropython/macros.rs @@ -118,72 +118,102 @@ macro_rules! obj_type { $(print_fn: $print_fn:path,)? $(parent: $parent:path,)? ) => {{ - #[allow(unused_unsafe)] - unsafe { - use $crate::micropython::ffi; + use $crate::micropython::ffi; - let name = $name.to_u16(); + let name = $name.to_u16(); - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut base_type: &'static ffi::mp_obj_type_t = &ffi::mp_type_type; - $(base_type = &$base;)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + // SAFETY: micropython ffi + let mut base_type: &'static ffi::mp_obj_type_t = unsafe { &ffi::mp_type_type }; + $(base_type = &$base;)? - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut attr: ffi::mp_attr_fun_t = None; - $(attr = Some($attr_fn);)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut attr: ffi::mp_attr_fun_t = None; + $(attr = Some($attr_fn);)? - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut call: ffi::mp_call_fun_t = None; - $(call = Some($call_fn);)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut call: ffi::mp_call_fun_t = None; + $(call = Some($call_fn);)? - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut make_new: ffi::mp_make_new_fun_t = None; - $(make_new = Some($make_new_fn);)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut make_new: ffi::mp_make_new_fun_t = None; + $(make_new = Some($make_new_fn);)? - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut print: ffi::mp_print_fun_t = None; - $(print = Some($print_fn);)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut print: ffi::mp_print_fun_t = None; + $(print = Some($print_fn);)? - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut parent: *const cty::c_void = ::core::ptr::null_mut(); - $(parent = $parent as *const _ as *mut _;)? + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut parent: Option<&ffi::mp_obj_type_t> = None; + $(parent = Some($parent);)? - // TODO: This is safe only if we pass in `Dict` with fixed `Map` (created by - // `Map::fixed()`, usually through `obj_map!`), because only then will - // MicroPython treat `locals_dict` as immutable, and make the mutable cast safe. - #[allow(unused_mut)] - #[allow(unused_assignments)] - let mut locals_dict = ::core::ptr::null_mut(); - $(locals_dict = $locals as *const _ as *mut _;)? + // TODO: This is safe only if we pass in `Dict` with fixed `Map` (created by + // `Map::fixed()`, usually through `obj_map!`), because only then will + // MicroPython treat `locals_dict` as immutable, and make the mutable cast safe. + #[allow(unused_mut)] + #[allow(unused_assignments)] + let mut locals_dict: Option<&ffi::mp_obj_dict_t> = None; + $(locals_dict = Some($locals);)? - ffi::mp_obj_type_t { - base: ffi::mp_obj_base_t { - type_: base_type, - }, - flags: 0, - name, - print, - make_new, - call, - unary_op: None, - binary_op: None, - attr, - subscr: None, - getiter: None, - iternext: None, - buffer_p: ffi::mp_buffer_p_t { get_buffer: None }, - protocol: ::core::ptr::null(), - parent, - locals_dict, - } + const fn slot(val: &Option, num: u8) -> u8 { + if val.is_some() { num } else { 0 } + } + + ffi::mp_obj_full_type_t { + base: ffi::mp_obj_base_t { + type_: base_type, + }, + flags: ffi::MP_TYPE_FLAG_NONE as u16, + name, + + slot_index_make_new: slot(&make_new, 1), + slot_index_print: slot(&print, 2), + slot_index_call: slot(&call, 3), + slot_index_unary_op: 0, + slot_index_binary_op: 0, + slot_index_attr: slot(&attr, 4), + slot_index_subscr: 0, + slot_index_iter: 0, + slot_index_buffer: 0, + slot_index_protocol: 0, + slot_index_parent: slot(&parent, 5), + slot_index_locals_dict: slot(&locals_dict, 6), + + slots: [ + obj_type!(@cast_fn make_new), + obj_type!(@cast_fn print), + obj_type!(@cast_fn call), + obj_type!(@cast_fn attr), + obj_type!(@cast_ref parent), + obj_type!(@cast_ref locals_dict), + ::core::ptr::null(), + ::core::ptr::null(), + ::core::ptr::null(), + ::core::ptr::null(), + ::core::ptr::null(), + ], } }}; + // Option => *const cty::c_void + (@cast_fn $e:expr) => { + match $e { + None => ::core::ptr::null(), + Some(x) => x as *const cty::c_void, + } + }; + // Option<&T> => *const cty::c_void + (@cast_ref $e:expr) => { + match $e { + None => ::core::ptr::null(), + Some(x) => x as *const _ as *const cty::c_void, + } + }; } /// Construct an upymod definition. diff --git a/core/embed/rust/src/micropython/simple_type.rs b/core/embed/rust/src/micropython/simple_type.rs index a348ab8055e..5d0480a2518 100644 --- a/core/embed/rust/src/micropython/simple_type.rs +++ b/core/embed/rust/src/micropython/simple_type.rs @@ -1,5 +1,5 @@ use super::obj::{Obj, ObjBase}; -use super::typ::Type; +use super::typ::FullType; /// Simple MicroPython object type builder. /// @@ -24,9 +24,11 @@ pub struct SimpleTypeObj { } impl SimpleTypeObj { - pub const fn new(base: &'static Type) -> Self { + // base would ideally be something like impl Into<&'static Type> but we don't + // have const traits and it's currently only used with FullType anyway + pub const fn new(base: &'static FullType) -> Self { Self { - base: base.as_base(), + base: base.as_type().as_base(), } } diff --git a/core/embed/rust/src/micropython/typ.rs b/core/embed/rust/src/micropython/typ.rs index dee138fb4bc..95ee34374f2 100644 --- a/core/embed/rust/src/micropython/typ.rs +++ b/core/embed/rust/src/micropython/typ.rs @@ -1,3 +1,5 @@ +use core::ops::Deref; + use super::ffi; use super::obj::{Obj, ObjBase}; @@ -33,3 +35,31 @@ impl Type { // SAFETY: We are in a single-threaded environment. unsafe impl Sync for Type {} + +/// Since Type has variable size due to its slots array, functions that +/// construct type objects return this which is a Type with the maximum number +/// of slots. +pub type FullType = ffi::mp_obj_full_type_t; + +impl FullType { + pub const fn as_type(&self) -> &Type { + let type_ptr = self as *const Self as *const ffi::mp_obj_type_t; + // SAFETY: + // - aligned, non-null, and dereferanceable because it came from a reference + // - pointee is valid because the initial part of FullType has the same layout + // as Type + // - aliasing the same as source reference + unsafe { type_ptr.as_ref_unchecked() } + } +} + +impl Deref for FullType { + type Target = Type; + + fn deref(&self) -> &Type { + self.as_type() + } +} + +// SAFETY: We are in a single-threaded environment. +unsafe impl Sync for FullType {} diff --git a/core/embed/rust/src/protobuf/obj.rs b/core/embed/rust/src/protobuf/obj.rs index edadbc53159..7d272c53557 100644 --- a/core/embed/rust/src/protobuf/obj.rs +++ b/core/embed/rust/src/protobuf/obj.rs @@ -11,7 +11,7 @@ use crate::micropython::map::Map; use crate::micropython::module::Module; use crate::micropython::obj::{Obj, ObjBase}; use crate::micropython::qstr::Qstr; -use crate::micropython::typ::Type; +use crate::micropython::typ::{FullType, Type}; use crate::micropython::{ffi, util}; #[repr(C)] @@ -45,7 +45,7 @@ impl MsgObj { } fn obj_type() -> &'static Type { - static TYPE: Type = obj_type! { + static TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_Msg, attr_fn: msg_obj_attr, }; @@ -165,7 +165,7 @@ impl MsgDefObj { } fn obj_type() -> &'static Type { - static TYPE: Type = obj_type! { + static TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_MsgDef, attr_fn: msg_def_obj_attr, call_fn: msg_def_obj_call, diff --git a/core/embed/rust/src/thp/micropython.rs b/core/embed/rust/src/thp/micropython.rs index 3dfd8be5b19..53347a38146 100644 --- a/core/embed/rust/src/thp/micropython.rs +++ b/core/embed/rust/src/thp/micropython.rs @@ -13,7 +13,7 @@ use crate::micropython::module::Module; use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; use crate::micropython::{exception, util}; extern "C" fn thp_init(iface_num: Obj, device_properties: Obj) -> Obj { @@ -303,15 +303,15 @@ extern "C" fn thp_handshake_key(iface_num: Obj, local_static_privkey: Obj) -> Ob } #[allow(non_upper_case_globals)] -pub static ThpError: Type = +pub static ThpError: FullType = exception::define_exception(Qstr::MP_QSTR_ThpError, exception::Exception); -static FAILED_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_FAILED, }; -static KEY_REQUIRED_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_KEY_REQUIRED, }; -static KEY_REQUIRED_UNLOCK_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_KEY_REQUIRED_UNLOCK, }; -static MESSAGE_READY_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_MESSAGE_READY, }; -static ACK_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_ACK, }; -static MESSAGE_READY_ACK_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_MESSAGE_READY_ACK, }; +static FAILED_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_FAILED, }; +static KEY_REQUIRED_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_KEY_REQUIRED, }; +static KEY_REQUIRED_UNLOCK_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_KEY_REQUIRED_UNLOCK, }; +static MESSAGE_READY_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_MESSAGE_READY, }; +static ACK_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_ACK, }; +static MESSAGE_READY_ACK_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_MESSAGE_READY_ACK, }; pub static FAILED_OBJ: SimpleTypeObj = SimpleTypeObj::new(&FAILED_TYPE); pub static KEY_REQUIRED_OBJ: SimpleTypeObj = SimpleTypeObj::new(&KEY_REQUIRED_TYPE); @@ -359,7 +359,7 @@ pub static mp_module_trezorthp: Module = obj_module! { Qstr::MP_QSTR___name__ => Qstr::MP_QSTR_trezorthp.to_obj(), /// ThpError: type[Exception] - Qstr::MP_QSTR_ThpError => ThpError.as_obj(), + Qstr::MP_QSTR_ThpError => ThpError.as_type().as_obj(), /// MESSAGE_READY: object Qstr::MP_QSTR_MESSAGE_READY => MESSAGE_READY_OBJ.as_obj(), diff --git a/core/embed/rust/src/translations/obj.rs b/core/embed/rust/src/translations/obj.rs index 5c18d5c96b2..33cadf94680 100644 --- a/core/embed/rust/src/translations/obj.rs +++ b/core/embed/rust/src/translations/obj.rs @@ -10,7 +10,7 @@ use crate::micropython::module::Module; use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; use crate::micropython::{ffi, util}; use crate::trezorhal::translations; @@ -37,7 +37,7 @@ unsafe extern "C" fn tr_attr_fn(_self_in: Obj, attr: ffi::qstr, dest: *mut Obj) unsafe { util::try_or_raise(block) } } -static TR_TYPE: Type = obj_type! { +static TR_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_TR, attr_fn: tr_attr_fn, }; @@ -85,7 +85,7 @@ pub extern "C" fn translations_header_from_flash(_cls_in: Obj) -> Obj { unsafe { util::try_or_raise(block) } } -static TRANSLATIONS_HEADER_TYPE: Type = obj_type! { +static TRANSLATIONS_HEADER_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_TranslationsHeader, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_load_from_flash => obj_fn_1!(translations_header_from_flash).as_obj(), diff --git a/core/embed/rust/src/trezorhal/ble/micropython.rs b/core/embed/rust/src/trezorhal/ble/micropython.rs index 7bbc55b51c6..49748d66c47 100644 --- a/core/embed/rust/src/trezorhal/ble/micropython.rs +++ b/core/embed/rust/src/trezorhal/ble/micropython.rs @@ -9,7 +9,7 @@ use crate::micropython::module::Module; use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; use crate::micropython::util; extern "C" fn py_erase_bonds() -> Obj { @@ -261,7 +261,7 @@ extern "C" fn py_iface_read(n_args: usize, args: *const Obj) -> Obj { unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) } } -static BLE_INTERFACE_TYPE: Type = obj_type! { +static BLE_INTERFACE_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_BLEIF, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_iface_num => obj_fn_1!(py_iface_num).as_obj(), diff --git a/core/embed/rust/src/trezorhal/uzlib.rs b/core/embed/rust/src/trezorhal/uzlib.rs index 89770c9e600..0f0ebe8559a 100644 --- a/core/embed/rust/src/trezorhal/uzlib.rs +++ b/core/embed/rust/src/trezorhal/uzlib.rs @@ -1,67 +1,19 @@ use core::cell::RefCell; use core::marker::PhantomData; use core::mem::MaybeUninit; -use core::ptr; use super::ffi; use crate::io::BinaryData; pub const UZLIB_WINDOW_SIZE: usize = 1 << 10; -pub use ffi::uzlib_uncomp; +pub use ffi::uzlib_uncomp_t; -impl Default for ffi::uzlib_uncomp { +impl Default for ffi::uzlib_uncomp_t { fn default() -> Self { unsafe { MaybeUninit::::zeroed().assume_init() } } } -pub struct UzlibContext<'a> { - uncomp: ffi::uzlib_uncomp, - src_data: PhantomData<&'a [u8]>, -} - -impl<'a> UzlibContext<'a> { - pub fn new(src: &'a [u8], window: Option<&'a mut [u8; UZLIB_WINDOW_SIZE]>) -> Self { - let mut ctx = Self { - uncomp: uzlib_uncomp::default(), - src_data: PhantomData, - }; - - unsafe { - ctx.uncomp.source = src.as_ptr(); - ctx.uncomp.source_limit = src.as_ptr().add(src.len()); - - if let Some(w) = window { - ffi::uzlib_uncompress_init( - &mut ctx.uncomp, - w.as_mut_ptr() as _, - UZLIB_WINDOW_SIZE as u32, - ); - } else { - ffi::uzlib_uncompress_init(&mut ctx.uncomp, ptr::null_mut(), 0); - } - } - - ctx - } - - /// Returns `Ok(true)` if all data was read. - pub fn uncompress(&mut self, dest_buf: &mut [u8]) -> Result { - unsafe { - self.uncomp.dest = dest_buf.as_mut_ptr(); - self.uncomp.dest_limit = self.uncomp.dest.add(dest_buf.len()); - - let res = ffi::uzlib_uncompress(&mut self.uncomp); - - match res { - 0 => Ok(false), - 1 => Ok(true), - _ => Err(()), - } - } - } -} - struct SourceReadContext<'a> { /// Compressed data data: BinaryData<'a>, @@ -86,7 +38,7 @@ impl<'a> SourceReadContext<'a> { } /// Fill the uncomp struct with the appropriate pointers to the source data - pub fn prepare_uncomp(&self, uncomp: &mut ffi::uzlib_uncomp) { + pub fn prepare_uncomp(&self, uncomp: &mut ffi::uzlib_uncomp_t) { // SAFETY: the offsets are within the buffer bounds. // - buf_head is either 0 or advanced by uzlib to at most buf_tail (via // advance()) @@ -104,7 +56,7 @@ impl<'a> SourceReadContext<'a> { /// The operation is only valid on an uncomp struct that has been filled via /// `prepare_uncomp` and the source pointer has been updated by the uzlib /// library after a single uncompress operation. - pub unsafe fn advance(&mut self, uncomp: &ffi::uzlib_uncomp) { + pub unsafe fn advance(&mut self, uncomp: &ffi::uzlib_uncomp_t) { unsafe { // SAFETY: we trust uzlib to move the `source` pointer only up to `source_limit` self.buf_head = uncomp.source.offset_from(self.buf.as_ptr()) as usize; @@ -116,7 +68,7 @@ impl<'a> SourceReadContext<'a> { /// If the uncomp buffer is exhausted, a callback is invoked that should (a) /// read one byte of data, and optionally (b) update the uncomp buffer /// with more data. - pub fn reader_callback(&mut self, uncomp: &mut ffi::uzlib_uncomp) -> Option { + pub fn reader_callback(&mut self, uncomp: &mut ffi::uzlib_uncomp_t) -> Option { // fill the internal buffer first let bytes_read = self.data.read(self.offset, self.buf.as_mut()); self.buf_head = 0; @@ -142,7 +94,7 @@ pub struct ZlibInflate<'a> { /// Compressed data reader data: RefCell>, /// Uzlib context - uncomp: ffi::uzlib_uncomp, + uncomp: ffi::uzlib_uncomp_t, window: PhantomData<&'a [u8]>, } @@ -158,7 +110,7 @@ impl<'a> ZlibInflate<'a> { ) -> Self { let mut inflate = Self { data: RefCell::new(SourceReadContext::new(data, offset)), - uncomp: uzlib_uncomp::default(), + uncomp: uzlib_uncomp_t::default(), window: PhantomData, }; @@ -185,6 +137,7 @@ impl<'a> ZlibInflate<'a> { self.uncomp.source_read_cb = Some(zlib_reader_callback); // Context for the source data callback self.uncomp.source_read_cb_context = &self.data as *const _ as *mut cty::c_void; + self.uncomp.source_read_data = &self.uncomp as *const _ as *mut cty::c_void; // Destination buffer self.uncomp.dest = dest.as_mut_ptr(); @@ -205,6 +158,7 @@ impl<'a> ZlibInflate<'a> { // Clear the source read callback (just for safety) self.uncomp.source_read_cb_context = core::ptr::null_mut(); + self.uncomp.source_read_data = core::ptr::null_mut(); match res { 0 => Ok(false), @@ -230,7 +184,8 @@ impl<'a> ZlibInflate<'a> { /// This function is called by the uzlib library to read more data from the /// input stream. -unsafe extern "C" fn zlib_reader_callback(uncomp: *mut ffi::uzlib_uncomp) -> i32 { +unsafe extern "C" fn zlib_reader_callback(arg: *mut cty::c_void) -> i32 { + let uncomp = arg as *mut ffi::uzlib_uncomp_t; // SAFETY: we assume that passed-in uncomp is not null and that we own it // exclusively (ensured by passing it as &mut into uzlib_uncompress()) let uncomp = unwrap!(unsafe { uncomp.as_mut() }); diff --git a/core/embed/rust/src/ui/backlight.rs b/core/embed/rust/src/ui/backlight.rs index d5415c6a729..65ddf80591d 100644 --- a/core/embed/rust/src/ui/backlight.rs +++ b/core/embed/rust/src/ui/backlight.rs @@ -3,7 +3,7 @@ use crate::micropython::macros::obj_type; use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; use crate::micropython::{ffi, util}; use crate::ui::{CommonUI, ModelUI}; @@ -16,7 +16,7 @@ use crate::ui::{CommonUI, ModelUI}; * things stay forever. Written in May 2024.) */ -static BACKLIGHT_LEVELS_TYPE: Type = obj_type! { +static BACKLIGHT_LEVELS_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_BacklightLevels, attr_fn: backlight_levels_attr, }; diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs index 76489623782..cc5eebb8583 100644 --- a/core/embed/rust/src/ui/geometry.rs +++ b/core/embed/rust/src/ui/geometry.rs @@ -373,7 +373,7 @@ impl Rect { /// Checks if the rectangle is empty. /// - /// It is possible to custruct a rectangle with negative width or height. + /// It is possible to construct a rectangle with negative width or height. /// All such rectangles are considered as empty. pub const fn is_empty(&self) -> bool { self.x0 >= self.x1 || self.y0 >= self.y1 diff --git a/core/embed/rust/src/ui/layout/base.rs b/core/embed/rust/src/ui/layout/base.rs index d42c0de98dd..833add7a35a 100644 --- a/core/embed/rust/src/ui/layout/base.rs +++ b/core/embed/rust/src/ui/layout/base.rs @@ -25,26 +25,26 @@ mod micropython { use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; - use crate::micropython::typ::Type; + use crate::micropython::typ::FullType; - static STATE_INITIAL_TYPE: Type = obj_type! { + static STATE_INITIAL_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_INITIAL, - base: LAYOUT_STATE_TYPE, + base: LAYOUT_STATE_TYPE.as_type(), }; - static STATE_ATTACHED_TYPE: Type = obj_type! { + static STATE_ATTACHED_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_ATTACHED, - base: LAYOUT_STATE_TYPE, + base: LAYOUT_STATE_TYPE.as_type(), }; - static STATE_TRANSITIONING_TYPE: Type = obj_type! { + static STATE_TRANSITIONING_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_TRANSITIONING, - base: LAYOUT_STATE_TYPE, + base: LAYOUT_STATE_TYPE.as_type(), }; - static STATE_DONE_TYPE: Type = obj_type! { + static STATE_DONE_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_DONE, - base: LAYOUT_STATE_TYPE, + base: LAYOUT_STATE_TYPE.as_type(), }; pub static STATE_INITIAL: SimpleTypeObj = SimpleTypeObj::new(&STATE_INITIAL_TYPE); @@ -52,7 +52,7 @@ mod micropython { pub static STATE_TRANSITIONING: SimpleTypeObj = SimpleTypeObj::new(&STATE_TRANSITIONING_TYPE); pub static STATE_DONE: SimpleTypeObj = SimpleTypeObj::new(&STATE_DONE_TYPE); - static LAYOUT_STATE_TYPE: Type = obj_type! { + static LAYOUT_STATE_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_LayoutState, locals: &obj_dict! { obj_map! { Qstr::MP_QSTR_INITIAL => STATE_INITIAL.as_obj(), diff --git a/core/embed/rust/src/ui/layout/device_menu_result.rs b/core/embed/rust/src/ui/layout/device_menu_result.rs index a31471e6d1b..d0d48449993 100644 --- a/core/embed/rust/src/ui/layout/device_menu_result.rs +++ b/core/embed/rust/src/ui/layout/device_menu_result.rs @@ -3,7 +3,7 @@ use crate::micropython::macros::obj_type; use crate::micropython::obj::Obj; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; use crate::micropython::{ffi, util}; #[derive(Copy, Clone)] @@ -87,7 +87,7 @@ impl DeviceMenuMsg { } // Create a DeviceMenuResult class that contains all result types -static DEVICE_MENU_RESULT_TYPE: Type = obj_type! { +static DEVICE_MENU_RESULT_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_DeviceMenuResult, attr_fn: device_menu_result_attr, }; diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs index 09eb58528ca..94e57bebf17 100644 --- a/core/embed/rust/src/ui/layout/obj.rs +++ b/core/embed/rust/src/ui/layout/obj.rs @@ -19,7 +19,7 @@ use crate::micropython::map::Map; use crate::micropython::obj::{Obj, ObjBase}; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::{FullType, Type}; use crate::micropython::util; use crate::time::Duration; use crate::ui::button_request::ButtonRequest; @@ -70,7 +70,7 @@ impl AttachType { } } -static ATTACH_TYPE: Type = obj_type! { +static ATTACH_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_AttachType, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_INITIAL => Obj::small_int(0u16), @@ -395,7 +395,7 @@ impl LayoutObj { } fn obj_type() -> &'static Type { - static TYPE: Type = obj_type! { + static TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_LayoutObj, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_attach_timer_fn => obj_fn_3!(ui_layout_attach_timer_fn).as_obj(), diff --git a/core/embed/rust/src/ui/layout/result.rs b/core/embed/rust/src/ui/layout/result.rs index 4e3f470c7f8..bec286d35de 100644 --- a/core/embed/rust/src/ui/layout/result.rs +++ b/core/embed/rust/src/ui/layout/result.rs @@ -1,12 +1,12 @@ use crate::micropython::macros::obj_type; use crate::micropython::qstr::Qstr; use crate::micropython::simple_type::SimpleTypeObj; -use crate::micropython::typ::Type; +use crate::micropython::typ::FullType; -static CONFIRMED_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_CONFIRMED, }; -static CANCELLED_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_CANCELLED, }; -static BACK_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_BACK, }; -static INFO_TYPE: Type = obj_type! { name: Qstr::MP_QSTR_INFO, }; +static CONFIRMED_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_CONFIRMED, }; +static CANCELLED_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_CANCELLED, }; +static BACK_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_BACK, }; +static INFO_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_INFO, }; pub static CONFIRMED: SimpleTypeObj = SimpleTypeObj::new(&CONFIRMED_TYPE); pub static CANCELLED: SimpleTypeObj = SimpleTypeObj::new(&CANCELLED_TYPE); diff --git a/core/embed/rust/src/ui/notification.rs b/core/embed/rust/src/ui/notification.rs index 53eb66cf43f..dfc6fcd03b1 100644 --- a/core/embed/rust/src/ui/notification.rs +++ b/core/embed/rust/src/ui/notification.rs @@ -5,7 +5,7 @@ use crate::micropython::{ obj::Obj, qstr::Qstr, simple_type::SimpleTypeObj, - typ::Type, + typ::FullType, }; use crate::strutil::TString; @@ -67,7 +67,7 @@ impl TryFrom for NotificationLevel { } #[cfg(feature = "micropython")] -static NOTIFICATION_LEVEL_TYPE: Type = obj_type! { +static NOTIFICATION_LEVEL_TYPE: FullType = obj_type! { name: Qstr::MP_QSTR_NotificationLevel, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_ALERT => Obj::small_int(0), diff --git a/core/embed/sec/image/stm32/boot_image.c b/core/embed/sec/image/stm32/boot_image.c index b3e100f141d..5c530dbdeb6 100644 --- a/core/embed/sec/image/stm32/boot_image.c +++ b/core/embed/sec/image/stm32/boot_image.c @@ -56,10 +56,10 @@ _Static_assert( BOOTLOADER_MAXSIZE <= IMAGE_CHUNK_SIZE, "BOOTLOADER_MAXSIZE must be less than or equal to IMAGE_CHUNK_SIZE"); -static void uzlib_prepare(struct uzlib_uncomp *decomp, uint8_t *window, +static void uzlib_prepare(uzlib_uncomp_t *decomp, uint8_t *window, const void *src, uint32_t srcsize, void *dest, uint32_t destsize) { - memzero(decomp, sizeof(struct uzlib_uncomp)); + memzero(decomp, sizeof(uzlib_uncomp_t)); if (window) { memzero(window, UZLIB_WINDOW_SIZE); } @@ -100,14 +100,14 @@ void boot_image_replace(const boot_image_t *image) { mpu_mode_t mode = mpu_reconfig(MPU_MODE_BOOTLOADER); - struct uzlib_uncomp decomp = {0}; + uzlib_uncomp_t decomp = {0}; uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0}; uint32_t decomp_out[IMAGE_HEADER_SIZE / sizeof(uint32_t)] = {0}; uzlib_prepare(&decomp, decomp_window, image->image_ptr, image->image_size, decomp_out, sizeof(decomp_out)); - ensure((uzlib_uncompress(&decomp) == TINF_OK) ? sectrue : secfalse, + ensure((uzlib_uncompress(&decomp) == UZLIB_OK) ? sectrue : secfalse, "Bootloader header decompression failed"); const image_header *new_bld_hdr = read_image_header( @@ -154,7 +154,7 @@ void boot_image_replace(const boot_image_t *image) { error_shutdown("Invalid bootloader contents"); } - memset(&decomp, 0, sizeof(struct uzlib_uncomp)); + memset(&decomp, 0, sizeof(uzlib_uncomp_t)); // cannot find valid header for current bootloader, something is wrong ensure(current_bld_hdr == (const image_header *)bl_data ? sectrue : secfalse, @@ -193,7 +193,7 @@ void boot_image_replace(const boot_image_t *image) { uzlib_prepare(&decomp, decomp_window, image->image_ptr, image->image_size, decomp_out, sizeof(decomp_out)); - ensure((uzlib_uncompress(&decomp) == TINF_OK) ? sectrue : secfalse, + ensure((uzlib_uncompress(&decomp) == UZLIB_OK) ? sectrue : secfalse, "Bootloader decompression failed"); do { diff --git a/core/embed/upymod/bindgen-static.c b/core/embed/upymod/bindgen-static.c new file mode 100644 index 00000000000..c23ca715d51 --- /dev/null +++ b/core/embed/upymod/bindgen-static.c @@ -0,0 +1,11 @@ +#include "py/obj.h" +#include "py/objlist.h" + +// Static wrappers + +void mp_obj_list_get__extern(mp_obj_t self_in, size_t *len, mp_obj_t **items) { + mp_obj_list_get(self_in, len, items); +} +void mp_obj_list_set_len__extern(mp_obj_t self_in, size_t len) { + mp_obj_list_set_len(self_in, len); +} diff --git a/core/embed/upymod/build.rs b/core/embed/upymod/build.rs index 3b231c3c827..850ec3655f4 100644 --- a/core/embed/upymod/build.rs +++ b/core/embed/upymod/build.rs @@ -18,7 +18,8 @@ fn main() -> Result<()> { if cfg!(feature = "emulator") { // There are two mpconfigport.h files in both ports/unix and projects/unix. - // The first one has precedence and is used for compilation. + // The first one has precedence and is used for compilation. We need mphalport.h + // from the other. lib.add_include("../projects/unix"); lib.add_include(PathBuf::from(mpy_dir).join("ports/unix")); } else if cfg!(feature = "mcu_stm32") { @@ -85,9 +86,7 @@ fn main() -> Result<()> { lib.add_private_define("MICROPY_OOM_CALLBACK", Some("0")); } else { lib.add_define("PYOPT", Some("0")); - // This is needed to compile modtrezorutils-meminfo.h that - // calls STATIC functions in other modules - lib.add_private_defines([("STATIC", Some("")), ("MICROPY_OOM_CALLBACK", Some("1"))]); + lib.add_private_define("MICROPY_OOM_CALLBACK", Some("1")); } // TODO: remove this hack (causing cyclic dependence) by moving micropython @@ -95,6 +94,10 @@ fn main() -> Result<()> { lib.add_private_include("../rust"); lib.add_sources([ + // Wrappers for micropython static/inline header functions that are called from rust. + // Currently needs to be updated manually even though it's generated by bindgen. + "bindgen-static.c", + "modtimeq.c", "modutime.c", "rustmods.c", "trezorobj.c", @@ -116,23 +119,11 @@ fn main() -> Result<()> { lib.add_sources_in_dir_with_attrs(mpy_dir, ["py/gc.c", "py/pystack.c", "py/vm.c"], attrs); - // silence warning about unterminated string literals - // TODO: remove this after we upgrade MicroPython - let attrs_silence_unterminated = - xbuild::CompileAttrs::new().with_flag("-Wno-unterminated-string-initialization"); - lib.add_sources_in_dir_with_attrs( - mpy_dir, - ["extmod/moductypes.c"], - Some(attrs_silence_unterminated), - ); - lib.add_sources_in_dir( mpy_dir, [ - "extmod/modubinascii.c", - "extmod/moduheapq.c", - "extmod/modutimeq.c", - "extmod/utime_mphal.c", + "extmod/modtime.c", + "extmod/moductypes.c", "shared/timeutils/timeutils.c", "py/argcheck.c", "py/asmarm.c", @@ -147,13 +138,13 @@ fn main() -> Result<()> { "py/builtinhelp.c", "py/builtinimport.c", "py/compile.c", + "py/cstack.c", "py/emitbc.c", "py/emitcommon.c", "py/emitglue.c", "py/emitinlinethumb.c", "py/formatfloat.c", "py/frozenmod.c", - "py/lexer.c", "py/malloc.c", "py/map.c", "py/modarray.c", @@ -166,8 +157,6 @@ fn main() -> Result<()> { "py/modmicropython.c", "py/modstruct.c", "py/modsys.c", - "py/modthread.c", - "py/moduerrno.c", "py/mpprint.c", "py/mpstate.c", "py/mpz.c", @@ -179,6 +168,7 @@ fn main() -> Result<()> { "py/objboundmeth.c", "py/objcell.c", "py/objclosure.c", + "py/objcode.c", "py/objcomplex.c", "py/objdeque.c", "py/objdict.c", @@ -217,7 +207,6 @@ fn main() -> Result<()> { "py/parsenumbase.c", "py/persistentcode.c", "py/qstr.c", - "py/reader.c", "py/repl.c", "py/runtime.c", "py/runtime_utils.c", @@ -235,28 +224,25 @@ fn main() -> Result<()> { ); if cfg!(feature = "emulator") { - lib.add_defines([("MP_CONFIGFILE", Some("\"mpconfigport.h\""))]); - if cfg!(feature = "frozen") { lib.add_define("TREZOR_EMULATOR_FROZEN", None); } - // TODO: refactor modtrezorutils-meminfo.h to avoid this - // - // The hack is needed to compile modtrezorutils-meminfo.h that - // calls STATIC functions in other modules - lib.add_private_define("STATIC", Some("")); - lib.add_sources_in_dir( mpy_dir, [ + "extmod/vfs.c", + "extmod/vfs_posix.c", "extmod/vfs_posix_file.c", - "extmod/moduos.c", + "extmod/vfs_reader.c", + "extmod/modos.c", + "extmod/modvfs.c", "py/emitnarm.c", "py/emitnative.c", "py/emitnthumb.c", "py/emitnx64.c", "py/emitnx86.c", + "py/lexer.c", "py/nlr.c", "py/nlraarch64.c", "py/nlrsetjmp.c", @@ -264,11 +250,13 @@ fn main() -> Result<()> { "py/nlrx64.c", "py/nlrx86.c", "py/profile.c", + "py/reader.c", "ports/unix/alloc.c", "ports/unix/gccollect.c", "ports/unix/input.c", "ports/unix/unix_mphal.c", "shared/runtime/gchelper_generic.c", + "shared/runtime/pyexec.c", "shared/readline/readline.c", ], ); @@ -285,7 +273,7 @@ fn main() -> Result<()> { "shared/runtime/interrupt_char.c", "shared/runtime/pyexec.c", "shared/runtime/stdout_helpers.c", - // "shared/runtime/gchelper_m3.s", // This file is added later + // "shared/runtime/gchelper_thumb2.s", // This file is added later ], ); } else { @@ -314,7 +302,7 @@ fn main() -> Result<()> { if cfg!(not(feature = "emulator")) { // This file must not be preprocessed in MpyBuilder so it is added here // after the build_genhdr step - lib.add_sources_in_dir(mpy_dir, ["shared/runtime/gchelper_m3.s"]); + lib.add_sources_in_dir(mpy_dir, ["shared/runtime/gchelper_thumb2.s"]); } Ok(()) @@ -507,6 +495,14 @@ impl<'a> MpyBuilder<'a> { // can be included directly in firmware. self.build_compressed_data(&compressed_collected)?; + // Extract all MP_REGISTER_ROOT_POINTER(...); statements from preprocessed + // .upydef files and store them in root_pointers.collected.h. + let root_pointers_collected = self.build_root_pointers_collected(&upydefs)?; + + // Run make_root_pointers.py on root_pointers.collected.h to generate + // root_pointers.h that micropython uses in the definition of `mp_state_vm_t`. + self.build_root_pointers_data(&root_pointers_collected)?; + // Generate protobuf blobs based on .proto for Rust code. self.build_protobuf_blobs(&qstr_generated)?; @@ -635,7 +631,7 @@ impl<'a> MpyBuilder<'a> { let output = self.genhdr_dir.join("moduledefs.collected.h"); let mut cmd = std::process::Command::new("sh"); cmd.arg("-c") - .arg(r#"out="$1"; shift; grep '^MP_REGISTER_MODULE' "$@" > "$out""#) + .arg(r#"out="$1"; shift; grep -E '^MP_REGISTER(_EXTENSIBLE)?_MODULE' "$@" > "$out""#) .arg("sh") .arg(&output) .args(upydef_files); @@ -779,6 +775,35 @@ impl<'a> MpyBuilder<'a> { Ok(output) } + fn build_root_pointers_collected(&self, upydef_files: &[PathBuf]) -> Result { + let output = self.genhdr_dir.join("root_pointers.collected.h"); + let mut cmd = std::process::Command::new("sh"); + cmd + .arg("-c") + .arg(r#"out="$1"; shift; cat "$@" | sed -nr 's/.*(MP_REGISTER_ROOT_POINTER\(.*\);).*/\1/p' > "$out""#) + .arg("sh") + .arg(&output) + .args(upydef_files); + + let inputs = upydef_files.iter().collect::>(); + xbuild::run_command(&mut cmd, &inputs, [&output]) + .context("Failed to build root_pointers collected")?; + + Ok(output) + } + + fn build_root_pointers_data(&self, root_pointers_collected: &Path) -> Result { + let mut cmd = std::process::Command::new("python3"); + let tool = self.mpy_dir.join("py/make_root_pointers.py"); + cmd.arg(&tool).arg(root_pointers_collected); + + let output = self.genhdr_dir.join("root_pointers.h"); + let inputs = [tool, root_pointers_collected.to_path_buf()]; + xbuild::run_command_to_file(&mut cmd, &inputs, &output) + .context("Failed to build root_pointers data")?; + Ok(output) + } + fn build_mpy_cross(&self) -> Result { // Here we build `mpy-cross` by calling make directly, so dependency // tracking is left entirely to the makefiles in the mpy-cross source. @@ -789,7 +814,6 @@ impl<'a> MpyBuilder<'a> { // Build mpy-cross in the folder common for all models and targets. let build_dir = xbuild::cargo_target_dir()?.join("mpy-cross"); - let mpy_cross = build_dir.join("mpy-cross"); let source_dir = self.mpy_dir.join("mpy-cross"); let mpycross_include = self.crate_dir.join("mpycross_include"); @@ -799,7 +823,6 @@ impl<'a> MpyBuilder<'a> { cmd.args(["-j", ¶llel_job_count.to_string()]) .args(["-C", &source_dir.to_string_lossy()]) .arg(format!("BUILD={}", &build_dir.to_string_lossy())) - .arg(format!("PROG={}", &mpy_cross.to_string_lossy())) .env("INC", format!("-I{}", &mpycross_include.to_string_lossy())); let cmd_output = cmd @@ -811,7 +834,7 @@ impl<'a> MpyBuilder<'a> { bail!(xbuild::format_command_error(&cmd, &cmd_output)); } - Ok(mpy_cross) + Ok(build_dir.join("mpy-cross")) } fn build_frozen_modules(&self, qstr_preprocessed: &Path) -> Result { diff --git a/core/embed/upymod/modtimeq.c b/core/embed/upymod/modtimeq.c new file mode 100644 index 00000000000..c5a680b45a2 --- /dev/null +++ b/core/embed/upymod/modtimeq.c @@ -0,0 +1,267 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Damien P. George + * Copyright (c) 2016-2017 Paul Sokolovsky + * Copyright (c) 2018 Jan Pochyla + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// copy of extmod/modtimeq.c from last commit before removal - +// 8211d56712301d58970904892da5312b11b2ab7c, plus discard method by +// jpochyla@gmail.com + +#include + +#include "py/objlist.h" +#include "py/runtime.h" +#include "py/smallint.h" + +#define MODULO MICROPY_PY_TIME_TICKS_PERIOD + +#define DEBUG 0 + +// the algorithm here is modelled on CPython's heapq.py + +struct qentry { + mp_uint_t time; + mp_uint_t id; + mp_obj_t callback; + mp_obj_t args; +}; + +typedef struct _mp_obj_timeq_t { + mp_obj_base_t base; + mp_uint_t alloc; + mp_uint_t len; + struct qentry items[]; +} mp_obj_timeq_t; + +static mp_uint_t timeq_id; + +static mp_obj_timeq_t *timeq_get_heap(mp_obj_t heap_in) { + return MP_OBJ_TO_PTR(heap_in); +} + +static bool time_less_than(struct qentry *item, struct qentry *parent) { + mp_uint_t item_tm = item->time; + mp_uint_t parent_tm = parent->time; + mp_uint_t res = parent_tm - item_tm; + if (res == 0) { + // TODO: This actually should use the same "ring" logic + // as for time, to avoid artifacts when id's overflow. + return item->id < parent->id; + } + if ((mp_int_t)res < 0) { + res += MODULO; + } + return res && res < (MODULO / 2); +} + +static mp_obj_t timeq_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); + mp_uint_t alloc = mp_obj_get_int(args[0]); + mp_obj_timeq_t *o = + mp_obj_malloc_var(mp_obj_timeq_t, items, struct qentry, alloc, type); + memset(o->items, 0, sizeof(*o->items) * alloc); + o->alloc = alloc; + o->len = 0; + return MP_OBJ_FROM_PTR(o); +} + +static void timeq_heap_siftdown(mp_obj_timeq_t *heap, mp_uint_t start_pos, + mp_uint_t pos) { + struct qentry item = heap->items[pos]; + while (pos > start_pos) { + mp_uint_t parent_pos = (pos - 1) >> 1; + struct qentry *parent = &heap->items[parent_pos]; + bool lessthan = time_less_than(&item, parent); + if (lessthan) { + heap->items[pos] = *parent; + pos = parent_pos; + } else { + break; + } + } + heap->items[pos] = item; +} + +static void timeq_heap_siftup(mp_obj_timeq_t *heap, mp_uint_t pos) { + mp_uint_t start_pos = pos; + mp_uint_t end_pos = heap->len; + struct qentry item = heap->items[pos]; + for (mp_uint_t child_pos = 2 * pos + 1; child_pos < end_pos; + child_pos = 2 * pos + 1) { + // choose right child if it's <= left child + if (child_pos + 1 < end_pos) { + bool lessthan = + time_less_than(&heap->items[child_pos], &heap->items[child_pos + 1]); + if (!lessthan) { + child_pos += 1; + } + } + // bubble up the smaller child + heap->items[pos] = heap->items[child_pos]; + pos = child_pos; + } + heap->items[pos] = item; + timeq_heap_siftdown(heap, start_pos, pos); +} + +static mp_obj_t mod_timeq_heappush(size_t n_args, const mp_obj_t *args) { + (void)n_args; + mp_obj_t heap_in = args[0]; + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); + if (heap->len == heap->alloc) { + mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("queue overflow")); + } + mp_uint_t l = heap->len; + heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]); + heap->items[l].id = timeq_id++; + heap->items[l].callback = args[2]; + heap->items[l].args = args[3]; + timeq_heap_siftdown(heap, 0, heap->len); + heap->len++; + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_timeq_heappush_obj, 4, 4, + mod_timeq_heappush); + +static mp_obj_t mod_timeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); + if (heap->len == 0) { + mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); + } + mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref); + if (!mp_obj_is_type(list_ref, &mp_type_list) || ret->len < 3) { + mp_raise_TypeError(NULL); + } + + struct qentry *item = &heap->items[0]; + ret->items[0] = MP_OBJ_NEW_SMALL_INT(item->time); + ret->items[1] = item->callback; + ret->items[2] = item->args; + heap->len -= 1; + heap->items[0] = heap->items[heap->len]; + heap->items[heap->len].callback = + MP_OBJ_NULL; // so we don't retain a pointer + heap->items[heap->len].args = MP_OBJ_NULL; + if (heap->len) { + timeq_heap_siftup(heap, 0); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_2(mod_timeq_heappop_obj, mod_timeq_heappop); + +static mp_obj_t mod_timeq_peektime(mp_obj_t heap_in) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); + if (heap->len == 0) { + mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); + } + + struct qentry *item = &heap->items[0]; + return MP_OBJ_NEW_SMALL_INT(item->time); +} +static MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_peektime_obj, mod_timeq_peektime); + +static mp_obj_t mod_timeq_discard(mp_obj_t heap_in, mp_obj_t callback) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); + if (heap->len == 0) { + return mp_const_none; + } + for (mp_uint_t i = 0; i < heap->len; i++) { + if (heap->items[i].callback != callback) { + continue; + } + heap->len -= 1; + heap->items[i] = heap->items[heap->len]; + heap->items[heap->len].callback = MP_OBJ_NULL; + heap->items[heap->len].args = MP_OBJ_NULL; + if (i < heap->len) { + timeq_heap_siftup(heap, i); + timeq_heap_siftdown(heap, 0, i); + } + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_2(mod_timeq_discard_obj, mod_timeq_discard); + +#if DEBUG +static mp_obj_t mod_timeq_dump(mp_obj_t heap_in) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); + for (int i = 0; i < heap->len; i++) { + printf(UINT_FMT "\t%p\t%p\n", heap->items[i].time, + MP_OBJ_TO_PTR(heap->items[i].callback), + MP_OBJ_TO_PTR(heap->items[i].args)); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_dump_obj, mod_timeq_dump); +#endif + +static mp_obj_t timeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + mp_obj_timeq_t *self = MP_OBJ_TO_PTR(self_in); + switch (op) { + case MP_UNARY_OP_BOOL: + return mp_obj_new_bool(self->len != 0); + case MP_UNARY_OP_LEN: + return MP_OBJ_NEW_SMALL_INT(self->len); + default: + return MP_OBJ_NULL; // op not supported + } +} + +static const mp_rom_map_elem_t timeq_locals_dict_table[] = { + {MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&mod_timeq_heappush_obj)}, + {MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&mod_timeq_heappop_obj)}, + {MP_ROM_QSTR(MP_QSTR_peektime), MP_ROM_PTR(&mod_timeq_peektime_obj)}, + {MP_ROM_QSTR(MP_QSTR_discard), MP_ROM_PTR(&mod_timeq_discard_obj)}, +#if DEBUG + {MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_timeq_dump_obj)}, +#endif +}; + +static MP_DEFINE_CONST_DICT(timeq_locals_dict, timeq_locals_dict_table); + +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(timeq_type, + MP_QSTR_timeq, MP_TYPE_FLAG_NONE, + make_new, timeq_make_new, + unary_op, timeq_unary_op, + locals_dict, &timeq_locals_dict); +// clang-format on + +static const mp_rom_map_elem_t mp_module_timeq_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timeq)}, + {MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&timeq_type)}, +}; + +static MP_DEFINE_CONST_DICT(mp_module_timeq_globals, + mp_module_timeq_globals_table); + +const mp_obj_module_t mp_module_timeq = { + .base = {&mp_type_module}, + .globals = (mp_obj_dict_t *)&mp_module_timeq_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_timeq); diff --git a/core/embed/upymod/modtrezorapp/modtrezorapp-image.h b/core/embed/upymod/modtrezorapp/modtrezorapp-image.h index ffa3819ebce..3597246e17e 100644 --- a/core/embed/upymod/modtrezorapp/modtrezorapp-image.h +++ b/core/embed/upymod/modtrezorapp/modtrezorapp-image.h @@ -36,7 +36,7 @@ typedef struct _mp_obj_AppImage_t { /// """ /// Writes data to the application image at the specified offset. /// """ -STATIC mp_obj_t mod_trezorapp_AppImage_write(mp_obj_t self, mp_obj_t offset_obj, +static mp_obj_t mod_trezorapp_AppImage_write(mp_obj_t self, mp_obj_t offset_obj, mp_obj_t data_obj) { mp_obj_AppImage_t *o = MP_OBJ_TO_PTR(self); app_cache_handle_t image = o->image; @@ -54,7 +54,7 @@ STATIC mp_obj_t mod_trezorapp_AppImage_write(mp_obj_t self, mp_obj_t offset_obj, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorapp_AppImage_write_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorapp_AppImage_write_obj, mod_trezorapp_AppImage_write); /// def finalize(self, bool accept) -> None: @@ -63,7 +63,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorapp_AppImage_write_obj, /// the image is marked as loaded and will be available for execution. /// If `accept` is false, the image is discarded. /// """ -STATIC mp_obj_t mod_trezorapp_AppImage_finalize(mp_obj_t self, +static mp_obj_t mod_trezorapp_AppImage_finalize(mp_obj_t self, mp_obj_t accept_obj) { mp_obj_AppImage_t *o = MP_OBJ_TO_PTR(self); @@ -82,19 +82,19 @@ STATIC mp_obj_t mod_trezorapp_AppImage_finalize(mp_obj_t self, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_AppImage_finalize_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_AppImage_finalize_obj, mod_trezorapp_AppImage_finalize); -STATIC const mp_rom_map_elem_t mod_trezorapp_AppImage_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorapp_AppImage_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_trezorapp_AppImage_write_obj)}, {MP_ROM_QSTR(MP_QSTR_finalize), MP_ROM_PTR(&mod_trezorapp_AppImage_finalize_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorapp_AppImage_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorapp_AppImage_locals_dict, mod_trezorapp_AppImage_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorapp_AppImage_type = { - {&mp_type_type}, - .name = MP_QSTR_AppImage, - .locals_dict = (void *)&mod_trezorapp_AppImage_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorapp_AppImage_type, + MP_QSTR_AppImage, MP_TYPE_FLAG_NONE, + locals_dict, &mod_trezorapp_AppImage_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorapp/modtrezorapp-task.h b/core/embed/upymod/modtrezorapp/modtrezorapp-task.h index ddfd41798a4..fe045189fca 100644 --- a/core/embed/upymod/modtrezorapp/modtrezorapp-task.h +++ b/core/embed/upymod/modtrezorapp/modtrezorapp-task.h @@ -36,18 +36,18 @@ typedef struct _mp_obj_AppTask_t { /// """ /// Returns the task id. /// """ -STATIC mp_obj_t mod_trezorapp_AppTask_id(mp_obj_t self) { +static mp_obj_t mod_trezorapp_AppTask_id(mp_obj_t self) { mp_obj_AppTask_t *o = MP_OBJ_TO_PTR(self); return MP_OBJ_NEW_SMALL_INT(o->task_id); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_id_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_id_obj, mod_trezorapp_AppTask_id); /// def is_running(self) -> bool: /// """ /// Returns whether the application is still running. /// """ -STATIC mp_obj_t mod_trezorapp_AppTask_is_running(mp_obj_t self) { +static mp_obj_t mod_trezorapp_AppTask_is_running(mp_obj_t self) { mp_obj_AppTask_t *o = MP_OBJ_TO_PTR(self); if (app_task_is_running(o->task_id)) { @@ -56,14 +56,14 @@ STATIC mp_obj_t mod_trezorapp_AppTask_is_running(mp_obj_t self) { return mp_const_false; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_is_running_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_is_running_obj, mod_trezorapp_AppTask_is_running); /// def unload(self) -> None: /// """ /// Unloads the application associated with this task. /// """ -STATIC mp_obj_t mod_trezorapp_AppTask_unload(mp_obj_t self) { +static mp_obj_t mod_trezorapp_AppTask_unload(mp_obj_t self) { mp_obj_AppTask_t *o = MP_OBJ_TO_PTR(self); app_task_unload(o->task_id); @@ -71,21 +71,21 @@ STATIC mp_obj_t mod_trezorapp_AppTask_unload(mp_obj_t self) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_unload_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_AppTask_unload_obj, mod_trezorapp_AppTask_unload); -STATIC const mp_rom_map_elem_t mod_trezorapp_AppTask_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorapp_AppTask_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_id), MP_ROM_PTR(&mod_trezorapp_AppTask_id_obj)}, {MP_ROM_QSTR(MP_QSTR_is_running), MP_ROM_PTR(&mod_trezorapp_AppTask_is_running_obj)}, {MP_ROM_QSTR(MP_QSTR_unload), MP_ROM_PTR(&mod_trezorapp_AppTask_unload_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorapp_AppTask_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorapp_AppTask_locals_dict, mod_trezorapp_AppTask_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorapp_AppTask_type = { - {&mp_type_type}, - .name = MP_QSTR_AppTask, - .locals_dict = (void *)&mod_trezorapp_AppTask_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorapp_AppTask_type, + MP_QSTR_AppTask, MP_TYPE_FLAG_NONE, + locals_dict, &mod_trezorapp_AppTask_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorapp/modtrezorapp.c b/core/embed/upymod/modtrezorapp/modtrezorapp.c index 15b04461eb8..0110742505d 100644 --- a/core/embed/upymod/modtrezorapp/modtrezorapp.c +++ b/core/embed/upymod/modtrezorapp/modtrezorapp.c @@ -41,7 +41,7 @@ /// """ /// Spawns an application task from the app cache. /// """ -STATIC mp_obj_t mod_trezorapp_spawn_task(mp_obj_t app_hash_obj) { +static mp_obj_t mod_trezorapp_spawn_task(mp_obj_t app_hash_obj) { mp_buffer_info_t hash = {0}; mp_get_buffer_raise(app_hash_obj, &hash, MP_BUFFER_READ); @@ -63,14 +63,14 @@ STATIC mp_obj_t mod_trezorapp_spawn_task(mp_obj_t app_hash_obj) { o->task_id = task_id; return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_spawn_task_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorapp_spawn_task_obj, mod_trezorapp_spawn_task); /// def create_image(app_hash: bytes, size: int) -> AppImage: /// """ /// Creates a new application image in the app cache. /// """ -STATIC mp_obj_t mod_trezorapp_create_image(mp_obj_t app_hash_obj, +static mp_obj_t mod_trezorapp_create_image(mp_obj_t app_hash_obj, mp_obj_t size_obj) { mp_buffer_info_t hash = {0}; mp_get_buffer_raise(app_hash_obj, &hash, MP_BUFFER_READ); @@ -94,7 +94,7 @@ STATIC mp_obj_t mod_trezorapp_create_image(mp_obj_t app_hash_obj, o->image = image; return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_create_image_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_create_image_obj, mod_trezorapp_create_image); #ifdef TREZOR_EMULATOR @@ -102,7 +102,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_create_image_obj, /// """ /// Loads an application image from a file into the app cache. /// """ -STATIC mp_obj_t mod_trezorapp_load_file(mp_obj_t app_hash_obj, +static mp_obj_t mod_trezorapp_load_file(mp_obj_t app_hash_obj, mp_obj_t filename_obj) { mp_buffer_info_t hash = {0}; mp_get_buffer_raise(app_hash_obj, &hash, MP_BUFFER_READ); @@ -123,11 +123,11 @@ STATIC mp_obj_t mod_trezorapp_load_file(mp_obj_t app_hash_obj, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_load_file_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorapp_load_file_obj, mod_trezorapp_load_file); #endif // TREZOR_EMULATOR -STATIC const mp_rom_map_elem_t mp_module_trezorapp_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorapp_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorapp)}, {MP_ROM_QSTR(MP_QSTR_spawn_task), @@ -139,7 +139,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorapp_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorapp_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorapp_globals, mp_module_trezorapp_globals_table); const mp_obj_module_t mp_module_trezorapp = { diff --git a/core/embed/upymod/modtrezorconfig/modtrezorconfig.c b/core/embed/upymod/modtrezorconfig/modtrezorconfig.c index 7f8cdf2b03e..ac8ecc426b8 100644 --- a/core/embed/upymod/modtrezorconfig/modtrezorconfig.c +++ b/core/embed/upymod/modtrezorconfig/modtrezorconfig.c @@ -31,6 +31,8 @@ #include "memzero.h" +MP_REGISTER_ROOT_POINTER(mp_obj_t trezorconfig_ui_wait_callback); + static secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress, enum storage_ui_message_t message) { if (mp_obj_is_callable(MP_STATE_VM(trezorconfig_ui_wait_callback))) { @@ -55,7 +57,7 @@ static secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress, /// Locks the storage if it is currently unlocked, and allows setting /// a new UI callback. /// """ -STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) { if (n_args > 0) { MP_STATE_VM(trezorconfig_ui_wait_callback) = args[0]; storage_setup(wrapped_ui_wait_callback); @@ -64,7 +66,7 @@ STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1, mod_trezorconfig_init); /// def unlock(pin: str, ext_salt: AnyBytes | None) -> bool: @@ -72,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1, /// Attempts to unlock the storage with the given PIN and external salt. /// Returns True on success, False on failure. /// """ -STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin, mp_obj_t ext_salt) { +static mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin, mp_obj_t ext_salt) { mp_buffer_info_t pin_b = {0}; mp_get_buffer_raise(pin, &pin_b, MP_BUFFER_READ); @@ -137,7 +139,7 @@ STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin, mp_obj_t ext_salt) { MP_ERROR_TEXT("Something went wrong during unlock.")); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_unlock_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_unlock_obj, mod_trezorconfig_unlock); /// def check_pin(pin: str, ext_salt: AnyBytes | None) -> bool: @@ -145,57 +147,57 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_unlock_obj, /// Check the given PIN with the given external salt. /// Returns True on success, False on failure. /// """ -STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin, mp_obj_t ext_salt) { +static mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin, mp_obj_t ext_salt) { return mod_trezorconfig_unlock(pin, ext_salt); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_check_pin_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_check_pin_obj, mod_trezorconfig_check_pin); /// def lock() -> None: /// """ /// Locks the storage. /// """ -STATIC mp_obj_t mod_trezorconfig_lock(void) { +static mp_obj_t mod_trezorconfig_lock(void) { storage_lock(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_lock_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_lock_obj, mod_trezorconfig_lock); /// def is_unlocked() -> bool: /// """ /// Returns True if storage is unlocked, False otherwise. /// """ -STATIC mp_obj_t mod_trezorconfig_is_unlocked(void) { +static mp_obj_t mod_trezorconfig_is_unlocked(void) { if (sectrue != storage_is_unlocked()) { return mp_const_false; } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_is_unlocked_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_is_unlocked_obj, mod_trezorconfig_is_unlocked); /// def has_pin() -> bool: /// """ /// Returns True if storage has a configured PIN, False otherwise. /// """ -STATIC mp_obj_t mod_trezorconfig_has_pin(void) { +static mp_obj_t mod_trezorconfig_has_pin(void) { if (sectrue != storage_has_pin()) { return mp_const_false; } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_pin_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_pin_obj, mod_trezorconfig_has_pin); /// def get_pin_rem() -> int: /// """ /// Returns the number of remaining PIN entry attempts. /// """ -STATIC mp_obj_t mod_trezorconfig_get_pin_rem(void) { +static mp_obj_t mod_trezorconfig_get_pin_rem(void) { return mp_obj_new_int_from_uint(storage_get_pin_rem()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_get_pin_rem_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_get_pin_rem_obj, mod_trezorconfig_get_pin_rem); /// def change_pin( @@ -206,7 +208,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_get_pin_rem_obj, /// Change PIN and external salt. Returns True on success, False on entering /// the wipe code. Has to be run with unlocked storage. /// """ -STATIC mp_obj_t mod_trezorconfig_change_pin(size_t n_args, +static mp_obj_t mod_trezorconfig_change_pin(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t newpin = {0}; mp_get_buffer_raise(args[0], &newpin, MP_BUFFER_READ); @@ -245,33 +247,33 @@ STATIC mp_obj_t mod_trezorconfig_change_pin(size_t n_args, mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Change PIN failed.")); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_change_pin_obj, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_change_pin_obj, 2, 2, mod_trezorconfig_change_pin); /// def ensure_not_wipe_code(pin: str) -> None: /// """ /// Wipes the device if the entered PIN is the wipe code. /// """ -STATIC mp_obj_t mod_trezorconfig_ensure_not_wipe_code(mp_obj_t pin) { +static mp_obj_t mod_trezorconfig_ensure_not_wipe_code(mp_obj_t pin) { mp_buffer_info_t pin_b = {0}; mp_get_buffer_raise(pin, &pin_b, MP_BUFFER_READ); storage_ensure_not_wipe_code(pin_b.buf, pin_b.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_ensure_not_wipe_code_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_ensure_not_wipe_code_obj, mod_trezorconfig_ensure_not_wipe_code); /// def has_wipe_code() -> bool: /// """ /// Returns True if storage has a configured wipe code, False otherwise. /// """ -STATIC mp_obj_t mod_trezorconfig_has_wipe_code(void) { +static mp_obj_t mod_trezorconfig_has_wipe_code(void) { if (sectrue != storage_has_wipe_code()) { return mp_const_false; } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_wipe_code_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_wipe_code_obj, mod_trezorconfig_has_wipe_code); /// def change_wipe_code( @@ -282,7 +284,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_wipe_code_obj, /// """ /// Change wipe code. Returns True on success, False on failure. /// """ -STATIC mp_obj_t mod_trezorconfig_change_wipe_code(size_t n_args, +static mp_obj_t mod_trezorconfig_change_wipe_code(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t pin_b = {0}; mp_get_buffer_raise(args[0], &pin_b, MP_BUFFER_READ); @@ -306,7 +308,7 @@ STATIC mp_obj_t mod_trezorconfig_change_wipe_code(size_t n_args, } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorconfig_change_wipe_code_obj, 3, 3, mod_trezorconfig_change_wipe_code); @@ -316,7 +318,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// Raises a RuntimeError if decryption or authentication of the stored /// value fails. /// """ -STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) { uint8_t app = trezor_obj_get_uint8(args[0]); if (app == 0 || app > MAX_APPID) { mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid app ID.")); @@ -340,16 +342,16 @@ STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Failed to get value from storage.")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_get_obj, 2, 3, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_get_obj, 2, 3, mod_trezorconfig_get); /// def set(app: int, key: int, value: AnyBytes, public: bool = False) -> None: /// """ /// Sets a value of given key for given app. /// """ -STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) { uint8_t app = trezor_obj_get_uint8(args[0]); if (app == 0 || app > MAX_APPID) { mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid app ID.")); @@ -367,7 +369,7 @@ STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_obj, 3, 4, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_obj, 3, 4, mod_trezorconfig_set); /// def delete( @@ -376,7 +378,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_obj, 3, 4, /// """ /// Deletes the given key of the given app. /// """ -STATIC mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) { uint8_t app = trezor_obj_get_uint8(args[0]); if (app == 0 || app > MAX_APPID) { mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid app ID.")); @@ -398,7 +400,7 @@ STATIC mp_obj_t mod_trezorconfig_delete(size_t n_args, const mp_obj_t *args) { } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_delete_obj, 2, 4, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_delete_obj, 2, 4, mod_trezorconfig_delete); /// def set_counter( @@ -407,7 +409,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_delete_obj, 2, 4, /// """ /// Sets the given key of the given app as a counter with the given value. /// """ -STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args, +static mp_obj_t mod_trezorconfig_set_counter(size_t n_args, const mp_obj_t *args) { uint8_t app = trezor_obj_get_uint8(args[0]); if (app == 0 || app > MAX_APPID) { @@ -427,7 +429,7 @@ STATIC mp_obj_t mod_trezorconfig_set_counter(size_t n_args, } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_counter_obj, 3, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_counter_obj, 3, 4, mod_trezorconfig_set_counter); /// def next_counter( @@ -437,7 +439,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_set_counter_obj, 3, /// Increments the counter stored under the given key of the given app and /// returns the new value. /// """ -STATIC mp_obj_t mod_trezorconfig_next_counter(size_t n_args, +static mp_obj_t mod_trezorconfig_next_counter(size_t n_args, const mp_obj_t *args) { uint8_t app = trezor_obj_get_uint8(args[0]); if (app == 0 || app > MAX_APPID) { @@ -457,18 +459,18 @@ STATIC mp_obj_t mod_trezorconfig_next_counter(size_t n_args, } return mp_obj_new_int_from_uint(count); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_next_counter_obj, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_next_counter_obj, 2, 3, mod_trezorconfig_next_counter); /// def wipe() -> None: /// """ /// Erases the whole config. Use with caution! /// """ -STATIC mp_obj_t mod_trezorconfig_wipe(void) { +static mp_obj_t mod_trezorconfig_wipe(void) { storage_wipe(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_wipe_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_wipe_obj, mod_trezorconfig_wipe); /// from enum import IntEnum @@ -478,15 +480,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_wipe_obj, /// PROCESSING_MSG = 2 /// STARTING_MSG = 3 /// WRONG_PIN_MSG = 4 -STATIC const qstr mod_trezorconfig_StorageMessage_fields[] = { +static const qstr mod_trezorconfig_StorageMessage_fields[] = { MP_QSTR_NO_MSG, MP_QSTR_VERIFYING_PIN_MSG, MP_QSTR_PROCESSING_MSG, MP_QSTR_STARTING_MSG, MP_QSTR_WRONG_PIN_MSG}; -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mod_trezorconfig_StorageMessage_obj, mod_trezorconfig_StorageMessage_fields, (sizeof(mod_trezorconfig_StorageMessage_fields) / sizeof(qstr)), MP_ROM_INT(0), MP_ROM_INT(1), MP_ROM_INT(2), MP_ROM_INT(3), MP_ROM_INT(4)); -STATIC const mp_rom_map_elem_t mp_module_trezorconfig_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorconfig_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorconfig)}, {MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mod_trezorconfig_init_obj)}, {MP_ROM_QSTR(MP_QSTR_check_pin), @@ -517,7 +519,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorconfig_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_StorageMessage), MP_ROM_PTR(&mod_trezorconfig_StorageMessage_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorconfig_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorconfig_globals, mp_module_trezorconfig_globals_table); const mp_obj_module_t mp_module_trezorconfig = { diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aes.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aes.h index aac688e0dd4..58a19b81706 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aes.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aes.h @@ -58,7 +58,7 @@ typedef struct _mp_obj_AES_t { /// """ /// Initialize AES context. /// """ -STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); @@ -81,8 +81,7 @@ STATIC mp_obj_t mod_trezorcrypto_AES_make_new(const mp_obj_type_t *type, } } - mp_obj_AES_t *o = m_new_obj_with_finaliser(mp_obj_AES_t); - o->base.type = type; + mp_obj_AES_t *o = mp_obj_malloc_with_finaliser(mp_obj_AES_t, type); o->mode = mode; if (iv.len != 0) { memcpy(o->iv, iv.buf, AES_BLOCK_SIZE); @@ -158,40 +157,40 @@ static mp_obj_t aes_update(mp_obj_t self, mp_obj_t data, bool encrypt) { aes_ctr_cbuf_inc, &(o->encrypt_ctx)); break; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } /// def encrypt(self, data: AnyBytes) -> bytes: /// """ /// Encrypt data and update AES context. /// """ -STATIC mp_obj_t mod_trezorcrypto_AES_encrypt(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_AES_encrypt(mp_obj_t self, mp_obj_t data) { return aes_update(self, data, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_encrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_encrypt_obj, mod_trezorcrypto_AES_encrypt); /// def decrypt(self, data: AnyBytes) -> bytes: /// """ /// Decrypt data and update AES context. /// """ -STATIC mp_obj_t mod_trezorcrypto_AES_decrypt(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_AES_decrypt(mp_obj_t self, mp_obj_t data) { return aes_update(self, data, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_decrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_decrypt_obj, mod_trezorcrypto_AES_decrypt); -STATIC mp_obj_t mod_trezorcrypto_AES___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_AES___del__(mp_obj_t self) { mp_obj_AES_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->encrypt_ctx), sizeof(aes_encrypt_ctx)); memzero(&(o->decrypt_ctx), sizeof(aes_decrypt_ctx)); memzero(o->iv, AES_BLOCK_SIZE); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AES___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AES___del___obj, mod_trezorcrypto_AES___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_AES_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_AES_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&mod_trezorcrypto_AES_encrypt_obj)}, {MP_ROM_QSTR(MP_QSTR_decrypt), @@ -204,12 +203,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_AES_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_OFB), MP_ROM_INT(OFB)}, {MP_ROM_QSTR(MP_QSTR_CTR), MP_ROM_INT(CTR)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_AES_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_AES_locals_dict, mod_trezorcrypto_AES_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_AES_type = { - {&mp_type_type}, - .name = MP_QSTR_AES, - .make_new = mod_trezorcrypto_AES_make_new, - .locals_dict = (void *)&mod_trezorcrypto_AES_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_AES_type, + MP_QSTR_AES, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_AES_make_new, + locals_dict, &mod_trezorcrypto_AES_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aesgcm.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aesgcm.h index eb3bffad3d7..c6fc685a6e9 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aesgcm.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-aesgcm.h @@ -46,7 +46,7 @@ typedef struct _mp_obj_AesGcm_t { /// """ /// Initialize the AES-GCM context for encryption. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_AesGcm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); @@ -58,8 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_make_new(const mp_obj_type_t *type, "Invalid length of key (has to be 128, 192 or 256 bits).")); } - mp_obj_AesGcm_t *o = m_new_obj_with_finaliser(mp_obj_AesGcm_t); - o->base.type = type; + mp_obj_AesGcm_t *o = mp_obj_malloc_with_finaliser(mp_obj_AesGcm_t, type); o->state = STATE_INIT; if (gcm_init_and_key(key.buf, key.len, &(o->ctx)) != RETURN_GOOD || gcm_init_message(iv.buf, iv.len, &(o->ctx)) != RETURN_GOOD) { @@ -75,7 +74,7 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_make_new(const mp_obj_type_t *type, /// be called repeatedly to add authenticated data at any point before /// finish(). /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_auth(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_AesGcm_auth(mp_obj_t self, mp_obj_t data) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Invalid state.")); @@ -88,14 +87,14 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_auth(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_auth_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_auth_obj, mod_trezorcrypto_AesGcm_auth); /// def reset(self, iv: AnyBytes) -> None: /// """ /// Reset the IV for encryption. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_reset(mp_obj_t self, mp_obj_t iv) { +static mp_obj_t mod_trezorcrypto_AesGcm_reset(mp_obj_t self, mp_obj_t iv) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t in = {0}; mp_get_buffer_raise(iv, &in, MP_BUFFER_READ); @@ -106,14 +105,14 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_reset(mp_obj_t self, mp_obj_t iv) { o->state = STATE_INIT; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_reset_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_reset_obj, mod_trezorcrypto_AesGcm_reset); /// def encrypt(self, data: AnyBytes) -> bytes: /// """ /// Encrypt data chunk. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_AesGcm_encrypt(mp_obj_t self, mp_obj_t data) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Invalid state.")); @@ -129,16 +128,16 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt(mp_obj_t self, mp_obj_t data) { o->state = STATE_FAILED; mp_raise_type(&mp_type_RuntimeError); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_encrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_encrypt_obj, mod_trezorcrypto_AesGcm_encrypt); /// def encrypt_in_place(self, data: AnyBuffer) -> int: /// """ /// Encrypt data chunk in place. Returns the length of the encrypted data. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt_in_place(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_AesGcm_encrypt_in_place(mp_obj_t self, mp_obj_t data) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { @@ -153,14 +152,14 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt_in_place(mp_obj_t self, } return mp_obj_new_int(in.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_encrypt_in_place_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_encrypt_in_place_obj, mod_trezorcrypto_AesGcm_encrypt_in_place); /// def finish(self) -> bytes: /// """ /// Compute the GCM authentication tag. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt_finish(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_AesGcm_encrypt_finish(mp_obj_t self) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Invalid state.")); @@ -174,9 +173,9 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_encrypt_finish(mp_obj_t self) { o->state = STATE_FAILED; mp_raise_type(&mp_type_RuntimeError); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &tag); + return mp_obj_new_bytes_from_vstr(&tag); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AesGcm_encrypt_finish_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AesGcm_encrypt_finish_obj, mod_trezorcrypto_AesGcm_encrypt_finish); /// class aesgcm_decrypt: @@ -205,7 +204,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AesGcm_encrypt_finish_obj, /// """ /// Decrypt data chunk. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_AesGcm_decrypt(mp_obj_t self, mp_obj_t data) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Invalid state.")); @@ -221,16 +220,16 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt(mp_obj_t self, mp_obj_t data) { o->state = STATE_FAILED; mp_raise_type(&mp_type_RuntimeError); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_obj, mod_trezorcrypto_AesGcm_decrypt); /// def decrypt_in_place(self, data: AnyBuffer) -> int: /// """ /// Decrypt data chunk in place. Returns the length of the decrypted data. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt_in_place(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_AesGcm_decrypt_in_place(mp_obj_t self, mp_obj_t data) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { @@ -245,14 +244,14 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt_in_place(mp_obj_t self, } return mp_obj_new_int(in.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_in_place_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_in_place_obj, mod_trezorcrypto_AesGcm_decrypt_in_place); /// def finish(self, expected_tag: AnyBytes) -> None: /// """ /// Verify the GCM authentication tag. /// """ -STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt_finish(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_AesGcm_decrypt_finish(mp_obj_t self, mp_obj_t expected_tag) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); if (o->state != STATE_INIT && o->state != STATE_PROCESSING) { @@ -281,18 +280,18 @@ STATIC mp_obj_t mod_trezorcrypto_AesGcm_decrypt_finish(mp_obj_t self, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_finish_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AesGcm_decrypt_finish_obj, mod_trezorcrypto_AesGcm_decrypt_finish); -STATIC mp_obj_t mod_trezorcrypto_AesGcm___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_AesGcm___del__(mp_obj_t self) { mp_obj_AesGcm_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(gcm_ctx)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AesGcm___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AesGcm___del___obj, mod_trezorcrypto_AesGcm___del__); -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_AesGcmEncrypt_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_auth), MP_ROM_PTR(&mod_trezorcrypto_AesGcm_auth_obj)}, @@ -308,10 +307,10 @@ STATIC const mp_rom_map_elem_t MP_ROM_PTR(&mod_trezorcrypto_AesGcm___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_AesGcmEncrypt_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_AesGcmEncrypt_locals_dict, mod_trezorcrypto_AesGcmEncrypt_locals_dict_table); -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_AesGcmDecrypt_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_auth), MP_ROM_PTR(&mod_trezorcrypto_AesGcm_auth_obj)}, @@ -327,19 +326,19 @@ STATIC const mp_rom_map_elem_t MP_ROM_PTR(&mod_trezorcrypto_AesGcm___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_AesGcmDecrypt_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_AesGcmDecrypt_locals_dict, mod_trezorcrypto_AesGcmDecrypt_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_AesGcmEncrypt_type = { - {&mp_type_type}, - .name = MP_QSTR_aesgcm_encrypt, - .make_new = mod_trezorcrypto_AesGcm_make_new, - .locals_dict = (void *)&mod_trezorcrypto_AesGcmEncrypt_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_AesGcmEncrypt_type, + MP_QSTR_aesgcm_encrypt, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_AesGcm_make_new, + locals_dict, &mod_trezorcrypto_AesGcmEncrypt_locals_dict); +// clang-format on -STATIC const mp_obj_type_t mod_trezorcrypto_AesGcmDecrypt_type = { - {&mp_type_type}, - .name = MP_QSTR_aesgcm_decrypt, - .make_new = mod_trezorcrypto_AesGcm_make_new, - .locals_dict = (void *)&mod_trezorcrypto_AesGcmDecrypt_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_AesGcmDecrypt_type, + MP_QSTR_aesgcm_decrypt, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_AesGcm_make_new, + locals_dict, &mod_trezorcrypto_AesGcmDecrypt_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bech32.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bech32.h index a57e2a78192..80751e83b48 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bech32.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bech32.h @@ -31,7 +31,7 @@ /// """ /// Decode a Bech32 or Bech32m string /// """ -STATIC mp_obj_t mod_trezorcrypto_bech32_decode(size_t n_args, +static mp_obj_t mod_trezorcrypto_bech32_decode(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bech = {0}; mp_get_buffer_raise(args[0], &bech, MP_BUFFER_READ); @@ -63,26 +63,26 @@ STATIC mp_obj_t mod_trezorcrypto_bech32_decode(size_t n_args, } mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); - tuple->items[0] = mp_obj_new_str(hrp, strlen(hrp)); + tuple->items[0] = mp_obj_new_str_from_cstr(hrp); tuple->items[1] = data_list; tuple->items[2] = MP_OBJ_NEW_SMALL_INT(enc); return MP_OBJ_FROM_PTR(tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_bech32_decode_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_bech32_decode_obj, 1, 2, mod_trezorcrypto_bech32_decode); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_bech32_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_bech32_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bech32)}, {MP_ROM_QSTR(MP_QSTR_decode), MP_ROM_PTR(&mod_trezorcrypto_bech32_decode_obj)}, {MP_ROM_QSTR(MP_QSTR_BECH32), MP_ROM_INT(BECH32_ENCODING_BECH32)}, {MP_ROM_QSTR(MP_QSTR_BECH32M), MP_ROM_INT(BECH32_ENCODING_BECH32M)}}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bech32_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_bech32_globals, mod_trezorcrypto_bech32_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_bech32_module = { +static const mp_obj_module_t mod_trezorcrypto_bech32_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_bech32_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip32.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip32.h index 2347e5b7587..d5ec43f0c33 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip32.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip32.h @@ -49,10 +49,10 @@ /// ) -> None: /// """ /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_depth, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none}}, @@ -115,8 +115,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, mp_raise_ValueError(MP_ERROR_TEXT("curve_name is invalid")); } - mp_obj_HDNode_t *o = m_new_obj_with_finaliser(mp_obj_HDNode_t); - o->base.type = type; + mp_obj_HDNode_t *o = mp_obj_malloc_with_finaliser(mp_obj_HDNode_t, type); o->fingerprint = fingerprint; o->hdnode.depth = depth; o->hdnode.child_num = child_num; @@ -146,7 +145,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, /// """ /// Derive a BIP0032 child node in place. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args, +static mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args, const mp_obj_t *args) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]); uint32_t i = trezor_obj_get_uint(args[1]); @@ -177,7 +176,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_HDNode_derive_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_HDNode_derive_obj, 2, 3, mod_trezorcrypto_HDNode_derive); @@ -186,7 +185,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_HDNode_derive_obj, /// Go through a list of indexes and iteratively derive a child node in /// place. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, mp_obj_t path) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); @@ -213,14 +212,14 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_path_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_path_obj, mod_trezorcrypto_HDNode_derive_path); /// def serialize_public(self, version: int) -> str: /// """ /// Serialize the public info from HD node to base58 string. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, mp_obj_t version) { uint32_t ver = trezor_obj_get_uint(version); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); @@ -238,112 +237,112 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_serialize_public(mp_obj_t self, } // written includes NULL at the end of the string xpub.len = written - 1; - return mp_obj_new_str_from_vstr(&mp_type_str, &xpub); + return mp_obj_new_str_from_vstr(&xpub); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_public_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_serialize_public_obj, mod_trezorcrypto_HDNode_serialize_public); /// def clone(self) -> HDNode: /// """ /// Returns a copy of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_clone(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_clone(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); - mp_obj_HDNode_t *copy = m_new_obj_with_finaliser(mp_obj_HDNode_t); - copy->base.type = &mod_trezorcrypto_HDNode_type; + mp_obj_HDNode_t *copy = mp_obj_malloc_with_finaliser( + mp_obj_HDNode_t, &mod_trezorcrypto_HDNode_type); copy->hdnode = o->hdnode; copy->fingerprint = o->fingerprint; return MP_OBJ_FROM_PTR(copy); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_clone_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_clone_obj, mod_trezorcrypto_HDNode_clone); /// def depth(self) -> int: /// """ /// Returns a depth of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_depth(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_int_from_uint(o->hdnode.depth); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_depth_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_depth_obj, mod_trezorcrypto_HDNode_depth); /// def fingerprint(self) -> int: /// """ /// Returns a fingerprint of the HD node (hash of the parent public key). /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_fingerprint(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_fingerprint(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_int_from_uint(o->fingerprint); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_fingerprint_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_fingerprint_obj, mod_trezorcrypto_HDNode_fingerprint); /// def child_num(self) -> int: /// """ /// Returns a child index of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_child_num(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_int_from_uint(o->hdnode.child_num); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_child_num_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_child_num_obj, mod_trezorcrypto_HDNode_child_num); /// def chain_code(self) -> bytes: /// """ /// Returns a chain code of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_chain_code(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_bytes(o->hdnode.chain_code, sizeof(o->hdnode.chain_code)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_chain_code_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_chain_code_obj, mod_trezorcrypto_HDNode_chain_code); /// def private_key(self) -> bytes: /// """ /// Returns a private key of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_private_key(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_bytes(o->hdnode.private_key, sizeof(o->hdnode.private_key)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_obj, mod_trezorcrypto_HDNode_private_key); /// def private_key_ext(self) -> bytes: /// """ /// Returns a private key extension of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_private_key_ext(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_private_key_ext(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_bytes(o->hdnode.private_key_extension, sizeof(o->hdnode.private_key_extension)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_ext_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_private_key_ext_obj, mod_trezorcrypto_HDNode_private_key_ext); /// def public_key(self) -> bytes: /// """ /// Returns a public key of the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_public_key(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); if (hdnode_fill_public_key(&o->hdnode) != 0) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid private key")); } return mp_obj_new_bytes(o->hdnode.public_key, sizeof(o->hdnode.public_key)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_public_key_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode_public_key_obj, mod_trezorcrypto_HDNode_public_key); /// def address(self, version: int) -> str: /// """ /// Compute a base58-encoded address string from the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, mp_obj_t version) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); @@ -355,9 +354,9 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, mp_raise_ValueError(MP_ERROR_TEXT("Failed to get address")); } address.len = strlen(address.buf); - return mp_obj_new_str_from_vstr(&mp_type_str, &address); + return mp_obj_new_str_from_vstr(&address); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, mod_trezorcrypto_HDNode_address); #if !BITCOIN_ONLY @@ -367,7 +366,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, /// """ /// Compute a NEM address string from the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self, mp_obj_t network) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); @@ -380,9 +379,9 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self, mp_raise_ValueError(MP_ERROR_TEXT("Failed to compute a NEM address")); } address.len = strlen(address.buf); - return mp_obj_new_str_from_vstr(&mp_type_str, &address); + return mp_obj_new_str_from_vstr(&address); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj, mod_trezorcrypto_HDNode_nem_address); /// def nem_encrypt( @@ -395,7 +394,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj, /// """ /// Encrypts payload using the transfer's public key /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args, +static mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args, const mp_obj_t *args) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(args[0]); @@ -429,9 +428,9 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_encrypt(size_t n_args, salt.buf, payload.buf, payload.len, (uint8_t *)vstr.buf)) { mp_raise_ValueError(MP_ERROR_TEXT("HDNode nem encrypt failed")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_HDNode_nem_encrypt_obj, 5, 5, mod_trezorcrypto_HDNode_nem_encrypt); @@ -441,15 +440,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Compute an Ethereum pubkeyhash (aka address) from the HD node. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode_ethereum_pubkeyhash(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); vstr_t pkh = {0}; vstr_init_len(&pkh, 20); hdnode_get_ethereum_pubkeyhash(&o->hdnode, (uint8_t *)pkh.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pkh); + return mp_obj_new_bytes_from_vstr(&pkh); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj, mod_trezorcrypto_HDNode_ethereum_pubkeyhash); @@ -459,16 +458,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( /// """ /// Cleans up sensitive memory. /// """ -STATIC mp_obj_t mod_trezorcrypto_HDNode___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_HDNode___del__(mp_obj_t self) { mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self); o->fingerprint = 0; memzero(&o->hdnode, sizeof(o->hdnode)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_HDNode___del___obj, mod_trezorcrypto_HDNode___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_HDNode_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_HDNode_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_HDNode___del___obj)}, {MP_ROM_QSTR(MP_QSTR_derive), @@ -506,15 +505,15 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_HDNode_locals_dict_table[] = { MP_ROM_PTR(&mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj)}, #endif }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_HDNode_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_HDNode_locals_dict, mod_trezorcrypto_HDNode_locals_dict_table); -const mp_obj_type_t mod_trezorcrypto_HDNode_type = { - {&mp_type_type}, - .name = MP_QSTR_HDNode, - .make_new = mod_trezorcrypto_HDNode_make_new, - .locals_dict = (void *)&mod_trezorcrypto_HDNode_locals_dict, -}; +// clang-format off +MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_HDNode_type, + MP_QSTR_HDNode, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_HDNode_make_new, + locals_dict, &mod_trezorcrypto_HDNode_locals_dict); +// clang-format on /// mock:global @@ -522,7 +521,7 @@ const mp_obj_type_t mod_trezorcrypto_HDNode_type = { /// """ /// Construct a BIP0032 HD node from a BIP0039 seed value. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, +static mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, mp_obj_t curve_name) { mp_buffer_info_t seedb = {0}; mp_get_buffer_raise(seed, &seedb, MP_BUFFER_READ); @@ -542,25 +541,25 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, mp_raise_ValueError(MP_ERROR_TEXT("Failed to derive the root node")); } - mp_obj_HDNode_t *o = m_new_obj_with_finaliser(mp_obj_HDNode_t); - o->base.type = &mod_trezorcrypto_HDNode_type; + mp_obj_HDNode_t *o = mp_obj_malloc_with_finaliser( + mp_obj_HDNode_t, &mod_trezorcrypto_HDNode_type); o->hdnode = hdnode; o->fingerprint = 0; return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj, mod_trezorcrypto_bip32_from_seed); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip32_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_bip32_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip32)}, {MP_ROM_QSTR(MP_QSTR_HDNode), MP_ROM_PTR(&mod_trezorcrypto_HDNode_type)}, {MP_ROM_QSTR(MP_QSTR_from_seed), MP_ROM_PTR(&mod_trezorcrypto_bip32_from_seed_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip32_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip32_globals, mod_trezorcrypto_bip32_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_bip32_module = { +static const mp_obj_module_t mod_trezorcrypto_bip32_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_bip32_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip340.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip340.h index c5bf0c42b01..6185858448a 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip340.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip340.h @@ -31,7 +31,7 @@ /// """ /// Generate secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_generate_secret() { +static mp_obj_t mod_trezorcrypto_bip340_generate_secret() { vstr_t sk = {0}; vstr_init_len(&sk, 32); for (;;) { @@ -53,16 +53,16 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_generate_secret() { continue; break; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sk); + return mp_obj_new_bytes_from_vstr(&sk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_bip340_generate_secret_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_bip340_generate_secret_obj, mod_trezorcrypto_bip340_generate_secret); /// def publickey(secret_key: AnyBytes) -> bytes: /// """ /// Computes public key from secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_publickey(mp_obj_t secret_key) { +static mp_obj_t mod_trezorcrypto_bip340_publickey(mp_obj_t secret_key) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); if (sk.len != 32) { @@ -76,10 +76,10 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_publickey(mp_obj_t secret_key) { vstr_clear(&pk); mp_raise_ValueError(MP_ERROR_TEXT("Invalid secret key")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_publickey_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_publickey_obj, mod_trezorcrypto_bip340_publickey); /// def sign( @@ -89,7 +89,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_publickey_obj, /// """ /// Uses secret key to produce the signature of the digest. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_sign(mp_obj_t secret_key, +static mp_obj_t mod_trezorcrypto_bip340_sign(mp_obj_t secret_key, mp_obj_t digest) { mp_buffer_info_t sk = {0}, dig = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); @@ -110,10 +110,10 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_sign(mp_obj_t secret_key, vstr_clear(&sig); mp_raise_ValueError(MP_ERROR_TEXT("Signing failed")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip340_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip340_sign_obj, mod_trezorcrypto_bip340_sign); /// def verify_publickey(public_key: AnyBytes) -> bool: @@ -121,7 +121,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip340_sign_obj, /// Verifies whether the public key is valid. /// Returns True on success. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_verify_publickey(mp_obj_t public_key) { +static mp_obj_t mod_trezorcrypto_bip340_verify_publickey(mp_obj_t public_key) { mp_buffer_info_t pk = {0}; mp_get_buffer_raise(public_key, &pk, MP_BUFFER_READ); if (pk.len != 32) { @@ -130,7 +130,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_verify_publickey(mp_obj_t public_key) { int ret = zkp_bip340_verify_publickey((const uint8_t *)pk.buf); return mp_obj_new_bool(ret == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_verify_publickey_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_verify_publickey_obj, mod_trezorcrypto_bip340_verify_publickey); /// def verify( @@ -140,7 +140,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip340_verify_publickey_obj, /// Uses public key to verify the signature of the digest. /// Returns True on success. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_verify(mp_obj_t public_key, +static mp_obj_t mod_trezorcrypto_bip340_verify(mp_obj_t public_key, mp_obj_t signature, mp_obj_t digest) { mp_buffer_info_t pk = {0}, sig = {0}, dig = {0}; @@ -161,7 +161,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_verify(mp_obj_t public_key, (const uint8_t *)dig.buf); return mp_obj_new_bool(ret == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_bip340_verify_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_bip340_verify_obj, mod_trezorcrypto_bip340_verify); /// def tweak_public_key( @@ -171,7 +171,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_bip340_verify_obj, /// """ /// Tweaks the public key with the specified root_hash. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_tweak_public_key(size_t n_args, +static mp_obj_t mod_trezorcrypto_bip340_tweak_public_key(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t pk = {0}; mp_get_buffer_raise(args[0], &pk, MP_BUFFER_READ); @@ -197,10 +197,10 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_tweak_public_key(size_t n_args, vstr_clear(&tpk); mp_raise_ValueError(MP_ERROR_TEXT("Failed to tweak public key")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &tpk); + return mp_obj_new_bytes_from_vstr(&tpk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_bip340_tweak_public_key_obj, 1, 2, mod_trezorcrypto_bip340_tweak_public_key); @@ -211,7 +211,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Tweaks the secret key with the specified root_hash. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip340_tweak_secret_key(size_t n_args, +static mp_obj_t mod_trezorcrypto_bip340_tweak_secret_key(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ); @@ -237,14 +237,14 @@ STATIC mp_obj_t mod_trezorcrypto_bip340_tweak_secret_key(size_t n_args, vstr_clear(&tsk); mp_raise_ValueError(MP_ERROR_TEXT("Failed to tweak secret key")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &tsk); + return mp_obj_new_bytes_from_vstr(&tsk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_bip340_tweak_secret_key_obj, 1, 2, mod_trezorcrypto_bip340_tweak_secret_key); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip340_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_bip340_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip340)}, {MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_bip340_generate_secret_obj)}, @@ -259,10 +259,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip340_globals_table[] = { MP_ROM_PTR(&mod_trezorcrypto_bip340_tweak_public_key_obj)}, {MP_ROM_QSTR(MP_QSTR_tweak_secret_key), MP_ROM_PTR(&mod_trezorcrypto_bip340_tweak_secret_key_obj)}}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip340_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip340_globals, mod_trezorcrypto_bip340_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_bip340_module = { +static const mp_obj_module_t mod_trezorcrypto_bip340_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_bip340_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip39.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip39.h index a7dc9c0d00d..d3e66cb55ef 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip39.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-bip39.h @@ -29,7 +29,7 @@ /// """ /// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes). /// """ -STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) { mp_buffer_info_t bin = {0}; mp_get_buffer_raise(data, &bin, MP_BUFFER_READ); if (bin.len % 4 || bin.len < 16 || bin.len > 32) { @@ -42,20 +42,20 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) { mnemonic_clear(); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_from_data_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_from_data_obj, mod_trezorcrypto_bip39_from_data); /// def check(mnemonic: str) -> bool: /// """ /// Check whether given mnemonic is valid. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) { +static mp_obj_t mod_trezorcrypto_bip39_check(mp_obj_t mnemonic) { mp_buffer_info_t text = {0}; mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ); return (text.len > 0 && mnemonic_check(text.buf)) ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_check_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_check_obj, mod_trezorcrypto_bip39_check); /// def seed( @@ -66,7 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_check_obj, /// """ /// Generate seed from mnemonic and passphrase. /// """ -STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args, +static mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t mnemo = {0}; mp_buffer_info_t phrase = {0}; @@ -86,9 +86,9 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_seed(size_t n_args, // generate without callback mnemonic_to_seed(pmnemonic, ppassphrase, (uint8_t *)seed.buf, NULL); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &seed); + return mp_obj_new_bytes_from_vstr(&seed); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_bip39_seed_obj, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_bip39_seed_obj, 2, 3, mod_trezorcrypto_bip39_seed); #if !BITCOIN_ONLY @@ -96,7 +96,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_bip39_seed_obj, 2, /// """ /// Convert the mnemonic to its binary representation (including checksum). /// """ -STATIC mp_obj_t mod_trezorcrypto_bip39_mnemonic_to_bits(mp_obj_t mnemonic) { +static mp_obj_t mod_trezorcrypto_bip39_mnemonic_to_bits(mp_obj_t mnemonic) { mp_buffer_info_t text = {0}; mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ); @@ -107,11 +107,11 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_mnemonic_to_bits(mp_obj_t mnemonic) { } return mp_obj_new_bytes(bits, (binary_mnemonics_len + 7) / 8); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_mnemonic_to_bits_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_mnemonic_to_bits_obj, mod_trezorcrypto_bip39_mnemonic_to_bits); #endif // !BITCOIN_ONLY -STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip39_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_bip39_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip39)}, {MP_ROM_QSTR(MP_QSTR_from_data), MP_ROM_PTR(&mod_trezorcrypto_bip39_from_data_obj)}, @@ -122,10 +122,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip39_globals_table[] = { MP_ROM_PTR(&mod_trezorcrypto_bip39_mnemonic_to_bits_obj)}, #endif // !BITCOIN_ONLY }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip39_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip39_globals, mod_trezorcrypto_bip39_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_bip39_module = { +static const mp_obj_module_t mod_trezorcrypto_bip39_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_bip39_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake256.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake256.h index bd46342d6fc..b4b36de2458 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake256.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake256.h @@ -35,18 +35,17 @@ typedef struct _mp_obj_Blake256_t { BLAKE256_CTX ctx; } mp_obj_Blake256_t; -STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Blake256_t *o = m_new_obj_with_finaliser(mp_obj_Blake256_t); - o->base.type = type; + mp_obj_Blake256_t *o = mp_obj_malloc_with_finaliser(mp_obj_Blake256_t, type); blake256_Init(&(o->ctx)); // constructor called with bytes/str as first parameter if (n_args == 1) { @@ -59,7 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) { mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -68,14 +67,14 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake256_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake256_update_obj, mod_trezorcrypto_Blake256_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) { mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, BLAKE256_DIGEST_LENGTH); @@ -83,20 +82,20 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(BLAKE256_CTX)); blake256_Final(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(BLAKE256_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256_digest_obj, mod_trezorcrypto_Blake256_digest); -STATIC mp_obj_t mod_trezorcrypto_Blake256___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake256___del__(mp_obj_t self) { mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(BLAKE256_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256___del___obj, mod_trezorcrypto_Blake256___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake256_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Blake256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Blake256_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -106,12 +105,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(BLAKE256_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(BLAKE256_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake256_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake256_locals_dict, mod_trezorcrypto_Blake256_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Blake256_type = { - {&mp_type_type}, - .name = MP_QSTR_Blake256, - .make_new = mod_trezorcrypto_Blake256_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Blake256_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Blake256_type, + MP_QSTR_Blake256, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Blake256_make_new, + locals_dict, &mod_trezorcrypto_Blake256_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2b.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2b.h index 903f25464f1..3b71205a530 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2b.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2b.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Blake2b_t { BLAKE2B_CTX ctx; } mp_obj_Blake2b_t; -STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -49,10 +49,10 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data); /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes}}, {MP_QSTR_outlen, MP_ARG_KW_ONLY | MP_ARG_INT, @@ -84,8 +84,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, MP_ERROR_TEXT("Cannot use Blake2b key and personal at the same time")); } - mp_obj_Blake2b_t *o = m_new_obj_with_finaliser(mp_obj_Blake2b_t); - o->base.type = type; + mp_obj_Blake2b_t *o = mp_obj_malloc_with_finaliser(mp_obj_Blake2b_t, type); int res = 0; if (key_len > 0) { @@ -113,7 +112,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) { mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -122,14 +121,14 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2b_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2b_update_obj, mod_trezorcrypto_Blake2b_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) { mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self); BLAKE2B_CTX ctx = {0}; memcpy(&ctx, &(o->ctx), sizeof(BLAKE2B_CTX)); @@ -137,20 +136,20 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_digest(mp_obj_t self) { vstr_init_len(&hash, ctx.outlen); blake2b_Final(&ctx, (uint8_t *)hash.buf, hash.len); memzero(&ctx, sizeof(BLAKE2B_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b_digest_obj, mod_trezorcrypto_Blake2b_digest); -STATIC mp_obj_t mod_trezorcrypto_Blake2b___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake2b___del__(mp_obj_t self) { mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(BLAKE2B_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b___del___obj, mod_trezorcrypto_Blake2b___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2b_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Blake2b_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Blake2b_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -160,12 +159,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2b_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(BLAKE2B_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(BLAKE2B_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2b_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2b_locals_dict, mod_trezorcrypto_Blake2b_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Blake2b_type = { - {&mp_type_type}, - .name = MP_QSTR_Blake2b, - .make_new = mod_trezorcrypto_Blake2b_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Blake2b_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Blake2b_type, + MP_QSTR_Blake2b, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Blake2b_make_new, + locals_dict, &mod_trezorcrypto_Blake2b_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2s.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2s.h index a09334f6984..15dc51ef93c 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2s.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-blake2s.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Blake2s_t { BLAKE2S_CTX ctx; } mp_obj_Blake2s_t; -STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -49,10 +49,10 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data); /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes}}, {MP_QSTR_outlen, MP_ARG_KW_ONLY | MP_ARG_INT, @@ -84,8 +84,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, MP_ERROR_TEXT("Cannot use Blake2s key and personal at the same time")); } - mp_obj_Blake2s_t *o = m_new_obj_with_finaliser(mp_obj_Blake2s_t); - o->base.type = type; + mp_obj_Blake2s_t *o = mp_obj_malloc_with_finaliser(mp_obj_Blake2s_t, type); int res = 0; if (key_len > 0) { @@ -113,7 +112,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) { mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -122,14 +121,14 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2s_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Blake2s_update_obj, mod_trezorcrypto_Blake2s_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) { mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self); BLAKE2S_CTX ctx = {0}; memcpy(&ctx, &(o->ctx), sizeof(BLAKE2S_CTX)); @@ -137,20 +136,20 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_digest(mp_obj_t self) { vstr_init_len(&hash, ctx.outlen); blake2s_Final(&ctx, (uint8_t *)hash.buf, hash.len); memzero(&ctx, sizeof(BLAKE2S_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s_digest_obj, mod_trezorcrypto_Blake2s_digest); -STATIC mp_obj_t mod_trezorcrypto_Blake2s___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Blake2s___del__(mp_obj_t self) { mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(BLAKE2S_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s___del___obj, mod_trezorcrypto_Blake2s___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2s_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Blake2s_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Blake2s_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -160,12 +159,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Blake2s_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(BLAKE2S_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(BLAKE2S_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2s_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Blake2s_locals_dict, mod_trezorcrypto_Blake2s_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Blake2s_type = { - {&mp_type_type}, - .name = MP_QSTR_Blake2s, - .make_new = mod_trezorcrypto_Blake2s_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Blake2s_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Blake2s_type, + MP_QSTR_Blake2s, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Blake2s_make_new, + locals_dict, &mod_trezorcrypto_Blake2s_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-cardano.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-cardano.h index 8b78da02412..68cf8f7ab85 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-cardano.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-cardano.h @@ -44,7 +44,7 @@ /// scheme. If `trezor_derivation` is True, the Icarus-Trezor variant is /// used (see CIP-3). /// """ -STATIC mp_obj_t mod_trezorcrypto_cardano_derive_icarus(size_t n_args, +static mp_obj_t mod_trezorcrypto_cardano_derive_icarus(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t binary_mnemonic = {0}, phrase = {0}; mp_get_buffer_raise(args[0], &binary_mnemonic, MP_BUFFER_READ); @@ -86,10 +86,10 @@ STATIC mp_obj_t mod_trezorcrypto_cardano_derive_icarus(size_t n_args, MP_ERROR_TEXT("Unexpected failure in Icarus derivation.")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_cardano_derive_icarus_obj, 3, 4, mod_trezorcrypto_cardano_derive_icarus); @@ -97,15 +97,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Creates a Cardano HD node from a master secret. /// """ -STATIC mp_obj_t mod_trezorcrypto_from_secret(mp_obj_t secret) { +static mp_obj_t mod_trezorcrypto_from_secret(mp_obj_t secret) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(secret, &bufinfo, MP_BUFFER_READ); if (bufinfo.len != CARDANO_SECRET_LENGTH) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid secret length")); } - mp_obj_HDNode_t *o = m_new_obj_with_finaliser(mp_obj_HDNode_t); - o->base.type = &mod_trezorcrypto_HDNode_type; + mp_obj_HDNode_t *o = mp_obj_malloc_with_finaliser( + mp_obj_HDNode_t, &mod_trezorcrypto_HDNode_type); const int res = hdnode_from_secret_cardano(bufinfo.buf, &o->hdnode); if (res != 1) { m_del_obj(mp_obj_HDNode_t, o); @@ -117,14 +117,14 @@ STATIC mp_obj_t mod_trezorcrypto_from_secret(mp_obj_t secret) { return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_secret_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_secret_obj, mod_trezorcrypto_from_secret); /// def from_seed_slip23(seed: AnyBytes) -> HDNode: /// """ /// Creates a Cardano HD node from a seed via SLIP-23 derivation. /// """ -STATIC mp_obj_t mod_trezorcrypto_from_seed_slip23(mp_obj_t seed) { +static mp_obj_t mod_trezorcrypto_from_seed_slip23(mp_obj_t seed) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(seed, &bufinfo, MP_BUFFER_READ); if (bufinfo.len == 0) { @@ -147,21 +147,21 @@ STATIC mp_obj_t mod_trezorcrypto_from_seed_slip23(mp_obj_t seed) { MP_ERROR_TEXT("Unexpected failure in constructing Cardano node.")); } - mp_obj_HDNode_t *o = m_new_obj_with_finaliser(mp_obj_HDNode_t); - o->base.type = &mod_trezorcrypto_HDNode_type; + mp_obj_HDNode_t *o = mp_obj_malloc_with_finaliser( + mp_obj_HDNode_t, &mod_trezorcrypto_HDNode_type); o->hdnode = hdnode; o->fingerprint = hdnode_fingerprint(&o->hdnode); return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_seed_slip23_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_seed_slip23_obj, mod_trezorcrypto_from_seed_slip23); /// def from_seed_ledger(seed: AnyBytes) -> HDNode: /// """ /// Creates a Cardano HD node from a seed via Ledger derivation. /// """ -STATIC mp_obj_t mod_trezorcrypto_from_seed_ledger(mp_obj_t seed) { +static mp_obj_t mod_trezorcrypto_from_seed_ledger(mp_obj_t seed) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(seed, &bufinfo, MP_BUFFER_READ); if (bufinfo.len == 0) { @@ -184,17 +184,17 @@ STATIC mp_obj_t mod_trezorcrypto_from_seed_ledger(mp_obj_t seed) { MP_ERROR_TEXT("Unexpected failure in constructing Cardano node.")); } - mp_obj_HDNode_t *o = m_new_obj_with_finaliser(mp_obj_HDNode_t); - o->base.type = &mod_trezorcrypto_HDNode_type; + mp_obj_HDNode_t *o = mp_obj_malloc_with_finaliser( + mp_obj_HDNode_t, &mod_trezorcrypto_HDNode_type); o->hdnode = hdnode; o->fingerprint = hdnode_fingerprint(&o->hdnode); return MP_OBJ_FROM_PTR(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_seed_ledger_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_from_seed_ledger_obj, mod_trezorcrypto_from_seed_ledger); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_cardano_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_cardano_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cardano)}, {MP_ROM_QSTR(MP_QSTR_derive_icarus), MP_ROM_PTR(&mod_trezorcrypto_cardano_derive_icarus_obj)}, @@ -205,10 +205,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_cardano_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_from_seed_ledger), MP_ROM_PTR(&mod_trezorcrypto_from_seed_ledger_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_cardano_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_cardano_globals, mod_trezorcrypto_cardano_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_cardano_module = { +static const mp_obj_module_t mod_trezorcrypto_cardano_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_cardano_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h index f22596d8b47..5f7e7a297eb 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h @@ -47,7 +47,7 @@ typedef struct _mp_obj_ChaCha20Poly1305_t { /// Initialize the ChaCha20 + Poly1305 context for encryption /// using a 32 byte key and 12 byte nonce as in the RFC 7539 style. /// """ -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new( +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new( const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); @@ -61,9 +61,8 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new( mp_raise_ValueError(MP_ERROR_TEXT("Invalid length of nonce")); } mp_obj_ChaCha20Poly1305_t *o = - m_new_obj_with_finaliser(mp_obj_ChaCha20Poly1305_t); + mp_obj_malloc_with_finaliser(mp_obj_ChaCha20Poly1305_t, type); rfc7539_init(&(o->ctx), key.buf, nonce.buf); - o->base.type = type; o->alen = 0; o->plen = 0; o->state = INIT; @@ -76,7 +75,7 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_make_new( /// style with 16 byte padding. This must only be called once and prior /// to encryption. /// """ -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self, mp_obj_t data) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); if (o->state != INIT) { @@ -89,7 +88,7 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_auth(mp_obj_t self, o->alen += in.len; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_auth_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_auth_obj, mod_trezorcrypto_ChaCha20Poly1305_auth); /// def encrypt(self, data: AnyBytes) -> bytes: @@ -97,7 +96,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_auth_obj, /// Encrypt data (length of data must be divisible by 64 except for the /// final value). /// """ -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self, mp_obj_t data) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); if (o->state != INIT && o->state != PROCESSING) { @@ -110,17 +109,17 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt(mp_obj_t self, vstr_init_len(&vstr, in.len); chacha20poly1305_encrypt(&(o->ctx), in.buf, (uint8_t *)vstr.buf, in.len); o->plen += in.len; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_encrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_encrypt_obj, mod_trezorcrypto_ChaCha20Poly1305_encrypt); /// def finish(self) -> bytes: /// """ /// Compute RFC 7539-style Poly1305 MAC. /// """ -STATIC mp_obj_t -mod_trezorcrypto_ChaCha20Poly1305_encrypt_finish(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_encrypt_finish( + mp_obj_t self) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); if (o->state != INIT && o->state != PROCESSING) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Invalid state.")); @@ -130,9 +129,9 @@ mod_trezorcrypto_ChaCha20Poly1305_encrypt_finish(mp_obj_t self) { vstr_t mac = {0}; vstr_init_len(&mac, 16); rfc7539_finish(&(o->ctx), o->alen, o->plen, (uint8_t *)mac.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &mac); + return mp_obj_new_bytes_from_vstr(&mac); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_ChaCha20Poly1305_encrypt_finish_obj, mod_trezorcrypto_ChaCha20Poly1305_encrypt_finish); @@ -159,7 +158,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( /// Decrypt data (length of data must be divisible by 64 except for the /// final value). /// """ -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self, mp_obj_t data) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); if (o->state != INIT && o->state != PROCESSING) { @@ -172,16 +171,16 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt(mp_obj_t self, vstr_init_len(&vstr, in.len); chacha20poly1305_decrypt(&(o->ctx), in.buf, (uint8_t *)vstr.buf, in.len); o->plen += in.len; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_decrypt_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ChaCha20Poly1305_decrypt_obj, mod_trezorcrypto_ChaCha20Poly1305_decrypt); /// def finish(self, expected_mac: AnyBytes) -> None: /// """ /// Verify RFC 7539-style Poly1305 MAC. /// """ -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt_finish( +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt_finish( mp_obj_t self, mp_obj_t expected_mac) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); if (o->state != INIT && o->state != PROCESSING) { @@ -206,21 +205,21 @@ STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305_decrypt_finish( return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2( +static MP_DEFINE_CONST_FUN_OBJ_2( mod_trezorcrypto_ChaCha20Poly1305_decrypt_finish_obj, mod_trezorcrypto_ChaCha20Poly1305_decrypt_finish); -STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_ChaCha20Poly1305___del__(mp_obj_t self) { mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(chacha20poly1305_ctx)); o->alen = 0; o->plen = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ChaCha20Poly1305___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ChaCha20Poly1305___del___obj, mod_trezorcrypto_ChaCha20Poly1305___del__); -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_ChaCha20Poly1305Encrypt_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&mod_trezorcrypto_ChaCha20Poly1305_encrypt_obj)}, @@ -231,11 +230,11 @@ STATIC const mp_rom_map_elem_t {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_ChaCha20Poly1305___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT( +static MP_DEFINE_CONST_DICT( mod_trezorcrypto_ChaCha20Poly1305Encrypt_locals_dict, mod_trezorcrypto_ChaCha20Poly1305Encrypt_locals_dict_table); -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_ChaCha20Poly1305Decrypt_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&mod_trezorcrypto_ChaCha20Poly1305_decrypt_obj)}, @@ -246,22 +245,20 @@ STATIC const mp_rom_map_elem_t {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_ChaCha20Poly1305___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT( +static MP_DEFINE_CONST_DICT( mod_trezorcrypto_ChaCha20Poly1305Decrypt_locals_dict, mod_trezorcrypto_ChaCha20Poly1305Decrypt_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_ChaCha20Poly1305Encrypt_type = { - {&mp_type_type}, - .name = MP_QSTR_chacha20poly1305_encrypt, - .make_new = mod_trezorcrypto_ChaCha20Poly1305_make_new, - .locals_dict = - (void *)&mod_trezorcrypto_ChaCha20Poly1305Encrypt_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_ChaCha20Poly1305Encrypt_type, + MP_QSTR_chacha20poly1305_encrypt, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_ChaCha20Poly1305_make_new, + locals_dict, &mod_trezorcrypto_ChaCha20Poly1305Encrypt_locals_dict); +// clang-format on -STATIC const mp_obj_type_t mod_trezorcrypto_ChaCha20Poly1305Decrypt_type = { - {&mp_type_type}, - .name = MP_QSTR_chacha20poly1305_decrypt, - .make_new = mod_trezorcrypto_ChaCha20Poly1305_make_new, - .locals_dict = - (void *)&mod_trezorcrypto_ChaCha20Poly1305Decrypt_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_ChaCha20Poly1305Decrypt_type, + MP_QSTR_chacha20poly1305_decrypt, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_ChaCha20Poly1305_make_new, + locals_dict, &mod_trezorcrypto_ChaCha20Poly1305Decrypt_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-crc.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-crc.h index 61f283c44b9..bd10ea3bd10 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-crc.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-crc.h @@ -44,17 +44,17 @@ mp_obj_t mod_trezorcrypto_crc_crc32(size_t n_args, const mp_obj_t *args) { crc = checksum_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff); return mp_obj_new_int_from_uint(crc ^ 0xffffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_crc_crc32_obj, 1, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_crc_crc32_obj, 1, 2, mod_trezorcrypto_crc_crc32); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_crc_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_crc_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_crc)}, {MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_trezorcrypto_crc_crc32_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_crc_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_crc_globals, mod_trezorcrypto_crc_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_crc_module = { +static const mp_obj_module_t mod_trezorcrypto_crc_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_crc_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-curve25519.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-curve25519.h index 04dec57a414..b693e729899 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-curve25519.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-curve25519.h @@ -29,7 +29,7 @@ /// """ /// Generate secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() { +static mp_obj_t mod_trezorcrypto_curve25519_generate_secret() { vstr_t sk = {0}; vstr_init_len(&sk, 32); rng_fill_buffer((uint8_t *)sk.buf, sk.len); @@ -37,9 +37,9 @@ STATIC mp_obj_t mod_trezorcrypto_curve25519_generate_secret() { sk.buf[0] &= 248; sk.buf[31] &= 127; sk.buf[31] |= 64; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sk); + return mp_obj_new_bytes_from_vstr(&sk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0( +static MP_DEFINE_CONST_FUN_OBJ_0( mod_trezorcrypto_curve25519_generate_secret_obj, mod_trezorcrypto_curve25519_generate_secret); @@ -47,7 +47,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0( /// """ /// Computes public key from secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) { +static mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); if (sk.len != 32) { @@ -56,9 +56,9 @@ STATIC mp_obj_t mod_trezorcrypto_curve25519_publickey(mp_obj_t secret_key) { vstr_t pk = {0}; vstr_init_len(&pk, 32); curve25519_scalarmult_basepoint((uint8_t *)pk.buf, (const uint8_t *)sk.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_curve25519_publickey_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_curve25519_publickey_obj, mod_trezorcrypto_curve25519_publickey); /// def multiply(secret_key: AnyBytes, public_key: AnyBytes) -> bytes: @@ -66,7 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_curve25519_publickey_obj, /// Multiplies point defined by public_key with scalar defined by /// secret_key. Useful for ECDH. /// """ -STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key, +static mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key, mp_obj_t public_key) { mp_buffer_info_t sk = {0}, pk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); @@ -81,12 +81,12 @@ STATIC mp_obj_t mod_trezorcrypto_curve25519_multiply(mp_obj_t secret_key, vstr_init_len(&out, 32); curve25519_scalarmult((uint8_t *)out.buf, (const uint8_t *)sk.buf, (const uint8_t *)pk.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_curve25519_multiply_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_curve25519_multiply_obj, mod_trezorcrypto_curve25519_multiply); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_curve25519_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_curve25519_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_curve25519)}, {MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_curve25519_generate_secret_obj)}, @@ -95,10 +95,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_curve25519_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_trezorcrypto_curve25519_multiply_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_curve25519_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_curve25519_globals, mod_trezorcrypto_curve25519_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_curve25519_module = { +static const mp_obj_module_t mod_trezorcrypto_curve25519_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_curve25519_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ed25519.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ed25519.h index 1c8df4952b7..36864ec8323 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ed25519.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ed25519.h @@ -30,20 +30,20 @@ /// """ /// Generate secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_generate_secret() { +static mp_obj_t mod_trezorcrypto_ed25519_generate_secret() { vstr_t sk = {0}; vstr_init_len(&sk, 32); rng_fill_buffer((uint8_t *)sk.buf, sk.len); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sk); + return mp_obj_new_bytes_from_vstr(&sk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_generate_secret_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_generate_secret_obj, mod_trezorcrypto_ed25519_generate_secret); /// def publickey(secret_key: AnyBytes) -> bytes: /// """ /// Computes public key from secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) { +static mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); if (sk.len != 32) { @@ -53,9 +53,9 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_publickey(mp_obj_t secret_key) { vstr_init_len(&pk, sizeof(ed25519_public_key)); ed25519_publickey(*(const ed25519_secret_key *)sk.buf, *(ed25519_public_key *)pk.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj, mod_trezorcrypto_ed25519_publickey); /// def sign( @@ -64,7 +64,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ed25519_publickey_obj, /// """ /// Uses secret key to produce the signature of message. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args, +static mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}, msg = {0}; mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ); @@ -94,9 +94,9 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_sign(size_t n_args, *(ed25519_signature *)sig.buf); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2, 3, mod_trezorcrypto_ed25519_sign); #if !BITCOIN_ONLY @@ -107,7 +107,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_ed25519_sign_obj, 2, /// """ /// Uses extended secret key to produce the cardano signature of message. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_scalar, +static mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_scalar, mp_obj_t secret_extension, mp_obj_t message) { mp_buffer_info_t sk = {0}, skext = {0}, msg = {0}; @@ -129,9 +129,9 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_sign_ext(mp_obj_t secret_scalar, ed25519_sign_ext(msg.buf, msg.len, *(const ed25519_secret_key *)sk.buf, *(const ed25519_secret_key *)skext.buf, *(ed25519_signature *)sig.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_sign_ext_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_sign_ext_obj, mod_trezorcrypto_ed25519_sign_ext); #endif @@ -143,7 +143,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_sign_ext_obj, /// Uses public key to verify the signature of the message. /// Returns True on success. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key, +static mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key, mp_obj_t signature, mp_obj_t message) { mp_buffer_info_t pk = {0}, sig = {0}, msg = {0}; @@ -165,15 +165,15 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_verify(mp_obj_t public_key, ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_verify_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ed25519_verify_obj, mod_trezorcrypto_ed25519_verify); /// def cosi_combine_publickeys(public_keys: Sequence[AnyBytes]) -> bytes: /// """ /// Combines a list of public keys used in COSI cosigning scheme. /// """ -STATIC mp_obj_t -mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) { +static mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_publickeys( + mp_obj_t public_keys) { size_t pklen = 0; mp_obj_t *pkitems = NULL; mp_obj_get_array(public_keys, &pklen, &pkitems); @@ -198,9 +198,9 @@ mod_trezorcrypto_ed25519_cosi_combine_publickeys(mp_obj_t public_keys) { vstr_clear(&pk); mp_raise_ValueError(MP_ERROR_TEXT("Error combining public keys")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_ed25519_cosi_combine_publickeys_obj, mod_trezorcrypto_ed25519_cosi_combine_publickeys); @@ -210,7 +210,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( /// """ /// Combines a list of signatures used in COSI cosigning scheme. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures( +static mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures( mp_obj_t R, mp_obj_t signatures) { mp_buffer_info_t sigR = {0}; mp_get_buffer_raise(R, &sigR, MP_BUFFER_READ); @@ -239,9 +239,9 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_combine_signatures( ed25519_cosi_combine_signatures(*(ed25519_signature *)sig.buf, *(const ed25519_public_key *)sigR.buf, sigs, siglen); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2( +static MP_DEFINE_CONST_FUN_OBJ_2( mod_trezorcrypto_ed25519_cosi_combine_signatures_obj, mod_trezorcrypto_ed25519_cosi_combine_signatures); @@ -249,7 +249,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2( /// """ /// Generate a nonce and commitment for the CoSi cosigning scheme. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_commit() { +static mp_obj_t mod_trezorcrypto_ed25519_cosi_commit() { vstr_t nonce = {0}; vstr_t commitment = {0}; vstr_init_len(&nonce, 32); @@ -257,11 +257,11 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_commit() { ed25519_cosi_commit(*(ed25519_secret_key *)nonce.buf, *(ed25519_public_key *)commitment.buf); mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL)); - tuple->items[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &nonce); - tuple->items[1] = mp_obj_new_str_from_vstr(&mp_type_bytes, &commitment); + tuple->items[0] = mp_obj_new_bytes_from_vstr(&nonce); + tuple->items[1] = mp_obj_new_bytes_from_vstr(&commitment); return MP_OBJ_FROM_PTR(tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_cosi_commit_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_cosi_commit_obj, mod_trezorcrypto_ed25519_cosi_commit); /// def cosi_sign( @@ -274,7 +274,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_ed25519_cosi_commit_obj, /// """ /// Produce signature of message using COSI cosigning scheme. /// """ -STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args, +static mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}, msg = {0}, nonce = {0}, sigR = {0}, pk = {0}; mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ); @@ -306,13 +306,13 @@ STATIC mp_obj_t mod_trezorcrypto_ed25519_cosi_sign(size_t n_args, vstr_clear(&sig); mp_raise_ValueError(MP_ERROR_TEXT("Signing failed")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_ed25519_cosi_sign_obj, 5, 5, mod_trezorcrypto_ed25519_cosi_sign); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_ed25519_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_ed25519_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ed25519)}, {MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_ed25519_generate_secret_obj)}, @@ -334,10 +334,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_ed25519_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_cosi_sign), MP_ROM_PTR(&mod_trezorcrypto_ed25519_cosi_sign_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_ed25519_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_ed25519_globals, mod_trezorcrypto_ed25519_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_ed25519_module = { +static const mp_obj_module_t mod_trezorcrypto_ed25519_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_ed25519_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-elligator2.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-elligator2.h index 4200f7d4aad..dcaf2c4439b 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-elligator2.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-elligator2.h @@ -44,21 +44,21 @@ mp_obj_t mod_trezorcrypto_elligator2_map_to_curve25519(mp_obj_t input) { mp_raise_ValueError(NULL); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &output_vstr); + return mp_obj_new_bytes_from_vstr(&output_vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_elligator2_map_to_curve25519_obj, mod_trezorcrypto_elligator2_map_to_curve25519); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_elligator2_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_elligator2_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_elligator2)}, {MP_ROM_QSTR(MP_QSTR_map_to_curve25519), MP_ROM_PTR(&mod_trezorcrypto_elligator2_map_to_curve25519_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_elligator2_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_elligator2_globals, mod_trezorcrypto_elligator2_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_elligator2_module = { +static const mp_obj_module_t mod_trezorcrypto_elligator2_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_elligator2_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-groestl.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-groestl.h index 0e2e4f80e09..38abd733937 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-groestl.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-groestl.h @@ -38,19 +38,19 @@ typedef struct _mp_obj_Groestl512_t { GROESTL512_CTX ctx; } mp_obj_Groestl512_t; -STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Groestl512_t *o = m_new_obj_with_finaliser(mp_obj_Groestl512_t); - o->base.type = type; + mp_obj_Groestl512_t *o = + mp_obj_malloc_with_finaliser(mp_obj_Groestl512_t, type); groestl512_Init(&(o->ctx)); if (n_args == 1) { mod_trezorcrypto_Groestl512_update(MP_OBJ_FROM_PTR(o), args[0]); @@ -62,7 +62,7 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, mp_obj_t data) { mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; @@ -72,14 +72,14 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Groestl512_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Groestl512_update_obj, mod_trezorcrypto_Groestl512_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) { mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, GROESTL512_DIGEST_LENGTH); @@ -87,21 +87,21 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(GROESTL512_CTX)); groestl512_Final(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(GROESTL512_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Groestl512_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Groestl512_digest_obj, mod_trezorcrypto_Groestl512_digest); -STATIC mp_obj_t mod_trezorcrypto_Groestl512___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Groestl512___del__(mp_obj_t self) { mp_obj_Groestl512_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(GROESTL512_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Groestl512___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Groestl512___del___obj, mod_trezorcrypto_Groestl512___del__); -STATIC const mp_rom_map_elem_t - mod_trezorcrypto_Groestl512_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Groestl512_locals_dict_table[] = + { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Groestl512_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -112,12 +112,12 @@ STATIC const mp_rom_map_elem_t {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(GROESTL512_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Groestl512_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Groestl512_locals_dict, mod_trezorcrypto_Groestl512_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Groestl512_type = { - {&mp_type_type}, - .name = MP_QSTR_Groestl512, - .make_new = mod_trezorcrypto_Groestl512_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Groestl512_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Groestl512_type, + MP_QSTR_Groestl512, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Groestl512_make_new, + locals_dict, &mod_trezorcrypto_Groestl512_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-hmac.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-hmac.h index 3e819d8f78e..fcfc2a88691 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-hmac.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-hmac.h @@ -42,7 +42,7 @@ typedef struct _mp_obj_Hmac_t { uint32_t hashtype; } mp_obj_Hmac_t; -STATIC mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -53,7 +53,7 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t data); /// """ /// Create a HMAC context. /// """ -STATIC mp_obj_t mod_trezorcrypto_Hmac_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Hmac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); @@ -65,8 +65,7 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_make_new(const mp_obj_type_t *type, key.buf = ""; } - mp_obj_Hmac_t *o = m_new_obj_with_finaliser(mp_obj_Hmac_t); - o->base.type = type; + mp_obj_Hmac_t *o = mp_obj_malloc_with_finaliser(mp_obj_Hmac_t, type); o->hashtype = trezor_obj_get_uint(args[0]); if (o->hashtype == SHA256) { hmac_sha256_Init(&(o->ctx256), key.buf, key.len); @@ -87,7 +86,7 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_make_new(const mp_obj_type_t *type, /// """ /// Update a HMAC context. /// """ -STATIC mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t message) { +static mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t message) { mp_obj_Hmac_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(message, &msg, MP_BUFFER_READ); @@ -100,14 +99,14 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t message) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Hmac_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Hmac_update_obj, mod_trezorcrypto_Hmac_update); /// def digest(self) -> bytes: /// """ /// Return the digest of processed data so far. /// """ -STATIC mp_obj_t mod_trezorcrypto_Hmac_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Hmac_digest(mp_obj_t self) { mp_obj_Hmac_t *o = MP_OBJ_TO_PTR(self); vstr_t mac = {0}; if (o->hashtype == SHA256) { @@ -125,21 +124,21 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_digest(mp_obj_t self) { } else { mp_raise_ValueError(MP_ERROR_TEXT("Invalid hashtype")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &mac); + return mp_obj_new_bytes_from_vstr(&mac); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Hmac_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Hmac_digest_obj, mod_trezorcrypto_Hmac_digest); -STATIC mp_obj_t mod_trezorcrypto_Hmac___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Hmac___del__(mp_obj_t self) { mp_obj_Hmac_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx256), sizeof(HMAC_SHA256_CTX)); memzero(&(o->ctx512), sizeof(HMAC_SHA512_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Hmac___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Hmac___del___obj, mod_trezorcrypto_Hmac___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Hmac_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Hmac_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Hmac_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -149,12 +148,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Hmac_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_SHA256), MP_ROM_INT(SHA256)}, {MP_ROM_QSTR(MP_QSTR_SHA512), MP_ROM_INT(SHA512)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Hmac_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Hmac_locals_dict, mod_trezorcrypto_Hmac_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Hmac_type = { - {&mp_type_type}, - .name = MP_QSTR_Hmac, - .make_new = mod_trezorcrypto_Hmac_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Hmac_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Hmac_type, + MP_QSTR_Hmac, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Hmac_make_new, + locals_dict, &mod_trezorcrypto_Hmac_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-mcu.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-mcu.h index 9cf636bb1b9..4d0469b1cfd 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-mcu.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-mcu.h @@ -27,7 +27,7 @@ /// """ /// Return MCU device certificate. /// """ -STATIC mp_obj_t mod_trezorcrypto_mcu_get_certificate(void) { +static mp_obj_t mod_trezorcrypto_mcu_get_certificate(void) { size_t cert_size = 0; if (mcu_attestation_cert_size(&cert_size) != sectrue) { mp_raise_msg(&mp_type_RuntimeError, @@ -44,16 +44,16 @@ STATIC mp_obj_t mod_trezorcrypto_mcu_get_certificate(void) { } cert.len = cert_size; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &cert); + return mp_obj_new_bytes_from_vstr(&cert); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_mcu_get_certificate_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_mcu_get_certificate_obj, mod_trezorcrypto_mcu_get_certificate); /// def sign(challenge: AnyBytes) -> bytes: /// """ /// Sign challenge bytes with MCU device attestation key. /// """ -STATIC mp_obj_t mod_trezorcrypto_mcu_sign(mp_obj_t challenge) { +static mp_obj_t mod_trezorcrypto_mcu_sign(mp_obj_t challenge) { mp_buffer_info_t challenge_buf = {0}; mp_get_buffer_raise(challenge, &challenge_buf, MP_BUFFER_READ); @@ -66,21 +66,21 @@ STATIC mp_obj_t mod_trezorcrypto_mcu_sign(mp_obj_t challenge) { } sig.len = MCU_ATTESTATION_SIG_SIZE; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_mcu_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_mcu_sign_obj, mod_trezorcrypto_mcu_sign); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_mcu_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_mcu_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mcu)}, {MP_ROM_QSTR(MP_QSTR_get_certificate), MP_ROM_PTR(&mod_trezorcrypto_mcu_get_certificate_obj)}, {MP_ROM_QSTR(MP_QSTR_sign), MP_ROM_PTR(&mod_trezorcrypto_mcu_sign_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_mcu_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_mcu_globals, mod_trezorcrypto_mcu_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_mcu_module = { +static const mp_obj_module_t mod_trezorcrypto_mcu_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_mcu_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h index 67c1de605e8..a67614b3c8c 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h @@ -49,9 +49,8 @@ typedef struct _mp_obj_bignum256modm_t { // Helpers // -STATIC const mp_obj_type_t mod_trezorcrypto_monero_ge25519_type; -STATIC const mp_obj_type_t mod_trezorcrypto_monero_bignum256modm_type; -STATIC const mp_obj_type_t mod_trezorcrypto_monero_hasher_type; +static const mp_obj_type_t mod_trezorcrypto_monero_ge25519_type; +static const mp_obj_type_t mod_trezorcrypto_monero_bignum256modm_type; #define MP_OBJ_IS_GE25519(o) \ MP_OBJ_IS_TYPE((o), &mod_trezorcrypto_monero_ge25519_type) @@ -78,14 +77,14 @@ static inline void assert_scalar(const mp_obj_t o) { } } -STATIC mp_obj_t mp_obj_new_scalar() { - mp_obj_bignum256modm_t *o = m_new_obj_with_finaliser(mp_obj_bignum256modm_t); - o->base.type = &mod_trezorcrypto_monero_bignum256modm_type; +static mp_obj_t mp_obj_new_scalar() { + mp_obj_bignum256modm_t *o = mp_obj_malloc_with_finaliser( + mp_obj_bignum256modm_t, &mod_trezorcrypto_monero_bignum256modm_type); set256_modm(o->p, 0); return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t mp_obj_new_scalar_r(mp_obj_t r) { +static mp_obj_t mp_obj_new_scalar_r(mp_obj_t r) { if (r == mp_const_none) { return mp_obj_new_scalar(); } @@ -94,14 +93,14 @@ STATIC mp_obj_t mp_obj_new_scalar_r(mp_obj_t r) { return r; } -STATIC mp_obj_t mp_obj_new_ge25519() { - mp_obj_ge25519_t *o = m_new_obj_with_finaliser(mp_obj_ge25519_t); - o->base.type = &mod_trezorcrypto_monero_ge25519_type; +static mp_obj_t mp_obj_new_ge25519() { + mp_obj_ge25519_t *o = mp_obj_malloc_with_finaliser( + mp_obj_ge25519_t, &mod_trezorcrypto_monero_ge25519_type); ge25519_set_neutral(&o->p); return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t mp_obj_new_ge25519_r(mp_obj_t r) { +static mp_obj_t mp_obj_new_ge25519_r(mp_obj_t r) { if (r == mp_const_none) { return mp_obj_new_ge25519(); } @@ -110,7 +109,7 @@ STATIC mp_obj_t mp_obj_new_ge25519_r(mp_obj_t r) { return r; } -STATIC void mp_unpack_ge25519(ge25519 *r, const mp_obj_t arg, mp_int_t offset) { +static void mp_unpack_ge25519(ge25519 *r, const mp_obj_t arg, mp_int_t offset) { mp_buffer_info_t buff = {0}; mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ); if (buff.len < 32 + offset) { @@ -123,7 +122,7 @@ STATIC void mp_unpack_ge25519(ge25519 *r, const mp_obj_t arg, mp_int_t offset) { } } -STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg, +static void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg, mp_int_t offset) { mp_buffer_info_t buff = {0}; mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ); @@ -147,12 +146,11 @@ STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg, /// Constructor /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_make_new( +static mp_obj_t mod_trezorcrypto_monero_ge25519_make_new( const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_ge25519_t *o = m_new_obj_with_finaliser(mp_obj_ge25519_t); - o->base.type = type; + mp_obj_ge25519_t *o = mp_obj_malloc_with_finaliser(mp_obj_ge25519_t, type); if (n_args == 0 || args[0] == mp_const_none) { ge25519_set_neutral(&o->p); @@ -168,12 +166,12 @@ STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_make_new( return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t mod_trezorcrypto_monero_ge25519___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_monero_ge25519___del__(mp_obj_t self) { mp_obj_ge25519_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->p), sizeof(ge25519)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj, mod_trezorcrypto_monero_ge25519___del__); /// class Scalar: @@ -186,12 +184,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj, /// Constructor /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_bignum256modm_make_new( +static mp_obj_t mod_trezorcrypto_monero_bignum256modm_make_new( const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_bignum256modm_t *o = m_new_obj_with_finaliser(mp_obj_bignum256modm_t); - o->base.type = type; + mp_obj_bignum256modm_t *o = + mp_obj_malloc_with_finaliser(mp_obj_bignum256modm_t, type); if (n_args == 0 || args[0] == mp_const_none) { set256_modm(o->p, 0); @@ -210,12 +208,12 @@ STATIC mp_obj_t mod_trezorcrypto_monero_bignum256modm_make_new( return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t mod_trezorcrypto_monero_bignum256modm___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_monero_bignum256modm___del__(mp_obj_t self) { mp_obj_bignum256modm_t *o = MP_OBJ_TO_PTR(self); memzero(o->p, sizeof(bignum256modm)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_monero_bignum256modm___del___obj, mod_trezorcrypto_monero_bignum256modm___del__); @@ -231,7 +229,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( /// """ /// Initializes a scalar /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_copy(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_sc_copy(const mp_obj_t dest, const mp_obj_t src) { mp_obj_t res = mp_obj_new_scalar_r(dest); @@ -247,54 +245,54 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_copy(const mp_obj_t dest, } return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_copy_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_copy_obj, mod_trezorcrypto_monero_sc_copy); /// def sc_check(val: Scalar) -> None: /// """ /// Throws exception if scalar is invalid /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_check(const mp_obj_t arg) { +static mp_obj_t mod_trezorcrypto_monero_sc_check(const mp_obj_t arg) { assert_scalar(arg); if (check256_modm(MP_OBJ_C_SCALAR(arg)) != 1) { mp_raise_ValueError(MP_ERROR_TEXT("Ed25519 scalar invalid")); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_sc_check_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_sc_check_obj, mod_trezorcrypto_monero_sc_check); /// def sc_iszero(val: Scalar) -> bool: /// """ /// Returns False if the scalar is zero /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_iszero(const mp_obj_t arg) { +static mp_obj_t mod_trezorcrypto_monero_sc_iszero(const mp_obj_t arg) { assert_scalar(arg); const int r = iszero256_modm(MP_OBJ_C_SCALAR(arg)); return mp_obj_new_int(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_sc_iszero_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_sc_iszero_obj, mod_trezorcrypto_monero_sc_iszero); /// def sc_eq(a: Scalar, b: Scalar) -> int: /// """ /// Compares scalars, returns 1 on the same value /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_eq(const mp_obj_t a, +static mp_obj_t mod_trezorcrypto_monero_sc_eq(const mp_obj_t a, const mp_obj_t b) { assert_scalar(a); assert_scalar(b); int r = eq256_modm(MP_OBJ_C_SCALAR(a), MP_OBJ_C_SCALAR(b)); return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_eq_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_eq_obj, mod_trezorcrypto_monero_sc_eq); /// def sc_add_into(r: Scalar | None, a: Scalar, b: Scalar) -> Scalar: /// """ /// Scalar addition /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_add_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_sc_add_into(const mp_obj_t dest, const mp_obj_t a, const mp_obj_t b) { mp_obj_t res = mp_obj_new_scalar_r(dest); @@ -304,14 +302,14 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_add_into(const mp_obj_t dest, add256_modm(MP_OBJ_SCALAR(res), MP_OBJ_C_SCALAR(a), MP_OBJ_C_SCALAR(b)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_add_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_add_into_obj, mod_trezorcrypto_monero_sc_add_into); /// def sc_sub_into(r: Scalar | None, a: Scalar, b: Scalar) -> Scalar: /// """ /// Scalar subtraction /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_sub_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_sc_sub_into(const mp_obj_t dest, const mp_obj_t a, const mp_obj_t b) { mp_obj_t res = mp_obj_new_scalar_r(dest); @@ -321,14 +319,14 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_sub_into(const mp_obj_t dest, sub256_modm(MP_OBJ_SCALAR(res), MP_OBJ_C_SCALAR(a), MP_OBJ_C_SCALAR(b)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_sub_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_sub_into_obj, mod_trezorcrypto_monero_sc_sub_into); /// def sc_mul_into(r: Scalar | None, a: Scalar, b: Scalar) -> Scalar: /// """ /// Scalar multiplication /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_mul_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_sc_mul_into(const mp_obj_t dest, const mp_obj_t a, const mp_obj_t b) { mp_obj_t res = mp_obj_new_scalar_r(dest); @@ -338,7 +336,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_mul_into(const mp_obj_t dest, mul256_modm(MP_OBJ_SCALAR(res), MP_OBJ_C_SCALAR(a), MP_OBJ_C_SCALAR(b)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_mul_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_mul_into_obj, mod_trezorcrypto_monero_sc_mul_into); /// def sc_mulsub_into( @@ -347,7 +345,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_sc_mul_into_obj, /// """ /// c - a*b /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_mulsub_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_sc_mulsub_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -359,7 +357,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_mulsub_into(size_t n_args, MP_OBJ_C_SCALAR(args[2]), MP_OBJ_C_SCALAR(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_sc_mulsub_into_obj, 4, 4, mod_trezorcrypto_monero_sc_mulsub_into); @@ -369,7 +367,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// c + a*b /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_muladd_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_sc_muladd_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -381,7 +379,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_muladd_into(size_t n_args, MP_OBJ_C_SCALAR(args[2]), MP_OBJ_C_SCALAR(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_sc_muladd_into_obj, 4, 4, mod_trezorcrypto_monero_sc_muladd_into); @@ -389,7 +387,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Scalar modular inversion /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_sc_inv_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_sc_inv_into(const mp_obj_t dest, const mp_obj_t arg) { mp_obj_t res = mp_obj_new_scalar_r(dest); assert_scalar(arg); @@ -413,7 +411,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_sc_inv_into(const mp_obj_t dest, return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_inv_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_inv_into_obj, mod_trezorcrypto_monero_sc_inv_into); /// def encodeint_into( @@ -422,7 +420,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_sc_inv_into_obj, /// """ /// Scalar compression /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_encodeint_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_encodeint_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 3, false); if (args[0] == mp_const_none) { @@ -430,7 +428,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_encodeint_into(size_t n_args, vstr_t out = {0}; vstr_init_len(&out, 32); contract256_modm((uint8_t *)out.buf, MP_OBJ_C_SCALAR(args[1])); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } else { mp_buffer_info_t bufm = {0}; mp_get_buffer_raise(args[0], &bufm, MP_BUFFER_WRITE); @@ -443,7 +441,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_encodeint_into(size_t n_args, return args[0]; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_encodeint_into_obj, 2, 3, mod_trezorcrypto_monero_encodeint_into); @@ -453,7 +451,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Scalar decompression /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_decodeint_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_decodeint_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 3, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -461,7 +459,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_decodeint_into(size_t n_args, mp_unpack_scalar(MP_OBJ_SCALAR(res), args[1], offset); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_decodeint_into_obj, 2, 3, mod_trezorcrypto_monero_decodeint_into); @@ -471,7 +469,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Scalar decompression, raw, without modular reduction /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_decodeint_into_noreduce( +static mp_obj_t mod_trezorcrypto_monero_decodeint_into_noreduce( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 3, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -486,7 +484,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_decodeint_into_noreduce( expand_raw256_modm(MP_OBJ_SCALAR(res), ((uint8_t *)buff.buf) + offset); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_decodeint_into_noreduce_obj, 2, 3, mod_trezorcrypto_monero_decodeint_into_noreduce); @@ -498,13 +496,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Sets neutral point /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_identity_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_identity_into(size_t n_args, const mp_obj_t *args) { mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none); ge25519_set_neutral(&MP_OBJ_GE25519(res)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_identity_into_obj, 0, 1, mod_trezorcrypto_monero_identity_into); @@ -512,48 +510,48 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Sets H point /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_H(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_xmr_H(size_t n_args, const mp_obj_t *args) { mp_obj_t res = mp_obj_new_ge25519_r(n_args == 1 ? args[0] : mp_const_none); ge25519_set_xmr_h(&MP_OBJ_GE25519(res)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_monero_xmr_H_obj, 0, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_monero_xmr_H_obj, 0, 1, mod_trezorcrypto_monero_xmr_H); /// def ge25519_check(r: Point) -> None: /// """ /// Checks point, throws if not on curve /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_check(const mp_obj_t arg) { +static mp_obj_t mod_trezorcrypto_monero_ge25519_check(const mp_obj_t arg) { assert_ge25519(arg); if (ge25519_check(&MP_OBJ_C_GE25519(arg)) != 1) { mp_raise_ValueError(MP_ERROR_TEXT("Ed25519 point not on curve")); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519_check_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519_check_obj, mod_trezorcrypto_monero_ge25519_check); /// def point_eq(a: Point, b: Point) -> bool: /// """ /// Compares EC points /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_point_eq(const mp_obj_t a, +static mp_obj_t mod_trezorcrypto_monero_point_eq(const mp_obj_t a, const mp_obj_t b) { assert_ge25519(a); assert_ge25519(b); int r = ge25519_eq(&MP_OBJ_C_GE25519(a), &MP_OBJ_C_GE25519(b)); return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_point_eq_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_point_eq_obj, mod_trezorcrypto_monero_point_eq); /// def point_add_into(r: Point | None, a: Point, b: Point) -> Point: /// """ /// Adds EC points /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_point_add_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_point_add_into(const mp_obj_t dest, const mp_obj_t a, const mp_obj_t b) { mp_obj_t res = mp_obj_new_ge25519_r(dest); @@ -564,14 +562,14 @@ STATIC mp_obj_t mod_trezorcrypto_monero_point_add_into(const mp_obj_t dest, 0); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_point_add_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_point_add_into_obj, mod_trezorcrypto_monero_point_add_into); /// def point_sub_into(r: Point | None, a: Point, b: Point) -> Point: /// """ /// Subtracts EC points /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_point_sub_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_point_sub_into(const mp_obj_t dest, const mp_obj_t a, const mp_obj_t b) { mp_obj_t res = mp_obj_new_ge25519_r(dest); @@ -582,21 +580,21 @@ STATIC mp_obj_t mod_trezorcrypto_monero_point_sub_into(const mp_obj_t dest, 1); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_point_sub_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_point_sub_into_obj, mod_trezorcrypto_monero_point_sub_into); /// def ge25519_mul8(r: Point | None, p: Point) -> Point: /// """ /// EC point * 8 /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_mul8(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_ge25519_mul8(const mp_obj_t dest, const mp_obj_t src) { mp_obj_t res = mp_obj_new_ge25519_r(dest); assert_ge25519(src); ge25519_mul8(&MP_OBJ_GE25519(res), &MP_OBJ_C_GE25519(src)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_ge25519_mul8_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_ge25519_mul8_obj, mod_trezorcrypto_monero_ge25519_mul8); /// def ge25519_double_scalarmult_vartime_into( @@ -605,7 +603,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_ge25519_mul8_obj, /// """ /// s1 * G + s2 * p1 /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_into( +static mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_into( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -618,7 +616,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_into( MP_OBJ_C_SCALAR(args[2]), MP_OBJ_C_SCALAR(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_into_obj, 4, 4, mod_trezorcrypto_monero_ge25519_double_scalarmult_vartime_into); @@ -628,7 +626,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// s * G /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_scalarmult_base_into( +static mp_obj_t mod_trezorcrypto_monero_scalarmult_base_into( const mp_obj_t dest, const mp_obj_t src) { mp_obj_t res = mp_obj_new_ge25519_r(dest); @@ -644,7 +642,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_scalarmult_base_into( return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2( +static MP_DEFINE_CONST_FUN_OBJ_2( mod_trezorcrypto_monero_scalarmult_base_into_obj, mod_trezorcrypto_monero_scalarmult_base_into); @@ -654,7 +652,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2( /// """ /// s * p /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_scalarmult_into(const mp_obj_t dest, +static mp_obj_t mod_trezorcrypto_monero_scalarmult_into(const mp_obj_t dest, const mp_obj_t p, const mp_obj_t s) { mp_obj_t res = mp_obj_new_ge25519_r(dest); @@ -673,7 +671,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_scalarmult_into(const mp_obj_t dest, return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_scalarmult_into_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_scalarmult_into_obj, mod_trezorcrypto_monero_scalarmult_into); /// def encodepoint_into( @@ -682,7 +680,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_monero_scalarmult_into_obj, /// """ /// Point compression /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_encodepoint_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_encodepoint_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 3, false); if (args[0] == mp_const_none) { @@ -690,7 +688,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_encodepoint_into(size_t n_args, vstr_t out = {0}; vstr_init_len(&out, 32); ge25519_pack((uint8_t *)out.buf, &MP_OBJ_C_GE25519(args[1])); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } else { mp_buffer_info_t bufm = {0}; mp_get_buffer_raise(args[0], &bufm, MP_BUFFER_WRITE); @@ -703,7 +701,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_encodepoint_into(size_t n_args, return args[0]; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_encodepoint_into_obj, 2, 3, mod_trezorcrypto_monero_encodepoint_into); @@ -713,7 +711,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Point decompression /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_decodepoint_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_decodepoint_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 3, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -721,7 +719,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_decodepoint_into(size_t n_args, mp_unpack_ge25519(&MP_OBJ_GE25519(res), args[1], offset); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_decodepoint_into_obj, 2, 3, mod_trezorcrypto_monero_decodepoint_into); @@ -733,7 +731,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Monero block base 58 encoding /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check( +static mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check( const mp_obj_t tag, const mp_obj_t buff) { vstr_t out = {0}; vstr_init_len(&out, 128); @@ -748,9 +746,9 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_encode_check( } out.len = sz; - return mp_obj_new_str_from_vstr(&mp_type_str, &out); + return mp_obj_new_str_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2( +static MP_DEFINE_CONST_FUN_OBJ_2( mod_trezorcrypto_monero_xmr_base58_addr_encode_check_obj, mod_trezorcrypto_monero_xmr_base58_addr_encode_check); @@ -759,8 +757,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2( /// Monero block base 58 decoding, returning (decoded, tag) or raising on /// error. /// """ -STATIC mp_obj_t -mod_trezorcrypto_monero_xmr_base58_addr_decode_check(const mp_obj_t buff) { +static mp_obj_t mod_trezorcrypto_monero_xmr_base58_addr_decode_check( + const mp_obj_t buff) { uint64_t tag = 0; vstr_t out = {0}; vstr_init_len(&out, 128); @@ -777,11 +775,11 @@ mod_trezorcrypto_monero_xmr_base58_addr_decode_check(const mp_obj_t buff) { out.len = sz; mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL)); - tuple->items[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + tuple->items[0] = mp_obj_new_bytes_from_vstr(&out); tuple->items[1] = mp_obj_new_int_from_ull(tag); return MP_OBJ_FROM_PTR(tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1( +static MP_DEFINE_CONST_FUN_OBJ_1( mod_trezorcrypto_monero_xmr_base58_addr_decode_check_obj, mod_trezorcrypto_monero_xmr_base58_addr_decode_check); @@ -789,13 +787,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( /// """ /// Generates a random scalar /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_random_scalar(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_random_scalar(size_t n_args, const mp_obj_t *args) { mp_obj_t res = mp_obj_new_scalar_r(n_args == 1 ? args[0] : mp_const_none); xmr_random_scalar(MP_OBJ_SCALAR(res)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_random_scalar_obj, 0, 1, mod_trezorcrypto_monero_random_scalar); @@ -808,7 +806,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// XMR fast hash /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_fast_hash_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_fast_hash_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 4, false); vstr_t out = {0}; @@ -836,11 +834,9 @@ STATIC mp_obj_t mod_trezorcrypto_monero_fast_hash_into(size_t n_args, mp_raise_ValueError(MP_ERROR_TEXT("Illegal offset/length")); } xmr_fast_hash(buff_use, (const char *)data.buf + offset, length); - return args[0] != mp_const_none - ? args[0] - : mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return args[0] != mp_const_none ? args[0] : mp_obj_new_bytes_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_fast_hash_into_obj, 2, 4, mod_trezorcrypto_monero_fast_hash_into); @@ -853,7 +849,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// XMR hashing to EC point /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_hash_to_point_into( +static mp_obj_t mod_trezorcrypto_monero_hash_to_point_into( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 4, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -870,7 +866,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_hash_to_point_into( xmr_hash_to_ec(&MP_OBJ_GE25519(res), (const char *)data.buf + offset, length); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_hash_to_point_into_obj, 2, 4, mod_trezorcrypto_monero_hash_to_point_into); @@ -883,7 +879,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// XMR hashing to EC scalar /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_hash_to_scalar_into( +static mp_obj_t mod_trezorcrypto_monero_hash_to_scalar_into( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 2, 4, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -900,7 +896,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_hash_to_scalar_into( length); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_hash_to_scalar_into_obj, 2, 4, mod_trezorcrypto_monero_hash_to_scalar_into); @@ -910,7 +906,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// H_s(derivation || varint(output_index)) /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar( +static mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar( const mp_obj_t dest, const mp_obj_t p, const mp_obj_t output_index) { mp_obj_t res = mp_obj_new_scalar_r(dest); assert_ge25519(p); @@ -918,7 +914,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derivation_to_scalar( mp_obj_get_int(output_index)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3( +static MP_DEFINE_CONST_FUN_OBJ_3( mod_trezorcrypto_monero_xmr_derivation_to_scalar_obj, mod_trezorcrypto_monero_xmr_derivation_to_scalar); @@ -928,7 +924,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3( /// """ /// 8*(key2*key1) /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation( +static mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation( const mp_obj_t dest, const mp_obj_t A, const mp_obj_t b) { mp_obj_t res = mp_obj_new_ge25519_r(dest); assert_ge25519(A); @@ -937,7 +933,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_generate_key_derivation( MP_OBJ_C_SCALAR(b)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3( +static MP_DEFINE_CONST_FUN_OBJ_3( mod_trezorcrypto_monero_xmr_generate_key_derivation_obj, mod_trezorcrypto_monero_xmr_generate_key_derivation); @@ -947,7 +943,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3( /// """ /// base + H_s(derivation || varint(output_index)) /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key( +static mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -957,7 +953,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_private_key( mp_obj_get_int(args[2]), MP_OBJ_C_SCALAR(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_xmr_derive_private_key_obj, 4, 4, mod_trezorcrypto_monero_xmr_derive_private_key); @@ -967,7 +963,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// H_s(derivation || varint(output_index))G + base /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key( +static mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -977,7 +973,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_derive_public_key( mp_obj_get_int(args[2]), &MP_OBJ_C_GE25519(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_xmr_derive_public_key_obj, 4, 4, mod_trezorcrypto_monero_xmr_derive_public_key); @@ -987,7 +983,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// aG + bB, G is basepoint /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_add_keys2_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_add_keys2_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -998,7 +994,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_add_keys2_into(size_t n_args, MP_OBJ_SCALAR(args[2]), &MP_OBJ_C_GE25519(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_add_keys2_into_obj, 4, 4, mod_trezorcrypto_monero_add_keys2_into); @@ -1008,7 +1004,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// aA + bB /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_add_keys3_into(size_t n_args, +static mp_obj_t mod_trezorcrypto_monero_add_keys3_into(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 5, 5, false); mp_obj_t res = mp_obj_new_ge25519_r(args[0]); @@ -1021,7 +1017,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_add_keys3_into(size_t n_args, &MP_OBJ_C_GE25519(args[4])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_add_keys3_into_obj, 5, 5, mod_trezorcrypto_monero_add_keys3_into); @@ -1031,7 +1027,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Hs(SubAddr || a || index_major || index_minor) /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key( +static mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key( size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 4, false); mp_obj_t res = mp_obj_new_scalar_r(args[0]); @@ -1041,7 +1037,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_xmr_get_subaddress_secret_key( MP_OBJ_C_SCALAR(args[3])); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_monero_xmr_get_subaddress_secret_key_obj, 4, 4, mod_trezorcrypto_monero_xmr_get_subaddress_secret_key); @@ -1049,7 +1045,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// aG + amount * H /// """ -STATIC mp_obj_t mod_trezorcrypto_monero_gen_commitment_into( +static mp_obj_t mod_trezorcrypto_monero_gen_commitment_into( const mp_obj_t dest, const mp_obj_t a, const mp_obj_t amount) { mp_obj_t res = mp_obj_new_ge25519_r(dest); assert_scalar(a); @@ -1057,7 +1053,7 @@ STATIC mp_obj_t mod_trezorcrypto_monero_gen_commitment_into( trezor_obj_get_uint64(amount)); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3( +static MP_DEFINE_CONST_FUN_OBJ_3( mod_trezorcrypto_monero_gen_commitment_into_obj, mod_trezorcrypto_monero_gen_commitment_into); @@ -1065,7 +1061,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3( /// """ /// Constant time buffer comparison /// """ -STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) { +static mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) { mp_buffer_info_t buff_a = {0}, buff_b = {0}; mp_get_buffer_raise(a, &buff_a, MP_BUFFER_READ); mp_get_buffer_raise(b, &buff_b, MP_BUFFER_READ); @@ -1077,46 +1073,46 @@ STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) { int r = consteq(buff_a.buf, buff_b.buf, buff_a.len); return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ct_equals_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ct_equals_obj, mod_trezorcrypto_ct_equals); // // Type defs // -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_monero_ge25519_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_monero_ge25519___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_ge25519_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_ge25519_locals_dict, mod_trezorcrypto_monero_ge25519_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_monero_ge25519_type = { - {&mp_type_type}, - .name = MP_QSTR_Point, - .make_new = mod_trezorcrypto_monero_ge25519_make_new, - .locals_dict = (void *)&mod_trezorcrypto_monero_ge25519_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_monero_ge25519_type, + MP_QSTR_Point, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_monero_ge25519_make_new, + locals_dict, &mod_trezorcrypto_monero_ge25519_locals_dict); +// clang-format on -STATIC const mp_rom_map_elem_t +static const mp_rom_map_elem_t mod_trezorcrypto_monero_bignum256modm_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorcrypto_monero_bignum256modm___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT( +static MP_DEFINE_CONST_DICT( mod_trezorcrypto_monero_bignum256modm_locals_dict, mod_trezorcrypto_monero_bignum256modm_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_monero_bignum256modm_type = { - {&mp_type_type}, - .name = MP_QSTR_Scalar, - .make_new = mod_trezorcrypto_monero_bignum256modm_make_new, - .locals_dict = (void *)&mod_trezorcrypto_monero_bignum256modm_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_monero_bignum256modm_type, + MP_QSTR_Scalar, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_monero_bignum256modm_make_new, + locals_dict, &mod_trezorcrypto_monero_bignum256modm_locals_dict); +// clang-format on /// BP_GI_PLUS_PRE: bytes -STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_GI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)"" +static const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_GI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)"" "\x38\xc5\xd4\xdb\x53\xae\xb8\x6f\x5a\x80\xde\xf9\xbe\x49\x53\xf2" "\x28\x8e\xd5\xa4\x4c\x66\xaf\x72\x3f\x46\x3d\x01\x70\x82\x90\x10" "\x8a\x6c\x81\x7d\xab\xe9\x0f\xdb\x50\xcc\x38\x67\x7b\x23\xff\xa7" @@ -1632,7 +1628,7 @@ STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_GI_PRE_obj = {{&mp_typ }; /// BP_HI_PLUS_PRE: bytes -STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_HI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)"" +static const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_HI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)"" "\x48\x62\x8d\xf3\x80\xa5\x01\x6d\x25\x45\x1a\xaa\x50\x17\x31\xa1" "\x1b\x72\xbf\x66\xdc\x41\xd8\x1f\x71\x9a\xbd\x35\xce\x92\xb0\xed" "\x11\x0d\x2b\x61\xf8\xc7\xc1\x08\x61\xc3\xe4\xff\xe7\x77\x4f\xab" @@ -2147,7 +2143,7 @@ STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_HI_PRE_obj = {{&mp_typ "\xd3\x3a\xb9\xb1\x12\x23\xee\x67\xea\x78\xb1\xd3\x8a\x6a\xe3\xeb" }; -STATIC const mp_rom_map_elem_t mod_trezorcrypto_monero_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_monero_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_monero)}, // types {MP_ROM_QSTR(MP_QSTR_Point), @@ -2242,10 +2238,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_monero_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_BP_PLUS_HI_PRE), MP_ROM_PTR(&mod_trezorcrypto_monero_BP_PLUS_HI_PRE_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_globals, mod_trezorcrypto_monero_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_monero_module = { +static const mp_obj_module_t mod_trezorcrypto_monero_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_monero_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nem.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nem.h index 128c89fa0fc..db4642b89bb 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nem.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nem.h @@ -29,7 +29,7 @@ /// """ /// Validate a NEM address /// """ -STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address, +static mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address, mp_obj_t network) { mp_buffer_info_t addr = {0}; mp_get_buffer_raise(address, &addr, MP_BUFFER_READ); @@ -37,14 +37,14 @@ STATIC mp_obj_t mod_trezorcrypto_nem_validate_address(mp_obj_t address, uint32_t n = trezor_obj_get_uint(network); return mp_obj_new_bool(nem_validate_address(addr.buf, n)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_validate_address_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_validate_address_obj, mod_trezorcrypto_nem_validate_address); /// def compute_address(public_key: AnyBytes, network: int) -> str: /// """ /// Compute a NEM address from a public key /// """ -STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key, +static mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key, mp_obj_t network) { mp_buffer_info_t p = {0}; mp_get_buffer_raise(public_key, &p, MP_BUFFER_READ); @@ -56,23 +56,23 @@ STATIC mp_obj_t mod_trezorcrypto_nem_compute_address(mp_obj_t public_key, mp_raise_ValueError(MP_ERROR_TEXT( "Failed to compute a NEM address from provided public key")); } - return mp_obj_new_str(address, strlen(address)); + return mp_obj_new_str_from_cstr(address); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_compute_address_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nem_compute_address_obj, mod_trezorcrypto_nem_compute_address); // objects definition -STATIC const mp_rom_map_elem_t mod_trezorcrypto_nem_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_nem_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_validate_address), MP_ROM_PTR(&mod_trezorcrypto_nem_validate_address_obj)}, {MP_ROM_QSTR(MP_QSTR_compute_address), MP_ROM_PTR(&mod_trezorcrypto_nem_compute_address_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_nem_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_nem_globals, mod_trezorcrypto_nem_globals_table); // module definition -STATIC const mp_obj_module_t mod_trezorcrypto_nem_module = { +static const mp_obj_module_t mod_trezorcrypto_nem_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_nem_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nist256p1.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nist256p1.h index 5f214ad05e2..5c47ba8d198 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-nist256p1.h @@ -30,7 +30,7 @@ /// """ /// Generate secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() { +static mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() { vstr_t sk = {0}; vstr_init_len(&sk, 32); for (;;) { @@ -52,16 +52,16 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_generate_secret() { continue; break; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sk); + return mp_obj_new_bytes_from_vstr(&sk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_nist256p1_generate_secret_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_nist256p1_generate_secret_obj, mod_trezorcrypto_nist256p1_generate_secret); /// def publickey(secret_key: AnyBytes, compressed: bool = True) -> bytes: /// """ /// Computes public key from secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args, +static mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ); @@ -83,9 +83,9 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_publickey(size_t n_args, mp_raise_ValueError(MP_ERROR_TEXT("Invalid secret key")); } } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_nist256p1_publickey_obj, 1, 2, mod_trezorcrypto_nist256p1_publickey); @@ -95,7 +95,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( /// """ /// Uses secret key to produce the signature of the digest. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args, +static mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}; mp_buffer_info_t dig = {0}; @@ -118,9 +118,9 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_sign(size_t n_args, mp_raise_ValueError(MP_ERROR_TEXT("Signing failed")); } sig.buf[0] = 27 + pby + compressed * 4; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_nist256p1_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_nist256p1_sign_obj, 2, 3, mod_trezorcrypto_nist256p1_sign); @@ -131,7 +131,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_nist256p1_sign_obj, /// Uses public key to verify the signature of the digest. /// Returns True on success. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key, +static mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key, mp_obj_t signature, mp_obj_t digest) { mp_buffer_info_t pk = {0}, sig = {0}, dig = {0}; @@ -153,7 +153,7 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify(mp_obj_t public_key, (const uint8_t *)sig.buf + offset, (const uint8_t *)dig.buf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj, mod_trezorcrypto_nist256p1_verify); /// def verify_recover(signature: AnyBytes, digest: AnyBytes) -> bytes: @@ -161,7 +161,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_nist256p1_verify_obj, /// Uses signature of the digest to verify the digest and recover the public /// key. Returns public key on success, None if the signature is invalid. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature, +static mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature, mp_obj_t digest) { mp_buffer_info_t sig = {0}, dig = {0}; mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ); @@ -187,12 +187,12 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_verify_recover(mp_obj_t signature, pk.buf[0] = 0x02 | (pk.buf[64] & 1); pk.len = 33; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } else { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_verify_recover_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_verify_recover_obj, mod_trezorcrypto_nist256p1_verify_recover); /// def multiply(secret_key: AnyBytes, public_key: AnyBytes) -> bytes: @@ -200,7 +200,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_verify_recover_obj, /// Multiplies point defined by public_key with scalar defined by /// secret_key. Useful for ECDH. /// """ -STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key, +static mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key, mp_obj_t public_key) { mp_buffer_info_t sk = {0}, pk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); @@ -218,12 +218,12 @@ STATIC mp_obj_t mod_trezorcrypto_nist256p1_multiply(mp_obj_t secret_key, vstr_clear(&out); mp_raise_ValueError(MP_ERROR_TEXT("Multiply failed")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_multiply_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_nist256p1_multiply_obj, mod_trezorcrypto_nist256p1_multiply); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_nist256p1_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_nist256p1_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nist256p1)}, {MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_nist256p1_generate_secret_obj)}, @@ -238,10 +238,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_nist256p1_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_multiply), MP_ROM_PTR(&mod_trezorcrypto_nist256p1_multiply_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_nist256p1_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_nist256p1_globals, mod_trezorcrypto_nist256p1_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_nist256p1_module = { +static const mp_obj_module_t mod_trezorcrypto_nist256p1_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_nist256p1_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-optiga.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-optiga.h index 3dccf6c6c74..f7b1515a8dc 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-optiga.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-optiga.h @@ -40,7 +40,7 @@ MP_DEFINE_EXCEPTION(SigningInaccessible, OptigaError) /// """ /// Return the certificate stored at the given index. /// """ -STATIC mp_obj_t mod_trezorcrypto_optiga_get_certificate(mp_obj_t cert_index) { +static mp_obj_t mod_trezorcrypto_optiga_get_certificate(mp_obj_t cert_index) { mp_int_t idx = mp_obj_get_int(cert_index); if (idx < 0 || idx >= OPTIGA_CERT_COUNT) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid index.")); @@ -61,9 +61,9 @@ STATIC mp_obj_t mod_trezorcrypto_optiga_get_certificate(mp_obj_t cert_index) { } cert.len = cert_size; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &cert); + return mp_obj_new_bytes_from_vstr(&cert); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_optiga_get_certificate_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_optiga_get_certificate_obj, mod_trezorcrypto_optiga_get_certificate); /// def sign( @@ -74,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_optiga_get_certificate_obj, /// Uses the private key at key_index to produce a DER-encoded signature of /// the digest. /// """ -STATIC mp_obj_t mod_trezorcrypto_optiga_sign(mp_obj_t key_index, +static mp_obj_t mod_trezorcrypto_optiga_sign(mp_obj_t key_index, mp_obj_t digest) { mp_int_t idx = mp_obj_get_int(key_index); if (idx < 0 || idx >= OPTIGA_ECC_KEY_COUNT) { @@ -104,23 +104,23 @@ STATIC mp_obj_t mod_trezorcrypto_optiga_sign(mp_obj_t key_index, } sig.len = sig_size; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_optiga_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_optiga_sign_obj, mod_trezorcrypto_optiga_sign); /// def get_sec() -> int | None: /// """ /// Returns the value of Optiga's security event counter. /// """ -STATIC mp_obj_t mod_trezorcrypto_optiga_get_sec() { +static mp_obj_t mod_trezorcrypto_optiga_get_sec() { uint8_t sec = 0; if (optiga_read_sec(&sec)) { return mp_obj_new_int_from_uint(sec); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_optiga_get_sec_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_optiga_get_sec_obj, mod_trezorcrypto_optiga_get_sec); #if USE_OPTIGA_TESTING @@ -128,18 +128,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_optiga_get_sec_obj, /// """ /// Set Optiga's security event counter to maximum. /// """ -STATIC mp_obj_t mod_trezorcrypto_optiga_set_sec_max() { +static mp_obj_t mod_trezorcrypto_optiga_set_sec_max() { optiga_set_sec_max(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_optiga_set_sec_max_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_optiga_set_sec_max_obj, mod_trezorcrypto_optiga_set_sec_max); #endif /// DEVICE_CERT_INDEX: int /// DEVICE_ECC_KEY_INDEX: int -STATIC const mp_rom_map_elem_t mod_trezorcrypto_optiga_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_optiga_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_optiga)}, {MP_ROM_QSTR(MP_QSTR_get_certificate), MP_ROM_PTR(&mod_trezorcrypto_optiga_get_certificate_obj)}, @@ -157,10 +157,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_optiga_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_OptigaError), MP_ROM_PTR(&mp_type_OptigaError)}, {MP_ROM_QSTR(MP_QSTR_SigningInaccessible), MP_ROM_PTR(&mp_type_SigningInaccessible)}}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_optiga_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_optiga_globals, mod_trezorcrypto_optiga_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_optiga_module = { +static const mp_obj_module_t mod_trezorcrypto_optiga_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_optiga_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h index cf2880d497b..342fbde7170 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h @@ -42,7 +42,7 @@ typedef struct _mp_obj_Pbkdf2_t { uint32_t prf; } mp_obj_Pbkdf2_t; -STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); /// """ /// Create a PBKDF2 context. /// """ -STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 3, 4, false); @@ -78,8 +78,7 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type, } mp_uint_t prf = trezor_obj_get_uint(args[0]); - mp_obj_Pbkdf2_t *o = m_new_obj_with_finaliser(mp_obj_Pbkdf2_t); - o->base.type = type; + mp_obj_Pbkdf2_t *o = mp_obj_malloc_with_finaliser(mp_obj_Pbkdf2_t, type); o->prf = prf; if (o->prf == PRF_HMAC_SHA256) { pbkdf2_hmac_sha256_Init(&(o->ctx256), password.buf, password.len, salt.buf, @@ -102,7 +101,7 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_make_new(const mp_obj_type_t *type, /// """ /// Update a PBKDF2 context. /// """ -STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iterations) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); uint32_t iter = trezor_obj_get_uint(iterations); @@ -116,14 +115,14 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Pbkdf2_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Pbkdf2_update_obj, mod_trezorcrypto_Pbkdf2_update); /// def key(self) -> bytes: /// """ /// Retrieve derived key. /// """ -STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); vstr_t out = {0}; if (o->prf == PRF_HMAC_SHA256) { @@ -141,21 +140,21 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_key(mp_obj_t self) { } else { mp_raise_ValueError(MP_ERROR_TEXT("Invalid PRF")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2_key_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2_key_obj, mod_trezorcrypto_Pbkdf2_key); -STATIC mp_obj_t mod_trezorcrypto_Pbkdf2___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Pbkdf2___del__(mp_obj_t self) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx256), sizeof(PBKDF2_HMAC_SHA256_CTX)); memzero(&(o->ctx512), sizeof(PBKDF2_HMAC_SHA512_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2___del___obj, mod_trezorcrypto_Pbkdf2___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Pbkdf2_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Pbkdf2_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_update_obj)}, {MP_ROM_QSTR(MP_QSTR_key), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_key_obj)}, @@ -164,12 +163,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Pbkdf2_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_HMAC_SHA256), MP_ROM_INT(PRF_HMAC_SHA256)}, {MP_ROM_QSTR(MP_QSTR_HMAC_SHA512), MP_ROM_INT(PRF_HMAC_SHA512)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Pbkdf2_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Pbkdf2_locals_dict, mod_trezorcrypto_Pbkdf2_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Pbkdf2_type = { - {&mp_type_type}, - .name = MP_QSTR_Pbkdf2, - .make_new = mod_trezorcrypto_Pbkdf2_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Pbkdf2_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Pbkdf2_type, + MP_QSTR_Pbkdf2, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Pbkdf2_make_new, + locals_dict, &mod_trezorcrypto_Pbkdf2_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-random.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-random.h index 39061ea2c29..289e9a47058 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-random.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-random.h @@ -30,14 +30,14 @@ /// """ /// Compute uniform random number from interval 0 ... n - 1. /// """ -STATIC mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) { +static mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) { uint32_t nn = trezor_obj_get_uint(n); if (nn == 0) { mp_raise_ValueError(MP_ERROR_TEXT("Maximum can't be zero")); } return mp_obj_new_int_from_uint(random_uniform(nn)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_uniform_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_uniform_obj, mod_trezorcrypto_random_uniform); /// import builtins @@ -46,7 +46,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_uniform_obj, /// Generate random bytes sequence of length len. If `strong` is set then /// maximum sources of entropy are used. /// """ -STATIC mp_obj_t mod_trezorcrypto_random_bytes(size_t n_args, +static mp_obj_t mod_trezorcrypto_random_bytes(size_t n_args, const mp_obj_t *args) { uint32_t len = trezor_obj_get_uint(args[0]); if (len > 1024) { @@ -63,16 +63,16 @@ STATIC mp_obj_t mod_trezorcrypto_random_bytes(size_t n_args, } else { rng_fill_buffer((uint8_t *)vstr.buf, len); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_random_bytes_obj, 1, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_random_bytes_obj, 1, 2, mod_trezorcrypto_random_bytes); /// def shuffle(data: list) -> None: /// """ /// Shuffles items of given list (in-place). /// """ -STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) { size_t count = 0; mp_obj_t *items = NULL; mp_obj_get_array(data, &count, &items); @@ -92,7 +92,7 @@ STATIC mp_obj_t mod_trezorcrypto_random_shuffle(mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_shuffle_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_shuffle_obj, mod_trezorcrypto_random_shuffle); #ifdef TREZOR_EMULATOR @@ -100,15 +100,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_shuffle_obj, /// """ /// Re-seed the RNG with given value. /// """ -STATIC mp_obj_t mod_trezorcrypto_random_reseed(mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_random_reseed(mp_obj_t data) { random_reseed(trezor_obj_get_uint(data)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_reseed_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_random_reseed_obj, mod_trezorcrypto_random_reseed); #endif -STATIC const mp_rom_map_elem_t mod_trezorcrypto_random_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_random_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random)}, {MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_trezorcrypto_random_uniform_obj)}, @@ -121,10 +121,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_random_globals_table[] = { MP_ROM_PTR(&mod_trezorcrypto_random_reseed_obj)}, #endif }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_random_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_random_globals, mod_trezorcrypto_random_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_random_module = { +static const mp_obj_module_t mod_trezorcrypto_random_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_random_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ripemd160.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ripemd160.h index cc889719d67..b48c50cbced 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-ripemd160.h @@ -35,18 +35,18 @@ typedef struct _mp_obj_Ripemd160_t { ripemd160_state ctx; } mp_obj_Ripemd160_t; -STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Ripemd160_t *o = m_new_obj_with_finaliser(mp_obj_Ripemd160_t); - o->base.type = type; + mp_obj_Ripemd160_t *o = + mp_obj_malloc_with_finaliser(mp_obj_Ripemd160_t, type); ripemd160_init(&(o->ctx)); // constructor called with bytes/str as first parameter if (n_args == 1) { @@ -59,7 +59,7 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, +static mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) { mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; @@ -69,14 +69,14 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ripemd160_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Ripemd160_update_obj, mod_trezorcrypto_Ripemd160_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) { mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, RIPEMD160_DIGEST_LENGTH); @@ -84,21 +84,21 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(ripemd160_state)); ripemd160_done(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(ripemd160_state)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160_digest_obj, mod_trezorcrypto_Ripemd160_digest); -STATIC mp_obj_t mod_trezorcrypto_Ripemd160___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Ripemd160___del__(mp_obj_t self) { mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(ripemd160_state)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160___del___obj, mod_trezorcrypto_Ripemd160___del__); -STATIC const mp_rom_map_elem_t - mod_trezorcrypto_Ripemd160_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Ripemd160_locals_dict_table[] = + { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -108,12 +108,12 @@ STATIC const mp_rom_map_elem_t {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(RIPEMD160_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(RIPEMD160_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Ripemd160_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Ripemd160_locals_dict, mod_trezorcrypto_Ripemd160_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Ripemd160_type = { - {&mp_type_type}, - .name = MP_QSTR_Ripemd160, - .make_new = mod_trezorcrypto_Ripemd160_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Ripemd160_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Ripemd160_type, + MP_QSTR_Ripemd160, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Ripemd160_make_new, + locals_dict, &mod_trezorcrypto_Ripemd160_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-secp256k1.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-secp256k1.h index 9de7d3bcbca..e60d339b3e5 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-secp256k1.h @@ -30,7 +30,7 @@ /// """ /// Generate secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() { +static mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() { vstr_t sk = {0}; vstr_init_len(&sk, 32); for (;;) { @@ -52,16 +52,16 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_generate_secret() { continue; break; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sk); + return mp_obj_new_bytes_from_vstr(&sk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_secp256k1_generate_secret_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorcrypto_secp256k1_generate_secret_obj, mod_trezorcrypto_secp256k1_generate_secret); /// def publickey(secret_key: AnyBytes, compressed: bool = True) -> bytes: /// """ /// Computes public key from secret key. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args, +static mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}; mp_get_buffer_raise(args[0], &sk, MP_BUFFER_READ); @@ -84,9 +84,9 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_publickey(size_t n_args, vstr_clear(&pk); mp_raise_ValueError(MP_ERROR_TEXT("Invalid secret key")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( mod_trezorcrypto_secp256k1_publickey_obj, 1, 2, mod_trezorcrypto_secp256k1_publickey); @@ -125,7 +125,7 @@ enum { /// """ /// Uses secret key to produce the signature of the digest. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args, +static mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk = {0}; mp_buffer_info_t dig = {0}; @@ -160,9 +160,9 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_sign(size_t n_args, mp_raise_ValueError(MP_ERROR_TEXT("Signing failed")); } sig.buf[0] = 27 + pby + compressed * 4; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_secp256k1_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_secp256k1_sign_obj, 2, 4, mod_trezorcrypto_secp256k1_sign); @@ -173,7 +173,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_secp256k1_sign_obj, /// Uses public key to verify the signature of the digest. /// Returns True on success. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key, +static mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key, mp_obj_t signature, mp_obj_t digest) { mp_buffer_info_t pk = {0}, sig = {0}, dig = {0}; @@ -195,7 +195,7 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify(mp_obj_t public_key, (const uint8_t *)dig.buf); return mp_obj_new_bool(ret == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj, mod_trezorcrypto_secp256k1_verify); /// def verify_recover(signature: AnyBytes, digest: AnyBytes) -> bytes: @@ -203,7 +203,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_secp256k1_verify_obj, /// Uses signature of the digest to verify the digest and recover the public /// key. Returns public key on success, None if the signature is invalid. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature, +static mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature, mp_obj_t digest) { mp_buffer_info_t sig = {0}, dig = {0}; mp_get_buffer_raise(signature, &sig, MP_BUFFER_READ); @@ -229,12 +229,12 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_verify_recover(mp_obj_t signature, pk.buf[0] = 0x02 | (pk.buf[64] & 1); pk.len = 33; } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &pk); + return mp_obj_new_bytes_from_vstr(&pk); } else { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_verify_recover_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_verify_recover_obj, mod_trezorcrypto_secp256k1_verify_recover); /// def multiply(secret_key: AnyBytes, public_key: AnyBytes) -> bytes: @@ -242,7 +242,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_verify_recover_obj, /// Multiplies point defined by public_key with scalar defined by /// secret_key. Useful for ECDH. /// """ -STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key, +static mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key, mp_obj_t public_key) { mp_buffer_info_t sk = {0}, pk = {0}; mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ); @@ -260,12 +260,12 @@ STATIC mp_obj_t mod_trezorcrypto_secp256k1_multiply(mp_obj_t secret_key, vstr_clear(&out); mp_raise_ValueError(MP_ERROR_TEXT("Multiply failed")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &out); + return mp_obj_new_bytes_from_vstr(&out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_multiply_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_secp256k1_multiply_obj, mod_trezorcrypto_secp256k1_multiply); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_secp256k1_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_secp256k1_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_secp256k1)}, {MP_ROM_QSTR(MP_QSTR_generate_secret), MP_ROM_PTR(&mod_trezorcrypto_secp256k1_generate_secret_obj)}, @@ -285,10 +285,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_secp256k1_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_CANONICAL_SIG_EOS), MP_ROM_INT(CANONICAL_SIG_EOS)}, #endif }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_secp256k1_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_secp256k1_globals, mod_trezorcrypto_secp256k1_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_secp256k1_module = { +static const mp_obj_module_t mod_trezorcrypto_secp256k1_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_secp256k1_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h index 82440ca0aa3..c3104d8046a 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h @@ -35,18 +35,17 @@ typedef struct _mp_obj_Sha1_t { SHA1_CTX ctx; } mp_obj_Sha1_t; -STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Sha1_t *o = m_new_obj_with_finaliser(mp_obj_Sha1_t); - o->base.type = type; + mp_obj_Sha1_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha1_t, type); sha1_Init(&(o->ctx)); // constructor called with bytes/str as first parameter if (n_args == 1) { @@ -59,7 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) { mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -68,14 +67,14 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj, mod_trezorcrypto_Sha1_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) { mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, SHA1_DIGEST_LENGTH); @@ -83,20 +82,20 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(SHA1_CTX)); sha1_Final(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(SHA1_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1_digest_obj, mod_trezorcrypto_Sha1_digest); -STATIC mp_obj_t mod_trezorcrypto_Sha1___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha1___del__(mp_obj_t self) { mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(SHA1_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1___del___obj, mod_trezorcrypto_Sha1___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha1_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Sha1_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha1_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -106,12 +105,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha1_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA1_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA1_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha1_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha1_locals_dict, mod_trezorcrypto_Sha1_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Sha1_type = { - {&mp_type_type}, - .name = MP_QSTR_Sha1, - .make_new = mod_trezorcrypto_Sha1_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Sha1_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha1_type, + MP_QSTR_Sha1, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Sha1_make_new, + locals_dict, &mod_trezorcrypto_Sha1_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha256.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha256.h index a88dbcf037a..62e673f9785 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha256.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha256.h @@ -35,18 +35,17 @@ typedef struct _mp_obj_Sha256_t { SHA256_CTX ctx; } mp_obj_Sha256_t; -STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Sha256_t *o = m_new_obj_with_finaliser(mp_obj_Sha256_t); - o->base.type = type; + mp_obj_Sha256_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha256_t, type); sha256_Init(&(o->ctx)); // constructor called with bytes/str as first parameter if (n_args == 1) { @@ -59,7 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -68,14 +67,14 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha256_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha256_update_obj, mod_trezorcrypto_Sha256_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) { mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, SHA256_DIGEST_LENGTH); @@ -83,20 +82,20 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(SHA256_CTX)); sha256_Final(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(SHA256_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256_digest_obj, mod_trezorcrypto_Sha256_digest); -STATIC mp_obj_t mod_trezorcrypto_Sha256___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha256___del__(mp_obj_t self) { mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(SHA256_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256___del___obj, mod_trezorcrypto_Sha256___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha256_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Sha256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha256_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -106,12 +105,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA256_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA256_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha256_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha256_locals_dict, mod_trezorcrypto_Sha256_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Sha256_type = { - {&mp_type_type}, - .name = MP_QSTR_Sha256, - .make_new = mod_trezorcrypto_Sha256_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Sha256_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha256_type, + MP_QSTR_Sha256, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Sha256_make_new, + locals_dict, &mod_trezorcrypto_Sha256_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-256.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-256.h index 6e672c6d611..bb43a593e73 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-256.h @@ -36,7 +36,7 @@ typedef struct _mp_obj_Sha3_256_t { bool keccak; } mp_obj_Sha3_256_t; -STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -46,11 +46,11 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data); /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, true); - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_none}}, {MP_QSTR_keccak, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL}}, }; @@ -58,8 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals); - mp_obj_Sha3_256_t *o = m_new_obj_with_finaliser(mp_obj_Sha3_256_t); - o->base.type = type; + mp_obj_Sha3_256_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha3_256_t, type); o->keccak = 0; sha3_256_Init(&(o->ctx)); if (vals[1].u_obj != MP_OBJ_NULL) { @@ -76,7 +75,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -85,14 +84,14 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_256_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_256_update_obj, mod_trezorcrypto_Sha3_256_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) { mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, SHA3_256_DIGEST_LENGTH); @@ -104,37 +103,37 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) { sha3_Final(&ctx, (uint8_t *)hash.buf); } memzero(&ctx, sizeof(SHA3_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256_digest_obj, mod_trezorcrypto_Sha3_256_digest); /// def copy(self) -> sha3_256: /// """ /// Returns the copy of the digest object with the current state /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_256_copy(size_t n_args, +static mp_obj_t mod_trezorcrypto_Sha3_256_copy(size_t n_args, const mp_obj_t *args) { mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(args[0]); - mp_obj_Sha3_256_t *out = m_new_obj_with_finaliser(mp_obj_Sha3_256_t); - out->base.type = o->base.type; + mp_obj_Sha3_256_t *out = + mp_obj_malloc_with_finaliser(mp_obj_Sha3_256_t, o->base.type); out->keccak = o->keccak; memcpy(&(out->ctx), &(o->ctx), sizeof(SHA3_CTX)); return MP_OBJ_FROM_PTR(out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_256_copy_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_256_copy_obj, 1, 1, mod_trezorcrypto_Sha3_256_copy); -STATIC mp_obj_t mod_trezorcrypto_Sha3_256___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha3_256___del__(mp_obj_t self) { mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(SHA3_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_256___del___obj, mod_trezorcrypto_Sha3_256___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_256_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Sha3_256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -146,12 +145,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_256_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA3_256_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA3_256_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_256_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_256_locals_dict, mod_trezorcrypto_Sha3_256_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Sha3_256_type = { - {&mp_type_type}, - .name = MP_QSTR_Sha3_256, - .make_new = mod_trezorcrypto_Sha3_256_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Sha3_256_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha3_256_type, + MP_QSTR_Sha3_256, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Sha3_256_make_new, + locals_dict, &mod_trezorcrypto_Sha3_256_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-512.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-512.h index b66e36827c8..42a40461095 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha3-512.h @@ -36,7 +36,7 @@ typedef struct _mp_obj_Sha3_512_t { bool keccak; } mp_obj_Sha3_512_t; -STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data); /// def __init__( /// self, @@ -46,11 +46,11 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data); /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, true); - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_none}}, {MP_QSTR_keccak, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL}}, }; @@ -58,8 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals); - mp_obj_Sha3_512_t *o = m_new_obj_with_finaliser(mp_obj_Sha3_512_t); - o->base.type = type; + mp_obj_Sha3_512_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha3_512_t, type); o->keccak = 0; sha3_512_Init(&(o->ctx)); if (vals[1].u_obj != MP_OBJ_NULL) { @@ -76,7 +75,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -85,14 +84,14 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_512_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha3_512_update_obj, mod_trezorcrypto_Sha3_512_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) { mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, SHA3_512_DIGEST_LENGTH); @@ -104,37 +103,37 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) { sha3_Final(&ctx, (uint8_t *)hash.buf); } memzero(&ctx, sizeof(SHA3_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512_digest_obj, mod_trezorcrypto_Sha3_512_digest); /// def copy(self) -> sha3_512: /// """ /// Returns the copy of the digest object with the current state /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha3_512_copy(size_t n_args, +static mp_obj_t mod_trezorcrypto_Sha3_512_copy(size_t n_args, const mp_obj_t *args) { mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(args[0]); - mp_obj_Sha3_512_t *out = m_new_obj_with_finaliser(mp_obj_Sha3_512_t); - out->base.type = o->base.type; + mp_obj_Sha3_512_t *out = + mp_obj_malloc_with_finaliser(mp_obj_Sha3_512_t, o->base.type); out->keccak = o->keccak; memcpy(&(out->ctx), &(o->ctx), sizeof(SHA3_CTX)); return MP_OBJ_FROM_PTR(out); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_512_copy_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_512_copy_obj, 1, 1, mod_trezorcrypto_Sha3_512_copy); -STATIC mp_obj_t mod_trezorcrypto_Sha3_512___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha3_512___del__(mp_obj_t self) { mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(SHA3_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha3_512___del___obj, mod_trezorcrypto_Sha3_512___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_512_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Sha3_512_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -146,12 +145,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha3_512_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA3_512_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA3_512_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_512_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha3_512_locals_dict, mod_trezorcrypto_Sha3_512_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Sha3_512_type = { - {&mp_type_type}, - .name = MP_QSTR_Sha3_512, - .make_new = mod_trezorcrypto_Sha3_512_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Sha3_512_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha3_512_type, + MP_QSTR_Sha3_512, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Sha3_512_make_new, + locals_dict, &mod_trezorcrypto_Sha3_512_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha512.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha512.h index 9c6ac8e41e4..173752cb836 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha512.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha512.h @@ -35,18 +35,17 @@ typedef struct _mp_obj_Sha512_t { SHA512_CTX ctx; } mp_obj_Sha512_t; -STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data); +static mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data); /// def __init__(self, __data: StrOrBytes | None = None) -> None: /// """ /// Creates a hash context object. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_Sha512_t *o = m_new_obj_with_finaliser(mp_obj_Sha512_t); - o->base.type = type; + mp_obj_Sha512_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha512_t, type); sha512_Init(&(o->ctx)); if (n_args == 1) { mod_trezorcrypto_Sha512_update(MP_OBJ_FROM_PTR(o), args[0]); @@ -58,7 +57,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type, /// """ /// Update the hash context with hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t msg = {0}; mp_get_buffer_raise(data, &msg, MP_BUFFER_READ); @@ -67,14 +66,14 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha512_update_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha512_update_obj, mod_trezorcrypto_Sha512_update); /// def digest(self) -> bytes: /// """ /// Returns the digest of hashed data. /// """ -STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) { mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); vstr_t hash = {0}; vstr_init_len(&hash, SHA512_DIGEST_LENGTH); @@ -82,20 +81,20 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_digest(mp_obj_t self) { memcpy(&ctx, &(o->ctx), sizeof(SHA512_CTX)); sha512_Final(&ctx, (uint8_t *)hash.buf); memzero(&ctx, sizeof(SHA512_CTX)); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash); + return mp_obj_new_bytes_from_vstr(&hash); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512_digest_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512_digest_obj, mod_trezorcrypto_Sha512_digest); -STATIC mp_obj_t mod_trezorcrypto_Sha512___del__(mp_obj_t self) { +static mp_obj_t mod_trezorcrypto_Sha512___del__(mp_obj_t self) { mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self); memzero(&(o->ctx), sizeof(SHA512_CTX)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512___del___obj, mod_trezorcrypto_Sha512___del__); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha512_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_Sha512_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mod_trezorcrypto_Sha512_update_obj)}, {MP_ROM_QSTR(MP_QSTR_digest), @@ -105,12 +104,12 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_Sha512_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA512_BLOCK_LENGTH)}, {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA512_DIGEST_LENGTH)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha512_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha512_locals_dict, mod_trezorcrypto_Sha512_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorcrypto_Sha512_type = { - {&mp_type_type}, - .name = MP_QSTR_Sha512, - .make_new = mod_trezorcrypto_Sha512_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Sha512_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha512_type, + MP_QSTR_Sha512, MP_TYPE_FLAG_NONE, + make_new, mod_trezorcrypto_Sha512_make_new, + locals_dict, &mod_trezorcrypto_Sha512_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-shamir.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-shamir.h index 5a4e35b1283..153e0bc76f2 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-shamir.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-shamir.h @@ -76,20 +76,20 @@ mp_obj_t mod_trezorcrypto_shamir_interpolate(mp_obj_t shares, mp_obj_t x) { mp_raise_ValueError( MP_ERROR_TEXT("Share indices must be pairwise distinct.")); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_shamir_interpolate_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_shamir_interpolate_obj, mod_trezorcrypto_shamir_interpolate); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_shamir_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_shamir_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_shamir)}, {MP_ROM_QSTR(MP_QSTR_interpolate), MP_ROM_PTR(&mod_trezorcrypto_shamir_interpolate_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_shamir_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_shamir_globals, mod_trezorcrypto_shamir_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_shamir_module = { +static const mp_obj_module_t mod_trezorcrypto_shamir_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_shamir_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-slip39.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-slip39.h index 587d2439556..a4e3b7a8fbc 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-slip39.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-slip39.h @@ -29,7 +29,7 @@ /// Finds index of given word. /// Raises ValueError if not found. /// """ -STATIC mp_obj_t mod_trezorcrypto_slip39_word_index(mp_obj_t _word) { +static mp_obj_t mod_trezorcrypto_slip39_word_index(mp_obj_t _word) { mp_buffer_info_t word = {0}; mp_get_buffer_raise(_word, &word, MP_BUFFER_READ); @@ -40,14 +40,14 @@ STATIC mp_obj_t mod_trezorcrypto_slip39_word_index(mp_obj_t _word) { } return mp_obj_new_int_from_uint(result); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_slip39_word_index_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_slip39_word_index_obj, mod_trezorcrypto_slip39_word_index); /// def get_word(index: int) -> str: /// """ /// Returns word on position 'index'. /// """ -STATIC mp_obj_t mod_trezorcrypto_slip39_get_word(mp_obj_t _index) { +static mp_obj_t mod_trezorcrypto_slip39_get_word(mp_obj_t _index) { uint16_t index = mp_obj_get_int(_index); const char *word = get_word(index); @@ -58,20 +58,20 @@ STATIC mp_obj_t mod_trezorcrypto_slip39_get_word(mp_obj_t _index) { return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)word, strlen(word)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_slip39_get_word_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_slip39_get_word_obj, mod_trezorcrypto_slip39_get_word); -STATIC const mp_rom_map_elem_t mod_trezorcrypto_slip39_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_slip39_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_slip39)}, {MP_ROM_QSTR(MP_QSTR_word_index), MP_ROM_PTR(&mod_trezorcrypto_slip39_word_index_obj)}, {MP_ROM_QSTR(MP_QSTR_get_word), MP_ROM_PTR(&mod_trezorcrypto_slip39_get_word_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_slip39_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_slip39_globals, mod_trezorcrypto_slip39_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_slip39_module = { +static const mp_obj_module_t mod_trezorcrypto_slip39_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_slip39_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-tropic.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-tropic.h index 308753978bb..142cbd301c8 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-tropic.h +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-tropic.h @@ -43,7 +43,7 @@ MP_DEFINE_EXCEPTION(TropicError, Exception) /// """ /// Test the session by pinging the chip. /// """ -STATIC mp_obj_t mod_trezorcrypto_tropic_ping(mp_obj_t message) { +static mp_obj_t mod_trezorcrypto_tropic_ping(mp_obj_t message) { mp_buffer_info_t message_b = {0}; mp_get_buffer_raise(message, &message_b, MP_BUFFER_READ); @@ -58,9 +58,9 @@ STATIC mp_obj_t mod_trezorcrypto_tropic_ping(mp_obj_t message) { memcpy(result.buf, msg_in, message_b.len); - return mp_obj_new_str_from_vstr(&mp_type_str, &result); + return mp_obj_new_str_from_vstr(&result); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_ping_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_ping_obj, mod_trezorcrypto_tropic_ping); /// def key_generate( @@ -69,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_ping_obj, /// """ /// Generate ECC key in the device's ECC key slot. /// """ -STATIC mp_obj_t mod_trezorcrypto_tropic_key_generate(mp_obj_t key_index) { +static mp_obj_t mod_trezorcrypto_tropic_key_generate(mp_obj_t key_index) { mp_int_t idx = mp_obj_get_int(key_index); if (idx < 0 || idx >= ECC_SLOT_COUNT) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid index.")); @@ -83,7 +83,7 @@ STATIC mp_obj_t mod_trezorcrypto_tropic_key_generate(mp_obj_t key_index) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_key_generate_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_key_generate_obj, mod_trezorcrypto_tropic_key_generate); /// def sign( @@ -93,7 +93,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_key_generate_obj, /// """ /// Uses the private key at key_index to produce a signature of the digest. /// """ -STATIC mp_obj_t mod_trezorcrypto_tropic_sign(mp_obj_t key_index, +static mp_obj_t mod_trezorcrypto_tropic_sign(mp_obj_t key_index, mp_obj_t digest) { mp_int_t idx = mp_obj_get_int(key_index); if (idx < 0 || idx >= ECC_SLOT_COUNT) { @@ -115,9 +115,9 @@ STATIC mp_obj_t mod_trezorcrypto_tropic_sign(mp_obj_t key_index, } sig.len = sizeof(ed25519_signature); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &sig); + return mp_obj_new_bytes_from_vstr(&sig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_tropic_sign_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_tropic_sign_obj, mod_trezorcrypto_tropic_sign); static bool get_slot_range(int index, uint16_t *first_slot, @@ -141,7 +141,7 @@ static bool get_slot_range(int index, uint16_t *first_slot, /// """ /// Return the user data stored at the given index. /// """ -STATIC mp_obj_t mod_trezorcrypto_tropic_get_user_data(mp_obj_t index) { +static mp_obj_t mod_trezorcrypto_tropic_get_user_data(mp_obj_t index) { mp_int_t idx = mp_obj_get_int(index); uint16_t first_slot = 0; uint16_t slot_count = 0; @@ -165,9 +165,9 @@ STATIC mp_obj_t mod_trezorcrypto_tropic_get_user_data(mp_obj_t index) { } data.len = data_size; - return mp_obj_new_str_from_vstr(&mp_type_bytes, &data); + return mp_obj_new_bytes_from_vstr(&data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_get_user_data_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_get_user_data_obj, mod_trezorcrypto_tropic_get_user_data); /// DEVICE_CERT_INDEX: int @@ -175,7 +175,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_tropic_get_user_data_obj, /// FIDO_CERT_INDEX: int /// FIDO_KEY_SLOT: int -STATIC const mp_rom_map_elem_t mod_trezorcrypto_tropic_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorcrypto_tropic_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tropic)}, {MP_ROM_QSTR(MP_QSTR_DEVICE_CERT_INDEX), MP_ROM_INT(TROPIC_DEVICE_CERT_INDEX)}, @@ -189,10 +189,10 @@ STATIC const mp_rom_map_elem_t mod_trezorcrypto_tropic_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_get_user_data), MP_ROM_PTR(&mod_trezorcrypto_tropic_get_user_data_obj)}, {MP_ROM_QSTR(MP_QSTR_TropicError), MP_ROM_PTR(&mp_type_TropicError)}}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_tropic_globals, +static MP_DEFINE_CONST_DICT(mod_trezorcrypto_tropic_globals, mod_trezorcrypto_tropic_globals_table); -STATIC const mp_obj_module_t mod_trezorcrypto_tropic_module = { +static const mp_obj_module_t mod_trezorcrypto_tropic_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorcrypto_tropic_globals, }; diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c index 15d1c214fa3..82edf4e8a59 100644 --- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c +++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c @@ -83,7 +83,7 @@ static void wrapped_ui_wait_callback(uint32_t current, uint32_t total) { MP_DEFINE_EXCEPTION(AuthenticationError, Exception) -STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorcrypto)}, {MP_ROM_QSTR(MP_QSTR_AuthenticationError), MP_ROM_PTR(&mp_type_AuthenticationError)}, @@ -157,7 +157,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_mcu), MP_ROM_PTR(&mod_trezorcrypto_mcu_module)}, #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorcrypto_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorcrypto_globals, mp_module_trezorcrypto_globals_table); const mp_obj_module_t mp_module_trezorcrypto = { diff --git a/core/embed/upymod/modtrezorio/modtrezorio-fatfs.h b/core/embed/upymod/modtrezorio/modtrezorio-fatfs.h index 3efa1b33f4c..7ccbe2b3b2c 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-fatfs.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-fatfs.h @@ -129,7 +129,7 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) { } } -STATIC mp_obj_t filinfo_to_tuple(const FILINFO *info) { +static mp_obj_t filinfo_to_tuple(const FILINFO *info) { mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); tuple->items[0] = mp_obj_new_int_from_uint(info->fsize); char attrs[] = "-----"; @@ -149,7 +149,7 @@ STATIC mp_obj_t filinfo_to_tuple(const FILINFO *info) { attrs[4] = 'a'; } tuple->items[1] = mp_obj_new_str(attrs, 5); - tuple->items[2] = mp_obj_new_str(info->fname, strlen(info->fname)); + tuple->items[2] = mp_obj_new_str_from_cstr(info->fname); return MP_OBJ_FROM_PTR(tuple); } @@ -176,7 +176,7 @@ typedef struct _mp_obj_FatFSFile_t { /// """ /// Close an open file object /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile___exit__(size_t n_args, +static mp_obj_t mod_trezorio_FatFSFile___exit__(size_t n_args, const mp_obj_t *args) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(args[0]); FRESULT res = f_close(&(o->fp)); @@ -185,7 +185,7 @@ STATIC mp_obj_t mod_trezorio_FatFSFile___exit__(size_t n_args, } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FatFSFile___exit___obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FatFSFile___exit___obj, 4, 4, mod_trezorio_FatFSFile___exit__); @@ -193,7 +193,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FatFSFile___exit___obj, /// """ /// Close an open file object /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_close(mp_obj_t self) { +static mp_obj_t mod_trezorio_FatFSFile_close(mp_obj_t self) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); FRESULT res = f_close(&(o->fp)); if (res != FR_OK) { @@ -201,14 +201,14 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_close(mp_obj_t self) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_close_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_close_obj, mod_trezorio_FatFSFile_close); /// def read(self, data: bytearray) -> int: /// """ /// Read data from the file /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_read(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorio_FatFSFile_read(mp_obj_t self, mp_obj_t data) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t buf = {0}; mp_get_buffer_raise(data, &buf, MP_BUFFER_WRITE); @@ -219,14 +219,14 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_read(mp_obj_t self, mp_obj_t data) { } return mp_obj_new_int_from_uint(read); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_read_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_read_obj, mod_trezorio_FatFSFile_read); /// def write(self, data: AnyBytes) -> int: /// """ /// Write data to the file /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_write(mp_obj_t self, mp_obj_t data) { +static mp_obj_t mod_trezorio_FatFSFile_write(mp_obj_t self, mp_obj_t data) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t buf = {0}; mp_get_buffer_raise(data, &buf, MP_BUFFER_READ); @@ -241,14 +241,14 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_write(mp_obj_t self, mp_obj_t data) { } return mp_obj_new_int_from_uint(written); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_write_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_write_obj, mod_trezorio_FatFSFile_write); /// def seek(self, offset: int) -> None: /// """ /// Move file pointer of the file object /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_seek(mp_obj_t self, mp_obj_t offset) { +static mp_obj_t mod_trezorio_FatFSFile_seek(mp_obj_t self, mp_obj_t offset) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); FSIZE_t ofs = trezor_obj_get_uint(offset); FRESULT res = f_lseek(&(o->fp), ofs); @@ -257,14 +257,14 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_seek(mp_obj_t self, mp_obj_t offset) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_seek_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_seek_obj, mod_trezorio_FatFSFile_seek); /// def truncate(self) -> None: /// """ /// Truncate the file /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_truncate(mp_obj_t self) { +static mp_obj_t mod_trezorio_FatFSFile_truncate(mp_obj_t self) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); FRESULT res = f_truncate(&(o->fp)); if (res != FR_OK) { @@ -272,14 +272,14 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_truncate(mp_obj_t self) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_truncate_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_truncate_obj, mod_trezorio_FatFSFile_truncate); /// def sync(self) -> None: /// """ /// Flush cached data of the writing file /// """ -STATIC mp_obj_t mod_trezorio_FatFSFile_sync(mp_obj_t self) { +static mp_obj_t mod_trezorio_FatFSFile_sync(mp_obj_t self) { mp_obj_FatFSFile_t *o = MP_OBJ_TO_PTR(self); FRESULT res = f_sync(&(o->fp)); if (res != FR_OK) { @@ -287,10 +287,10 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_sync(mp_obj_t self) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_sync_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSFile_sync_obj, mod_trezorio_FatFSFile_sync); -STATIC const mp_rom_map_elem_t mod_trezorio_FatFSFile_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorio_FatFSFile_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj)}, {MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mod_trezorio_FatFSFile___exit___obj)}, @@ -302,14 +302,14 @@ STATIC const mp_rom_map_elem_t mod_trezorio_FatFSFile_locals_dict_table[] = { MP_ROM_PTR(&mod_trezorio_FatFSFile_truncate_obj)}, {MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_trezorio_FatFSFile_sync_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_FatFSFile_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorio_FatFSFile_locals_dict, mod_trezorio_FatFSFile_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorio_FatFSFile_type = { - {&mp_type_type}, - .name = MP_QSTR_FatFSFile, - .locals_dict = (void *)&mod_trezorio_FatFSFile_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorio_FatFSFile_type, + MP_QSTR_FatFSFile, MP_TYPE_FLAG_NONE, + locals_dict, &mod_trezorio_FatFSFile_locals_dict); +// clang-format on /// class FatFSDir(Iterator[tuple[int, str, str]]): /// """ @@ -324,7 +324,7 @@ typedef struct _mp_obj_FatFSDir_t { /// """ /// Read an entry in the directory /// """ -STATIC mp_obj_t mod_trezorio_FatFSDir_iternext(mp_obj_t self) { +static mp_obj_t mod_trezorio_FatFSDir_iternext(mp_obj_t self) { mp_obj_FatFSDir_t *o = MP_OBJ_TO_PTR(self); FILINFO info = {0}; FRESULT res = f_readdir(&(o->dp), &info); @@ -338,15 +338,14 @@ STATIC mp_obj_t mod_trezorio_FatFSDir_iternext(mp_obj_t self) { } return filinfo_to_tuple(&info); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSDir_iternext_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFSDir_iternext_obj, mod_trezorio_FatFSDir_iternext); -STATIC const mp_obj_type_t mod_trezorio_FatFSDir_type = { - {&mp_type_type}, - .name = MP_QSTR_FatFSDir, - .getiter = mp_identity_getiter, - .iternext = mod_trezorio_FatFSDir_iternext, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorio_FatFSDir_type, + MP_QSTR_FatFSDir, MP_TYPE_FLAG_ITER_IS_ITERNEXT, + iter, mod_trezorio_FatFSDir_iternext); +// clang-format on /// mock:global @@ -354,7 +353,7 @@ STATIC const mp_obj_type_t mod_trezorio_FatFSDir_type = { /// """ /// Open or create a file /// """ -STATIC mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) { +static mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) { FATFS_ONLY_MOUNTED; mp_buffer_info_t _path = {0}, _flags = {0}; mp_get_buffer_raise(path, &_path, MP_BUFFER_READ); @@ -390,14 +389,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) { f->fp = fp; return f; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_fatfs_open_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_fatfs_open_obj, mod_trezorio_fatfs_open); /// def listdir(path: str) -> FatFSDir: /// """ /// List a directory (return generator) /// """ -STATIC mp_obj_t mod_trezorio_fatfs_listdir(mp_obj_t path) { +static mp_obj_t mod_trezorio_fatfs_listdir(mp_obj_t path) { FATFS_ONLY_MOUNTED; mp_buffer_info_t _path = {0}; mp_get_buffer_raise(path, &_path, MP_BUFFER_READ); @@ -411,14 +410,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_listdir(mp_obj_t path) { d->dp = dp; return d; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_listdir_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_listdir_obj, mod_trezorio_fatfs_listdir); /// def mkdir(path: str, exist_ok: bool=False) -> None: /// """ /// Create a sub directory /// """ -STATIC mp_obj_t mod_trezorio_fatfs_mkdir(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorio_fatfs_mkdir(size_t n_args, const mp_obj_t *args) { FATFS_ONLY_MOUNTED; mp_buffer_info_t path = {0}; mp_get_buffer_raise(args[0], &path, MP_BUFFER_READ); @@ -432,14 +431,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_mkdir(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkdir_obj, 1, 2, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkdir_obj, 1, 2, mod_trezorio_fatfs_mkdir); /// def unlink(path: str) -> None: /// """ /// Delete an existing file or directory /// """ -STATIC mp_obj_t mod_trezorio_fatfs_unlink(mp_obj_t path) { +static mp_obj_t mod_trezorio_fatfs_unlink(mp_obj_t path) { FATFS_ONLY_MOUNTED; mp_buffer_info_t _path = {0}; mp_get_buffer_raise(path, &_path, MP_BUFFER_READ); @@ -449,14 +448,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_unlink(mp_obj_t path) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_unlink_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_unlink_obj, mod_trezorio_fatfs_unlink); /// def stat(path: str) -> tuple[int, str, str]: /// """ /// Get file status /// """ -STATIC mp_obj_t mod_trezorio_fatfs_stat(mp_obj_t path) { +static mp_obj_t mod_trezorio_fatfs_stat(mp_obj_t path) { FATFS_ONLY_MOUNTED; mp_buffer_info_t _path = {0}; mp_get_buffer_raise(path, &_path, MP_BUFFER_READ); @@ -467,14 +466,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_stat(mp_obj_t path) { } return filinfo_to_tuple(&info); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_stat_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_stat_obj, mod_trezorio_fatfs_stat); /// def rename(oldpath: str, newpath: str) -> None: /// """ /// Rename/Move a file or directory /// """ -STATIC mp_obj_t mod_trezorio_fatfs_rename(mp_obj_t oldpath, mp_obj_t newpath) { +static mp_obj_t mod_trezorio_fatfs_rename(mp_obj_t oldpath, mp_obj_t newpath) { FATFS_ONLY_MOUNTED; mp_buffer_info_t _oldpath = {0}, _newpath = {0}; mp_get_buffer_raise(oldpath, &_oldpath, MP_BUFFER_READ); @@ -485,14 +484,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_rename(mp_obj_t oldpath, mp_obj_t newpath) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_fatfs_rename_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_fatfs_rename_obj, mod_trezorio_fatfs_rename); /// def mount() -> None: /// """ /// Mount the SD card filesystem. /// """ -STATIC mp_obj_t mod_trezorio_fatfs_mount() { +static mp_obj_t mod_trezorio_fatfs_mount() { FRESULT res = f_mount(&fs_instance, "", 1); if (res != FR_OK) { if (res == FR_NO_FILESYSTEM) { @@ -503,33 +502,33 @@ STATIC mp_obj_t mod_trezorio_fatfs_mount() { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_mount_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_mount_obj, mod_trezorio_fatfs_mount); /// def unmount() -> None: /// """ /// Unmount the SD card filesystem. /// """ -STATIC mp_obj_t mod_trezorio_fatfs_unmount() { +static mp_obj_t mod_trezorio_fatfs_unmount() { _fatfs_unmount_instance(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_unmount_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_unmount_obj, mod_trezorio_fatfs_unmount); /// def is_mounted() -> bool: /// """ /// Check if the filesystem is mounted. /// """ -STATIC mp_obj_t mod_trezorio_fatfs_is_mounted() { +static mp_obj_t mod_trezorio_fatfs_is_mounted() { return mp_obj_new_bool(_fatfs_instance_is_mounted()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_is_mounted_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_fatfs_is_mounted_obj, mod_trezorio_fatfs_is_mounted); -STATIC mp_obj_t ui_wait_callback = mp_const_none; +static mp_obj_t ui_wait_callback = mp_const_none; -STATIC void wrapped_ui_wait_callback(uint32_t current) { +static void wrapped_ui_wait_callback(uint32_t current) { if (mp_obj_is_callable(ui_wait_callback)) { mp_call_function_1_protected(ui_wait_callback, mp_obj_new_int(current)); } @@ -539,7 +538,7 @@ STATIC void wrapped_ui_wait_callback(uint32_t current) { /// """ /// Create a FAT volume on the SD card, /// """ -STATIC mp_obj_t mod_trezorio_fatfs_mkfs(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorio_fatfs_mkfs(size_t n_args, const mp_obj_t *args) { if (_fatfs_instance_is_mounted()) { FATFS_RAISE(FatFSError, FR_LOCKED); } @@ -562,14 +561,14 @@ STATIC mp_obj_t mod_trezorio_fatfs_mkfs(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkfs_obj, 0, 1, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkfs_obj, 0, 1, mod_trezorio_fatfs_mkfs); /// def setlabel(label: str) -> None: /// """ /// Set volume label /// """ -STATIC mp_obj_t mod_trezorio_fatfs_setlabel(mp_obj_t label) { +static mp_obj_t mod_trezorio_fatfs_setlabel(mp_obj_t label) { /* setlabel is marked as only-mounted, because "mounting" in ff.c terms means having parsed the FAT table, which is of course a prerequisite for setting label. */ @@ -582,10 +581,10 @@ STATIC mp_obj_t mod_trezorio_fatfs_setlabel(mp_obj_t label) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_setlabel_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_fatfs_setlabel_obj, mod_trezorio_fatfs_setlabel); -STATIC const mp_rom_map_elem_t mod_trezorio_fatfs_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_fatfs_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_fatfs)}, {MP_ROM_QSTR(MP_QSTR_FatFSFile), MP_ROM_PTR(&mod_trezorio_FatFSFile_type)}, {MP_ROM_QSTR(MP_QSTR_FatFSDir), MP_ROM_PTR(&mod_trezorio_FatFSDir_type)}, @@ -633,10 +632,10 @@ STATIC const mp_rom_map_elem_t mod_trezorio_fatfs_globals_table[] = { FATFS_ROM_INT(FR_INVALID_PARAMETER)}, {MP_ROM_QSTR(MP_QSTR_FR_NO_SPACE), FATFS_ROM_INT(FR_NO_SPACE)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_fatfs_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_fatfs_globals, mod_trezorio_fatfs_globals_table); -STATIC const mp_obj_module_t mod_trezorio_fatfs_module = { +static const mp_obj_module_t mod_trezorio_fatfs_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorio_fatfs_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-haptic.h b/core/embed/upymod/modtrezorio/modtrezorio-haptic.h index 3e332f4eca6..e2f3311734e 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-haptic.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-haptic.h @@ -25,23 +25,23 @@ /// """ /// Enable/Disable the haptic feedback. /// """ -STATIC mp_obj_t mod_trezorio_haptic_set_enabled(mp_obj_t enable) { +static mp_obj_t mod_trezorio_haptic_set_enabled(mp_obj_t enable) { haptic_set_enabled(mp_obj_is_true(enable)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_haptic_set_enabled_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_haptic_set_enabled_obj, mod_trezorio_haptic_set_enabled); -STATIC const mp_rom_map_elem_t mod_trezorio_haptic_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_haptic_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_haptic)}, {MP_ROM_QSTR(MP_QSTR_haptic_set_enabled), MP_ROM_PTR(&mod_trezorio_haptic_set_enabled_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_haptic_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_haptic_globals, mod_trezorio_haptic_globals_table); -STATIC const mp_obj_module_t mod_trezorio_haptic_module = { +static const mp_obj_module_t mod_trezorio_haptic_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorio_haptic_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-ipc.h b/core/embed/upymod/modtrezorio/modtrezorio-ipc.h index 9a44ec6a14a..ace68a538a5 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-ipc.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-ipc.h @@ -27,7 +27,7 @@ /// """ /// Sends an IPC message to the specified remote task. /// """ -STATIC mp_obj_t mod_trezorio_ipc_send(mp_obj_t remote_obj, mp_obj_t fn_obj, +static mp_obj_t mod_trezorio_ipc_send(mp_obj_t remote_obj, mp_obj_t fn_obj, mp_obj_t data_obj) { mp_buffer_info_t bufinfo = {0}; mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ); @@ -41,7 +41,7 @@ STATIC mp_obj_t mod_trezorio_ipc_send(mp_obj_t remote_obj, mp_obj_t fn_obj, } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_ipc_send_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_ipc_send_obj, mod_trezorio_ipc_send); /// class IpcMessage: @@ -57,29 +57,29 @@ typedef struct _mp_obj_IpcMessage_t { /// """ /// Returns the function number. /// """ -STATIC mp_obj_t mod_trezorio_IpcMessage_fn(mp_obj_t self) { +static mp_obj_t mod_trezorio_IpcMessage_fn(mp_obj_t self) { mp_obj_IpcMessage_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_int_from_uint(o->message.fn); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_fn_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_fn_obj, mod_trezorio_IpcMessage_fn); /// def remote(self) -> int: /// """ /// Returns the remote task ID. /// """ -STATIC mp_obj_t mod_trezorio_IpcMessage_remote(mp_obj_t self) { +static mp_obj_t mod_trezorio_IpcMessage_remote(mp_obj_t self) { mp_obj_IpcMessage_t *o = MP_OBJ_TO_PTR(self); return MP_OBJ_NEW_SMALL_INT(o->message.remote); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_remote_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_remote_obj, mod_trezorio_IpcMessage_remote); /// def free(self) -> None: /// """ /// Frees the IPC message resources. /// """ -STATIC mp_obj_t mod_trezorio_IpcMessage_free(mp_obj_t self) { +static mp_obj_t mod_trezorio_IpcMessage_free(mp_obj_t self) { mp_obj_IpcMessage_t *o = MP_OBJ_TO_PTR(self); ipc_message_free(&o->message); @@ -87,33 +87,33 @@ STATIC mp_obj_t mod_trezorio_IpcMessage_free(mp_obj_t self) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_free_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_free_obj, mod_trezorio_IpcMessage_free); /// def data(self) -> bytes: /// """ /// Returns the IPC message data as bytes. /// """ -STATIC mp_obj_t mod_trezorio_IpcMessage_data(mp_obj_t self) { +static mp_obj_t mod_trezorio_IpcMessage_data(mp_obj_t self) { mp_obj_IpcMessage_t *o = MP_OBJ_TO_PTR(self); return mp_obj_new_bytes(o->message.data, o->message.size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_data_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_IpcMessage_data_obj, mod_trezorio_IpcMessage_data); -STATIC const mp_rom_map_elem_t mod_trezorio_IpcMessage_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorio_IpcMessage_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_remote), MP_ROM_PTR(&mod_trezorio_IpcMessage_remote_obj)}, {MP_ROM_QSTR(MP_QSTR_fn), MP_ROM_PTR(&mod_trezorio_IpcMessage_fn_obj)}, {MP_ROM_QSTR(MP_QSTR_data), MP_ROM_PTR(&mod_trezorio_IpcMessage_data_obj)}, {MP_ROM_QSTR(MP_QSTR_free), MP_ROM_PTR(&mod_trezorio_IpcMessage_free_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_IpcMessage_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorio_IpcMessage_locals_dict, mod_trezorio_IpcMessage_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorio_IpcMessage_type = { - {&mp_type_type}, - .name = MP_QSTR_IpcMessage, - .locals_dict = (void *)&mod_trezorio_IpcMessage_locals_dict, -}; +// clang-format off +static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorio_IpcMessage_type, + MP_QSTR_IpcMessage, MP_TYPE_FLAG_NONE, + locals_dict, &mod_trezorio_IpcMessage_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorio/modtrezorio-pm.h b/core/embed/upymod/modtrezorio/modtrezorio-pm.h index 89f8d19aea2..623f7f69ccf 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-pm.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-pm.h @@ -46,7 +46,7 @@ /// Returns the state of charge (SoC) in percent (0-100). Raises /// RuntimeError on failure. /// """ -STATIC mp_obj_t mod_trezorio_pm_soc() { +static mp_obj_t mod_trezorio_pm_soc() { pm_state_t state = {0}; pm_status_t res = pm_get_state(&state); if (res != PM_OK) { @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorio_pm_soc() { } return mp_obj_new_int(state.soc); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_soc_obj, mod_trezorio_pm_soc); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_soc_obj, mod_trezorio_pm_soc); /// def suspend() -> int: /// """ @@ -63,7 +63,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_soc_obj, mod_trezorio_pm_soc); /// failure. /// Wakeup flags: BUTTON=1, POWER=2, BLE=4, NFC=8, RTC=16, USB=32, TOUCH=64 /// """ -STATIC mp_obj_t mod_trezorio_pm_suspend() { +static mp_obj_t mod_trezorio_pm_suspend() { wakeup_flags_t wakeup_flags = 0; pm_status_t res = pm_suspend(&wakeup_flags); if (res != PM_OK) { @@ -71,21 +71,21 @@ STATIC mp_obj_t mod_trezorio_pm_suspend() { } return mp_obj_new_int_from_uint(wakeup_flags); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_suspend_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_suspend_obj, mod_trezorio_pm_suspend); /// def hibernate() -> None: /// """ /// Hibernates the device. Raises RuntimeError on failure. /// """ -STATIC mp_obj_t mod_trezorio_pm_hibernate() { +static mp_obj_t mod_trezorio_pm_hibernate() { pm_status_t res = pm_hibernate(); if (res != PM_OK) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Failed to hibernate")); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_hibernate_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_hibernate_obj, mod_trezorio_pm_hibernate); /// def is_usb_connected() -> bool: @@ -93,7 +93,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_hibernate_obj, /// Returns True if USB is connected, False otherwise. Raises RuntimeError /// on failure. /// """ -STATIC mp_obj_t mod_trezorio_pm_is_usb_connected() { +static mp_obj_t mod_trezorio_pm_is_usb_connected() { pm_state_t state; pm_status_t res = pm_get_state(&state); if (res != PM_OK) { @@ -102,7 +102,7 @@ STATIC mp_obj_t mod_trezorio_pm_is_usb_connected() { } return mp_obj_new_bool(state.usb_connected); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_usb_connected_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_usb_connected_obj, mod_trezorio_pm_is_usb_connected); /// def is_wireless_connected() -> bool: @@ -110,7 +110,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_usb_connected_obj, /// Returns True if Wireless power source is connected, False otherwise. /// Raises RuntimeError on failure. /// """ -STATIC mp_obj_t mod_trezorio_pm_is_wireless_connected() { +static mp_obj_t mod_trezorio_pm_is_wireless_connected() { pm_state_t state; pm_status_t res = pm_get_state(&state); if (res != PM_OK) { @@ -119,7 +119,7 @@ STATIC mp_obj_t mod_trezorio_pm_is_wireless_connected() { } return mp_obj_new_bool(state.wireless_connected); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_wireless_connected_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_wireless_connected_obj, mod_trezorio_pm_is_wireless_connected); #ifdef TREZOR_EMULATOR @@ -138,7 +138,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_wireless_connected_obj, /// Only available on emulator. Pass None to leave a field unchanged. /// Charging status and power status are derived from connection states. /// """ -STATIC mp_obj_t mod_trezorio_pm_set_emu_battery_state(size_t n_args, +static mp_obj_t mod_trezorio_pm_set_emu_battery_state(size_t n_args, const mp_obj_t* pos_args, mp_map_t* kw_args) { static const mp_arg_t allowed_args[] = { @@ -177,12 +177,12 @@ STATIC mp_obj_t mod_trezorio_pm_set_emu_battery_state(size_t n_args, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_trezorio_pm_set_emu_battery_state_obj, 0, +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_trezorio_pm_set_emu_battery_state_obj, 0, mod_trezorio_pm_set_emu_battery_state); #endif #endif -STATIC const mp_rom_map_elem_t mod_trezorio_pm_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_pm_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pm)}, {MP_ROM_QSTR(MP_QSTR_soc), MP_ROM_PTR(&mod_trezorio_pm_soc_obj)}, {MP_ROM_QSTR(MP_QSTR_suspend), MP_ROM_PTR(&mod_trezorio_pm_suspend_obj)}, @@ -222,10 +222,10 @@ STATIC const mp_rom_map_elem_t mod_trezorio_pm_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_EVENT_BATTERY_TEMP_JUMP_UPDATED), MP_ROM_INT(1 << 9)}, {MP_ROM_QSTR(MP_QSTR_EVENT_SOC_UPDATED), MP_ROM_INT(1 << 10)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_pm_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_pm_globals, mod_trezorio_pm_globals_table); -STATIC const mp_obj_module_t mod_trezorio_pm_module = { +static const mp_obj_module_t mod_trezorio_pm_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t*)&mod_trezorio_pm_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-poll.h b/core/embed/upymod/modtrezorio/modtrezorio-poll.h index f5f0e41b5ac..a649e9f672a 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-poll.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-poll.h @@ -87,7 +87,7 @@ static mp_obj_t parse_ble_event_data(const ble_event_t *event) { /// /// If timeout occurs, False is returned, True otherwise. /// """ -STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, +static mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, mp_obj_t timeout_ms) { mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref); if (!MP_OBJ_IS_TYPE(list_ref, &mp_type_list) || ret->len < 2) { @@ -268,4 +268,4 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, } } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_poll_obj, mod_trezorio_poll); +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_poll_obj, mod_trezorio_poll); diff --git a/core/embed/upymod/modtrezorio/modtrezorio-rgb_led.h b/core/embed/upymod/modtrezorio/modtrezorio-rgb_led.h index 1489dbe7785..b0c44d0d289 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-rgb_led.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-rgb_led.h @@ -25,23 +25,23 @@ /// """ /// Enable/Disable the RGB LED. /// """ -STATIC mp_obj_t mod_trezorio_rgb_led_set_enabled(mp_obj_t enable) { +static mp_obj_t mod_trezorio_rgb_led_set_enabled(mp_obj_t enable) { rgb_led_set_enabled(mp_obj_is_true(enable)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_rgb_led_set_enabled_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_rgb_led_set_enabled_obj, mod_trezorio_rgb_led_set_enabled); -STATIC const mp_rom_map_elem_t mod_trezorio_rgb_led_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_rgb_led_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rgb_led)}, {MP_ROM_QSTR(MP_QSTR_rgb_led_set_enabled), MP_ROM_PTR(&mod_trezorio_rgb_led_set_enabled_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_rgb_led_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_rgb_led_globals, mod_trezorio_rgb_led_globals_table); -STATIC const mp_obj_module_t mod_trezorio_rgb_led_module = { +static const mp_obj_module_t mod_trezorio_rgb_led_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorio_rgb_led_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-sdcard.h b/core/embed/upymod/modtrezorio/modtrezorio-sdcard.h index 3f10ff125ee..fba0fc3619d 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-sdcard.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-sdcard.h @@ -29,10 +29,10 @@ /// """ /// Returns True if SD card is detected, False otherwise. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_is_present() { +static mp_obj_t mod_trezorio_sdcard_is_present() { return mp_obj_new_bool(sdcard_is_present()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_is_present_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_is_present_obj, mod_trezorio_sdcard_is_present); /// def power_on() -> None: @@ -41,36 +41,36 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_is_present_obj, /// Raises OSError if the SD card cannot be powered on, e.g., when there /// is no SD card inserted. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_power_on() { +static mp_obj_t mod_trezorio_sdcard_power_on() { if (sectrue != sdcard_power_on()) { mp_raise_OSError(MP_EIO); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_power_on_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_power_on_obj, mod_trezorio_sdcard_power_on); /// def power_off() -> None: /// """ /// Power off the SD card interface. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_power_off() { +static mp_obj_t mod_trezorio_sdcard_power_off() { /* XXX should this call happen inside sdcard_power_off()? */ _fatfs_unmount_instance(); sdcard_power_off(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_power_off_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_power_off_obj, mod_trezorio_sdcard_power_off); /// def capacity() -> int: /// """ /// Returns capacity of the SD card in bytes, or zero if not present. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_capacity() { +static mp_obj_t mod_trezorio_sdcard_capacity() { return mp_obj_new_int_from_ull(sdcard_get_capacity_in_bytes()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_capacity_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_capacity_obj, mod_trezorio_sdcard_capacity); /// def read(block_num: int, buf: bytearray) -> None: @@ -79,7 +79,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_capacity_obj, /// Number of bytes read is length of buf rounded down to multiply of /// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_read(mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t mod_trezorio_sdcard_read(mp_obj_t block_num, mp_obj_t buf) { uint32_t block = trezor_obj_get_uint(block_num); mp_buffer_info_t bufinfo = {0}; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); @@ -89,7 +89,7 @@ STATIC mp_obj_t mod_trezorio_sdcard_read(mp_obj_t block_num, mp_obj_t buf) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_read_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_read_obj, mod_trezorio_sdcard_read); /// def write(block_num: int, buf: AnyBytes) -> None: @@ -98,7 +98,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_read_obj, /// Number of bytes written is length of buf rounded down to multiply of /// SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_write(mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t mod_trezorio_sdcard_write(mp_obj_t block_num, mp_obj_t buf) { uint32_t block = trezor_obj_get_uint(block_num); mp_buffer_info_t bufinfo = {0}; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); @@ -108,10 +108,10 @@ STATIC mp_obj_t mod_trezorio_sdcard_write(mp_obj_t block_num, mp_obj_t buf) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_write_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_sdcard_write_obj, mod_trezorio_sdcard_write); -STATIC const mp_rom_map_elem_t mod_trezorio_sdcard_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_sdcard_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcard)}, {MP_ROM_QSTR(MP_QSTR_is_present), @@ -126,10 +126,10 @@ STATIC const mp_rom_map_elem_t mod_trezorio_sdcard_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mod_trezorio_sdcard_read_obj)}, {MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_trezorio_sdcard_write_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_sdcard_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_sdcard_globals, mod_trezorio_sdcard_globals_table); -STATIC const mp_obj_module_t mod_trezorio_sdcard_module = { +static const mp_obj_module_t mod_trezorio_sdcard_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorio_sdcard_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-touch.h b/core/embed/upymod/modtrezorio/modtrezorio-touch.h index 7c45012acec..e2d52faa099 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-touch.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-touch.h @@ -27,26 +27,26 @@ /// """ /// Enable/disable touch wakeup during suspend. /// """ -STATIC mp_obj_t mod_trezorio_touch_wakeup_set_enabled(mp_obj_t enable) { +static mp_obj_t mod_trezorio_touch_wakeup_set_enabled(mp_obj_t enable) { touch_wakeup_set_enabled(mp_obj_is_true(enable)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_touch_wakeup_set_enabled_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_touch_wakeup_set_enabled_obj, mod_trezorio_touch_wakeup_set_enabled); /// def touch_wakeup_get_enabled() -> bool: /// """ /// Return whether touch wakeup during suspend is enabled. /// """ -STATIC mp_obj_t mod_trezorio_touch_wakeup_get_enabled(void) { +static mp_obj_t mod_trezorio_touch_wakeup_get_enabled(void) { return mp_obj_new_bool(touch_wakeup_get_enabled()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_touch_wakeup_get_enabled_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_touch_wakeup_get_enabled_obj, mod_trezorio_touch_wakeup_get_enabled); #endif // USE_TOUCH_WAKEUP -STATIC const mp_rom_map_elem_t mod_trezorio_touch_globals_table[] = { +static const mp_rom_map_elem_t mod_trezorio_touch_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_touch)}, #ifdef USE_TOUCH_WAKEUP {MP_ROM_QSTR(MP_QSTR_touch_wakeup_set_enabled), @@ -55,10 +55,10 @@ STATIC const mp_rom_map_elem_t mod_trezorio_touch_globals_table[] = { MP_ROM_PTR(&mod_trezorio_touch_wakeup_get_enabled_obj)}, #endif // USE_TOUCH_WAKEUP }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_touch_globals, +static MP_DEFINE_CONST_DICT(mod_trezorio_touch_globals, mod_trezorio_touch_globals_table); -STATIC const mp_obj_module_t mod_trezorio_touch_module = { +static const mp_obj_module_t mod_trezorio_touch_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mod_trezorio_touch_globals, }; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-usb-if.h b/core/embed/upymod/modtrezorio/modtrezorio-usb-if.h index f4ed0631f8b..19b56f5259c 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-usb-if.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-usb-if.h @@ -36,10 +36,10 @@ typedef struct _mp_obj_USBIF_t { /// ) -> None: /// """ /// """ -STATIC mp_obj_t mod_trezorio_USBIF_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorio_USBIF_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { {MP_QSTR_handle, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0}}, @@ -63,18 +63,18 @@ STATIC mp_obj_t mod_trezorio_USBIF_make_new(const mp_obj_type_t *type, /// """ /// Returns the configured number of this interface. /// """ -STATIC mp_obj_t mod_trezorio_USBIF_iface_num(mp_obj_t self) { +static mp_obj_t mod_trezorio_USBIF_iface_num(mp_obj_t self) { mp_obj_USBIF_t *o = MP_OBJ_TO_PTR(self); return MP_OBJ_NEW_SMALL_INT(o->handle); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USBIF_iface_num_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USBIF_iface_num_obj, mod_trezorio_USBIF_iface_num); /// def write(self, msg: AnyBytes) -> int: /// """ /// Sends message using USB interface. /// """ -STATIC mp_obj_t mod_trezorio_USBIF_write(mp_obj_t self, mp_obj_t msg) { +static mp_obj_t mod_trezorio_USBIF_write(mp_obj_t self, mp_obj_t msg) { mp_obj_USBIF_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t buf = {0}; mp_get_buffer_raise(msg, &buf, MP_BUFFER_READ); @@ -91,14 +91,14 @@ STATIC mp_obj_t mod_trezorio_USBIF_write(mp_obj_t self, mp_obj_t msg) { return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USBIF_write_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USBIF_write_obj, mod_trezorio_USBIF_write); /// def write_blocking(self, msg: AnyBytes, timeout_ms: int) -> int: /// """ /// Sends message using USB interface. /// """ -STATIC mp_obj_t mod_trezorio_USBIF_write_blocking(mp_obj_t self, mp_obj_t msg, +static mp_obj_t mod_trezorio_USBIF_write_blocking(mp_obj_t self, mp_obj_t msg, mp_obj_t timeout_ms) { mp_obj_USBIF_t *o = MP_OBJ_TO_PTR(self); mp_buffer_info_t buf = {0}; @@ -114,14 +114,14 @@ STATIC mp_obj_t mod_trezorio_USBIF_write_blocking(mp_obj_t self, mp_obj_t msg, return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_USBIF_write_blocking_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_USBIF_write_blocking_obj, mod_trezorio_USBIF_write_blocking); /// def read(self, buf: bytearray, offset: int = 0) -> int: /// """ /// Reads message using USB interface /// """ -STATIC mp_obj_t mod_trezorio_USBIF_read(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorio_USBIF_read(size_t n_args, const mp_obj_t *args) { mp_obj_USBIF_t *o = MP_OBJ_TO_PTR(args[0]); mp_buffer_info_t buf = {0}; mp_get_buffer_raise(args[1], &buf, MP_BUFFER_WRITE); @@ -155,7 +155,7 @@ STATIC mp_obj_t mod_trezorio_USBIF_read(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_USBIF_read_obj, 2, 3, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_USBIF_read_obj, 2, 3, mod_trezorio_USBIF_read); /// RX_PACKET_LEN: ClassVar[int] @@ -164,7 +164,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_USBIF_read_obj, 2, 3, /// TX_PACKET_LEN: ClassVar[int] /// """Length of one USB TX packet.""" -STATIC const mp_rom_map_elem_t mod_trezorio_USBIF_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorio_USBIF_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_iface_num), MP_ROM_PTR(&mod_trezorio_USBIF_iface_num_obj)}, {MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_trezorio_USBIF_write_obj)}, @@ -174,12 +174,12 @@ STATIC const mp_rom_map_elem_t mod_trezorio_USBIF_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_RX_PACKET_LEN), MP_ROM_INT(USB_PACKET_LEN)}, {MP_ROM_QSTR(MP_QSTR_TX_PACKET_LEN), MP_ROM_INT(USB_PACKET_LEN)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_USBIF_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorio_USBIF_locals_dict, mod_trezorio_USBIF_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorio_USBIF_type = { - {&mp_type_type}, - .name = MP_QSTR_USBIF, - .make_new = mod_trezorio_USBIF_make_new, - .locals_dict = (void *)&mod_trezorio_USBIF_locals_dict, -}; +// clang-format off +MP_DEFINE_CONST_OBJ_TYPE(mod_trezorio_USBIF_type, + MP_QSTR_USBIF, MP_TYPE_FLAG_NONE, + make_new, mod_trezorio_USBIF_make_new, + locals_dict, &mod_trezorio_USBIF_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorio/modtrezorio-usb.h b/core/embed/upymod/modtrezorio/modtrezorio-usb.h index 77c6b564a32..ecd11a7603d 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-usb.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-usb.h @@ -46,11 +46,10 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) { /// ) -> None: /// """ /// """ -STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_obj_USB_t *o = m_new_obj_with_finaliser(mp_obj_USB_t); - o->base.type = type; + mp_obj_USB_t *o = mp_obj_malloc_with_finaliser(mp_obj_USB_t, type); return MP_OBJ_FROM_PTR(o); } @@ -59,7 +58,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, /// """ /// Initializes the USB stack. /// """ -STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self, +static mp_obj_t mod_trezorio_USB_open(mp_obj_t self, mp_obj_t serial_number_obj) { const char *serial_number = get_0str(serial_number_obj, 0, USB_MAX_STR_SIZE); if (serial_number == NULL) { @@ -81,38 +80,38 @@ STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USB_open_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_USB_open_obj, mod_trezorio_USB_open); /// def close(self) -> None: /// """ /// Cleans up the USB stack. /// """ -STATIC mp_obj_t mod_trezorio_USB_close(mp_obj_t self) { +static mp_obj_t mod_trezorio_USB_close(mp_obj_t self) { usb_stop(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USB_close_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USB_close_obj, mod_trezorio_USB_close); -STATIC mp_obj_t mod_trezorio_USB___del__(mp_obj_t self) { +static mp_obj_t mod_trezorio_USB___del__(mp_obj_t self) { usb_stop(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USB___del___obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_USB___del___obj, mod_trezorio_USB___del__); -STATIC const mp_rom_map_elem_t mod_trezorio_USB_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorio_USB_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mod_trezorio_USB_open_obj)}, {MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mod_trezorio_USB_close_obj)}, {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_trezorio_USB___del___obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_USB_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorio_USB_locals_dict, mod_trezorio_USB_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorio_USB_type = { - {&mp_type_type}, - .name = MP_QSTR_USB, - .make_new = mod_trezorio_USB_make_new, - .locals_dict = (void *)&mod_trezorio_USB_locals_dict, -}; +// clang-format off +MP_DEFINE_CONST_OBJ_TYPE(mod_trezorio_USB_type, + MP_QSTR_USB, MP_TYPE_FLAG_NONE, + make_new, mod_trezorio_USB_make_new, + locals_dict, &mod_trezorio_USB_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorio/modtrezorio.c b/core/embed/upymod/modtrezorio/modtrezorio.c index 8136d388c75..75db57a8114 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio.c +++ b/core/embed/upymod/modtrezorio/modtrezorio.c @@ -103,7 +103,7 @@ uint32_t last_touch_sample_time = 0; /// USBIF_DEBUG: int # interface id of the USB debug interface /// USBIF_WEBAUTHN: int # interface id of the USB WebAuthn -STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)}, #ifdef USE_SD_CARD @@ -157,7 +157,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_USB_EVENT), MP_ROM_INT(SYSHANDLE_USB)}, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorio_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorio_globals, mp_module_trezorio_globals_table); const mp_obj_module_t mp_module_trezorio = { diff --git a/core/embed/upymod/modtrezorui/modtrezorui-display.h b/core/embed/upymod/modtrezorui/modtrezorui-display.h index 3b5b437cf21..f1bb36833c2 100644 --- a/core/embed/upymod/modtrezorui/modtrezorui-display.h +++ b/core/embed/upymod/modtrezorui/modtrezorui-display.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Display_t { /// """ /// Initialize the display. /// """ -STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, +static mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -52,7 +52,7 @@ STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, /// Call without the degrees parameter to just perform the read of the /// value. /// """ -STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args, +static mp_obj_t mod_trezorui_Display_orientation(size_t n_args, const mp_obj_t *args) { mp_int_t deg; if (n_args > 1) { @@ -66,7 +66,7 @@ STATIC mp_obj_t mod_trezorui_Display_orientation(size_t n_args, } return MP_OBJ_NEW_SMALL_INT(deg); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj, 1, 2, mod_trezorui_Display_orientation); /// def record_start( @@ -76,7 +76,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj, /// Starts screen recording with specified target directory and refresh /// index. /// """ -STATIC mp_obj_t mod_trezorui_Display_record_start(mp_obj_t self, +static mp_obj_t mod_trezorui_Display_record_start(mp_obj_t self, mp_obj_t target_directory, mp_obj_t refresh_index) { #ifdef TREZOR_EMULATOR @@ -87,23 +87,23 @@ STATIC mp_obj_t mod_trezorui_Display_record_start(mp_obj_t self, #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorui_Display_record_start_obj, +static MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorui_Display_record_start_obj, mod_trezorui_Display_record_start); /// def record_stop(self) -> None: /// """ /// Stops screen recording. /// """ -STATIC mp_obj_t mod_trezorui_Display_record_stop(mp_obj_t self) { +static mp_obj_t mod_trezorui_Display_record_stop(mp_obj_t self) { #ifdef TREZOR_EMULATOR display_record_stop(); #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_record_stop_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_Display_record_stop_obj, mod_trezorui_Display_record_stop); -STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = { +static const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_trezorui_Display_orientation_obj)}, {MP_ROM_QSTR(MP_QSTR_record_start), @@ -113,12 +113,12 @@ STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(DISPLAY_RESX)}, {MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(DISPLAY_RESY)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict, +static MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict, mod_trezorui_Display_locals_dict_table); -STATIC const mp_obj_type_t mod_trezorui_Display_type = { - {&mp_type_type}, - .name = MP_QSTR_Display, - .make_new = mod_trezorui_Display_make_new, - .locals_dict = (void *)&mod_trezorui_Display_locals_dict, -}; +// clang-format off +MP_DEFINE_CONST_OBJ_TYPE(mod_trezorui_Display_type, + MP_QSTR_Display, MP_TYPE_FLAG_NONE, + make_new, mod_trezorui_Display_make_new, + locals_dict, &mod_trezorui_Display_locals_dict); +// clang-format on diff --git a/core/embed/upymod/modtrezorui/modtrezorui.c b/core/embed/upymod/modtrezorui/modtrezorui.c index a47314dd797..47d640d0b70 100644 --- a/core/embed/upymod/modtrezorui/modtrezorui.c +++ b/core/embed/upymod/modtrezorui/modtrezorui.c @@ -26,12 +26,12 @@ #include "../trezorobj.h" #include "modtrezorui-display.h" -STATIC const mp_rom_map_elem_t mp_module_trezorui_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorui_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorui)}, {MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&mod_trezorui_Display_type)}, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorui_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorui_globals, mp_module_trezorui_globals_table); const mp_obj_module_t mp_module_trezorui = { diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils-meminfo.h b/core/embed/upymod/modtrezorutils/modtrezorutils-meminfo.h index b3b3e71f1c6..dceef2c8597 100644 --- a/core/embed/upymod/modtrezorutils/modtrezorutils-meminfo.h +++ b/core/embed/upymod/modtrezorutils/modtrezorutils-meminfo.h @@ -72,49 +72,50 @@ #define ATB_3_IS_FREE(a) (((a) & ATB_MASK_3) == 0) #define BLOCK_SHIFT(block) (2 * ((block) & (BLOCKS_PER_ATB - 1))) -#define ATB_GET_KIND(block) \ - ((MP_STATE_MEM(gc_alloc_table_start)[(block) / BLOCKS_PER_ATB] >> \ - BLOCK_SHIFT(block)) & \ +#define ATB_GET_KIND(block) \ + ((MP_STATE_MEM(area.gc_alloc_table_start)[(block) / BLOCKS_PER_ATB] >> \ + BLOCK_SHIFT(block)) & \ 3) #define ATB_ANY_TO_FREE(block) \ do { \ - MP_STATE_MEM(gc_alloc_table_start) \ + MP_STATE_MEM(area.gc_alloc_table_start) \ [(block) / BLOCKS_PER_ATB] &= (~(AT_MARK << BLOCK_SHIFT(block))); \ } while (0) #define ATB_FREE_TO_HEAD(block) \ do { \ - MP_STATE_MEM(gc_alloc_table_start) \ + MP_STATE_MEM(area.gc_alloc_table_start) \ [(block) / BLOCKS_PER_ATB] |= (AT_HEAD << BLOCK_SHIFT(block)); \ } while (0) #define ATB_FREE_TO_TAIL(block) \ do { \ - MP_STATE_MEM(gc_alloc_table_start) \ + MP_STATE_MEM(area.gc_alloc_table_start) \ [(block) / BLOCKS_PER_ATB] |= (AT_TAIL << BLOCK_SHIFT(block)); \ } while (0) #define ATB_HEAD_TO_MARK(block) \ do { \ - MP_STATE_MEM(gc_alloc_table_start) \ + MP_STATE_MEM(area.gc_alloc_table_start) \ [(block) / BLOCKS_PER_ATB] |= (AT_MARK << BLOCK_SHIFT(block)); \ } while (0) #define ATB_MARK_TO_HEAD(block) \ do { \ - MP_STATE_MEM(gc_alloc_table_start) \ + MP_STATE_MEM(area.gc_alloc_table_start) \ [(block) / BLOCKS_PER_ATB] &= (~(AT_TAIL << BLOCK_SHIFT(block))); \ } while (0) #define BLOCK_FROM_PTR(ptr) \ - (((byte *)(ptr) - MP_STATE_MEM(gc_pool_start)) / BYTES_PER_BLOCK) + (((byte *)(ptr) - MP_STATE_MEM(area.gc_pool_start)) / BYTES_PER_BLOCK) #define PTR_FROM_BLOCK(block) \ - (((block) * BYTES_PER_BLOCK + (uintptr_t)MP_STATE_MEM(gc_pool_start))) + (((block) * BYTES_PER_BLOCK + (uintptr_t)MP_STATE_MEM(area.gc_pool_start))) #define ATB_FROM_BLOCK(bl) ((bl) / BLOCKS_PER_ATB) // ptr should be of type void* -#define VERIFY_PTR(ptr) \ - (((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) == \ - 0 /* must be aligned on a block */ \ - && ptr >= (void *)MP_STATE_MEM( \ - gc_pool_start) /* must be above start of pool */ \ - && ptr < (void *)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \ +#define VERIFY_PTR(ptr) \ + (((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) == \ + 0 /* must be aligned on a block */ \ + && ptr >= (void *)MP_STATE_MEM( \ + area.gc_pool_start) /* must be above start of pool */ \ + && ptr < (void *)MP_STATE_MEM( \ + area.gc_pool_end) /* must be below end of pool */ \ ) #define Q_GET_DATA(q) \ @@ -410,11 +411,14 @@ void dump_instance(FILE *out, const mp_obj_instance_t *obj) { void dump_type(FILE *out, const mp_obj_type_t *type) { print_type(out, "type", qstr_str(type->name), type, false); - fprintf(out, ",\n\"locals\": \"%p\"", type->locals_dict); - fprintf(out, ",\n\"parent\": \"%p\"},\n", type->parent); - - dump_value(out, type->parent); - dump_value(out, type->locals_dict); + // XXX 3ac8b5851e5f4dade465d52b91ed2ccc17851263 #7542 + fprintf(out, ",\n\"locals\": \"%p\"", + MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, locals_dict)); + fprintf(out, ",\n\"parent\": \"%p\"},\n", + MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, parent)); + + dump_value(out, MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, parent)); + dump_value(out, MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, locals_dict)); } void dump_list(FILE *out, const mp_obj_list_t *list) { @@ -456,7 +460,13 @@ typedef struct _mp_obj_set_t { mp_set_t set; } mp_obj_set_t; -bool is_set_or_frozenset(mp_const_obj_t o); +bool is_set_or_frozenset(mp_const_obj_t o) { + return mp_obj_is_type(o, &mp_type_set) +#if MICROPY_PY_BUILTINS_FROZENSET + || mp_obj_is_type(o, &mp_type_frozenset) +#endif + ; +} void dump_set(FILE *out, const mp_obj_set_t *set) { print_type(out, "set", NULL, set, false); @@ -482,7 +492,7 @@ void dump_set(FILE *out, const mp_obj_set_t *set) { void dump_protomsg(FILE *out, const mp_obj_protomsg_t *value) { mp_obj_t name[2] = {MP_OBJ_NULL, MP_OBJ_NULL}; mp_obj_type_t *type = protobuf_debug_msg_type(); - type->attr((mp_obj_t)value, MP_QSTR_MESSAGE_NAME, name); + MP_OBJ_TYPE_GET_SLOT(type, attr)((mp_obj_t)value, MP_QSTR_MESSAGE_NAME, name); print_type(out, "protomsg", NULL, value, false); fprintf(out, ",\n\"message_name\": "); @@ -494,7 +504,7 @@ void dump_protomsg(FILE *out, const mp_obj_protomsg_t *value) { void dump_protodef(FILE *out, const mp_obj_t *value) { mp_obj_t name[2] = {MP_OBJ_NULL, MP_OBJ_NULL}; mp_obj_type_t *type = protobuf_debug_msg_def_type(); - type->attr((mp_obj_t)value, MP_QSTR_MESSAGE_NAME, name); + MP_OBJ_TYPE_GET_SLOT(type, attr)((mp_obj_t)value, MP_QSTR_MESSAGE_NAME, name); print_type(out, "protodef", NULL, value, false); fprintf(out, ",\n\"message_name\": "); @@ -670,8 +680,8 @@ static void dump_meminfo_json(FILE *out) { #endif } fprintf(out, "\n[\n[" UINT_FMT ", " UINT_FMT ", " UINT_FMT "],\n", - (mp_uint_t)MP_STATE_MEM(gc_pool_start), - (mp_uint_t)MP_STATE_MEM(gc_pool_end), BYTES_PER_BLOCK); + (mp_uint_t)MP_STATE_MEM(area.gc_pool_start), + (mp_uint_t)MP_STATE_MEM(area.gc_pool_end), BYTES_PER_BLOCK); // void **ptrs = (void **)(void *)&mp_state_ctx; // size_t root_start = offsetof(mp_state_ctx_t, thread.dict_locals); @@ -706,11 +716,13 @@ static void dump_meminfo_json(FILE *out) { fprintf(out, "\"dict_main\",\n"); dump_value_opt(out, &MP_STATE_VM(dict_main), true); - fprintf(out, "\"mp_sys_path_obj\",\n"); - dump_value_opt(out, &MP_STATE_VM(mp_sys_path_obj), true); + fprintf(out, "\"mp_sys_path\",\n"); + dump_value_opt(out, &mp_sys_path, true); +#if MICROPY_PY_SYS_ARGV fprintf(out, "\"mp_sys_argv_obj\",\n"); dump_value_opt(out, &MP_STATE_VM(mp_sys_argv_obj), true); +#endif fprintf(out, "\"ui_wait_callback\",\n"); dump_value(out, MP_STATE_VM(trezorconfig_ui_wait_callback)); @@ -729,14 +741,14 @@ static void dump_meminfo_json(FILE *out) { fflush(out); } for (size_t block = 0; - block < MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB; + block < MP_STATE_MEM(area.gc_alloc_table_byte_len) * BLOCKS_PER_ATB; block++) { if (ATB_GET_KIND(block) == AT_MARK) { ATB_MARK_TO_HEAD(block); } } - gc_dump_alloc_table(); + gc_dump_alloc_table(&mp_plat_print); } /// def meminfo(filename: str | None) -> None: @@ -744,7 +756,7 @@ static void dump_meminfo_json(FILE *out) { /// Dumps map of micropython GC arena to a file. /// The JSON file can be decoded by analyze-memory-dump.py /// """ -STATIC mp_obj_t mod_trezorutils_meminfo(mp_obj_t filename) { +static mp_obj_t mod_trezorutils_meminfo(mp_obj_t filename) { size_t fn_len; FILE *out = (filename == mp_const_none) ? NULL @@ -753,7 +765,7 @@ STATIC mp_obj_t mod_trezorutils_meminfo(mp_obj_t filename) { dump_meminfo_json(out); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_meminfo_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_meminfo_obj, mod_trezorutils_meminfo); #define MEMINFO_DICT_ENTRIES \ diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils.c b/core/embed/upymod/modtrezorutils/modtrezorutils.c index 4bc19857047..50300ce6907 100644 --- a/core/embed/upymod/modtrezorutils/modtrezorutils.c +++ b/core/embed/upymod/modtrezorutils/modtrezorutils.c @@ -23,6 +23,7 @@ #if MICROPY_OOM_CALLBACK #include #endif +#include "py/objmodule.h" #include "py/objstr.h" #include "py/runtime.h" @@ -77,7 +78,7 @@ /// (min_temp_milli_c, max_temp_milli_c, battery_errors, battery_cycles) /// or None if telemetry is not available. /// """ -STATIC mp_obj_t mod_trezorutils_telemetry_get(void) { +static mp_obj_t mod_trezorutils_telemetry_get(void) { telemetry_data_t data; if (!telemetry_get(&data)) { return mp_const_none; @@ -91,7 +92,7 @@ STATIC mp_obj_t mod_trezorutils_telemetry_get(void) { return mp_obj_new_tuple(4, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_telemetry_get_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_telemetry_get_obj, mod_trezorutils_telemetry_get); #endif @@ -101,7 +102,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_telemetry_get_obj, /// information in `pub`. Runs in constant time, corresponding to the /// length of `pub`. /// """ -STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) { +static mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) { mp_buffer_info_t secbuf = {0}; mp_get_buffer_raise(sec, &secbuf, MP_BUFFER_READ); mp_buffer_info_t pubbuf = {0}; @@ -124,7 +125,7 @@ STATIC mp_obj_t mod_trezorutils_consteq(mp_obj_t sec, mp_obj_t pub) { return mp_const_false; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj, mod_trezorutils_consteq); /// def memcpy( @@ -140,7 +141,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj, /// copied bytes. If `n` is not specified, tries to copy /// as much as possible. /// """ -STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) { mp_arg_check_num(n_args, 0, 4, 5, false); mp_buffer_info_t dst = {0}; @@ -166,7 +167,7 @@ STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) { return mp_obj_new_int(ncpy); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 4, 5, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 4, 5, mod_trezorutils_memcpy); /// def memzero( @@ -175,20 +176,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 4, 5, /// """ /// Zeroes all bytes at `dst`. /// """ -STATIC mp_obj_t mod_trezorutils_memzero(const mp_obj_t dst) { +static mp_obj_t mod_trezorutils_memzero(const mp_obj_t dst) { mp_buffer_info_t buf = {0}; mp_get_buffer_raise(dst, &buf, MP_BUFFER_WRITE); memzero(buf.buf, buf.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_memzero_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_memzero_obj, mod_trezorutils_memzero); /// def halt(msg: str | None = None) -> None: /// """ /// Halts execution. /// """ -STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t msg = {0}; if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) { error_shutdown(msg.buf); @@ -197,7 +198,7 @@ STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, mod_trezorutils_halt); /// def firmware_hash( @@ -208,7 +209,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, /// Computes the Blake2s hash of the firmware with an optional challenge as /// the key. /// """ -STATIC mp_obj_t mod_trezorutils_firmware_hash(size_t n_args, +static mp_obj_t mod_trezorutils_firmware_hash(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t chal = {0}; if (n_args > 0 && args[0] != mp_const_none) { @@ -247,17 +248,17 @@ STATIC mp_obj_t mod_trezorutils_firmware_hash(size_t n_args, } } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_firmware_hash_obj, 0, +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_firmware_hash_obj, 0, 2, mod_trezorutils_firmware_hash); /// def firmware_vendor() -> str: /// """ /// Returns the firmware vendor string from the vendor header. /// """ -STATIC mp_obj_t mod_trezorutils_firmware_vendor(void) { +static mp_obj_t mod_trezorutils_firmware_vendor(void) { #ifdef TREZOR_EMULATOR return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)"EMULATOR", 8); #else @@ -269,7 +270,7 @@ STATIC mp_obj_t mod_trezorutils_firmware_vendor(void) { return mp_obj_new_str_copy(&mp_type_str, (byte *)vendor, strlen(vendor)); #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_firmware_vendor_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_firmware_vendor_obj, mod_trezorutils_firmware_vendor); /// def delegated_identity(rotation_index: int) -> bytes: @@ -277,7 +278,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_firmware_vendor_obj, /// Returns the delegated identity key used for registration and space /// management at Quota Manager. /// """ -STATIC mp_obj_t mod_trezorutils_delegated_identity(mp_obj_t index) { +static mp_obj_t mod_trezorutils_delegated_identity(mp_obj_t index) { uint16_t rotation_index = trezor_obj_get_uint16(index); uint8_t private_key[ECDSA_PRIVATE_KEY_SIZE] = {0}; if (secret_key_delegated_identity(rotation_index, private_key) != sectrue) { @@ -286,46 +287,46 @@ STATIC mp_obj_t mod_trezorutils_delegated_identity(mp_obj_t index) { } return mp_obj_new_bytes(private_key, sizeof(private_key)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_delegated_identity_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_delegated_identity_obj, mod_trezorutils_delegated_identity); /// def unit_color() -> int | None: /// """ /// Returns the color of the unit. /// """ -STATIC mp_obj_t mod_trezorutils_unit_color(void) { +static mp_obj_t mod_trezorutils_unit_color(void) { if (!unit_properties()->color_is_valid) { return mp_const_none; } return mp_obj_new_int(unit_properties()->color); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_color_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_color_obj, mod_trezorutils_unit_color); /// def unit_btconly() -> bool | None: /// """ /// Returns True if the unit is BTConly. /// """ -STATIC mp_obj_t mod_trezorutils_unit_btconly(void) { +static mp_obj_t mod_trezorutils_unit_btconly(void) { if (!unit_properties()->btconly_is_valid) { return mp_const_none; } return unit_properties()->btconly ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_btconly_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_btconly_obj, mod_trezorutils_unit_btconly); /// def unit_packaging() -> int | None: /// """ /// Returns the packaging version of the unit. /// """ -STATIC mp_obj_t mod_trezorutils_unit_packaging(void) { +static mp_obj_t mod_trezorutils_unit_packaging(void) { if (!unit_properties()->packaging_is_valid) { return mp_const_none; } return mp_obj_new_int(unit_properties()->packaging); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_packaging_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_packaging_obj, mod_trezorutils_unit_packaging); /// def unit_production_date() -> tuple[int, int, int] | None: @@ -333,7 +334,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_packaging_obj, /// Returns the unit production date as (year, month, day), or None if /// unavailable. /// """ -STATIC mp_obj_t mod_trezorutils_unit_production_date(void) { +static mp_obj_t mod_trezorutils_unit_production_date(void) { const unit_properties_t *props = unit_properties(); if (props == NULL) { return mp_const_none; @@ -354,7 +355,7 @@ STATIC mp_obj_t mod_trezorutils_unit_production_date(void) { items[2] = mp_obj_new_int(day); return mp_obj_new_tuple(3, items); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_production_date_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_production_date_obj, mod_trezorutils_unit_production_date); #if USE_SERIAL_NUMBER @@ -364,7 +365,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_unit_production_date_obj, /// """ /// Returns unit serial number. /// """ -STATIC mp_obj_t mod_trezorutils_serial_number(void) { +static mp_obj_t mod_trezorutils_serial_number(void) { uint8_t device_sn[MAX_DEVICE_SN_SIZE] = {0}; size_t device_sn_size = 0; if (!unit_properties_get_sn(device_sn, MAX_DEVICE_SN_SIZE, &device_sn_size)) { @@ -373,7 +374,7 @@ STATIC mp_obj_t mod_trezorutils_serial_number(void) { } return mp_obj_new_str_copy(&mp_type_str, device_sn, device_sn_size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_serial_number_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_serial_number_obj, mod_trezorutils_serial_number); #endif // USE_SERIAL_NUMBER @@ -382,10 +383,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_serial_number_obj, /// """ /// Returns True if SD card hot swapping is enabled /// """ -STATIC mp_obj_t mod_trezorutils_sd_hotswap_enabled(void) { +static mp_obj_t mod_trezorutils_sd_hotswap_enabled(void) { return unit_properties()->sd_hotswap_enabled ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_sd_hotswap_enabled_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_sd_hotswap_enabled_obj, mod_trezorutils_sd_hotswap_enabled); /// def presize_module(mod: module, n: int): @@ -396,7 +397,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_sd_hotswap_enabled_obj, /// on the symbols defined in the file itself, but also on the number of /// submodules that will be inserted into the module's namespace. /// """ -STATIC mp_obj_t mod_trezorutils_presize_module(mp_obj_t mod, mp_obj_t n) { +static mp_obj_t mod_trezorutils_presize_module(mp_obj_t mod, mp_obj_t n) { if (!mp_obj_is_type(mod, &mp_type_module)) { mp_raise_TypeError(MP_ERROR_TEXT("expected module type")); } @@ -405,7 +406,7 @@ STATIC mp_obj_t mod_trezorutils_presize_module(mp_obj_t mod, mp_obj_t n) { mp_obj_dict_presize(globals, size); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_presize_module_obj, +static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_presize_module_obj, mod_trezorutils_presize_module); #if !PYOPT @@ -414,18 +415,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_presize_module_obj, /// """ /// Zero unused stack memory. /// """ -STATIC mp_obj_t mod_trezorutils_zero_unused_stack(void) { +static mp_obj_t mod_trezorutils_zero_unused_stack(void) { clear_unused_stack(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_zero_unused_stack_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_zero_unused_stack_obj, mod_trezorutils_zero_unused_stack); /// def estimate_unused_stack() -> int: /// """ /// Estimate unused stack size. /// """ -STATIC mp_obj_t mod_trezorutils_estimate_unused_stack(void) { +static mp_obj_t mod_trezorutils_estimate_unused_stack(void) { const uint8_t *stack_top = (const uint8_t *)MP_STATE_THREAD(stack_top); size_t stack_limit = MP_STATE_THREAD(stack_limit); @@ -438,14 +439,14 @@ STATIC mp_obj_t mod_trezorutils_estimate_unused_stack(void) { } return mp_obj_new_int_from_uint(offset); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_estimate_unused_stack_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_estimate_unused_stack_obj, mod_trezorutils_estimate_unused_stack); #endif // LOG_STACK_USAGE #if MICROPY_OOM_CALLBACK static void gc_oom_callback(void) { - gc_dump_info(); + gc_dump_info(&mp_plat_print); #if BLOCK_ON_VCP dump_meminfo_json(NULL); // dump to stdout #endif @@ -456,11 +457,11 @@ static void gc_oom_callback(void) { /// """ /// Dump GC info in case of an OOM. /// """ -STATIC mp_obj_t mod_trezorutils_enable_oom_dump(void) { +static mp_obj_t mod_trezorutils_enable_oom_dump(void) { gc_set_oom_callback(gc_oom_callback); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_enable_oom_dump_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_enable_oom_dump_obj, mod_trezorutils_enable_oom_dump); #endif // MICROPY_OOM_CALLBACK @@ -471,12 +472,12 @@ static gc_info_t current_gc_info = {0}; /// """ /// Clear GC heap stats. /// """ -STATIC mp_obj_t mod_trezorutils_clear_gc_info() { +static mp_obj_t mod_trezorutils_clear_gc_info() { memzero(¤t_gc_info, sizeof(current_gc_info)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_clear_gc_info_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_clear_gc_info_obj, mod_trezorutils_clear_gc_info); /// if __debug__: @@ -484,7 +485,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_clear_gc_info_obj, /// """ /// Get GC heap stats, updated by `update_gc_info`. /// """ -STATIC mp_obj_t mod_trezorutils_get_gc_info() { +static mp_obj_t mod_trezorutils_get_gc_info() { mp_obj_t result = mp_obj_new_dict(4); mp_obj_dict_store(result, MP_OBJ_NEW_QSTR(MP_QSTR_total), mp_obj_new_int_from_uint(current_gc_info.total)); @@ -497,7 +498,7 @@ STATIC mp_obj_t mod_trezorutils_get_gc_info() { MICROPY_BYTES_PER_GC_BLOCK)); return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_get_gc_info_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_get_gc_info_obj, mod_trezorutils_get_gc_info); /// if __debug__: @@ -507,7 +508,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_get_gc_info_obj, /// On emulator, also assert that free heap memory doesn't decrease. /// Enabled only for frozen debug builds. /// """ -STATIC mp_obj_t mod_trezorutils_update_gc_info() { +static mp_obj_t mod_trezorutils_update_gc_info() { #if MICROPY_MODULE_FROZEN_MPY #ifdef TREZOR_EMULATOR size_t prev_free = current_gc_info.free; @@ -517,7 +518,7 @@ STATIC mp_obj_t mod_trezorutils_update_gc_info() { // pointers (resulting in `gc_mark_subtree` false-positives). #ifdef TREZOR_EMULATOR if (prev_free > current_gc_info.free) { - gc_dump_info(); + gc_dump_info(&mp_plat_print); mp_raise_msg(&mp_type_AssertionError, MP_ERROR_TEXT("Free heap size decreased")); } @@ -525,7 +526,7 @@ STATIC mp_obj_t mod_trezorutils_update_gc_info() { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_update_gc_info_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_update_gc_info_obj, mod_trezorutils_update_gc_info); /// if __debug__: @@ -534,7 +535,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_update_gc_info_obj, /// Assert known sources for heap fragmentation. /// Enabled only for frozen debug builds. /// """ -STATIC mp_obj_t mod_trezorutils_check_heap_fragmentation(void) { +static mp_obj_t mod_trezorutils_check_heap_fragmentation(void) { #if MICROPY_MODULE_FROZEN_MPY mp_obj_dict_t *modules = &MP_STATE_VM(mp_loaded_modules_dict); if (modules->map.alloc > MICROPY_LOADED_MODULES_DICT_SIZE) { @@ -564,7 +565,7 @@ STATIC mp_obj_t mod_trezorutils_check_heap_fragmentation(void) { #endif // MICROPY_MODULE_FROZEN_MPY return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_check_heap_fragmentation_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_check_heap_fragmentation_obj, mod_trezorutils_check_heap_fragmentation); #endif // !PYOPT @@ -574,7 +575,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_check_heap_fragmentation_obj, /// """ /// Reboots to perform upgrade to FW with specified hash. /// """ -STATIC mp_obj_t mod_trezorutils_reboot_and_upgrade(mp_obj_t hash_obj) { +static mp_obj_t mod_trezorutils_reboot_and_upgrade(mp_obj_t hash_obj) { // Reboot and continue with the firmware upgrade mp_buffer_info_t hash = {0}; @@ -588,28 +589,28 @@ STATIC mp_obj_t mod_trezorutils_reboot_and_upgrade(mp_obj_t hash_obj) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_reboot_and_upgrade_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_reboot_and_upgrade_obj, mod_trezorutils_reboot_and_upgrade); /// def reboot_to_bootloader() -> None: /// """ /// Reboots the device and stay in bootloader. /// """ -STATIC mp_obj_t mod_trezorutils_reboot_to_bootloader(void) { +static mp_obj_t mod_trezorutils_reboot_to_bootloader(void) { // Reboot and stay in bootloader reboot_to_bootloader(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_to_bootloader_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_to_bootloader_obj, mod_trezorutils_reboot_to_bootloader); /// def reboot() -> None: /// """ /// Reboots the device. /// """ -STATIC mp_obj_t mod_trezorutils_reboot(void) { +static mp_obj_t mod_trezorutils_reboot(void) { #ifdef USE_BLE ble_switch_off(); #endif @@ -623,7 +624,7 @@ STATIC mp_obj_t mod_trezorutils_reboot(void) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_obj, mod_trezorutils_reboot); /// VersionTuple = Tuple[int, int, int, int] @@ -638,7 +639,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_obj, /// def check_firmware_header(header : AnyBytes) -> FirmwareHeaderInfo: /// """Parses incoming firmware header and returns information about it.""" -STATIC mp_obj_t mod_trezorutils_check_firmware_header(mp_obj_t header) { +static mp_obj_t mod_trezorutils_check_firmware_header(mp_obj_t header) { mp_buffer_info_t header_buf = {0}; mp_get_buffer_raise(header, &header_buf, MP_BUFFER_READ); @@ -662,7 +663,7 @@ STATIC mp_obj_t mod_trezorutils_check_firmware_header(mp_obj_t header) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid value.")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_check_firmware_header_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_check_firmware_header_obj, mod_trezorutils_check_firmware_header); /// def bootloader_locked() -> bool | None: @@ -670,7 +671,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_check_firmware_header_obj, /// Returns True/False if the bootloader is locked/unlocked and None if /// the feature is not supported. /// """ -STATIC mp_obj_t mod_trezorutils_bootloader_locked() { +static mp_obj_t mod_trezorutils_bootloader_locked() { #if LOCKABLE_BOOTLOADER && defined USE_SECRET #ifdef TREZOR_EMULATOR return mp_const_true; @@ -682,14 +683,14 @@ STATIC mp_obj_t mod_trezorutils_bootloader_locked() { return mp_const_none; #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_bootloader_locked_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_bootloader_locked_obj, mod_trezorutils_bootloader_locked); /// def notify_send(event: int) -> None: /// """ /// Sends a notification to host /// """ -STATIC mp_obj_t mod_trezorutils_notify_send(const mp_obj_t event) { +static mp_obj_t mod_trezorutils_notify_send(const mp_obj_t event) { mp_int_t value = mp_obj_get_int(event); if (value < 0) { mp_raise_ValueError(MP_ERROR_TEXT("Invalid event.")); @@ -697,7 +698,7 @@ STATIC mp_obj_t mod_trezorutils_notify_send(const mp_obj_t event) { notify_send((notification_event_t)value); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_notify_send_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_notify_send_obj, mod_trezorutils_notify_send); #ifdef USE_NRF @@ -705,7 +706,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_notify_send_obj, /// """ /// Reads version of nRF firmware /// """ -STATIC mp_obj_t mod_trezorutils_nrf_get_version(void) { +static mp_obj_t mod_trezorutils_nrf_get_version(void) { uint32_t version = nrf_get_version(); mp_obj_t nrf_version[4] = {mp_obj_new_int((version >> 24) & 0xff), @@ -718,7 +719,7 @@ STATIC mp_obj_t mod_trezorutils_nrf_get_version(void) { return version_tuple; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_nrf_get_version_obj, +static MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_nrf_get_version_obj, mod_trezorutils_nrf_get_version); #endif @@ -727,13 +728,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_nrf_get_version_obj, /// """ /// Sets filter string for syslog /// """ -STATIC mp_obj_t mod_trezorutils_set_log_filter(mp_obj_t filter) { +static mp_obj_t mod_trezorutils_set_log_filter(mp_obj_t filter) { mp_buffer_info_t filter_buf = {0}; mp_get_buffer_raise(filter, &filter_buf, MP_BUFFER_READ); syslog_set_filter(filter_buf.buf, filter_buf.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_set_log_filter_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_set_log_filter_obj, mod_trezorutils_set_log_filter); #endif @@ -741,7 +742,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_set_log_filter_obj, /// """ /// Returns SCM revision of the firmware. /// """ -STATIC mp_obj_t mod_trezorutil_get_scm_revision(mp_obj_t xor2) { +static mp_obj_t mod_trezorutil_get_scm_revision(mp_obj_t xor2) { // Why the revision ID is obfuscated: // // When a firmware update is loaded onto a fake Trezor device, @@ -779,31 +780,31 @@ STATIC mp_obj_t mod_trezorutil_get_scm_revision(mp_obj_t xor2) { return mp_obj_new_bytes(scm_revision, sizeof(scm_revision)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutil_get_scm_revision_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutil_get_scm_revision_obj, mod_trezorutil_get_scm_revision); -STATIC const mp_obj_str_t mod_trezorutils_model_name_obj = { +static const mp_obj_str_t mod_trezorutils_model_name_obj = { {&mp_type_str}, 0, sizeof(MODEL_NAME) - 1, (const byte *)MODEL_NAME}; -STATIC const mp_obj_str_t mod_trezorutils_full_name_obj = { +static const mp_obj_str_t mod_trezorutils_full_name_obj = { {&mp_type_str}, 0, sizeof(MODEL_FULL_NAME) - 1, (const byte *)MODEL_FULL_NAME}; -STATIC const mp_obj_str_t mod_trezorutils_model_usb_manufacturer_obj = { +static const mp_obj_str_t mod_trezorutils_model_usb_manufacturer_obj = { {&mp_type_str}, 0, sizeof(MODEL_USB_MANUFACTURER) - 1, (const byte *)MODEL_USB_MANUFACTURER}; -STATIC const mp_obj_str_t mod_trezorutils_model_usb_product_obj = { +static const mp_obj_str_t mod_trezorutils_model_usb_product_obj = { {&mp_type_str}, 0, sizeof(MODEL_USB_PRODUCT) - 1, (const byte *)MODEL_USB_PRODUCT}; -STATIC const mp_obj_tuple_t mod_trezorutils_version_obj = { +static const mp_obj_tuple_t mod_trezorutils_version_obj = { {&mp_type_tuple}, 4, {MP_OBJ_NEW_SMALL_INT(VERSION_MAJOR), MP_OBJ_NEW_SMALL_INT(VERSION_MINOR), @@ -896,7 +897,7 @@ STATIC const mp_obj_tuple_t mod_trezorutils_version_obj = { /// LOG_STACK_USAGE: bool /// """Whether the firmware should log estimated stack usage.""" -STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { +static const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils)}, {MP_ROM_QSTR(MP_QSTR_consteq), MP_ROM_PTR(&mod_trezorutils_consteq_obj)}, {MP_ROM_QSTR(MP_QSTR_memcpy), MP_ROM_PTR(&mod_trezorutils_memcpy_obj)}, @@ -1127,7 +1128,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { #endif // PYOPT }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, +static MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, mp_module_trezorutils_globals_table); const mp_obj_module_t mp_module_trezorutils = { diff --git a/core/embed/upymod/modutime.c b/core/embed/upymod/modutime.c index 956c8374477..627710f4f61 100644 --- a/core/embed/upymod/modutime.c +++ b/core/embed/upymod/modutime.c @@ -24,12 +24,12 @@ * THE SOFTWARE. */ -#include "extmod/utime_mphal.h" +#include "extmod/modtime.h" #include "shared/timeutils/timeutils.h" // copy of ports/stm32/modutime.c:time_localtime, without support // for getting current clock time (i.e., timestamp must always be provided) -STATIC mp_obj_t time_gmtime2000(mp_obj_t timestamp) { +static mp_obj_t time_gmtime2000(mp_obj_t timestamp) { mp_int_t seconds = mp_obj_get_int(timestamp); timeutils_struct_time_t tm; timeutils_seconds_since_2000_to_struct_time(seconds, &tm); @@ -48,21 +48,21 @@ STATIC mp_obj_t time_gmtime2000(mp_obj_t timestamp) { MP_DEFINE_CONST_FUN_OBJ_1(time_gmtime2000_obj, time_gmtime2000); -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { +static const mp_rom_map_elem_t time_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime)}, {MP_ROM_QSTR(MP_QSTR_gmtime2000), MP_ROM_PTR(&time_gmtime2000_obj)}, - {MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj)}, - {MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj)}, - {MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj)}, - {MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj)}, - {MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj)}, - {MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj)}, - {MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj)}, - {MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj)}, + {MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_time_sleep_obj)}, + {MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_time_sleep_ms_obj)}, + {MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_time_sleep_us_obj)}, + {MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_time_ticks_ms_obj)}, + {MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_time_ticks_us_obj)}, + {MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_time_ticks_cpu_obj)}, + {MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_time_ticks_add_obj)}, + {MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_time_ticks_diff_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); +static MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); const mp_obj_module_t mp_module_utime = { .base = {&mp_type_module}, diff --git a/core/embed/upymod/mpycross_include/mpconfigport.h b/core/embed/upymod/mpycross_include/mpconfigport.h index 899f602a0af..e889fa68699 100644 --- a/core/embed/upymod/mpycross_include/mpconfigport.h +++ b/core/embed/upymod/mpycross_include/mpconfigport.h @@ -28,6 +28,7 @@ #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) #define MICROPY_PERSISTENT_CODE_LOAD (0) +#define MICROPY_PERSISTENT_CODE_LOAD_NATIVE (0) #define MICROPY_PERSISTENT_CODE_SAVE (1) #ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE @@ -47,11 +48,16 @@ #define MICROPY_EMIT_XTENSA (1) #define MICROPY_EMIT_INLINE_XTENSA (1) #define MICROPY_EMIT_XTENSAWIN (1) +#define MICROPY_EMIT_RV32 (1) +#define MICROPY_EMIT_INLINE_RV32 (1) +#define MICROPY_EMIT_NATIVE_DEBUG (1) +#define MICROPY_EMIT_NATIVE_DEBUG_PRINTER (&mp_stdout_print) #define MICROPY_DYNAMIC_COMPILER (1) #define MICROPY_COMP_CONST_FOLDING (1) #define MICROPY_COMP_MODULE_CONST (1) #define MICROPY_COMP_CONST (1) +#define MICROPY_COMP_CONST_FLOAT (1) #define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1) #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1) #define MICROPY_COMP_RETURN_IF_EXPR (1) @@ -76,6 +82,7 @@ #define MICROPY_USE_INTERNAL_PRINTF (0) #define MICROPY_PY_FSTRINGS (1) +#define MICROPY_PY_TSTRINGS (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || \ @@ -86,11 +93,12 @@ #define MICROPY_GCREGS_SETJMP (1) #endif -#define MICROPY_PY___FILE__ (0) +#define MICROPY_MODULE___FILE__ (0) #define MICROPY_PY_ARRAY (0) #define MICROPY_PY_ATTRTUPLE (0) #define MICROPY_PY_COLLECTIONS (0) -#define MICROPY_PY_MATH (0) +#define MICROPY_PY_MATH (MICROPY_COMP_CONST_FLOAT) +#define MICROPY_PY_MATH_CONSTANTS (MICROPY_COMP_CONST_FLOAT) #define MICROPY_PY_CMATH (0) #define MICROPY_PY_GC (0) #define MICROPY_PY_IO (0) @@ -98,23 +106,6 @@ // type definitions for the specific machine -#ifdef __LP64__ -typedef long mp_int_t; // must be pointer size -typedef unsigned long mp_uint_t; // must be pointer size -#elif defined(__MINGW32__) && defined(_WIN64) -#include -typedef __int64 mp_int_t; -typedef unsigned __int64 mp_uint_t; -#elif defined(_MSC_VER) && defined(_WIN64) -typedef __int64 mp_int_t; -typedef unsigned __int64 mp_uint_t; -#else -// These are definitions for machines where sizeof(int) == sizeof(void*), -// regardless for actual size. -typedef int mp_int_t; // must be pointer size -typedef unsigned int mp_uint_t; // must be pointer size -#endif - // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) typedef long long mp_off_t; @@ -125,7 +116,7 @@ typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) (void)0 // We need to provide a declaration/definition of alloca() -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) #include #elif defined(_WIN32) #include @@ -139,8 +130,9 @@ typedef long mp_off_t; #ifdef _MSC_VER #define MP_ENDIANNESS_LITTLE (1) -#define NORETURN __declspec(noreturn) +#define MP_NORETURN __declspec(noreturn) #define MP_NOINLINE __declspec(noinline) +#define MP_ALWAYSINLINE __forceinline #define MP_LIKELY(x) (x) #define MP_UNLIKELY(x) (x) #define MICROPY_PORT_CONSTANTS {MP_ROM_QSTR(MP_QSTR_dummy), MP_ROM_PTR(NULL)} @@ -169,3 +161,5 @@ typedef int ssize_t; typedef mp_off_t off_t; #endif + +extern const struct _mp_print_t mp_stdout_print; diff --git a/core/embed/upymod/trezorobj.h b/core/embed/upymod/trezorobj.h index 825f229df34..835d23705f1 100644 --- a/core/embed/upymod/trezorobj.h +++ b/core/embed/upymod/trezorobj.h @@ -30,10 +30,10 @@ // Casts int object into mp_int_t, without any conversions. Raises if object is // not int or if it does not fit into mp_int_t representation. static inline mp_int_t trezor_obj_get_int(mp_obj_t obj) { - if (MP_OBJ_IS_SMALL_INT(obj)) { + if (mp_obj_is_small_int(obj)) { mp_int_t i = MP_OBJ_SMALL_INT_VALUE(obj); return i; - } else if (MP_OBJ_IS_TYPE(obj, &mp_type_int)) { + } else if (mp_obj_is_exact_type(obj, &mp_type_int)) { mp_int_t i = 0; mp_obj_int_t *self = MP_OBJ_TO_PTR(obj); if (!mpz_as_int_checked(&self->mpz, &i)) { @@ -50,14 +50,14 @@ static inline mp_int_t trezor_obj_get_int(mp_obj_t obj) { // not int or if it does not fit into mp_uint_t representation (or is less than // 0). static inline mp_uint_t trezor_obj_get_uint(mp_obj_t obj) { - if (MP_OBJ_IS_SMALL_INT(obj)) { + if (mp_obj_is_small_int(obj)) { mp_int_t i = MP_OBJ_SMALL_INT_VALUE(obj); if (i < 0) { mp_raise_TypeError(MP_ERROR_TEXT("value is negative")); } mp_uint_t u = i; return u; - } else if (MP_OBJ_IS_TYPE(obj, &mp_type_int)) { + } else if (mp_obj_is_exact_type(obj, &mp_type_int)) { mp_uint_t u = 0; mp_obj_int_t *self = MP_OBJ_TO_PTR(obj); if (!mpz_as_uint_checked(&self->mpz, &u)) { @@ -89,20 +89,21 @@ static inline uint16_t trezor_obj_get_uint16(mp_obj_t obj) { } static inline uint64_t trezor_obj_get_uint64(mp_const_obj_t obj) { - if (MP_OBJ_IS_SMALL_INT(obj)) { + if (mp_obj_is_small_int(obj)) { mp_int_t i = MP_OBJ_SMALL_INT_VALUE(obj); if (i < 0) { mp_raise_TypeError(MP_ERROR_TEXT("value is negative")); } mp_uint_t u = i; return u; - } else if (MP_OBJ_IS_TYPE(obj, &mp_type_int)) { + } else if (mp_obj_is_exact_type(obj, &mp_type_int)) { uint64_t u = 0; mp_obj_int_t *self = MP_OBJ_TO_PTR(obj); if (self->mpz.neg != 0) { mp_raise_TypeError(MP_ERROR_TEXT("value is negative")); } - mpz_as_bytes(&self->mpz, MP_ENDIANNESS_BIG, sizeof(uint64_t), (byte *)&u); + mpz_as_bytes(&self->mpz, MP_ENDIANNESS_BIG, /*as_signed=*/false, + sizeof(uint64_t), (byte *)&u); return u; } else { mp_raise_TypeError(MP_ERROR_TEXT("value is not int")); diff --git a/core/mocks/generated/timeq.pyi b/core/mocks/generated/timeq.pyi new file mode 120000 index 00000000000..aa61762e5b8 --- /dev/null +++ b/core/mocks/generated/timeq.pyi @@ -0,0 +1 @@ +../timeq.pyi \ No newline at end of file diff --git a/core/mocks/generated/ubinascii.pyi b/core/mocks/generated/ubinascii.pyi deleted file mode 120000 index b129e0cecdc..00000000000 --- a/core/mocks/generated/ubinascii.pyi +++ /dev/null @@ -1 +0,0 @@ -../ubinascii.pyi \ No newline at end of file diff --git a/core/mocks/generated/uio.pyi b/core/mocks/generated/uio.pyi deleted file mode 120000 index ac036f48a5d..00000000000 --- a/core/mocks/generated/uio.pyi +++ /dev/null @@ -1 +0,0 @@ -../uio.pyi \ No newline at end of file diff --git a/core/mocks/generated/uos.pyi b/core/mocks/generated/uos.pyi deleted file mode 120000 index c5cae7aaa73..00000000000 --- a/core/mocks/generated/uos.pyi +++ /dev/null @@ -1 +0,0 @@ -../uos.pyi \ No newline at end of file diff --git a/core/mocks/generated/ustruct.pyi b/core/mocks/generated/ustruct.pyi deleted file mode 120000 index a3dbad3ef46..00000000000 --- a/core/mocks/generated/ustruct.pyi +++ /dev/null @@ -1 +0,0 @@ -../ustruct.pyi \ No newline at end of file diff --git a/core/mocks/generated/utimeq.pyi b/core/mocks/generated/utimeq.pyi deleted file mode 120000 index 248c18120a7..00000000000 --- a/core/mocks/generated/utimeq.pyi +++ /dev/null @@ -1 +0,0 @@ -../utimeq.pyi \ No newline at end of file diff --git a/core/mocks/generated/vfs.pyi b/core/mocks/generated/vfs.pyi new file mode 120000 index 00000000000..fa1093fe8a6 --- /dev/null +++ b/core/mocks/generated/vfs.pyi @@ -0,0 +1 @@ +../vfs.pyi \ No newline at end of file diff --git a/core/mocks/utimeq.pyi b/core/mocks/timeq.pyi similarity index 95% rename from core/mocks/utimeq.pyi rename to core/mocks/timeq.pyi index c18f5828aca..5d3287effc3 100644 --- a/core/mocks/utimeq.pyi +++ b/core/mocks/timeq.pyi @@ -1,6 +1,6 @@ from typing import * -class utimeq: +class timeq: def __init__(self, max_queue_size: int) -> None: ... def push(self, time: int, callback: Any, value: Any) -> None: ... def pop(self, entry: List[Any]) -> None: ... diff --git a/core/mocks/ubinascii.pyi b/core/mocks/ubinascii.pyi deleted file mode 100644 index 969d21dd3cc..00000000000 --- a/core/mocks/ubinascii.pyi +++ /dev/null @@ -1,7 +0,0 @@ -from buffer_types import AnyBytes, StrOrBytes - -def hexlify(data: AnyBytes, sep: AnyBytes = ...) -> bytes: ... -def unhexlify(data: StrOrBytes) -> bytes: ... -def a2b_base64(data: AnyBytes) -> bytes: ... -def b2a_base64(data: AnyBytes) -> bytes: ... -def crc32(data: AnyBytes, crc: int = ...) -> int: ... diff --git a/core/mocks/uio.pyi b/core/mocks/uio.pyi deleted file mode 100644 index 6cf1e651b38..00000000000 --- a/core/mocks/uio.pyi +++ /dev/null @@ -1,16 +0,0 @@ -class FileIO: - def __enter__(self) -> FileIO: ... - - def __exit__(*args) -> None: ... - - def write(self, data: bytes | str) -> int: ... - -class StringIO: - def __init__(self, _: int | str) -> None: ... - -class BytesIO: - def __init__(self, _: int | bytes) -> None: ... - def getvalue(self) -> bytes: ... - -def open(name: str, mode: str = ...) -> FileIO: - pass diff --git a/core/mocks/uos.pyi b/core/mocks/uos.pyi deleted file mode 100644 index 9fb4e3a85aa..00000000000 --- a/core/mocks/uos.pyi +++ /dev/null @@ -1 +0,0 @@ -def getenv(env: str) -> str: ... diff --git a/core/mocks/ustruct.pyi b/core/mocks/ustruct.pyi deleted file mode 100644 index 99821c2c3ec..00000000000 --- a/core/mocks/ustruct.pyi +++ /dev/null @@ -1,8 +0,0 @@ -from typing import * -from buffer_types import * - -def calcsize(fmt: str) -> int: ... -def pack(fmt: str, *args: Any) -> bytes: ... -def pack_into(fmt: str, buffer: AnyBuffer, offset: int, *args: Any) -> None: ... -def unpack(fmt: str, data: AnyBytes) -> Tuple: ... -def unpack_from(fmt: str, data: AnyBytes, offset: int = ...) -> Tuple: ... diff --git a/core/mocks/vfs.pyi b/core/mocks/vfs.pyi new file mode 100644 index 00000000000..f4ea6058b66 --- /dev/null +++ b/core/mocks/vfs.pyi @@ -0,0 +1,4 @@ +def mount(fsobj: Any = None, mount_point: str | None = None, *args: Any) -> list: ... + +class VfsPosix: + def __init__(root: Any = None) -> None: ... diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py index d354404d088..53123440227 100644 --- a/core/site_scons/site_tools/micropython/__init__.py +++ b/core/site_scons/site_tools/micropython/__init__.py @@ -30,7 +30,7 @@ def generate(env): ) env["BUILDERS"]["CollectModules"] = SCons.Builder.Builder( - action="grep ^MP_REGISTER_MODULE $SOURCES > $TARGET" + action="grep -E '^MP_REGISTER(_EXTENSIBLE)?_MODULE' $SOURCES > $TARGET" # action="$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" # " | $PYTHON $MODULECOL > $TARGET" ) @@ -43,6 +43,14 @@ def generate(env): action="$MAKECOMPRESSEDDATA $SOURCE > $TARGET", ) + env["BUILDERS"]["CollectRootPointers"] = SCons.Builder.Builder( + action="cat $SOURCES | sed -nr 's/.*(MP_REGISTER_ROOT_POINTER\\(.*\\);).*/\\1/p' > $TARGET", + ) + + env["BUILDERS"]["GenerateRootPointers"] = SCons.Builder.Builder( + action="$MAKEROOTPOINTERS $SOURCE > $TARGET" + ) + def generate_frozen_module(source, target, env, for_signature): target = str(target[0]) source = str(source[0]) diff --git a/core/src/apps/bitcoin/sign_tx/layout.py b/core/src/apps/bitcoin/sign_tx/layout.py index a4640709bc3..2f2b0ebc2ed 100644 --- a/core/src/apps/bitcoin/sign_tx/layout.py +++ b/core/src/apps/bitcoin/sign_tx/layout.py @@ -226,11 +226,9 @@ async def show_payment_request_details( async def confirm_replacement(title: str, txid: AnyBytes) -> None: - from ubinascii import hexlify - await layouts.confirm_replacement( title, - hexlify(txid).decode(), + txid.hex(), ) diff --git a/core/src/apps/bitcoin/sign_tx/omni.py b/core/src/apps/bitcoin/sign_tx/omni.py index 9e840b92f80..9aebe0d4994 100644 --- a/core/src/apps/bitcoin/sign_tx/omni.py +++ b/core/src/apps/bitcoin/sign_tx/omni.py @@ -20,7 +20,7 @@ def is_valid(data: AnyBytes) -> bool: def parse(data: AnyBytes) -> str: - from ustruct import unpack + from struct import unpack from trezor import TR from trezor.strings import format_amount, format_amount_unit diff --git a/core/src/apps/bitcoin/sign_tx/zcash_v4.py b/core/src/apps/bitcoin/sign_tx/zcash_v4.py index 3b69bfe2682..b036110bbf0 100644 --- a/core/src/apps/bitcoin/sign_tx/zcash_v4.py +++ b/core/src/apps/bitcoin/sign_tx/zcash_v4.py @@ -51,7 +51,7 @@ def hash143( coin: CoinInfo, hash_type: int, ) -> bytes: - import ustruct as struct + import struct from ..scripts import write_bip143_script_code_prefixed from ..writers import get_tx_hash, write_bytes_fixed diff --git a/core/src/apps/cardano/get_public_key.py b/core/src/apps/cardano/get_public_key.py index 1a4bb850135..f0726db8e19 100644 --- a/core/src/apps/cardano/get_public_key.py +++ b/core/src/apps/cardano/get_public_key.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify from trezor import TR @@ -55,8 +54,8 @@ def _get_public_key( node = keychain.derive(derivation_path) - public_key = hexlify(derive_public_key(keychain, derivation_path)).decode() - chain_code = hexlify(node.chain_code()).decode() + public_key = derive_public_key(keychain, derivation_path).hex() + chain_code = node.chain_code().hex() xpub_key = public_key + chain_code node_type = HDNodeType( diff --git a/core/src/apps/common/cbor.py b/core/src/apps/common/cbor.py index 0db1ab27e7c..cd4ddcbc6a6 100644 --- a/core/src/apps/common/cbor.py +++ b/core/src/apps/common/cbor.py @@ -51,7 +51,7 @@ def _header(typ: int, l: int) -> bytes: - from ustruct import pack + from struct import pack if l < 24: return pack(">B", typ + l) diff --git a/core/src/apps/common/signverify.py b/core/src/apps/common/signverify.py index 2511aba6696..22874549a7f 100644 --- a/core/src/apps/common/signverify.py +++ b/core/src/apps/common/signverify.py @@ -29,12 +29,10 @@ def message_digest(coin: CoinInfo, message: AnyBytes) -> bytes: def decode_message(message: AnyBytes) -> str: - from ubinascii import hexlify - try: return bytes(message).decode() except UnicodeError: - return f"hex({hexlify(message).decode()})" + return f"hex({message.hex()})" def is_printable_ascii(bytestring: AnyBytes) -> bool: diff --git a/core/src/apps/ethereum/clear_signing.py b/core/src/apps/ethereum/clear_signing.py index c57d718f33b..ca100e73c2f 100644 --- a/core/src/apps/ethereum/clear_signing.py +++ b/core/src/apps/ethereum/clear_signing.py @@ -465,9 +465,7 @@ async def format( elif isinstance(value, str): return value, None, None elif isinstance(value, (bytes, bytearray)): - from ubinascii import hexlify - - return hexlify(value).decode(), None, None + return value.hex(), None, None elif isinstance(value, bool): return str(value), None, None elif isinstance(value, int): @@ -1251,8 +1249,6 @@ def callee_str() -> str: def raw_rows() -> list[DisplayedField]: """No subparsing. Show the callee and the raw hex blob.""" - from ubinascii import hexlify - to_label = TR.ethereum__subcall_to blob_label = field_definition.label if index is not None: @@ -1260,7 +1256,7 @@ def raw_rows() -> list[DisplayedField]: blob_label = f"({subcall}) {blob_label}" return [ ((to_label, callee_str(), None), None, None), - ((blob_label, hexlify(blob).decode(), None), None, None), + ((blob_label, blob.hex(), None), None, None), ] if nested: diff --git a/core/src/apps/ethereum/get_public_key.py b/core/src/apps/ethereum/get_public_key.py index c39061d3ed8..ea081d4f947 100644 --- a/core/src/apps/ethereum/get_public_key.py +++ b/core/src/apps/ethereum/get_public_key.py @@ -5,8 +5,6 @@ async def get_public_key(msg: EthereumGetPublicKey) -> EthereumPublicKey: - from ubinascii import hexlify - from trezor.messages import EthereumPublicKey, GetPublicKey from trezor.ui.layouts import show_pubkey @@ -17,6 +15,6 @@ async def get_public_key(msg: EthereumGetPublicKey) -> EthereumPublicKey: resp = await bitcoin_get_public_key.get_public_key(btc_pubkey_msg) if msg.show_display: - await show_pubkey(hexlify(resp.node.public_key).decode()) + await show_pubkey(resp.node.public_key.hex()) return EthereumPublicKey(node=resp.node, xpub=resp.xpub) diff --git a/core/src/apps/ethereum/helpers.py b/core/src/apps/ethereum/helpers.py index 5ce2c271760..b36f16ee09c 100644 --- a/core/src/apps/ethereum/helpers.py +++ b/core/src/apps/ethereum/helpers.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify from trezor import TR @@ -36,7 +35,7 @@ def address_from_bytes( else: prefix = "" - address_hex = hexlify(address_bytes) + address_hex = address_bytes.hex().encode() writer = keccak256(prefix.encode()) writer.extend(address_hex) digest = writer.get_digest() @@ -60,17 +59,15 @@ def _maybe_upper(i: int) -> str: def bytes_from_address(address: str) -> bytes: - from ubinascii import unhexlify - from trezor import wire if len(address) == 40: - return unhexlify(address) + return bytes.fromhex(address) elif len(address) == 42: if address[0:2] not in ("0x", "0X"): raise wire.ProcessError("Ethereum: invalid beginning of an address") - return unhexlify(address[2:]) + return bytes.fromhex(address[2:]) elif len(address) == 0: return bytes() @@ -121,7 +118,7 @@ def get_type_name(field: EthereumFieldType) -> str: def decode_typed_data(data: AnyBytes, type_name: str) -> str: """Used by sign_typed_data module to show data to user.""" if type_name.startswith("bytes"): - return hexlify(data).decode() + return data.hex() elif type_name == "string": return bytes(data).decode() elif type_name == "address": diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 38fe10bab2f..ba32de4a8b8 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify from trezor import TR from trezor.enums import ButtonRequestType @@ -290,7 +289,7 @@ async def require_confirm_vault_tx( account, account_path = get_account_and_path(address_n) extra_data_str: str | None = ( - "0x" + hexlify(extra_data).decode() if extra_data is not None else None + "0x" + extra_data.hex() if extra_data is not None else None ) await confirm_ethereum_vault_tx( @@ -402,11 +401,9 @@ def require_confirm_address( br_name: str | None = None, footer: str | None = None, ) -> Awaitable[None]: - from ubinascii import hexlify - from trezor.ui.layouts import confirm_address - address_hex = "0x" + hexlify(address_bytes).decode() + address_hex = "0x" + address_bytes.hex() return confirm_address( title or TR.ethereum__title_signing_address, address_hex, @@ -419,11 +416,9 @@ def require_confirm_address( async def confirm_message_hash(message_hash: bytes) -> None: - from ubinascii import hexlify - from trezor.ui.layouts import confirm_value - message_hash_hex = "0x" + hexlify(message_hash).decode() + message_hash_hex = "0x" + message_hash.hex() await confirm_value( TR.ethereum__title_confirm_message_hash, diff --git a/core/src/apps/ethereum/sc_constants.py.mako b/core/src/apps/ethereum/sc_constants.py.mako index 75839b19406..17f1f013d78 100644 --- a/core/src/apps/ethereum/sc_constants.py.mako +++ b/core/src/apps/ethereum/sc_constants.py.mako @@ -5,10 +5,8 @@ from typing import Iterator <% -from binascii import unhexlify - def fmt_addr(addr_hex: str) -> str: - data = "".join(f'\\x{b:02x}' for b in unhexlify(addr_hex)) + data = "".join(f'\\x{b:02x}' for b in bytes.fromhex(addr_hex)) return f'b"{data}"' diff --git a/core/src/apps/ethereum/staking.py b/core/src/apps/ethereum/staking.py index e02a168170e..94218296f1e 100644 --- a/core/src/apps/ethereum/staking.py +++ b/core/src/apps/ethereum/staking.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import unhexlify from trezor.utils import BufferReader from trezor.wire import DataError @@ -13,18 +12,18 @@ from .keychain import MsgInSignTx -FUNC_SIG_STAKE = unhexlify("3a29dbae") -FUNC_SIG_UNSTAKE = unhexlify("76ec871c") -FUNC_SIG_CLAIM = unhexlify("33986ffa") +FUNC_SIG_STAKE = b"\x3a\x29\xdb\xae" +FUNC_SIG_UNSTAKE = b"\x76\xec\x87\x1c" +FUNC_SIG_CLAIM = b"\x33\x98\x6f\xfa" # addresses for pool (stake/unstake) and accounting (claim) operations ADDRESSES_POOL = ( - unhexlify("AFA848357154a6a624686b348303EF9a13F63264"), # Hoodi testnet - unhexlify("D523794C879D9eC028960a231F866758e405bE34"), # mainnet + b"\xaf\xa8\x48\x35\x71\x54\xa6\xa6\x24\x68\x6b\x34\x83\x03\xef\x9a\x13\xf6\x32\x64", # Hoodi testnet + b"\xd5\x23\x79\x4c\x87\x9d\x9e\xc0\x28\x96\x0a\x23\x1f\x86\x67\x58\xe4\x05\xbe\x34", # mainnet ) ADDRESSES_ACCOUNTING = ( - unhexlify("624087DD1904ab122A32878Ce9e933C7071F53B9"), # Hoodi testnet - unhexlify("7a7f0b3c23C23a31cFcb0c44709be70d4D545c6e"), # mainnet + b"\x62\x40\x87\xdd\x19\x04\xab\x12\x2a\x32\x87\x8c\xe9\xe9\x33\xc7\x07\x1f\x53\xb9", # Hoodi testnet + b"\x7a\x7f\x0b\x3c\x23\xc2\x3a\x31\xcf\xcb\x0c\x44\x70\x9b\xe7\x0d\x4d\x54\x5c\x6e", # mainnet ) diff --git a/core/src/apps/management/reboot_to_bootloader.py b/core/src/apps/management/reboot_to_bootloader.py index e712594da38..f62ced50cc2 100644 --- a/core/src/apps/management/reboot_to_bootloader.py +++ b/core/src/apps/management/reboot_to_bootloader.py @@ -13,8 +13,6 @@ async def install_upgrade(firmware_header: AnyBytes) -> AnyBytes: - from ubinascii import hexlify - from trezor import TR, utils, wire from trezor.ui.layouts import confirm_firmware_update @@ -38,7 +36,7 @@ async def install_upgrade(firmware_header: AnyBytes) -> AnyBytes: description=TR.reboot_to_bootloader__version_by_template.format( version_str, hdr.vendor ), - fingerprint=hexlify(hdr.fingerprint).decode(), + fingerprint=hdr.fingerprint.hex(), ) return hdr.hash diff --git a/core/src/apps/management/reset_device/layout.py b/core/src/apps/management/reset_device/layout.py index 802b3552ed0..35212936cd7 100644 --- a/core/src/apps/management/reset_device/layout.py +++ b/core/src/apps/management/reset_device/layout.py @@ -29,6 +29,9 @@ async def _confirm_word( # remove duplicates non_duplicates = list(set(share_words)) + # sort list to make UI tests independent on micropython hash function + if __debug__: + non_duplicates.sort() # shuffle list random.shuffle(non_duplicates) # take top _NUM_OF_CHOICES words diff --git a/core/src/apps/misc/sign_identity.py b/core/src/apps/misc/sign_identity.py index 54c90c947f7..edbb0f15e6a 100644 --- a/core/src/apps/misc/sign_identity.py +++ b/core/src/apps/misc/sign_identity.py @@ -91,7 +91,7 @@ def serialize_identity_without_proto(identity: IdentityType) -> str: def get_identity_path(identity: str, index: int, num: int) -> Bip32Path: - from ustruct import pack, unpack + from struct import pack, unpack from apps.common.paths import HARDENED diff --git a/core/src/apps/nostr/sign_event.py b/core/src/apps/nostr/sign_event.py index d061a4de162..41141d82655 100644 --- a/core/src/apps/nostr/sign_event.py +++ b/core/src/apps/nostr/sign_event.py @@ -10,8 +10,6 @@ @auto_keychain(__name__) async def sign_event(msg: NostrSignEvent, keychain: Keychain) -> NostrEventSignature: - from ubinascii import hexlify - from trezor import TR from trezor.crypto.curve import bip340 from trezor.crypto.hashlib import sha256 @@ -46,7 +44,9 @@ async def sign_event(msg: NostrSignEvent, keychain: Keychain) -> NostrEventSigna ] await confirm_value(title, content, "", "nostr_sign_event", info_items=info_items) - serialized_event = f'[0,"{hexlify(pk).decode()}",{created_at},{kind},[{serialized_tags}],"{content}"]' + serialized_event = ( + f'[0,"{pk.hex()}",{created_at},{kind},[{serialized_tags}],"{content}"]' + ) event_id = sha256(serialized_event).digest() # The event signature is basically the signature of the event ID computed above diff --git a/core/src/apps/stellar/helpers.py b/core/src/apps/stellar/helpers.py index 1d877aaf141..189b8cf26d7 100644 --- a/core/src/apps/stellar/helpers.py +++ b/core/src/apps/stellar/helpers.py @@ -88,7 +88,7 @@ def _crc16_checksum(data: AnyBytes) -> bytes: Initial value changed to 0x0000 to match Stellar configuration. """ - import ustruct + import struct crc = 0x0000 polynomial = 0x1021 @@ -101,4 +101,4 @@ def _crc16_checksum(data: AnyBytes) -> bytes: if c15 ^ bit: crc ^= polynomial - return ustruct.pack(" str: elif t == StellarSCValType.SCV_BYTES: if val.bytes is None: raise DataError("Stellar: missing bytes value") - return "0x" + hexlify(val.bytes).decode() + return "0x" + val.bytes.hex() elif t == StellarSCValType.SCV_STRING: if val.string is None: raise DataError("Stellar: missing string value") @@ -404,7 +403,7 @@ def _format_sc_val(val: StellarSCVal) -> str: try: return f'"{_escape_str(bytes(val.string).decode())}"' except UnicodeError: - return "0x" + hexlify(val.string).decode() + return "0x" + val.string.hex() elif t == StellarSCValType.SCV_SYMBOL: if val.symbol is None: raise DataError("Stellar: missing symbol value") diff --git a/core/src/apps/stellar/operations/layout.py b/core/src/apps/stellar/operations/layout.py index 96b485331e6..e6fd66aa8e8 100644 --- a/core/src/apps/stellar/operations/layout.py +++ b/core/src/apps/stellar/operations/layout.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify from trezor import TR from trezor.ui.layouts import ( @@ -381,7 +380,7 @@ async def confirm_set_options_op(op: StellarSetOptionsOp) -> None: async def confirm_claim_claimable_balance_op( op: StellarClaimClaimableBalanceOp, ) -> None: - balance_id = hexlify(op.balance_id).decode() + balance_id = op.balance_id.hex() await confirm_properties( "op_claim_claimable_balance", TR.stellar__claim_claimable_balance, diff --git a/core/src/apps/stellar/sign_tx.py b/core/src/apps/stellar/sign_tx.py index f694d7f0e24..ef24d4062f0 100644 --- a/core/src/apps/stellar/sign_tx.py +++ b/core/src/apps/stellar/sign_tx.py @@ -14,8 +14,6 @@ *[PATTERN], slip44_id=SLIP44_ID, curve=CURVE, slip21_namespaces=[[b"SLIP-0024"]] ) async def sign_tx(msg: StellarSignTx, keychain: Slip21Keychain) -> StellarSignedTx: - from ubinascii import hexlify - from trezor import TR from trezor.crypto.curve import ed25519 from trezor.crypto.hashlib import sha256 @@ -105,7 +103,7 @@ async def sign_tx(msg: StellarSignTx, keychain: Slip21Keychain) -> StellarSigned if msg.memo_hash is None: raise DataError("Stellar: Missing memo hash") writers.write_bytes_fixed(w, bytearray(msg.memo_hash), 32) - memo_confirm_text = hexlify(msg.memo_hash).decode() + memo_confirm_text = msg.memo_hash.hex() else: raise ProcessError("Stellar invalid memo type") diff --git a/core/src/apps/tron/sc_constants.py b/core/src/apps/tron/sc_constants.py index dd8d02053d3..964095eeff6 100644 --- a/core/src/apps/tron/sc_constants.py +++ b/core/src/apps/tron/sc_constants.py @@ -1,5 +1,4 @@ from micropython import const -from ubinascii import unhexlify # smart contract 'data' field lengths in bytes SC_FUNC_SIG_BYTES = const(4) @@ -10,5 +9,5 @@ # Known TRC-20/ERC-20 functions -SC_FUNC_SIG_TRANSFER = unhexlify("a9059cbb") -SC_FUNC_SIG_APPROVE = unhexlify("095ea7b3") +SC_FUNC_SIG_TRANSFER = b"\xa9\x05\x9c\xbb" +SC_FUNC_SIG_APPROVE = b"\x09\x5e\xa7\xb3" diff --git a/core/src/apps/webauthn/credential.py b/core/src/apps/webauthn/credential.py index 355ce7ede92..3ae76eeef23 100644 --- a/core/src/apps/webauthn/credential.py +++ b/core/src/apps/webauthn/credential.py @@ -1,7 +1,6 @@ -import ustruct +import struct from micropython import const from typing import TYPE_CHECKING -from ubinascii import hexlify import storage.device as storage_device from trezor import utils @@ -301,13 +300,13 @@ def account_name(self) -> str | None: elif self.user_display_name: return self.user_display_name elif self.user_id: - return hexlify(self.user_id).decode() + return self.user_id.hex() else: return None def _private_key(self) -> bytes: path = [HARDENED | 10022, HARDENED | int.from_bytes(self.id[:4], "big")] + [ - HARDENED | i for i in ustruct.unpack(">4L", self.id[-16:]) + HARDENED | i for i in struct.unpack(">4L", self.id[-16:]) ] node = seed.derive_node_without_passphrase(path, _CURVE_NAME[self.curve]) return node.private_key() @@ -424,7 +423,7 @@ def generate_key_handle(self) -> None: self.node = seed.derive_node_without_passphrase(nodepath, "nist256p1") # first half of keyhandle is keypath - keypath = ustruct.pack("<8L", *path) + keypath = struct.pack("<8L", *path) # second half of keyhandle is a hmac of rp_id_hash and keypath mac = hmac(hmac.SHA256, self.node.private_key(), self.rp_id_hash) @@ -439,8 +438,8 @@ def app_name(self) -> str: if app is not None: return app.label - start = hexlify(self.rp_id_hash[:4]).decode() - end = hexlify(self.rp_id_hash[-4:]).decode() + start = self.rp_id_hash[:4].hex() + end = self.rp_id_hash[-4:].hex() return f"{start}...{end}" @staticmethod @@ -473,7 +472,7 @@ def _node_from_key_handle( # unpack the keypath from the first half of keyhandle keypath = keyhandle[:32] - path = ustruct.unpack(pathformat, keypath) + path = struct.unpack(pathformat, keypath) # check high bit for hardened keys for i in path: diff --git a/core/src/apps/webauthn/fido2.py b/core/src/apps/webauthn/fido2.py index a579223e3e9..fb2a82b4065 100644 --- a/core/src/apps/webauthn/fido2.py +++ b/core/src/apps/webauthn/fido2.py @@ -1,5 +1,5 @@ +import struct import uctypes -import ustruct import utime from micropython import const from typing import TYPE_CHECKING @@ -1421,7 +1421,7 @@ def _msg_authenticate_sign( # get next counter ctr = cred.next_signature_counter() - ctrbuf = ustruct.pack(">L", ctr) + ctrbuf = struct.pack(">L", ctr) # sign the input data together with counter sig = cred.sign((rp_id_hash, flags, ctrbuf, challenge)) @@ -1437,15 +1437,15 @@ def _msg_authenticate_sign( def msg_error(cid: int, code: int) -> Cmd: - return Cmd(cid, _CMD_MSG, ustruct.pack(">H", code)) + return Cmd(cid, _CMD_MSG, struct.pack(">H", code)) def cmd_error(cid: int, code: int) -> Cmd: - return Cmd(cid, _CMD_ERROR, ustruct.pack(">B", code)) + return Cmd(cid, _CMD_ERROR, struct.pack(">B", code)) def cbor_error(cid: int, code: int) -> Cmd: - return Cmd(cid, _CMD_CBOR, ustruct.pack(">B", code)) + return Cmd(cid, _CMD_CBOR, struct.pack(">B", code)) def credentials_from_descriptor_list( diff --git a/core/src/prof/__main__.py b/core/src/prof/__main__.py index cc3240a3804..70dd8a3d6f6 100644 --- a/core/src/prof/__main__.py +++ b/core/src/prof/__main__.py @@ -1,10 +1,11 @@ import micropython import sys +import vfs +from io import open +from os import getenv from typing import TYPE_CHECKING, Any, Callable, TypeAlias import coveragedata -from uio import open -from uos import getenv if TYPE_CHECKING: from types import FrameType @@ -119,4 +120,7 @@ def trace_handler(frame: FrameType, event: str, _arg: Any) -> TraceFunction: import main # noqa: F401 finally: print("\n------------------ script exited ------------------") + # enable filesystem access for frozen emulator + if len(vfs.mount()) == 0: + vfs.mount(vfs.VfsPosix(), "/") __prof__.write_data() diff --git a/core/src/storage/device.py b/core/src/storage/device.py index 343de482668..29125fb30b3 100644 --- a/core/src/storage/device.py +++ b/core/src/storage/device.py @@ -103,12 +103,11 @@ def is_initialized() -> bool: def get_device_id() -> str: from trezorcrypto import random # avoid pulling in trezor.crypto - from ubinascii import hexlify dev_id = common.get(_NAMESPACE, DEVICE_ID, public=True) if not dev_id: # _new_device_id - new_dev_id_str = hexlify(random.bytes(12)).decode().upper() + new_dev_id_str = random.bytes(12).hex().upper() dev_id = new_dev_id_str.encode() common.set(_NAMESPACE, DEVICE_ID, dev_id, public=True) return dev_id.decode() diff --git a/core/src/trezor/crypto/base32.py b/core/src/trezor/crypto/base32.py index 49360665b17..ef4d5a368a0 100644 --- a/core/src/trezor/crypto/base32.py +++ b/core/src/trezor/crypto/base32.py @@ -14,7 +14,7 @@ def encode(s: AnyBytes) -> str: - from ustruct import unpack + from struct import unpack s = bytes(s) quanta, leftover = divmod(len(s), 5) @@ -58,8 +58,6 @@ def encode(s: AnyBytes) -> str: def decode(s: str) -> bytes: - from ubinascii import unhexlify - data = s.encode() _, leftover = divmod(len(data), 8) if leftover: @@ -85,11 +83,11 @@ def decode(s: str) -> bytes: acc += _b32rev[c] << shift shift -= 5 if shift < 0: - parts.append(unhexlify((f"{acc:010x}").encode())) + parts.append(bytes.fromhex(f"{acc:010x}")) acc = 0 shift = 35 # Process the last, partial quanta - last = unhexlify(bytes(f"{acc:010x}", "ascii")) + last = bytes.fromhex(f"{acc:010x}") if padchars == 0: last = b"" # No characters elif padchars == 1: diff --git a/core/src/trezor/loop.py b/core/src/trezor/loop.py index 95ba235a777..753a4e73a43 100644 --- a/core/src/trezor/loop.py +++ b/core/src/trezor/loop.py @@ -7,8 +7,8 @@ See `schedule`, `run`, and syscalls `sleep`, `wait`, `signal` and `race`. """ +import timeq import utime -import utimeq from typing import TYPE_CHECKING from trezor import io, log @@ -28,7 +28,7 @@ T = 0 # tasks scheduled for execution in the future -_queue = utimeq.utimeq(64) +_queue = timeq.timeq(64) # tasks paused on I/O _paused: dict[int, set[Task]] = {} diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 0e49c436ffd..f8810d02f15 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -89,10 +89,10 @@ from trezorutils import estimate_unused_stack, zero_unused_stack # noqa: F401 if EMULATOR: - import uos + import os - DISABLE_ANIMATION = uos.getenv("TREZOR_DISABLE_ANIMATION") == "1" - LOG_MEMORY = uos.getenv("TREZOR_LOG_MEMORY") == "1" + DISABLE_ANIMATION = os.getenv("TREZOR_DISABLE_ANIMATION") == "1" + LOG_MEMORY = os.getenv("TREZOR_LOG_MEMORY") == "1" else: from trezorutils import DISABLE_ANIMATION @@ -236,14 +236,10 @@ def __init__(self, ctx: HashContext) -> None: self.data = "" def update(self, data: bytes) -> None: - from ubinascii import hexlify - self.ctx.update(data) - self.data += hexlify(data).decode() + " " + self.data += data.hex() + " " def digest(self) -> bytes: - from ubinascii import hexlify - from trezor import log digest = self.ctx.digest() @@ -251,7 +247,7 @@ def digest(self) -> bytes: __name__, "%s hash: %s, data: %s", self.ctx.__class__.__name__, - hexlify(digest).decode(), + digest.hex(), self.data, ) return digest @@ -410,9 +406,7 @@ def hexlify_if_bytes(data: str | bytes | bytearray | memoryview) -> str: if isinstance(data, str): return data elif isinstance(data, (bytes, bytearray, memoryview)): - from ubinascii import hexlify - - return hexlify(data).decode() + return data.hex() else: raise TypeError("Expected str, bytes, bytearray, or memoryview") diff --git a/core/src/trezor/wire/codec/codec_v1.py b/core/src/trezor/wire/codec/codec_v1.py index 610b58ab329..43e0fb67317 100644 --- a/core/src/trezor/wire/codec/codec_v1.py +++ b/core/src/trezor/wire/codec/codec_v1.py @@ -1,4 +1,4 @@ -import ustruct +import struct from micropython import const from typing import TYPE_CHECKING @@ -33,7 +33,7 @@ async def read_message( iface.read(report, 0) if report[0] != _REP_MARKER: raise CodecError("Invalid magic") - _, magic1, magic2, mtype, msize = ustruct.unpack(_REP_INIT, report) + _, magic1, magic2, mtype, msize = struct.unpack(_REP_INIT, report) if magic1 != _REP_MAGIC or magic2 != _REP_MAGIC: raise CodecError("Invalid magic") @@ -88,7 +88,7 @@ async def write_message(iface: WireInterface, mtype: int, mdata: AnyBytes) -> No # prepare the report buffer with header data report = bytearray(iface.TX_PACKET_LEN) repofs = _REP_INIT_DATA - ustruct.pack_into( + struct.pack_into( _REP_INIT, report, 0, _REP_MARKER, _REP_MAGIC, _REP_MAGIC, mtype, msize ) diff --git a/core/src/trezor/wire/thp/memory_manager.py b/core/src/trezor/wire/thp/memory_manager.py index 6b5eba54814..a8aa3d04cfe 100644 --- a/core/src/trezor/wire/thp/memory_manager.py +++ b/core/src/trezor/wire/thp/memory_manager.py @@ -1,6 +1,6 @@ from micropython import const +from struct import pack_into from typing import TYPE_CHECKING -from ustruct import pack_into from trezor import protobuf, wire from trezorthp import APP_HEADER_LEN, SEND_BUFFER_OVERHEAD diff --git a/core/src/trezor/wire/thp/pairing_context.py b/core/src/trezor/wire/thp/pairing_context.py index 38ccd449d56..bd0c5eea4d5 100644 --- a/core/src/trezor/wire/thp/pairing_context.py +++ b/core/src/trezor/wire/thp/pairing_context.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify from trezor import loop, protobuf, workflow from trezor.wire import context, message_handler, protocol_common @@ -167,7 +166,7 @@ def _get_code_code_entry_str(self) -> str: def _get_code_qr_code_str(self) -> str: if self.code_qr_code is not None: - code_str = (hexlify(self.code_qr_code)).decode("utf-8") + code_str = self.code_qr_code.hex() if __debug__: log.debug( __name__, "code_qr_code_hexlified: %s", code_str, iface=self.iface diff --git a/core/tests/common.py b/core/tests/common.py index cbb67e85c85..f9c8ad39d28 100644 --- a/core/tests/common.py +++ b/core/tests/common.py @@ -1,6 +1,5 @@ import unittest # noqa: F401 from typing import Any, Awaitable -from ubinascii import hexlify, unhexlify # noqa: F401 from trezor import utils # noqa: F401 from trezor.wire import context diff --git a/core/tests/ethereum_common.py b/core/tests/ethereum_common.py index 407e0baad4f..7101d17dba0 100644 --- a/core/tests/ethereum_common.py +++ b/core/tests/ethereum_common.py @@ -1,5 +1,3 @@ -from ubinascii import unhexlify # noqa: F401 - from trezor import messages, protobuf from trezor.crypto import cosi from trezor.crypto.curve import ed25519 diff --git a/core/tests/test_apps.bitcoin.address.py b/core/tests/test_apps.bitcoin.address.py index a6ebbe413d5..70791905633 100644 --- a/core/tests/test_apps.bitcoin.address.py +++ b/core/tests/test_apps.bitcoin.address.py @@ -31,7 +31,7 @@ class TestAddress(unittest.TestCase): def test_p2wpkh_in_p2sh_address(self): coin = coins.by_name("Testnet") address = address_p2wpkh_in_p2sh( - unhexlify( + bytes.fromhex( "03a1af804ac108a8a51782198c2d034b28bf90c8803f5a53f76276fa69a4eae77f" ), coin, @@ -62,7 +62,7 @@ def test_p2wpkh_address(self): # test data from https://bc-2.jp/tools/bech32demo/index.html coin = coins.by_name("Testnet") address = address_p2wpkh( - unhexlify( + bytes.fromhex( "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" ), coin, @@ -73,7 +73,7 @@ def test_p2sh_address(self): coin = coins.by_name("Testnet") address = address_p2sh( - unhexlify("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin + bytes.fromhex("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin ) self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp") @@ -81,7 +81,7 @@ def test_p2wsh_address(self): coin = coins.by_name("Testnet") # pubkey OP_CHECKSIG - script = unhexlify( + script = bytes.fromhex( "210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac" ) h = HashWriter(sha256()) @@ -97,7 +97,7 @@ def test_p2wsh_in_p2sh_address(self): # test data from Mastering Bitcoin address = _address_p2wsh_in_p2sh( - unhexlify( + bytes.fromhex( "9592d601848d04b172905e0ddb0adde59f1590f1e553ffc81ddc4b0ed927dd73" ), coin, @@ -110,19 +110,19 @@ def test_multisig_address_p2sh(self): # # commented out because uncompressed public keys are not supported # coin = coins.by_name('Bitcoin') # pubkeys = [ - # unhexlify('04a882d414e478039cd5b52a92ffb13dd5e6bd4515497439dffd691a0f12af9575fa349b5694ed3155b136f09e63975a1700c9f4d4df849323dac06cf3bd6458cd'), - # unhexlify('046ce31db9bdd543e72fe3039a1f1c047dab87037c36a669ff90e28da1848f640de68c2fe913d363a51154a0c62d7adea1b822d05035077418267b1a1379790187'), - # unhexlify('0411ffd36c70776538d079fbae117dc38effafb33304af83ce4894589747aee1ef992f63280567f52f5ba870678b4ab4ff6c8ea600bd217870a8b4f1f09f3a8e83'), + # bytes.fromhex('04a882d414e478039cd5b52a92ffb13dd5e6bd4515497439dffd691a0f12af9575fa349b5694ed3155b136f09e63975a1700c9f4d4df849323dac06cf3bd6458cd'), + # bytes.fromhex('046ce31db9bdd543e72fe3039a1f1c047dab87037c36a669ff90e28da1848f640de68c2fe913d363a51154a0c62d7adea1b822d05035077418267b1a1379790187'), + # bytes.fromhex('0411ffd36c70776538d079fbae117dc38effafb33304af83ce4894589747aee1ef992f63280567f52f5ba870678b4ab4ff6c8ea600bd217870a8b4f1f09f3a8e83'), # ] # address = _address_multisig_p2sh(pubkeys, 2, coin.address_type_p2sh) # self.assertEqual(address, '347N1Thc213QqfYCz3PZkjoJpNv5b14kBd') coin = coins.by_name("Bitcoin") pubkeys = [ - unhexlify( + bytes.fromhex( "02fe6f0a5a297eb38c391581c4413e084773ea23954d93f7753db7dc0adc188b2f" ), - unhexlify( + bytes.fromhex( "02ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8" ), ] @@ -138,10 +138,10 @@ def test_multisig_address_p2wsh_in_p2sh(self): # https://bitcoin.stackexchange.com/questions/62656/generate-a-p2sh-p2wsh-address-and-spend-output-sent-to-it coin = coins.by_name("Testnet") pubkeys = [ - unhexlify( + bytes.fromhex( "020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0" ), - unhexlify( + bytes.fromhex( "0320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae" ), ] @@ -343,7 +343,7 @@ def test_address_mac(self): for coin_name, address_n, address, mac in VECTORS: coin = coins.by_name(coin_name) - mac = unhexlify(mac) + mac = bytes.fromhex(mac) keychain = Keychain( seed, coin.curve_name, diff --git a/core/tests/test_apps.bitcoin.address_grs.py b/core/tests/test_apps.bitcoin.address_grs.py index 724e8f95b86..431963a27e1 100644 --- a/core/tests/test_apps.bitcoin.address_grs.py +++ b/core/tests/test_apps.bitcoin.address_grs.py @@ -74,7 +74,7 @@ def test_p2sh_address(self): coin = coins.by_name("Groestlcoin Testnet") address = address_p2sh( - unhexlify("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin + bytes.fromhex("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin ) self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e") diff --git a/core/tests/test_apps.bitcoin.change_detector.py b/core/tests/test_apps.bitcoin.change_detector.py index 46193dbbb2f..4e22d1c5fe7 100644 --- a/core/tests/test_apps.bitcoin.change_detector.py +++ b/core/tests/test_apps.bitcoin.change_detector.py @@ -12,10 +12,10 @@ depth=2, fingerprint=50263508, child_num=0, - chain_code=unhexlify( + chain_code=bytes.fromhex( "8eb1f96a45dcb693dbad61f5184871d999127a37f1b0d4dae9964eaf3fb0e15b" ), - public_key=unhexlify( + public_key=bytes.fromhex( "03922315cd2d2d874e4c55add2e0ea41af9c2957f02c0abe0f55285d364a067b61" ), ) @@ -25,10 +25,10 @@ depth=2, fingerprint=50263508, child_num=1, - chain_code=unhexlify( + chain_code=bytes.fromhex( "acad50a7e52e44841d42bec6886df516974f8d366bc471a8515dfc69a6692700" ), - public_key=unhexlify( + public_key=bytes.fromhex( "02e6f3bf3093b45705e3d838490377e0d99eed911ca01990d1e94acd445dee59e8" ), ) @@ -38,10 +38,10 @@ depth=2, fingerprint=50263508, child_num=2, - chain_code=unhexlify( + chain_code=bytes.fromhex( "5204b124a264b0bbf86360e365f0c9a0cb6e3ea57dda97196af015d64ccfa6b1" ), - public_key=unhexlify( + public_key=bytes.fromhex( "021cd5d138ba442c7f8ee9a2b8f4e254dc599a57d42c69b7194074135a0ba82926" ), ) diff --git a/core/tests/test_apps.bitcoin.ownership_proof.py b/core/tests/test_apps.bitcoin.ownership_proof.py index efaab336d77..ab5688bdc43 100644 --- a/core/tests/test_apps.bitcoin.ownership_proof.py +++ b/core/tests/test_apps.bitcoin.ownership_proof.py @@ -40,7 +40,7 @@ def test_p2wpkh_gen_proof(self): ownership_id = ownership.get_identifier(script_pubkey, keychain) self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad5707" ), ) @@ -57,13 +57,13 @@ def test_p2wpkh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "3045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac5" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b" ), ) @@ -92,7 +92,7 @@ def test_p2wpkh_in_p2sh_gen_proof(self): self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "92caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f46" ), ) @@ -109,13 +109,13 @@ def test_p2wpkh_in_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c0019010192caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f4617160014e0cffbee1925a411844f44c3b8d81365ab51d0360247304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c012103a961687895a78da9aef98eed8e1f2a3e91cfb69d2f3cf11cbd0bb1773d951928" ), ) @@ -143,7 +143,7 @@ def test_p2tr_gen_proof(self): ownership_id = ownership.get_identifier(script_pubkey, keychain) self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec" ), ) @@ -160,13 +160,13 @@ def test_p2tr_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec000140647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497" ), ) @@ -194,7 +194,7 @@ def test_p2pkh_gen_proof(self): ownership_id = ownership.get_identifier(script_pubkey, keychain) self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda" ), ) @@ -211,13 +211,13 @@ def test_p2pkh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "3045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c00190001ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda6b483045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0012102f63159e21fbcb54221ec993def967ad2183a9c243c8bff6e7d60f4d5ed3b386500" ), ) @@ -240,8 +240,8 @@ def test_p2wpkh_verify_proof(self): commitment_data = b"" # Proof for "all all ... all" seed without passphrase. - script_pubkey = unhexlify("0014b2f771c370ccf219cd3059cda92bdf7f00cf2103") - proof = unhexlify( + script_pubkey = bytes.fromhex("0014b2f771c370ccf219cd3059cda92bdf7f00cf2103") + proof = bytes.fromhex( "534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b" ) self.assertTrue( @@ -263,10 +263,10 @@ def test_p2tr_verify_proof(self): commitment_data = b"" # Proof for "all all ... all" seed without passphrase. - script_pubkey = unhexlify( + script_pubkey = bytes.fromhex( "51204102897557de0cafea0a8401ea5b59668eccb753e4b100aebe6a19609f3cc79f" ) - proof = unhexlify( + proof = bytes.fromhex( "534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec0001401b553e5b9cc787b531bbc78417aea901272b4ea905136a2babc4d6ca471549743b5e0e39ddc14e620b254e42faa7f6d5bd953e97aa231d764d21bc5a58e8b7d9" ) self.assertTrue( @@ -322,19 +322,19 @@ def test_p2wsh_gen_proof(self): ] self.assertEqual( ownership_ids[0], - unhexlify( + bytes.fromhex( "309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a" ), ) self.assertEqual( ownership_ids[1], - unhexlify( + bytes.fromhex( "46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa344" ), ) self.assertEqual( ownership_ids[2], - unhexlify( + bytes.fromhex( "3892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d94" ), ) @@ -352,7 +352,7 @@ def test_p2wsh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "30450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc4303" ), ) @@ -371,13 +371,13 @@ def test_p2wsh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a92" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c00190003309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa3443892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d940004004830450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc43030147304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a9201695221032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b2103025324888e429ab8e3dbaf1f7802648b9cd01e9b418485c5fa4c1b9b5700e1a621033057150eb57e2b21d69866747f3d377e928f864fa88ecc5ddb1c0e501cce3f8153ae" ), ) @@ -425,7 +425,7 @@ def test_p2wsh_in_p2sh_gen_proof(self): ownership_ids = [b"\x00" * 32, b"\x01" * 32, b"\x02" * 32, ownership_id] self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "66f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0" ), ) @@ -443,7 +443,7 @@ def test_p2wsh_in_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "30450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb39" ), ) @@ -462,7 +462,7 @@ def test_p2wsh_in_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee" ), ) @@ -481,13 +481,13 @@ def test_p2wsh_in_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b7" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c0019000400000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202020202020202020266f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0232200208c256ed80a97a421656daa1468f6d4d43f475cb52ed79532d8bcb3155182981205004830450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb390147304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee0147304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b701ad5321032922ce9b0b71ae2d2d8a7f239610ae8226e0fb8c0f445ec4c88cf9aa4787f44b21028373a1cdb9a1afbc67e57f75eeea1f53e7210ae8ec4b3441a5f2bc4a250b663c21028ab4c06e3ad19053b370eff097697d4cb6d3738712ebcdcdc27c58a5639ac3aa2103e3247fab300aeba459257e4605245f85378ecbfe092ca3bc55ec1259baa456f521023b0d8d97398d97c4dba10f788344abd4bd1058ad3959724d32079ad04bdbde8a55ae" ), ) @@ -535,7 +535,7 @@ def test_p2sh_gen_proof(self): ownership_ids = [b"\x00" * 32, ownership_id] self.assertEqual( ownership_id, - unhexlify( + bytes.fromhex( "ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4" ), ) @@ -553,7 +553,7 @@ def test_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "3044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca14" ), ) @@ -572,13 +572,13 @@ def test_p2sh_gen_proof(self): ) self.assertEqual( signature, - unhexlify( + bytes.fromhex( "304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff" ), ) self.assertEqual( proof, - unhexlify( + bytes.fromhex( "534c001900020000000000000000000000000000000000000000000000000000000000000000ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4d900473044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca140147304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff014752210203ed6187880ae932660086e55d4561a57952dd200aa3ed2aa66b73e5723a0ce7210360e7f32fd3c8dee27a166f6614c598929699ee66acdcbda5fb24571bf2ae1ca052ae00" ), ) diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py index b93e7658020..e28bb392cc3 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py @@ -27,7 +27,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): inp1 = TxInput( address_n=[0], # Trezor expects hash in reversed format - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff" ), prev_index=0, @@ -39,7 +39,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): inp2 = TxInput( address_n=[1], # Trezor expects hash in reversed format - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef" ), prev_index=1, @@ -70,8 +70,8 @@ def test_prevouts(self): sig_hasher.add_input(self.inp2, b"") prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double) self.assertEqual( - hexlify(prevouts_hash), - b"96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37", + prevouts_hash.hex(), + "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37", ) def test_sequence(self): @@ -83,8 +83,8 @@ def test_sequence(self): sig_hasher.h_sequences, double=coin.sign_hash_double ) self.assertEqual( - hexlify(sequence_hash), - b"52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b", + sequence_hash.hex(), + "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b", ) def test_outputs(self): @@ -98,8 +98,8 @@ def test_outputs(self): outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double) self.assertEqual( - hexlify(outputs_hash), - b"863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5", + outputs_hash.hex(), + "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5", ) def test_preimage_testdata(self): @@ -127,8 +127,8 @@ def test_preimage_testdata(self): self.inp2, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL ) self.assertEqual( - hexlify(result), - b"2fa3f1351618b2532228d7182d3221d95c21fd3d496e7e22e9ded873cf022a8b", + result.hex(), + "2fa3f1351618b2532228d7182d3221d95c21fd3d496e7e22e9ded873cf022a8b", ) diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py index a5fcad4ebbd..4c6c549c3f3 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py @@ -27,7 +27,7 @@ class TestSegwitBip143(unittest.TestCase): inp1 = TxInput( address_n=[0], # Trezor expects hash in reversed format - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb" ), prev_index=1, @@ -57,8 +57,8 @@ def test_bip143_prevouts(self): sig_hasher.add_input(self.inp1, b"") prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double) self.assertEqual( - hexlify(prevouts_hash), - b"b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a", + prevouts_hash.hex(), + "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a", ) def test_bip143_sequence(self): @@ -69,8 +69,8 @@ def test_bip143_sequence(self): sig_hasher.h_sequences, double=coin.sign_hash_double ) self.assertEqual( - hexlify(sequence_hash), - b"18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198", + sequence_hash.hex(), + "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198", ) def test_bip143_outputs(self): @@ -84,8 +84,8 @@ def test_bip143_outputs(self): outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double) self.assertEqual( - hexlify(outputs_hash), - b"de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83", + outputs_hash.hex(), + "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83", ) def test_bip143_preimage_testdata(self): @@ -109,8 +109,8 @@ def test_bip143_preimage_testdata(self): self.inp1, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL ) self.assertEqual( - hexlify(result), - b"6e28aca7041720995d4acf59bbda64eef5d6f23723d23f2e994757546674bbd9", + result.hex(), + "6e28aca7041720995d4acf59bbda64eef5d6f23723d23f2e994757546674bbd9", ) diff --git a/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py b/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py index bec4b1aa279..c39ab798b45 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py +++ b/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py @@ -20,11 +20,11 @@ "inputs": [ TxInput( amount=420000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "9c4e333b5f116359b5f5578fe4a74c6f58b3bab9d28149a583da86f6bf0ce27d" ), prev_index=1, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "512053a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343" ), script_type=InputScriptType.SPENDTAPROOT, @@ -32,11 +32,11 @@ ), TxInput( amount=462000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "99ddaf6d9b75447d5127e17312f6def68acba2d4f464d0e2ac93137bb5cab7d7" ), prev_index=0, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "5120147c9c57132f6e7ecddba9800bb0c4449251c92a1e60371ee77557b6620f3ea3" ), script_type=InputScriptType.SPENDTAPROOT, @@ -44,11 +44,11 @@ ), TxInput( amount=294000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4218a419542757d960174457dc82e06b3613ac8ed2c528926833433883f5e1f8" ), prev_index=0, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914751e76e8199196d454941c45d1b3a323f1433bd688ac" ), script_type=InputScriptType.SPENDADDRESS, @@ -56,11 +56,11 @@ ), TxInput( amount=504000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "3b8504d63a84a0fd1043e7ec832adaeeb7382a6d3ca762b10cb363aa809168f0" ), prev_index=1, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "5120e4d810fd50586274face62b8a807eb9719cef49c04177cc6b76a9a4251d5450e" ), script_type=InputScriptType.SPENDTAPROOT, @@ -68,11 +68,11 @@ ), TxInput( amount=630000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "7a488f58881cecb2523690afcf22eb8892372bae018a125e1f006283a38c630c" ), prev_index=0, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "512091b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605" ), script_type=InputScriptType.SPENDTAPROOT, @@ -80,21 +80,23 @@ ), TxInput( amount=378000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "50d0ac326d44a3a29358214139fecb8a7129aa2f2dbeb28e96aa6fc6bd496195" ), prev_index=0, - script_pubkey=unhexlify("00147dd65592d0ab2fe0d0257d571abf032cd9db93dc"), + script_pubkey=bytes.fromhex( + "00147dd65592d0ab2fe0d0257d571abf032cd9db93dc" + ), script_type=InputScriptType.SPENDWITNESS, sequence=0x00000000, ), TxInput( amount=672000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "3a013eb5a6a664585ddbc210e02147847cde7317c0ce4e056ee4f0f167a2ef81" ), prev_index=1, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "512075169f4001aa68f15bbed28b218df1d0a62cbbcf1188c6665110c293c907b831" ), script_type=InputScriptType.SPENDTAPROOT, @@ -102,11 +104,11 @@ ), TxInput( amount=546000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "eebd075c693d6823dd39fe11e3a6d1993fdec6109860937d50624a3c9c6690a6" ), prev_index=0, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "51200f63ca2c7639b9bb4be0465cc0aa3ee78a0761ba5f5f7d6ff8eab340f09da561" ), script_type=InputScriptType.SPENDTAPROOT, @@ -114,11 +116,11 @@ ), TxInput( amount=588000000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "9e667967d1eb839b9b0a1fd17b2f29e838ff0240a83c61f896844377f8b57a72" ), prev_index=1, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "5120053690babeabbb7850c32eead0acf8df990ced79f7a31e358fabf2658b4bc587" ), script_type=InputScriptType.SPENDTAPROOT, @@ -128,44 +130,44 @@ "outputs": [ PrevOutput( amount=1000000000, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac" ), # 1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP ), PrevOutput( amount=3410000000, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "ac9a87f5594be208f8532db38cff670c450ed2fea8fcdefcc9a663f78bab962b" ), ), ], - "sha_amounts": unhexlify( + "sha_amounts": bytes.fromhex( "58a6964a4f5f8f0b642ded0a8a553be7622a719da71d1f5befcefcdee8e0fde6" ), - "sha_outputs": unhexlify( + "sha_outputs": bytes.fromhex( "a2e6dab7c1f0dcd297c8d61647fd17d821541ea69c3cc37dcbad7f90d4eb4bc5" ), - "sha_prevouts": unhexlify( + "sha_prevouts": bytes.fromhex( "2bd4d5a417902673919b2c209d14f8efaa285ede022a88d6a45edf4bdd43db11" ), - "sha_scriptpubkeys": unhexlify( + "sha_scriptpubkeys": bytes.fromhex( "26003c31f2f1786d22fcb3e1f690ddcdff53627a59f9219d5a2c77985a8930c0" ), - "sha_sequences": unhexlify( + "sha_sequences": bytes.fromhex( "18959c7221ab5ce9e26c3cd67b22c24f8baa54bac281d8e6b05e400e6c3a957e" ), "signature_hashes": [ { "index": 3, "hash_type": SigHashType.SIGHASH_ALL, - "result": unhexlify( + "result": bytes.fromhex( "6ffd256e108685b41831385f57eebf2fca041bc6b5e607ea11b3e03d4cf9d9ba" ), }, { "index": 4, "hash_type": SigHashType.SIGHASH_ALL_TAPROOT, - "result": unhexlify( + "result": bytes.fromhex( "9f90136737540ccc18707e1fd398ad222a1a7e4dd65cbfd22dbe4660191efa58" ), }, @@ -181,7 +183,7 @@ ), "inputs": [ TxInput( - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "8dcb562f365cfeb249be74e7865135cf035add604234fc0d8330b49bec92605f" ), prev_index=0, @@ -189,10 +191,12 @@ script_type=InputScriptType.SPENDWITNESS, multisig=None, sequence=0, - script_pubkey=unhexlify("0014196a5bea745288a7f947993c28e3a0f2108d2e0a"), + script_pubkey=bytes.fromhex( + "0014196a5bea745288a7f947993c28e3a0f2108d2e0a" + ), ), TxInput( - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "e1323b577ed0d216f4e52bf2b4c490710dfa0088dae3d15e8ba26ad792184361" ), prev_index=1, @@ -200,7 +204,7 @@ amount=600000000, # 6 btc script_type=InputScriptType.SPENDTAPROOT, sequence=0, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "512029d942d0408906b359397b6f87c5145814a9aefc8c396dd05efa8b5b73576bf2" ), ), @@ -208,31 +212,31 @@ "outputs": [ PrevOutput( amount=1000000000, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914682dfdbc97ab5c31300f36d3c12c6fd854b1b35a88ac" ), # 1AVrNUPAytZZbisNduCacWcEVJS6eGRvaa ), ], - "sha_amounts": unhexlify( + "sha_amounts": bytes.fromhex( "5733468db74734c00efa0b466bca091d8f1aab074af2538f36bd0a734a5940c5" ), - "sha_outputs": unhexlify( + "sha_outputs": bytes.fromhex( "8cdee56004a241f9c79cc55b7d79eaed04909d84660502a2d4e9c357c2047cf5" ), - "sha_prevouts": unhexlify( + "sha_prevouts": bytes.fromhex( "32553b113292dfa8216546e721388a6c19c76626ca65dc187e0348d6ed445f81" ), - "sha_scriptpubkeys": unhexlify( + "sha_scriptpubkeys": bytes.fromhex( "423cd73484fc5e3e0a623442846c279c2216f25a2f32d161fea6c5821a1adde7" ), - "sha_sequences": unhexlify( + "sha_sequences": bytes.fromhex( "af5570f5a1810b7af78caf4bc70a660f0df51e42baf91d4de5b2328de0e83dfc" ), "signature_hashes": [ { "index": 1, "hash_type": SigHashType.SIGHASH_ALL_TAPROOT, - "result": unhexlify( + "result": bytes.fromhex( "07333acfe6dce8196f1ad62b2e039a3d9f0b6627bf955be767c519c0f8789ff4" ), }, diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py index 1c1ebc84440..26a94d65eda 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py @@ -47,7 +47,7 @@ def test_send_native_p2wpkh(self): # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" ), prev_index=0, @@ -59,19 +59,21 @@ def test_send_native_p2wpkh(self): version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), - prev_hash=unhexlify( + script_sig=bytes.fromhex("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, sequence=4294967295, ) pout1 = PrevOutput( - script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), + script_pubkey=bytes.fromhex("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), amount=12300000, ) pout2 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=111145789, ) @@ -170,7 +172,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -179,7 +181,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02" ), ), @@ -190,7 +192,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" ), signature_index=None, @@ -204,7 +206,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5" ), signature_index=None, @@ -216,11 +218,11 @@ def test_send_native_p2wpkh(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95" ), ), @@ -247,7 +249,7 @@ def test_send_native_p2wpkh_change(self): # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" ), prev_index=0, @@ -259,19 +261,21 @@ def test_send_native_p2wpkh_change(self): version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), - prev_hash=unhexlify( + script_sig=bytes.fromhex("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, sequence=4294967295, ) pout1 = PrevOutput( - script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), + script_pubkey=bytes.fromhex("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), amount=12300000, ) pout2 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=111145789, ) @@ -374,7 +378,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -383,7 +387,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02" ), ), @@ -395,7 +399,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" ), signature_index=None, @@ -409,7 +413,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5" ), signature_index=None, @@ -421,11 +425,11 @@ def test_send_native_p2wpkh_change(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95" ), ), @@ -452,7 +456,7 @@ def test_send_native_invalid_address(self): # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" ), prev_index=0, diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py index a1b1ef683a1..c5e6e6957ec 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py @@ -48,7 +48,7 @@ def test_send_native_p2wpkh(self): # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" ), prev_index=0, @@ -64,21 +64,21 @@ def test_send_native_p2wpkh(self): extra_data_len=0, ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160" ), prev_index=1, sequence=4294967293, ) pout1 = PrevOutput( - script_pubkey=unhexlify("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), + script_pubkey=bytes.fromhex("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), amount=12300000, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac" ), amount=9887699777, @@ -183,7 +183,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -192,7 +192,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02" ), ), @@ -203,7 +203,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" ), signature_index=None, @@ -217,7 +217,7 @@ def test_send_native_p2wpkh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b" ), signature_index=None, @@ -229,11 +229,11 @@ def test_send_native_p2wpkh(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3" ), ), @@ -260,7 +260,7 @@ def test_send_native_p2wpkh_change(self): # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" ), prev_index=0, @@ -276,21 +276,21 @@ def test_send_native_p2wpkh_change(self): extra_data_len=0, ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160" ), prev_index=1, sequence=4294967293, ) pout1 = PrevOutput( - script_pubkey=unhexlify("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), + script_pubkey=bytes.fromhex("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), amount=12300000, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac" ), amount=9887699777, @@ -397,7 +397,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -406,7 +406,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02" ), ), @@ -418,7 +418,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" ), signature_index=None, @@ -432,7 +432,7 @@ def test_send_native_p2wpkh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b" ), signature_index=None, @@ -444,11 +444,11 @@ def test_send_native_p2wpkh_change(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3" ), ), diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py index 289e7f75e3d..1e492d92954 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py @@ -47,7 +47,7 @@ def test_send_p2wpkh_in_p2sh(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, @@ -59,21 +59,23 @@ def test_send_p2wpkh_in_p2sh(self): version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" ), prev_index=0, sequence=4294967295, ) pout1 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=123456789, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" ), amount=865519308, @@ -177,7 +179,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -186,7 +188,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02" ), ), @@ -197,7 +199,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac" ), signature_index=None, @@ -211,7 +213,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" ), signature_index=None, @@ -223,11 +225,11 @@ def test_send_p2wpkh_in_p2sh(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b" ), ), @@ -254,7 +256,7 @@ def test_send_p2wpkh_in_p2sh_change(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, @@ -266,21 +268,23 @@ def test_send_p2wpkh_in_p2sh_change(self): version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" ), prev_index=0, sequence=4294967295, ) pout1 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=123456789, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" ), amount=865519308, @@ -380,7 +384,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -389,7 +393,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02" ), ), @@ -401,7 +405,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac" ), signature_index=None, @@ -415,7 +419,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" ), signature_index=None, @@ -427,11 +431,11 @@ def test_send_p2wpkh_in_p2sh_change(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b" ), ), @@ -458,7 +462,7 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=10, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, @@ -470,21 +474,23 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self): version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" ), prev_index=0, sequence=4294967295, ) pout1 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=123456789, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" ), amount=865519308, @@ -494,7 +500,7 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=9, # modified! - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, @@ -591,7 +597,7 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), ] diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py index 4130cd4e6c4..c343798412e 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py @@ -48,7 +48,7 @@ def test_send_p2wpkh_in_p2sh(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf" ), prev_index=0, @@ -64,21 +64,23 @@ def test_send_p2wpkh_in_p2sh(self): extra_data_len=0, ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" ), prev_index=1, sequence=4294967294, ) pout1 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=123456789, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac" ), amount=9764242764, @@ -188,7 +190,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -197,7 +199,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02" ), ), @@ -208,7 +210,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac" ), signature_index=None, @@ -222,7 +224,7 @@ def test_send_p2wpkh_in_p2sh(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" ), signature_index=None, @@ -234,11 +236,11 @@ def test_send_p2wpkh_in_p2sh(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80" ), ), @@ -265,7 +267,7 @@ def test_send_p2wpkh_in_p2sh_change(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf" ), prev_index=0, @@ -281,21 +283,23 @@ def test_send_p2wpkh_in_p2sh_change(self): extra_data_len=0, ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" ), prev_index=1, sequence=4294967294, ) pout1 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + script_pubkey=bytes.fromhex( + "a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), amount=123456789, ) pout2 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac" ), amount=9764242764, @@ -401,7 +405,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized header - serialized_tx=unhexlify("01000000000101"), + serialized_tx=bytes.fromhex("01000000000101"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -410,7 +414,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized inp1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02" ), ), @@ -422,7 +426,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out1 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac" ), signature_index=None, @@ -436,7 +440,7 @@ def test_send_p2wpkh_in_p2sh_change(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( # returned serialized out2 - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" ), signature_index=None, @@ -448,11 +452,11 @@ def test_send_p2wpkh_in_p2sh_change(self): request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" ), signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80" ), ), diff --git a/core/tests/test_apps.bitcoin.sign_tx.writers.py b/core/tests/test_apps.bitcoin.sign_tx.writers.py index f2588bd5457..b412fdde900 100644 --- a/core/tests/test_apps.bitcoin.sign_tx.writers.py +++ b/core/tests/test_apps.bitcoin.sign_tx.writers.py @@ -12,7 +12,7 @@ def test_tx_input(self): inp = TxInput( address_n=[0], amount=390000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), prev_index=0, @@ -34,13 +34,13 @@ def test_tx_input_check(self): inp = TxInput( address_n=[0], amount=390000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, sequence=0xFFFFFFFF, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac" ), script_sig=b"0123456789", diff --git a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py index b0ef6e57e71..8b0b27c2ada 100644 --- a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py +++ b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py @@ -48,18 +48,18 @@ def test_over_fee_threshold(self): coin_bitcoin = coins.by_name('Bitcoin') ptx1 = PrevTx(version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), - prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), + pinp1 = PrevInput(script_sig=bytes.fromhex('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), + prev_hash=bytes.fromhex('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_index=1) - pinp2 = PrevInput(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'), - prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), + pinp2 = PrevInput(script_sig=bytes.fromhex('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'), + prev_hash=bytes.fromhex('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), prev_index=1) - pout1 = PrevOutput(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'), + pout1 = PrevOutput(script_pubkey=bytes.fromhex('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'), amount=390000) inp1 = TxInput(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e # amount=390000, - prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), + prev_hash=bytes.fromhex('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_index=0, amount=None) out1 = TxOutput(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', @@ -76,13 +76,13 @@ def test_over_fee_threshold(self): TxAckInput(tx=TxAckInputWrapper(input=inp1)), helpers.UiConfirmForeignAddress(address_n=inp1.address_n), True, - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), + TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=bytes.fromhex('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxAckPrevMeta(tx=ptx1), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), + TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=bytes.fromhex('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), + TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=bytes.fromhex('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp2)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), + TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=bytes.fromhex('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), @@ -114,27 +114,27 @@ def test_under_threshold(self): version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf" ), prev_index=1, sequence=0xFFFF_FFFF, ) pinp2 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf" ), prev_index=1, sequence=0xFFFF_FFFF, ) pout1 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac" ), amount=390000, @@ -143,7 +143,7 @@ def test_under_threshold(self): inp1 = TxInput( address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e amount=390000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), prev_index=0, @@ -201,7 +201,7 @@ def test_under_threshold(self): request_type=TXMETA, details=TxRequestDetailsType( request_index=None, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), ), @@ -212,7 +212,7 @@ def test_under_threshold(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), ), @@ -223,7 +223,7 @@ def test_under_threshold(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=1, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), ), @@ -234,7 +234,7 @@ def test_under_threshold(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), ), @@ -245,7 +245,7 @@ def test_under_threshold(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify("0100000001") + serialized_tx=bytes.fromhex("0100000001") ), ), ] diff --git a/core/tests/test_apps.bitcoin.signtx.omni.py b/core/tests/test_apps.bitcoin.signtx.omni.py index b6893db4740..a04a5cc4d5f 100644 --- a/core/tests/test_apps.bitcoin.signtx.omni.py +++ b/core/tests/test_apps.bitcoin.signtx.omni.py @@ -16,7 +16,7 @@ def test_is_valid(self): "6f6d6e69000000000000001f0000000020c855": True, } for k, v in VECTORS.items(): - k = unhexlify(k) + k = bytes.fromhex(k) self.assertEqual(is_valid(k), v) def test_parse(self): @@ -28,7 +28,7 @@ def test_parse(self): "6f6d6e6901000000": "Unknown transaction", } for k, v in VECTORS.items(): - k = unhexlify(k) + k = bytes.fromhex(k) self.assertEqual(parse(k), v) diff --git a/core/tests/test_apps.bitcoin.signtx.py b/core/tests/test_apps.bitcoin.signtx.py index ec3ee4286a1..3c649add552 100644 --- a/core/tests/test_apps.bitcoin.signtx.py +++ b/core/tests/test_apps.bitcoin.signtx.py @@ -49,27 +49,27 @@ def test_one_one_fee(self): version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "47304402202df6c8885489be0fd52ed1f82c20b4c2c03e479369ea8439ed6233a3bb349ddd02207f749a00dd98d1aca699178d8fa954dc45b9faff33d3c9f03b81fa766061f2d70121038b60c00f69d78f2c5df84a24b30894c3700e4d6176a1f440461c8c69bf1f4262" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "468c0de3bf9dfcc4915354904108611db9547a16ec38a24bf6b240ccc946e0d3" ), prev_index=0, sequence=0xFFFF_FFFF, ) pinp2 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "483045022100b11b3804e9b5fbbad70532e550192b3bbdd65b51f30572638a5559a86600856702204b3bd50a847ddf66426c0f413b9e1a98388b0d36479e66ef37b2d53d9ad13d47012103d443712f673afafafc006ccb6e19220de7ae0c07c9832666103974293d04a93c" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "ebb32bba661e3dccb216acf593de26223f5f2c17f6a75634f2a0b581c4855fa0" ), prev_index=0, sequence=0xFFFF_FFFF, ) pout1 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914be145c9a7c131ad0c6c9b86f83748d660b42e2f488ac" ), amount=3_801_747, @@ -77,7 +77,7 @@ def test_one_one_fee(self): inp1 = TxInput( address_n=[44 | 0x80000000, 0 | 0x80000000, 0 | 0x80000000, 0, 10], - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3" ), prev_index=0, @@ -137,7 +137,7 @@ def test_one_one_fee(self): request_type=TXMETA, details=TxRequestDetailsType( request_index=None, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3" ), ), @@ -148,7 +148,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3" ), ), @@ -159,7 +159,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=1, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3" ), ), @@ -170,7 +170,7 @@ def test_one_one_fee(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3" ), ), @@ -181,7 +181,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify("0100000001") + serialized_tx=bytes.fromhex("0100000001") ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -196,10 +196,10 @@ def test_one_one_fee(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100bebe58e7eac8170334f987d0f67032a2eddd0e2f378e002502ec88a69460ea460220040a8effc41167f5d5a5ffc77f37317d8125c7cd05f92d142e4d977f2f132c94" ), - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "f36ea247c36f027a45d0265718c74ae8ab87bd45b3fb6e14ef558d76656f321f000000006b483045022100bebe58e7eac8170334f987d0f67032a2eddd0e2f378e002502ec88a69460ea460220040a8effc41167f5d5a5ffc77f37317d8125c7cd05f92d142e4d977f2f132c940121038bac33bcdaeec5626e2f2c5680a9fdc5e551d4e1167f272825bea98e6158d4c8ffffffff01" ), ), @@ -211,7 +211,7 @@ def test_one_one_fee(self): serialized=TxRequestSerializedType( signature_index=None, signature=None, - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "433f3900000000001976a9145d48886f4e2aad3164e55e23a7a41b921646a33488ac00000000" ), ), diff --git a/core/tests/test_apps.bitcoin.signtx_decred.py b/core/tests/test_apps.bitcoin.signtx_decred.py index fda79355cf6..f090798d346 100644 --- a/core/tests/test_apps.bitcoin.signtx_decred.py +++ b/core/tests/test_apps.bitcoin.signtx_decred.py @@ -43,22 +43,26 @@ version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "47304402207d127d59a44187952d9d0de94ad34a19dd9a84beb124fd8a3fb439c862544d3202206618f321385c30bda96fb01ce03f70a269d78a301c0b0c2e3e3689dfae3f4733012102ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "21012b08c5077036460e8f75bbc57beb11d7bc30e7ad224ad5e67d15bd086500" ), prev_index=2, sequence=0xFFFF_FFFF, ) pout1 = PrevOutput( - script_pubkey=unhexlify("76a914e4111051ae0349ab5589cf2b7e125c6da694a1a188ac"), + script_pubkey=bytes.fromhex( + "76a914e4111051ae0349ab5589cf2b7e125c6da694a1a188ac" + ), amount=153_185_001, decred_script_version=0, ) pout2 = PrevOutput( - script_pubkey=unhexlify("76a914dc1a98d791735eb9a8715a2a219c23680edcedad88ac"), + script_pubkey=bytes.fromhex( + "76a914dc1a98d791735eb9a8715a2a219c23680edcedad88ac" + ), amount=200_000_000, decred_script_version=0, ) @@ -72,7 +76,7 @@ class TestSignTxDecred(unittest.TestCase): def test_one_one_fee(self): inp1 = TxInput( address_n=[44 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), prev_index=1, @@ -103,7 +107,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify("0100000001") + serialized_tx=bytes.fromhex("0100000001") ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -111,7 +115,7 @@ def test_one_one_fee(self): request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "1064cbf0f0889b919ce083c82065612710b1a6adcdb3f15d7ffc5e6de2cd8a4d0100000000ffffffff01" ) ), @@ -134,7 +138,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "603bea0b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac0000000000000000" ) ), @@ -144,7 +148,7 @@ def test_one_one_fee(self): request_type=TXMETA, details=TxRequestDetailsType( request_index=None, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -155,7 +159,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -166,7 +170,7 @@ def test_one_one_fee(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -177,7 +181,7 @@ def test_one_one_fee(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=1, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -187,7 +191,7 @@ def test_one_one_fee(self): TxRequest( request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType(serialized_tx=unhexlify("01")), + serialized=TxRequestSerializedType(serialized_tx=bytes.fromhex("01")), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), TxRequest( @@ -195,10 +199,10 @@ def test_one_one_fee(self): details=TxRequestDetailsType(request_index=None, tx_hash=None), serialized=TxRequestSerializedType( signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "304402205ea5a0aec7e405eb3c792165f103f61f8ef862e76a2b0146bec1082b243cfbff022061e307113d389b969313bbee2c9a149fad4afdf715e8bd78df579438ef692814" ), - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "00c2eb0b0000000000000000ffffffff6a47304402205ea5a0aec7e405eb3c792165f103f61f8ef862e76a2b0146bec1082b243cfbff022061e307113d389b969313bbee2c9a149fad4afdf715e8bd78df579438ef6928140121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" ), ), @@ -226,7 +230,7 @@ def test_one_one_fee(self): def test_purchase_ticket(self): inp1 = TxInput( address_n=[44 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), prev_index=1, @@ -270,7 +274,7 @@ def test_purchase_ticket(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify("0100000001") + serialized_tx=bytes.fromhex("0100000001") ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -278,7 +282,7 @@ def test_purchase_ticket(self): request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "1064cbf0f0889b919ce083c82065612710b1a6adcdb3f15d7ffc5e6de2cd8a4d0100000000ffffffff03" ) ), @@ -292,7 +296,7 @@ def test_purchase_ticket(self): request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "603bea0b0000000000001aba76a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac" ) ), @@ -302,7 +306,7 @@ def test_purchase_ticket(self): request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=2, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "00000000000000000000206a1edc1a98d791735eb9a8715a2a219c23680edcedad00c2eb0b000000000058" ) ), @@ -321,7 +325,7 @@ def test_purchase_ticket(self): request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "000000000000000000001abd76a914000000000000000000000000000000000000000088ac0000000000000000" ) ), @@ -331,7 +335,7 @@ def test_purchase_ticket(self): request_type=TXMETA, details=TxRequestDetailsType( request_index=None, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -342,7 +346,7 @@ def test_purchase_ticket(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -353,7 +357,7 @@ def test_purchase_ticket(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -364,7 +368,7 @@ def test_purchase_ticket(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=1, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410" ), ), @@ -374,7 +378,7 @@ def test_purchase_ticket(self): TxRequest( request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType(serialized_tx=unhexlify("01")), + serialized=TxRequestSerializedType(serialized_tx=bytes.fromhex("01")), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), TxRequest( @@ -382,10 +386,10 @@ def test_purchase_ticket(self): details=TxRequestDetailsType(), serialized=TxRequestSerializedType( signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "3045022100b3a11ff4befcc035623de7665aaa76dacc9252e53aabf2a5d61238151e696532022004cbcc537c1d539e04c823140bac4524bdba09f528f5c4b76f3f1022b7dc0ad4" ), - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "00c2eb0b0000000000000000ffffffff6b483045022100b3a11ff4befcc035623de7665aaa76dacc9252e53aabf2a5d61238151e696532022004cbcc537c1d539e04c823140bac4524bdba09f528f5c4b76f3f1022b7dc0ad40121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" ), ), diff --git a/core/tests/test_apps.bitcoin.signtx_grs.py b/core/tests/test_apps.bitcoin.signtx_grs.py index 15fe027f3d4..988cb4358d9 100644 --- a/core/tests/test_apps.bitcoin.signtx_grs.py +++ b/core/tests/test_apps.bitcoin.signtx_grs.py @@ -52,17 +52,17 @@ def test_one_one_fee(self): extra_data_len=0, ) pinp1 = PrevInput( - script_sig=unhexlify( + script_sig=bytes.fromhex( "48304502210096a287593b1212a188e778596eb8ecd4cc169b93a4d115226460d8e3deae431c02206c78ec09b3df977f04a6df5eb53181165c4ea5a0b35f826551349130f879d6b8012102cf5126ff54e38a80a919579d7091cafe24840eab1d30fe2b4d59bdd9d267cad8" ), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "7dc74a738c50c2ae1228ce9890841e5355fd6d7f2c1367e0a74403ab60db3224" ), prev_index=0, sequence=4294967294, ) pout1 = PrevOutput( - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914172b4e06e9b7881a48d2ee8062b495d0b2517fe888ac" ), amount=210016, @@ -76,7 +76,7 @@ def test_one_one_fee(self): 0, 2, ], # FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" ), prev_index=0, @@ -131,7 +131,7 @@ def test_one_one_fee(self): request_type=TXMETA, details=TxRequestDetailsType( request_index=None, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" ), ), @@ -142,7 +142,7 @@ def test_one_one_fee(self): request_type=TXINPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" ), ), @@ -153,7 +153,7 @@ def test_one_one_fee(self): request_type=TXOUTPUT, details=TxRequestDetailsType( request_index=0, - tx_hash=unhexlify( + tx_hash=bytes.fromhex( "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" ), ), @@ -168,7 +168,7 @@ def test_one_one_fee(self): serialized=TxRequestSerializedType( signature_index=None, signature=None, - serialized_tx=unhexlify("0100000001"), + serialized_tx=bytes.fromhex("0100000001"), ), ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), @@ -183,10 +183,10 @@ def test_one_one_fee(self): details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( signature_index=0, - signature=unhexlify( + signature=bytes.fromhex( "304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a74302368761" ), - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "4a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01" ), ), @@ -198,7 +198,7 @@ def test_one_one_fee(self): serialized=TxRequestSerializedType( signature_index=None, signature=None, - serialized_tx=unhexlify( + serialized_tx=bytes.fromhex( "a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000" ), ), diff --git a/core/tests/test_apps.bitcoin.txweight.py b/core/tests/test_apps.bitcoin.txweight.py index 229b5bd02f9..69342a9c376 100644 --- a/core/tests/test_apps.bitcoin.txweight.py +++ b/core/tests/test_apps.bitcoin.txweight.py @@ -22,7 +22,7 @@ def test_p2pkh_txweight(self): inp1 = TxInput( address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e # amount=390000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), prev_index=0, @@ -58,7 +58,7 @@ def test_p2wpkh_in_p2sh_txweight(self): # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" ), prev_index=0, @@ -99,7 +99,7 @@ def test_native_p2wpkh_txweight(self): # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" ), prev_index=0, @@ -138,7 +138,7 @@ def test_taproot_txweight(self): inp1 = TxInput( address_n=[86 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=4600, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" ), prev_index=1, @@ -185,7 +185,7 @@ def test_legacy_multisig_txweight(self): inp1 = TxInput( address_n=[48 | 0x80000000, 0 | 0x80000000, 1 | 0x80000000, 0, 0], amount=100000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52" ), prev_index=1, @@ -232,7 +232,7 @@ def test_segwit_multisig_txweight(self): inp1 = TxInput( address_n=[49 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc" ), prev_index=1, @@ -260,7 +260,7 @@ def test_mixed_txweight(self): inp1 = TxInput( address_n=[49 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=20000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "8c3ea7a10ab6d289119b722ec8c27b70c17c722334ced31a0370d782e4b6775d" ), prev_index=0, @@ -269,7 +269,7 @@ def test_mixed_txweight(self): inp2 = TxInput( address_n=[84 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=15000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" ), prev_index=0, @@ -278,7 +278,7 @@ def test_mixed_txweight(self): inp3 = TxInput( address_n=[86 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=4450, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" ), prev_index=0, @@ -287,7 +287,7 @@ def test_mixed_txweight(self): inp4 = TxInput( address_n=[44 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=10000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "3ac32e90831d79385eee49d6030a2123cd9d009fe8ffc3d470af9a6a777a119b" ), prev_index=2, @@ -341,20 +341,20 @@ def test_external_txweight(self): inp1 = TxInput( amount=100000, - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "e5b7e21b5ba720e81efd6bfa9f854ababdcddc75a43bfa60bf0fe069cfd1bb8a" ), prev_index=0, script_type=InputScriptType.EXTERNAL, - script_pubkey=unhexlify("00149c02608d469160a92f40fdf8c6ccced029493088"), - ownership_proof=unhexlify( + script_pubkey=bytes.fromhex("00149c02608d469160a92f40fdf8c6ccced029493088"), + ownership_proof=bytes.fromhex( "534c001900016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c40002483045022100d4ad0374c922848c71d913fba59c81b9075e0d33e884d953f0c4b4806b8ffd0c022024740e6717a2b6a5aa03148c3a28b02c713b4e30fc8aeae67fa69eb20e8ddcd9012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d" ), ) inp2 = TxInput( address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "70f9871eb03a38405cfd7a01e0e1448678132d815e2c9f552ad83ae23969509e" ), prev_index=0, @@ -365,15 +365,15 @@ def test_external_txweight(self): inp3 = TxInput( # tb1qldlynaqp0hy4zc2aag3pkenzvxy65saesxw3wd # address_n=parse_path("m/84h/1h/0h/0/1"), - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "65b768dacccfb209eebd95a1fb80a04f1dd6a3abc6d7b41d5e9d9f91605b37d9" ), prev_index=0, amount=10000, script_type=InputScriptType.EXTERNAL, - script_pubkey=unhexlify("0014fb7e49f4017dc951615dea221b66626189aa43b9"), + script_pubkey=bytes.fromhex("0014fb7e49f4017dc951615dea221b66626189aa43b9"), script_sig=bytes(0), - witness=unhexlify( + witness=bytes.fromhex( "024730440220432ac60461de52713ad543cbb1484f7eca1a72c615d539b3f42f5668da4501d2022063786a6d6940a5c1ed9c2d2fd02cef90b6c01ddd84829c946561e15be6c0aae1012103dcf3bc936ecb2ec57b8f468050abce8c8756e75fd74273c9977744b1a0be7d03" ), ) diff --git a/core/tests/test_apps.bitcoin.zcash.zip243.py b/core/tests/test_apps.bitcoin.zcash.zip243.py index b6d1f48aee5..32d9aba1e0e 100644 --- a/core/tests/test_apps.bitcoin.zcash.zip243.py +++ b/core/tests/test_apps.bitcoin.zcash.zip243.py @@ -38,10 +38,10 @@ class TestZcashZip243(unittest.TestCase): "version": 4, "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, - "prevouts_hash": b"bd4318eecf841a0cf01c2be532cf4bc3303e881e2aface159f1882f153152688", - "sequence_hash": b"9ac6a31952ff626bf5a0a30d3d8ac63a0d4298d33d7bc38854bfa5860695e30a", - "outputs_hash": b"d0cadf116b4441f5e1e17814908dee509ec262a79f3c88f7f3389e8200658992", - "preimage_hash": b"f8772c6ecf9d903698fb8c51cd7b99605af298478989945936935da65e064695", + "prevouts_hash": "bd4318eecf841a0cf01c2be532cf4bc3303e881e2aface159f1882f153152688", + "sequence_hash": "9ac6a31952ff626bf5a0a30d3d8ac63a0d4298d33d7bc38854bfa5860695e30a", + "outputs_hash": "d0cadf116b4441f5e1e17814908dee509ec262a79f3c88f7f3389e8200658992", + "preimage_hash": "f8772c6ecf9d903698fb8c51cd7b99605af298478989945936935da65e064695", }, { "expiry": 231041495, @@ -75,10 +75,10 @@ class TestZcashZip243(unittest.TestCase): "version": 4, "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, - "prevouts_hash": b"8e286c6c0dde3119271c9c1398ef46614b0253c502b00a3691cec2e9047da35b", - "sequence_hash": b"58477fd9ecd5faf3e08159e0ab5fdaab66cab364d081498ddcef41de0af3624e", - "outputs_hash": b"c518797fc6f2c08fc22aa3f66122047b360e1db4df5c3feb28573c00cdf45fa1", - "preimage_hash": b"0eb47dc51d89cc52378fc182242f78ebd3609544a365d2270c23b4052f301025", + "prevouts_hash": "8e286c6c0dde3119271c9c1398ef46614b0253c502b00a3691cec2e9047da35b", + "sequence_hash": "58477fd9ecd5faf3e08159e0ab5fdaab66cab364d081498ddcef41de0af3624e", + "outputs_hash": "c518797fc6f2c08fc22aa3f66122047b360e1db4df5c3feb28573c00cdf45fa1", + "preimage_hash": "0eb47dc51d89cc52378fc182242f78ebd3609544a365d2270c23b4052f301025", }, { "expiry": 186996458, @@ -99,10 +99,10 @@ class TestZcashZip243(unittest.TestCase): "version": 4, "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, - "prevouts_hash": b"445bc6328cd33b3c86259953dd674bded341ff1e1104dc21856919e9761036dd", - "sequence_hash": b"42e1d5c2636f165afaa954afa6d7a50779eb145e947bf668f1a40dd771c711fc", - "outputs_hash": b"869eda84eecf7257f9979a4848bbf52f4969a5736594ab7ba41452e7bb906824", - "preimage_hash": b"7f6b5439a64b20faf6f9f9460bc75c333c4799e9b04c80c26a79b8e801b8b6e1", + "prevouts_hash": "445bc6328cd33b3c86259953dd674bded341ff1e1104dc21856919e9761036dd", + "sequence_hash": "42e1d5c2636f165afaa954afa6d7a50779eb145e947bf668f1a40dd771c711fc", + "outputs_hash": "869eda84eecf7257f9979a4848bbf52f4969a5736594ab7ba41452e7bb906824", + "preimage_hash": "7f6b5439a64b20faf6f9f9460bc75c333c4799e9b04c80c26a79b8e801b8b6e1", }, { "expiry": 254788522, @@ -135,10 +135,10 @@ class TestZcashZip243(unittest.TestCase): "version": 4, "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, - "prevouts_hash": b"509abdfafcc75265037f1ce6a4658ac9ecadd7b82378c3fbaeb48ab437ff6898", - "sequence_hash": b"2b13f671cd1a9aa04c1e250eef74a316d7d2b049360d20604514ddc2dfacfd23", - "outputs_hash": b"4f01b8785e80779290aa86c16b24952f9b7f8bc09da44e68f760ab1920ab8f2a", - "preimage_hash": b"46152b79ebeba4089d05724e33d4a5e6d6ea9e3a2fe777af6644318ba93a1ca0", + "prevouts_hash": "509abdfafcc75265037f1ce6a4658ac9ecadd7b82378c3fbaeb48ab437ff6898", + "sequence_hash": "2b13f671cd1a9aa04c1e250eef74a316d7d2b049360d20604514ddc2dfacfd23", + "outputs_hash": "4f01b8785e80779290aa86c16b24952f9b7f8bc09da44e68f760ab1920ab8f2a", + "preimage_hash": "46152b79ebeba4089d05724e33d4a5e6d6ea9e3a2fe777af6644318ba93a1ca0", }, # "Test vector 3" from https://github.com/zcash/zips/blob/master/zip-0243.rst { @@ -169,10 +169,10 @@ class TestZcashZip243(unittest.TestCase): "version": 4, "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, - "prevouts_hash": b"fae31b8dec7b0b77e2c8d6b6eb0e7e4e55abc6574c26dd44464d9408a8e33f11", - "sequence_hash": b"6c80d37f12d89b6f17ff198723e7db1247c4811d1a695d74d930f99e98418790", - "outputs_hash": b"d2b04118469b7810a0d1cc59568320aad25a84f407ecac40b4f605a4e6868454", - "preimage_hash": b"6c210ce6417539d4aa9546f6184e33ca89224ac4559d2a9c4cf090b646692bd9", + "prevouts_hash": "fae31b8dec7b0b77e2c8d6b6eb0e7e4e55abc6574c26dd44464d9408a8e33f11", + "sequence_hash": "6c80d37f12d89b6f17ff198723e7db1247c4811d1a695d74d930f99e98418790", + "outputs_hash": "d2b04118469b7810a0d1cc59568320aad25a84f407ecac40b4f605a4e6868454", + "preimage_hash": "6c210ce6417539d4aa9546f6184e33ca89224ac4559d2a9c4cf090b646692bd9", }, ] @@ -196,7 +196,7 @@ def test_zip243(self): for i in v["inputs"]: txi = TxInput( amount=i["amount"], - prev_hash=unhexlify(i["prevout"][0]), + prev_hash=bytes.fromhex(i["prevout"][0]), prev_index=i["prevout"][1], script_type=i["script_type"], sequence=i["sequence"], @@ -206,28 +206,22 @@ def test_zip243(self): for o in v["outputs"]: txo = PrevOutput( amount=o["amount"], - script_pubkey=unhexlify(o["script_pubkey"]), + script_pubkey=bytes.fromhex(o["script_pubkey"]), ) zip243.add_output(txo, txo.script_pubkey) + self.assertEqual(get_tx_hash(zip243.h_prevouts).hex(), v["prevouts_hash"]) + self.assertEqual(get_tx_hash(zip243.h_sequence).hex(), v["sequence_hash"]) + self.assertEqual(get_tx_hash(zip243.h_outputs).hex(), v["outputs_hash"]) self.assertEqual( - hexlify(get_tx_hash(zip243.h_prevouts)), v["prevouts_hash"] - ) - self.assertEqual( - hexlify(get_tx_hash(zip243.h_sequence)), v["sequence_hash"] - ) - self.assertEqual(hexlify(get_tx_hash(zip243.h_outputs)), v["outputs_hash"]) - self.assertEqual( - hexlify( - zip243.hash143( - txi, - [unhexlify(i["pubkey"])], - 1, - tx, - coin, - SigHashType.SIGHASH_ALL, - ) - ), + zip243.hash143( + txi, + [bytes.fromhex(i["pubkey"])], + 1, + tx, + coin, + SigHashType.SIGHASH_ALL, + ).hex(), v["preimage_hash"], ) diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index 63dc5001da1..2591e28e4d1 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -61,22 +61,22 @@ def test_hardened_address_derivation_scheme(self): nodes = [ ( - b"3881a8de77d069001010d7f7d5211552e7d539b0e253add710367f95e528ed51", - b"9b77608b38e0a0c7861aa234557c81482f42aae2d17993a8ddaec1868fb04d60", - b"a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", - b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", + "3881a8de77d069001010d7f7d5211552e7d539b0e253add710367f95e528ed51", + "9b77608b38e0a0c7861aa234557c81482f42aae2d17993a8ddaec1868fb04d60", + "a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", + "cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", ), ( - b"3003aca659846540b9ed04f2b844f2d8ea964856ca38a7dffedef4f6e528ed51", - b"8844ccc81d633e1c7126f30c2524c1652617cf58da755014070215bf5070ba38", - b"be28c00ed6cb9b70310f78028f8e3a2db935baf482d84afa590b0b5b864571cc", - b"584b4631d752023a249e980779517280e6c0b3ac7a7f27c6e9456bfd228ca60b", + "3003aca659846540b9ed04f2b844f2d8ea964856ca38a7dffedef4f6e528ed51", + "8844ccc81d633e1c7126f30c2524c1652617cf58da755014070215bf5070ba38", + "be28c00ed6cb9b70310f78028f8e3a2db935baf482d84afa590b0b5b864571cc", + "584b4631d752023a249e980779517280e6c0b3ac7a7f27c6e9456bfd228ca60b", ), ( - b"68e4482add0a741e14c8f2306bf83206a623e3729dd24175915eedece428ed51", - b"3165a80c5efe846224d46a0427cdb2be4f31ea3585c51f4131faefc4328ad95a", - b"9a32499976ffb582daa9988dfc42a303de5ed00c320c929f496be3c6eb1cf405", - b"da07ca30a3d1c5fe3c34ce5fa197722446a646624a10bdf8889a4b9c347b2ef2", + "68e4482add0a741e14c8f2306bf83206a623e3729dd24175915eedece428ed51", + "3165a80c5efe846224d46a0427cdb2be4f31ea3585c51f4131faefc4328ad95a", + "9a32499976ffb582daa9988dfc42a303de5ed00c320c929f496be3c6eb1cf405", + "da07ca30a3d1c5fe3c34ce5fa197722446a646624a10bdf8889a4b9c347b2ef2", ), ] @@ -84,10 +84,10 @@ def test_hardened_address_derivation_scheme(self): n = self.keychain.derive( [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000 + i] ) - self.assertEqual(hexlify(n.private_key()), priv) - self.assertEqual(hexlify(n.private_key_ext()), ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) - self.assertEqual(hexlify(n.chain_code()), chain) + self.assertEqual(n.private_key().hex(), priv) + self.assertEqual(n.private_key_ext().hex(), ext) + self.assertEqual(seed.remove_ed25519_prefix(n.public_key()).hex(), pub) + self.assertEqual(n.chain_code().hex(), chain) def test_non_hardened_address_derivation_scheme(self): addresses = [ @@ -112,22 +112,22 @@ def test_non_hardened_address_derivation_scheme(self): nodes = [ ( - b"d03ba81163fd55af97bd132bf651a0da5b5e6201b15b1caca60b0be8e028ed51", - b"493f44aa8d25fe0d3fe2935c76ea6b3e9e41c79e9dbcbe7131357c5aa1b6cac5", - b"b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", - b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", + "d03ba81163fd55af97bd132bf651a0da5b5e6201b15b1caca60b0be8e028ed51", + "493f44aa8d25fe0d3fe2935c76ea6b3e9e41c79e9dbcbe7131357c5aa1b6cac5", + "b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", + "fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", ), ( - b"08b6438c8dd49d34b71c8e914d6ac3184e5ab3dcc8af023d08503a7edf28ed51", - b"3fee605fdfaddc1ee2ea0b246b02c9abc54ad741054bc83943e8b21487b5a053", - b"89053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea", - b"26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a635", + "08b6438c8dd49d34b71c8e914d6ac3184e5ab3dcc8af023d08503a7edf28ed51", + "3fee605fdfaddc1ee2ea0b246b02c9abc54ad741054bc83943e8b21487b5a053", + "89053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea", + "26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a635", ), ( - b"088f0275bf4a1bd18f08d7ef06c6ddb6ce7e3dc415fb4e89fe21bf39e628ed51", - b"4c44563c7df519ea9b4d1801c1ab98b449db28b87f1c3837759c20f68c4c1e65", - b"52548cb98e6f46a592bdf7f3598a9abc0126c78dfa3f46d1894ee52a5213e833", - b"91af0668ee449e613e61bbb2482e5ddee1d9b15785727ec3e362c36861bff923", + "088f0275bf4a1bd18f08d7ef06c6ddb6ce7e3dc415fb4e89fe21bf39e628ed51", + "4c44563c7df519ea9b4d1801c1ab98b449db28b87f1c3837759c20f68c4c1e65", + "52548cb98e6f46a592bdf7f3598a9abc0126c78dfa3f46d1894ee52a5213e833", + "91af0668ee449e613e61bbb2482e5ddee1d9b15785727ec3e362c36861bff923", ), ] @@ -135,10 +135,10 @@ def test_non_hardened_address_derivation_scheme(self): n = self.keychain.derive( [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i] ) - self.assertEqual(hexlify(n.private_key()), priv) - self.assertEqual(hexlify(n.private_key_ext()), ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) - self.assertEqual(hexlify(n.chain_code()), chain) + self.assertEqual(n.private_key().hex(), priv) + self.assertEqual(n.private_key_ext().hex(), ext) + self.assertEqual(seed.remove_ed25519_prefix(n.public_key()).hex(), pub) + self.assertEqual(n.chain_code().hex(), chain) def test_root_address_derivation_scheme(self): # 44'/1815' @@ -157,17 +157,17 @@ def test_root_address_derivation_scheme(self): ) priv, ext, pub, chain = ( - b"204ec79cbb6502a141de60d274962010c7f1c94a2987b26506433184d228ed51", - b"975cdd1c8610b44701567f05934c45c8716064263ccfe72ed2167ccb705c09b6", - b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", - b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", + "204ec79cbb6502a141de60d274962010c7f1c94a2987b26506433184d228ed51", + "975cdd1c8610b44701567f05934c45c8716064263ccfe72ed2167ccb705c09b6", + "8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", + "02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", ) n = self.keychain.derive([0x80000000 | 44, 0x80000000 | 1815]) - self.assertEqual(hexlify(n.private_key()), priv) - self.assertEqual(hexlify(n.private_key_ext()), ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) - self.assertEqual(hexlify(n.chain_code()), chain) + self.assertEqual(n.private_key().hex(), priv) + self.assertEqual(n.private_key_ext().hex(), ext) + self.assertEqual(seed.remove_ed25519_prefix(n.public_key()).hex(), pub) + self.assertEqual(n.chain_code().hex(), chain) def test_address_hash(self): data = [ @@ -203,17 +203,15 @@ def test_slip39_128(self): node = cardano.from_seed_slip23(master_secret) # Check root node. - root_priv = b"c0fe4a6973df4de06262693fc9186f71faf292960350882d49456bf108d13954" - root_ext = b"4064253ffefc4127489bce1b825a47329010c5afb4d21154ef949ef786204405" - root_pub = b"83e3ecaf57f90f022c45e10d1b8cb78499c30819515ad9a81ad82139fdb12a90" - root_chain = b"22c12755afdd192742613b3062069390743ea232bc1b366c8f41e37292af9305" + root_priv = "c0fe4a6973df4de06262693fc9186f71faf292960350882d49456bf108d13954" + root_ext = "4064253ffefc4127489bce1b825a47329010c5afb4d21154ef949ef786204405" + root_pub = "83e3ecaf57f90f022c45e10d1b8cb78499c30819515ad9a81ad82139fdb12a90" + root_chain = "22c12755afdd192742613b3062069390743ea232bc1b366c8f41e37292af9305" - self.assertEqual(hexlify(node.private_key()), root_priv) - self.assertEqual(hexlify(node.private_key_ext()), root_ext) - self.assertEqual( - hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub - ) - self.assertEqual(hexlify(node.chain_code()), root_chain) + self.assertEqual(node.private_key().hex(), root_priv) + self.assertEqual(node.private_key_ext().hex(), root_ext) + self.assertEqual(seed.remove_ed25519_prefix(node.public_key()).hex(), root_pub) + self.assertEqual(node.chain_code().hex(), root_chain) # Check derived nodes and addresses. keychain = Keychain(node) @@ -221,24 +219,24 @@ def test_slip39_128(self): nodes = [ ( "Ae2tdPwUPEYxF9NAMNdd3v2LZoMeWp7gCZiDb6bZzFQeeVASzoP7HC4V9s6", - b"e0acfe234aa6e1219ce7d3d8d91853e0808bab92ecb8a0ff0f345ff31ad13954", - b"ff89dc71365c4b67bb7bb75d566e65b8a95f16e4d70cce51c25937db15614530", - b"bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", - b"dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", + "e0acfe234aa6e1219ce7d3d8d91853e0808bab92ecb8a0ff0f345ff31ad13954", + "ff89dc71365c4b67bb7bb75d566e65b8a95f16e4d70cce51c25937db15614530", + "bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", + "dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", ), ( "Ae2tdPwUPEZ1TjYcvfkWAbiHtGVxv4byEHHZoSyQXjPJ362DifCe1ykgqgy", - b"d0ce3e7a6445bc91801319b9bbaf47fdfca9364257295fb13bc5046a20d13954", - b"c800359abdc875944754ae7368bab7ef75184d48816c368f5a28af4bcf1d1ee8", - b"24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", - b"6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", + "d0ce3e7a6445bc91801319b9bbaf47fdfca9364257295fb13bc5046a20d13954", + "c800359abdc875944754ae7368bab7ef75184d48816c368f5a28af4bcf1d1ee8", + "24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", + "6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", ), ( "Ae2tdPwUPEZGXmSbda1kBNfyhRQGRcQxJFdk7mhWZXAGnapyejv2b2U3aRb", - b"e8320644cce22a6e9fc33865fc5a598b1cda061c47a548aead3af4ed1cd13954", - b"9e2ece5d7fe8119cb76090009be926a84fc5d3b95855b5962ffe2f880836cf09", - b"831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", - b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", + "e8320644cce22a6e9fc33865fc5a598b1cda061c47a548aead3af4ed1cd13954", + "9e2ece5d7fe8119cb76090009be926a84fc5d3b95855b5962ffe2f880836cf09", + "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", + "672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", ), ] @@ -256,10 +254,10 @@ def test_slip39_128(self): ) n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i]) self.assertEqual(a, address) - self.assertEqual(hexlify(n.private_key()), priv) - self.assertEqual(hexlify(n.private_key_ext()), ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) - self.assertEqual(hexlify(n.chain_code()), chain) + self.assertEqual(n.private_key().hex(), priv) + self.assertEqual(n.private_key_ext().hex(), ext) + self.assertEqual(seed.remove_ed25519_prefix(n.public_key()).hex(), pub) + self.assertEqual(n.chain_code().hex(), chain) def test_slip39_256(self): mnemonics = [ @@ -279,17 +277,15 @@ def test_slip39_256(self): node = cardano.from_seed_slip23(master_secret) # Check root node. - root_priv = b"90633724b5daf770a8b420b8658e7d8bc21e066b60ec8cd4d5730681cc294e4f" - root_ext = b"f9d99bf3cd9c7e12663e8646afa40cb3aecf15d91f2abc15d21056c6bccb3414" - root_pub = b"eea170f0ef97b59d22907cb429888029721ed67d3e7a1b56b81731086ab7db64" - root_chain = b"04f1de750b62725fcc1ae1b93ca4063acb53c486b959cadaa100ebd7828e5460" + root_priv = "90633724b5daf770a8b420b8658e7d8bc21e066b60ec8cd4d5730681cc294e4f" + root_ext = "f9d99bf3cd9c7e12663e8646afa40cb3aecf15d91f2abc15d21056c6bccb3414" + root_pub = "eea170f0ef97b59d22907cb429888029721ed67d3e7a1b56b81731086ab7db64" + root_chain = "04f1de750b62725fcc1ae1b93ca4063acb53c486b959cadaa100ebd7828e5460" - self.assertEqual(hexlify(node.private_key()), root_priv) - self.assertEqual(hexlify(node.private_key_ext()), root_ext) - self.assertEqual( - hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub - ) - self.assertEqual(hexlify(node.chain_code()), root_chain) + self.assertEqual(node.private_key().hex(), root_priv) + self.assertEqual(node.private_key_ext().hex(), root_ext) + self.assertEqual(seed.remove_ed25519_prefix(node.public_key()).hex(), root_pub) + self.assertEqual(node.chain_code().hex(), root_chain) # Check derived nodes and addresses. keychain = Keychain(node) @@ -297,24 +293,24 @@ def test_slip39_256(self): nodes = [ ( "Ae2tdPwUPEYyDD1C2FbVJFAE3FuAxLspfMYt29TJ1urnSKr57cVhEcioSCC", - b"38e8a4b17ca07b6a309f1cee83f87593e34a1fc3a289785ea451ef65df294e4f", - b"405d10ef71c2b0019250d11837de8db825d8556bf1e57f8866920af6d8c90002", - b"967a9a041ad1379e31c2c7f2aa4bc2b3f7769341c0ea89ccfb12a904f2e10877", - b"7b15d8d9006afe3cd7e04f375a1126a8c7c7c07c59a6f0c5b0310f4245f4edbb", + "38e8a4b17ca07b6a309f1cee83f87593e34a1fc3a289785ea451ef65df294e4f", + "405d10ef71c2b0019250d11837de8db825d8556bf1e57f8866920af6d8c90002", + "967a9a041ad1379e31c2c7f2aa4bc2b3f7769341c0ea89ccfb12a904f2e10877", + "7b15d8d9006afe3cd7e04f375a1126a8c7c7c07c59a6f0c5b0310f4245f4edbb", ), ( "Ae2tdPwUPEZHJGtyz47F6wD7qAegt1JNRJWuiE36QLvFzeqJPBZ2EBvhr8M", - b"a09f90e3f76a7bdb7f8721cc0c142dbd6398fd704b83455e123fa886dc294e4f", - b"917e4166bb404def9f12634e84ecbcb98afdea051ba7c38745e208178a9e9baf", - b"6f3805bbc1b7a75afa95dffec331671f3c4662800615e80d2ec1202a9d874c86", - b"44baf30fd549e6a1e05f99c2a2c8971aea8894ee8d9c5fc2c5ae6ee839a56b2d", + "a09f90e3f76a7bdb7f8721cc0c142dbd6398fd704b83455e123fa886dc294e4f", + "917e4166bb404def9f12634e84ecbcb98afdea051ba7c38745e208178a9e9baf", + "6f3805bbc1b7a75afa95dffec331671f3c4662800615e80d2ec1202a9d874c86", + "44baf30fd549e6a1e05f99c2a2c8971aea8894ee8d9c5fc2c5ae6ee839a56b2d", ), ( "Ae2tdPwUPEYxD9xNPBJTzYmtFVVWEPB6KW4TCDijQ4pDwU11wt5621PyCi4", - b"78dd824aea33bed5c1502d1a17f11a4adbe923aac1cd1f7ae98c9506db294e4f", - b"ddfe7f27e2894b983df773d8ac2a07973fc37ff36e93a2f2d71fb7327d4e18f4", - b"7f145b50ef07fb9accc40ee07a01fe93ceb6fa07d5a9f20fc3c8a48246dd4d02", - b"e67d2864614ada5eec8fb8ee1225a94a6fb0a1b3c347c854ec3037351c6a0fc7", + "78dd824aea33bed5c1502d1a17f11a4adbe923aac1cd1f7ae98c9506db294e4f", + "ddfe7f27e2894b983df773d8ac2a07973fc37ff36e93a2f2d71fb7327d4e18f4", + "7f145b50ef07fb9accc40ee07a01fe93ceb6fa07d5a9f20fc3c8a48246dd4d02", + "e67d2864614ada5eec8fb8ee1225a94a6fb0a1b3c347c854ec3037351c6a0fc7", ), ] @@ -332,10 +328,10 @@ def test_slip39_256(self): ) n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i]) self.assertEqual(a, address) - self.assertEqual(hexlify(n.private_key()), priv) - self.assertEqual(hexlify(n.private_key_ext()), ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) - self.assertEqual(hexlify(n.chain_code()), chain) + self.assertEqual(n.private_key().hex(), priv) + self.assertEqual(n.private_key_ext().hex(), ext) + self.assertEqual(seed.remove_ed25519_prefix(n.public_key()).hex(), pub) + self.assertEqual(n.chain_code().hex(), chain) def test_testnet_byron_address(self): addresses = [ @@ -371,7 +367,7 @@ def test_derive_address(self): "BASE_OWN_STAKING_KEY_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" ), ), @@ -379,7 +375,7 @@ def test_derive_address(self): "BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277" ), ), @@ -387,7 +383,7 @@ def test_derive_address(self): "BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_0": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277" ), ), @@ -400,23 +396,23 @@ def test_derive_address(self): 2, 0, ], - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), ), "BASE_KEY_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE_KEY_SCRIPT, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - script_staking_hash=unhexlify( + script_staking_hash=bytes.fromhex( "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" ), ), "BASE_SCRIPT_SCRIPT_HASHES": CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), - script_staking_hash=unhexlify( + script_staking_hash=bytes.fromhex( "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" ), ), @@ -439,7 +435,7 @@ def test_derive_address(self): certificate_pointer=CardanoBlockchainPointerType( block_index=24157, tx_index=177, certificate_index=42 ), - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), ), @@ -449,7 +445,7 @@ def test_derive_address(self): ), "ENTERPRISE_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.ENTERPRISE_SCRIPT, - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), ), @@ -465,7 +461,7 @@ def test_derive_address(self): ), "REWARD_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.REWARD_SCRIPT, - script_staking_hash=unhexlify( + script_staking_hash=bytes.fromhex( "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" ), ), @@ -667,7 +663,7 @@ def test_validate_address_parameters(self): 2, 0, ], - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" ), ), @@ -676,7 +672,7 @@ def test_validate_address_parameters(self): address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n_staking=None, - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d" ), ), @@ -697,14 +693,14 @@ def test_validate_address_parameters(self): CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_KEY, script_payment_hash=None, - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d" ), ), # base_script_key address - address_n_staking is not a staking path CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_KEY, - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), address_n_staking=[ @@ -725,14 +721,14 @@ def test_validate_address_parameters(self): CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, script_payment_hash=None, - script_staking_hash=unhexlify( + script_staking_hash=bytes.fromhex( "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" ), ), # base_script_script address - script_staking and script_staking_hash are None CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), script_staking_hash=None, @@ -746,7 +742,7 @@ def test_validate_address_parameters(self): # pointer_script address - pointer is None CardanoAddressParametersType( address_type=CardanoAddressType.POINTER_SCRIPT, - script_payment_hash=unhexlify( + script_payment_hash=bytes.fromhex( "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" ), certificate_pointer=None, @@ -778,14 +774,14 @@ def test_validate_address_parameters(self): CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - staking_key_hash=unhexlify( + staking_key_hash=bytes.fromhex( "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" ), ), CardanoAddressParametersType( address_type=CardanoAddressType.BASE_KEY_SCRIPT, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - script_staking_hash=unhexlify( + script_staking_hash=bytes.fromhex( "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" ), ), diff --git a/core/tests/test_apps.cardano.certificate.py b/core/tests/test_apps.cardano.certificate.py index 198d5e7444b..d14d2c23aff 100644 --- a/core/tests/test_apps.cardano.certificate.py +++ b/core/tests/test_apps.cardano.certificate.py @@ -27,13 +27,13 @@ def test_validate_certificate(self): ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -44,14 +44,14 @@ def test_validate_certificate(self): ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -59,25 +59,25 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), @@ -87,13 +87,13 @@ def test_validate_certificate(self): ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -104,14 +104,14 @@ def test_validate_certificate(self): ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, ), CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -119,10 +119,10 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_POOL_REGISTRATION, pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -137,38 +137,38 @@ def test_validate_certificate(self): ), CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.KEY_HASH, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), ), CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.SCRIPT_HASH, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), ), CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep(type=CardanoDRepType.ABSTAIN), ), CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep(type=CardanoDRepType.NO_CONFIDENCE), @@ -184,17 +184,17 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), # STAKE_REGISTRATION both script_hash and key_hash are set CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -202,7 +202,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), @@ -217,10 +217,10 @@ def test_validate_certificate(self): type=CardanoCertificateType.STAKE_REGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -241,7 +241,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -249,10 +249,10 @@ def test_validate_certificate(self): # STAKE_REGISTRATION_CONWAY both script_hash and key_hash are set CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -261,7 +261,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), deposit=2000000, @@ -276,10 +276,10 @@ def test_validate_certificate(self): type=CardanoCertificateType.STAKE_REGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -295,7 +295,7 @@ def test_validate_certificate(self): # STAKE_DELEGATION neither path or script_hash is set CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), @@ -303,23 +303,23 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), # STAKE_DELEGATION both script_hash and key_hash are set CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), @@ -327,14 +327,14 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DELEGATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -354,17 +354,17 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), # STAKE_DEREGISTRATION both script_hash and key_hash are set CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -372,7 +372,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), ), @@ -387,10 +387,10 @@ def test_validate_certificate(self): type=CardanoCertificateType.STAKE_DEREGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -411,7 +411,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -419,10 +419,10 @@ def test_validate_certificate(self): # STAKE_DEREGISTRATION_CONWAY both script_hash and key_hash are set CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), deposit=2000000, @@ -431,7 +431,7 @@ def test_validate_certificate(self): CardanoTxCertificate( type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), deposit=2000000, @@ -446,10 +446,10 @@ def test_validate_certificate(self): type=CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -471,10 +471,10 @@ def test_validate_certificate(self): type=CardanoCertificateType.STAKE_POOL_REGISTRATION, path=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -489,14 +489,14 @@ def test_validate_certificate(self): # STAKE_POOL_REGISTRATION script hash is set CardanoTxCertificate( type=CardanoCertificateType.STAKE_POOL_REGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -511,14 +511,14 @@ def test_validate_certificate(self): # STAKE_POOL_REGISTRATION key hash is set CardanoTxCertificate( type=CardanoCertificateType.STAKE_POOL_REGISTRATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -533,17 +533,17 @@ def test_validate_certificate(self): # STAKE_POOL_REGISTRATION pool is set CardanoTxCertificate( type=CardanoCertificateType.STAKE_POOL_REGISTRATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - pool=unhexlify( + pool=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), pool_parameters=CardanoPoolParametersType( - pool_id=unhexlify( + pool_id=bytes.fromhex( "f61c42cbf7c8c53af3f520508212ad3e72f674f957fe23ff0acb4973" ), - vrf_key_hash=unhexlify( + vrf_key_hash=bytes.fromhex( "198890ad6c92e80fbdab554dda02da9fb49d001bbd96181f3e07f7a6ab0d0640" ), pledge=500000000, @@ -558,14 +558,14 @@ def test_validate_certificate(self): # VOTE_REGISTRATION missing drep CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), # VOTE_REGISTRATION missing key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep(type=CardanoDRepType.KEY_HASH), @@ -573,7 +573,7 @@ def test_validate_certificate(self): # VOTE_REGISTRATION missing script hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep(type=CardanoDRepType.SCRIPT_HASH), @@ -581,12 +581,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected script hash set instead of key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.KEY_HASH, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -594,12 +594,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected key hash set instead of script hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.SCRIPT_HASH, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -607,15 +607,15 @@ def test_validate_certificate(self): # VOTE_REGISTRATION key hash set but unexpected script hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.KEY_HASH, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -623,15 +623,15 @@ def test_validate_certificate(self): # VOTE_REGISTRATION script hash set but unexpected key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.SCRIPT_HASH, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -639,12 +639,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.ABSTAIN, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -652,12 +652,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.NO_CONFIDENCE, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -665,12 +665,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected script hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.ABSTAIN, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -678,12 +678,12 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected script hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.NO_CONFIDENCE, - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -691,15 +691,15 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected script hash and key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.ABSTAIN, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), @@ -707,15 +707,15 @@ def test_validate_certificate(self): # VOTE_REGISTRATION unexpected script hash and key hash CardanoTxCertificate( type=CardanoCertificateType.VOTE_DELEGATION, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), drep=CardanoDRep( type=CardanoDRepType.NO_CONFIDENCE, - key_hash=unhexlify( + key_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), - script_hash=unhexlify( + script_hash=bytes.fromhex( "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" ), ), diff --git a/core/tests/test_apps.cardano.get_public_key.py b/core/tests/test_apps.cardano.get_public_key.py index be487b5d018..f5f55a8d660 100644 --- a/core/tests/test_apps.cardano.get_public_key.py +++ b/core/tests/test_apps.cardano.get_public_key.py @@ -34,25 +34,25 @@ def test_get_public_key_scheme_12_words(self): ] public_keys = [ - b"a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", - b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", - b"17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791", - b"b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", - b"f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e0211", - b"e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf6647", - b"6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370", - b"5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1", + "a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", + "8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", + "17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791", + "b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", + "f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e0211", + "e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf6647", + "6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370", + "5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1", ] chain_codes = [ - b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", - b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", - b"646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d", - b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", - b"13cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636", - b"58f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52", - b"f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66", - b"f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088", + "cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", + "02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", + "646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d", + "fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", + "13cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636", + "58f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52", + "f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66", + "f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088", ] xpub_keys = [ @@ -69,8 +69,8 @@ def test_get_public_key_scheme_12_words(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) def test_get_public_key_scheme_18_words(self): @@ -84,13 +84,13 @@ def test_get_public_key_scheme_18_words(self): ] public_keys = [ - b"82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0", - b"d92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90", + "82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0", + "d92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90", ] chain_codes = [ - b"974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f", - b"352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b", + "974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f", + "352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b", ] xpub_keys = [ @@ -101,8 +101,8 @@ def test_get_public_key_scheme_18_words(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) def test_get_public_key_scheme_24_words(self): @@ -116,13 +116,13 @@ def test_get_public_key_scheme_24_words(self): ] public_keys = [ - b"9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6", - b"a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8", + "9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6", + "a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8", ] chain_codes = [ - b"aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a", - b"e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219", + "aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a", + "e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219", ] xpub_keys = [ @@ -133,8 +133,8 @@ def test_get_public_key_scheme_24_words(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) def test_slip39_128(self): @@ -164,15 +164,15 @@ def test_slip39_128(self): ] public_keys = [ - b"bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", - b"24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", - b"831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", + "bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", + "24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", + "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", ] chain_codes = [ - b"dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", - b"6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", - b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", + "dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", + "6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", + "672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", ] xpub_keys = [ @@ -184,8 +184,8 @@ def test_slip39_128(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) def test_slip39_256(self): @@ -215,15 +215,15 @@ def test_slip39_256(self): ] public_keys = [ - b"967a9a041ad1379e31c2c7f2aa4bc2b3f7769341c0ea89ccfb12a904f2e10877", - b"6f3805bbc1b7a75afa95dffec331671f3c4662800615e80d2ec1202a9d874c86", - b"7f145b50ef07fb9accc40ee07a01fe93ceb6fa07d5a9f20fc3c8a48246dd4d02", + "967a9a041ad1379e31c2c7f2aa4bc2b3f7769341c0ea89ccfb12a904f2e10877", + "6f3805bbc1b7a75afa95dffec331671f3c4662800615e80d2ec1202a9d874c86", + "7f145b50ef07fb9accc40ee07a01fe93ceb6fa07d5a9f20fc3c8a48246dd4d02", ] chain_codes = [ - b"7b15d8d9006afe3cd7e04f375a1126a8c7c7c07c59a6f0c5b0310f4245f4edbb", - b"44baf30fd549e6a1e05f99c2a2c8971aea8894ee8d9c5fc2c5ae6ee839a56b2d", - b"e67d2864614ada5eec8fb8ee1225a94a6fb0a1b3c347c854ec3037351c6a0fc7", + "7b15d8d9006afe3cd7e04f375a1126a8c7c7c07c59a6f0c5b0310f4245f4edbb", + "44baf30fd549e6a1e05f99c2a2c8971aea8894ee8d9c5fc2c5ae6ee839a56b2d", + "e67d2864614ada5eec8fb8ee1225a94a6fb0a1b3c347c854ec3037351c6a0fc7", ] xpub_keys = [ @@ -235,8 +235,8 @@ def test_slip39_256(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) diff --git a/core/tests/test_apps.cardano.native_script.py b/core/tests/test_apps.cardano.native_script.py index 5385d0ee16d..11038faffe1 100644 --- a/core/tests/test_apps.cardano.native_script.py +++ b/core/tests/test_apps.cardano.native_script.py @@ -18,11 +18,11 @@ [ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" ), ), - b"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd", + "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd", ], # PUB_KEY with path [ @@ -30,7 +30,7 @@ type=CardanoNativeScriptType.PUB_KEY, key_path=[1854 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], ), - b"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd", + "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd", ], # ALL [ @@ -43,13 +43,13 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), ], ), - b"af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6", + "af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6", ], # ALL with 1855 path [ @@ -62,18 +62,18 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), ], ), - b"fbf6672eb655c29b0f148fa1429be57c2174b067a7b3e3942e967fe8", + "fbf6672eb655c29b0f148fa1429be57c2174b067a7b3e3942e967fe8", ], # ALL scripts are empty [ CardanoNativeScript(type=CardanoNativeScriptType.ALL, scripts=[]), - b"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf", + "d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf", ], # ANY [ @@ -86,18 +86,18 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), ], ), - b"d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db", + "d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db", ], # ANY scripts are empty [ CardanoNativeScript(type=CardanoNativeScriptType.ANY, scripts=[]), - b"52dc3d43b6d2465e96109ce75ab61abe5e9c1d8a3c9ce6ff8a3af528", + "52dc3d43b6d2465e96109ce75ab61abe5e9c1d8a3c9ce6ff8a3af528", ], # N OF K [ @@ -111,19 +111,19 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" ), ), ], ), - b"2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9", + "2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9", ], # N_OF_K scripts are empty [ @@ -132,7 +132,7 @@ required_signatures_count=0, scripts=[], ), - b"3530cc9ae7f2895111a99b7a02184dd7c0cea7424f1632d73951b1d7", + "3530cc9ae7f2895111a99b7a02184dd7c0cea7424f1632d73951b1d7", ], # INVALID BEFORE [ @@ -141,7 +141,7 @@ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" ), ), @@ -150,7 +150,7 @@ ), ], ), - b"c6262ef9bb2b1291c058d93b46dabf458e2d135f803f60713f84b0b7", + "c6262ef9bb2b1291c058d93b46dabf458e2d135f803f60713f84b0b7", ], # INVALID HEREAFTER [ @@ -159,7 +159,7 @@ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" ), ), @@ -169,7 +169,7 @@ ), ], ), - b"b12ac304f89f4cd4d23f59a2b90d2b2697f7540b8f470d6aa05851b5", + "b12ac304f89f4cd4d23f59a2b90d2b2697f7540b8f470d6aa05851b5", ], # NESTED SCRIPT [ @@ -178,7 +178,7 @@ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" ), ), @@ -201,7 +201,7 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), @@ -223,13 +223,13 @@ ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" ), ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" ), ), @@ -244,7 +244,7 @@ ), ], ), - b"4a6b4288459bf34668c0b281f922691460caf0c7c09caee3a726c27a", + "4a6b4288459bf34668c0b281f922691460caf0c7c09caee3a726c27a", ], ] @@ -252,7 +252,7 @@ # PUB_KEY key_hash has invalid length CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "3a55d9f68255dfbefa1efd711f82d005fae1be2e145d616c90cf0f" ), ), @@ -272,7 +272,7 @@ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "3a55d9f68255dfbefa1efd711f82d005fae1be2e145d616c90cf0fa9" ), ), @@ -285,7 +285,7 @@ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_hash=unhexlify( + key_hash=bytes.fromhex( "3a55d9f68255dfbefa1efd711f82d005fae1be2e145d616c90cf0fa9" ), ), @@ -310,7 +310,7 @@ def test_get_native_script_hash(self): for script, expected_hash in VALID_NATIVE_SCRIPTS: actual_hash = get_native_script_hash(keychain, script) - self.assertEqual(hexlify(actual_hash), expected_hash) + self.assertEqual(actual_hash.hex(), expected_hash) def test_validate_native_script(self): for script, _ in VALID_NATIVE_SCRIPTS: diff --git a/core/tests/test_apps.cardano.seed.py b/core/tests/test_apps.cardano.seed.py index 94cec6fdc99..1e51cdd4e6c 100644 --- a/core/tests/test_apps.cardano.seed.py +++ b/core/tests/test_apps.cardano.seed.py @@ -31,21 +31,21 @@ def test_various_paths_at_once(self): ] public_keys = [ - b"badd2852ccda7492364be0f88f2ba0b78c5f2d7179a941f1d19f756112b66afa", - b"34377409140c061d76778626d43456880d5471c1cbade8c372cb6a3be9678072", - b"73fea80d424276ad0978d4fe5310e8bc2d485f5f6bb3bf87612989f112ad5a7d", - b"f626ab887eb5f40b502463ccf2ec5a7311676ee9e5d55c492059a366c0b4d4a1", - b"408ee7b2d1c84d7899dba07150fae88c5411974f1762cb659dd928db8aac206b", - b"86e8a3880767e1ed521a47de1e031d47f33d5a8095be467bffbbd3295e27258e", + "badd2852ccda7492364be0f88f2ba0b78c5f2d7179a941f1d19f756112b66afa", + "34377409140c061d76778626d43456880d5471c1cbade8c372cb6a3be9678072", + "73fea80d424276ad0978d4fe5310e8bc2d485f5f6bb3bf87612989f112ad5a7d", + "f626ab887eb5f40b502463ccf2ec5a7311676ee9e5d55c492059a366c0b4d4a1", + "408ee7b2d1c84d7899dba07150fae88c5411974f1762cb659dd928db8aac206b", + "86e8a3880767e1ed521a47de1e031d47f33d5a8095be467bffbbd3295e27258e", ] chain_codes = [ - b"e1c5d15875d3ed68667978af38fe3fe586511d87a784c0962a333c21e63a865d", - b"15c987276326a82defa4cb6762d43442f09e5dcbcc37fa0c58f24ae2dba3d3eb", - b"dd75e154da417becec55cdd249327454138f082110297d5e87ab25e15fad150f", - b"f7ab126f2884db9059fa09ca83be6b8bd0250426aeb62191bdd9861457b8bc91", - b"18d5c9d20c8d23bed068c9ff3a1126b940f0e537f9d94891828a999dda6fafd1", - b"580bba4bb0b9c56974e16a6998322a91e857e2fac28674404da993f6197fd29f", + "e1c5d15875d3ed68667978af38fe3fe586511d87a784c0962a333c21e63a865d", + "15c987276326a82defa4cb6762d43442f09e5dcbcc37fa0c58f24ae2dba3d3eb", + "dd75e154da417becec55cdd249327454138f082110297d5e87ab25e15fad150f", + "f7ab126f2884db9059fa09ca83be6b8bd0250426aeb62191bdd9861457b8bc91", + "18d5c9d20c8d23bed068c9ff3a1126b940f0e537f9d94891828a999dda6fafd1", + "580bba4bb0b9c56974e16a6998322a91e857e2fac28674404da993f6197fd29f", ] xpub_keys = [ @@ -60,8 +60,8 @@ def test_various_paths_at_once(self): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) - self.assertEqual(hexlify(key.node.public_key), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) + self.assertEqual(key.node.public_key.hex(), public_keys[index]) + self.assertEqual(key.node.chain_code.hex(), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) @@ -75,7 +75,7 @@ def test_icarus(self): secret = cardano.derive_icarus(binary_mnemonic, "", False) self.assertEqual( - hexlify(secret).decode(), + secret.hex(), "c065afd2832cd8b087c4d9ab7011f481ee1e0721e78ea5dd609f3ab3f156d245" "d176bd8fd4ec60b4731c3918a2a72a0226c0cd119ec35b47e4d55884667f552a" "23f7fdcd4a10c6cd2c7393ac61d877873e248f417634aa3d812af327ffe9d620", @@ -85,7 +85,7 @@ def test_icarus(self): secret = cardano.derive_icarus(binary_mnemonic, "foo", False) self.assertEqual( - hexlify(secret).decode(), + secret.hex(), "70531039904019351e1afb361cd1b312a4d0565d4ff9f8062d38acf4b15cce41" "d7b5738d9c893feea55512a3004acb0d222c35d3e3d5cde943a15a9824cbac59" "443cf67e589614076ba01e354b1a432e0e6db3b59e37fc56b5fb0222970a010e", @@ -102,7 +102,7 @@ def test_icarus_trezor(self): binary_mnemonic = bip39.mnemonic_to_bits(mnemonic) secret = cardano.derive_icarus(binary_mnemonic, "", True) self.assertEqual( - hexlify(secret).decode(), + secret.hex(), "409bb7a2998ec48029c8d2956fabd043a368ccc9b5120e42dd8a5c7145d08f45" "e8e8664d06f62b4fc3bab0134778af27ddf059a4ad1eb0efefeedd8189bbfe00" "deb289c5cdc2cf8ccfa19aea63b28424a4b0045b4b762292d46b73aa1c5cc99a", @@ -113,7 +113,7 @@ def test_icarus_trezor(self): PASSPHRASE = "foo" secret = cardano.derive_icarus(binary_mnemonic, PASSPHRASE, True) self.assertEqual( - hexlify(secret).decode(), + secret.hex(), "c8ab7a160a66bfa7a118f553c4eebfe7444e36e449dac7d6eeae21f3bbaa9551" "8593025160068776a4d61c0efc4f698585bb59f1aebe93c58e1eaf557ab59502" "d9f68fbea3049bc2255d15fc63803e9c3dbb78abff2d53f8356794807d402568", diff --git a/core/tests/test_apps.cardano.utils.py b/core/tests/test_apps.cardano.utils.py index be4670260f0..ba8a45c1506 100644 --- a/core/tests/test_apps.cardano.utils.py +++ b/core/tests/test_apps.cardano.utils.py @@ -56,7 +56,8 @@ def test_format_asset_fingerprint(self): for params, expected in test_vectors: actual = format_asset_fingerprint( - policy_id=unhexlify(params[0]), asset_name_bytes=unhexlify(params[1]) + policy_id=bytes.fromhex(params[0]), + asset_name_bytes=bytes.fromhex(params[1]), ) self.assertEqual(actual, expected) diff --git a/core/tests/test_apps.common.cbor.py b/core/tests/test_apps.common.cbor.py index ae62d8e180d..e7ef7ae8dbe 100644 --- a/core/tests/test_apps.common.cbor.py +++ b/core/tests/test_apps.common.cbor.py @@ -26,7 +26,7 @@ def test_create_array_header(self): ((2**64) - 1, "9bffffffffffffffff"), ] for val, header_hex in test_vectors: - header = unhexlify(header_hex) + header = bytes.fromhex(header_hex) self.assertEqual(create_array_header(val), header) with self.assertRaises(NotImplementedError): @@ -42,7 +42,7 @@ def test_create_tagged_set_header(self): ((2**64) - 1, "d901029bffffffffffffffff"), ] for val, header_hex in test_vectors: - header = unhexlify(header_hex) + header = bytes.fromhex(header_hex) self.assertEqual(create_tagged_set_header(val), header) with self.assertRaises(NotImplementedError): @@ -58,7 +58,7 @@ def test_create_map_header(self): ((2**64) - 1, "bbffffffffffffffff"), ] for val, header_hex in test_vectors: - header = unhexlify(header_hex) + header = bytes.fromhex(header_hex) self.assertEqual(create_map_header(val), header) with self.assertRaises(NotImplementedError): @@ -74,7 +74,7 @@ def test_create_embedded_cbor_bytes_header(self): ((2**64) - 1, "d8185bffffffffffffffff"), ] for val, header_hex in test_vectors: - header = unhexlify(header_hex) + header = bytes.fromhex(header_hex) self.assertEqual(create_embedded_cbor_bytes_header(val), header) with self.assertRaises(NotImplementedError): @@ -105,7 +105,7 @@ def test_cbor_encoding(self): (-1000000000000, "3B000000E8D4A50FFF"), # binary strings (b"", "40"), - (unhexlify("01020304"), "4401020304"), + (bytes.fromhex("01020304"), "4401020304"), # text strings ("", "60"), ("Fun", "6346756e"), @@ -115,7 +115,7 @@ def test_cbor_encoding(self): ), # tags (Tagged(1, 1363896240), "c11a514b67b0"), - (Tagged(23, unhexlify("01020304")), "d74401020304"), + (Tagged(23, bytes.fromhex("01020304")), "d74401020304"), # arrays ([], "80"), ([1, 2, 3], "83010203"), @@ -142,7 +142,7 @@ def test_cbor_encoding(self): (None, "f6"), ] for val, encoded_hex in test_vectors: - encoded = unhexlify(encoded_hex) + encoded = bytes.fromhex(encoded_hex) self.assertEqual(encode(val), encoded) self.assertEqual(decode(encoded), val) @@ -161,7 +161,7 @@ def test_cbor_tuples(self): ] for val, encoded_hex in test_vectors: value_tuple = tuple(val) - encoded = unhexlify(encoded_hex) + encoded = bytes.fromhex(encoded_hex) self.assertEqual(encode(value_tuple), encoded) self.assertEqual(decode(encoded), val) @@ -180,7 +180,7 @@ def test_cbor_ordered_map(self): for key, value in val: ordered_map[key] = value - encoded = unhexlify(encoded_hex) + encoded = bytes.fromhex(encoded_hex) self.assertEqual(encode(ordered_map), encoded) self.assertEqual(decode(encoded), {k: v for k, v in val}) diff --git a/core/tests/test_apps.common.payment_request.py b/core/tests/test_apps.common.payment_request.py index c305d3caf56..1100afa8d01 100644 --- a/core/tests/test_apps.common.payment_request.py +++ b/core/tests/test_apps.common.payment_request.py @@ -80,7 +80,9 @@ def _get_request_without_memos() -> PaymentRequest: "e55efcc85de5ab52a57a8ecf675d8454d6204c98298f93faf71c668fec9340070" ) return PaymentRequest( - recipient_name="TEST Recipient", signature=unhexlify(debug_signature), memos=[] + recipient_name="TEST Recipient", + signature=bytes.fromhex(debug_signature), + memos=[], ) @@ -116,14 +118,14 @@ def _get_request_with_coin_purchase_memo() -> PaymentRequest: def _get_sell_payment_request(include_nonce=b"DEBUG NONCE") -> PaymentRequest: text_memo = TextMemo(text="text memo text") mac = "a7594205d318491c7335d460acfebadc3c862b803abfd5a0fcf7ea6082bff1dc" - refund_memo = RefundMemo(address="ADDRESS", mac=unhexlify(mac)) + refund_memo = RefundMemo(address="ADDRESS", mac=bytes.fromhex(mac)) debug_signature = ( "20a71af90876caf75f987c432d7769311e04e0cf23afb31279acdf5563a0154a2" "372a44d16c605b0710e9c7c93a0e9a382d946d99c43490edfcdf366bdbca5305c" ) return PaymentRequest( recipient_name="TEST Recipient", - signature=unhexlify(debug_signature), + signature=bytes.fromhex(debug_signature), nonce=include_nonce, memos=[ PaymentRequestMemo(text_memo=text_memo), @@ -140,12 +142,12 @@ def _get_coin_swap_request(include_nonce=b"DEBUG NONCE") -> PaymentRequest: "e4c26c0ee3666380476deff2ac3d1899e86a298d98e249302207ffd14e70a3030" ) coin_purchase_memo = CoinPurchaseMemo( - coin_type=0, amount="AMOUNT", address="ADDRESS", mac=unhexlify(mac) + coin_type=0, amount="AMOUNT", address="ADDRESS", mac=bytes.fromhex(mac) ) - refund_memo = RefundMemo(address="Refund address", mac=unhexlify(mac2)) + refund_memo = RefundMemo(address="Refund address", mac=bytes.fromhex(mac2)) return PaymentRequest( recipient_name="TEST Recipient", - signature=unhexlify(debug_signature), + signature=bytes.fromhex(debug_signature), nonce=include_nonce, memos=[ PaymentRequestMemo(coin_purchase_memo=coin_purchase_memo), diff --git a/core/tests/test_apps.common.seed.py b/core/tests/test_apps.common.seed.py index 37e82d214f4..ea1f4f64fca 100644 --- a/core/tests/test_apps.common.seed.py +++ b/core/tests/test_apps.common.seed.py @@ -17,22 +17,22 @@ def test_slip21(self): keychain = Keychain(seed, "", [], slip21_namespaces=[[b"SLIP-0021"]]) # Key(m) - KEY_M = unhexlify( - b"dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756" + KEY_M = bytes.fromhex( + "dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756" ) self.assertEqual(node1.key(), KEY_M) # Key(m/"SLIP-0021") - KEY_M_SLIP0021 = unhexlify( - b"1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d" + KEY_M_SLIP0021 = bytes.fromhex( + "1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d" ) node1.derive_path([b"SLIP-0021"]) self.assertEqual(node1.key(), KEY_M_SLIP0021) self.assertEqual(keychain.derive_slip21([b"SLIP-0021"]).key(), KEY_M_SLIP0021) # Key(m/"SLIP-0021"/"Master encryption key") - KEY_M_SLIP0021_MEK = unhexlify( - b"ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde" + KEY_M_SLIP0021_MEK = bytes.fromhex( + "ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde" ) node1.derive_path([b"Master encryption key"]) self.assertEqual(node1.key(), KEY_M_SLIP0021_MEK) @@ -42,8 +42,8 @@ def test_slip21(self): ) # Key(m/"SLIP-0021"/"Authentication key") - KEY_M_SLIP0021_AK = unhexlify( - b"47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6" + KEY_M_SLIP0021_AK = bytes.fromhex( + "47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6" ) node2.derive_path([b"SLIP-0021", b"Authentication key"]) self.assertEqual(node2.key(), KEY_M_SLIP0021_AK) diff --git a/core/tests/test_apps.eos.get_public_key.py b/core/tests/test_apps.eos.get_public_key.py index e07502d3429..e5c8d95b67a 100644 --- a/core/tests/test_apps.eos.get_public_key.py +++ b/core/tests/test_apps.eos.get_public_key.py @@ -30,10 +30,10 @@ def test_get_public_key_scheme(self): ] public_keys = [ - b"0315c358024ce46767102578947584c4342a6982b922d454f63588effa34597197", - b"029622eff7248c4d298fe28f2df19ee0d5f7674f678844e05c31d1a5632412869e", - b"02625f33c10399703e95e41bd5054beef3ab893dcc7df2bb9bdcee48359b29069d", - b"037c9b7d24d42589941cca3f4debc75b37c0e7b881e6eb00d2e674958debe3bbc3", + "0315c358024ce46767102578947584c4342a6982b922d454f63588effa34597197", + "029622eff7248c4d298fe28f2df19ee0d5f7674f678844e05c31d1a5632412869e", + "02625f33c10399703e95e41bd5054beef3ab893dcc7df2bb9bdcee48359b29069d", + "037c9b7d24d42589941cca3f4debc75b37c0e7b881e6eb00d2e674958debe3bbc3", ] wif_keys = [ @@ -48,7 +48,7 @@ def test_get_public_key_scheme(self): node.derive_path(path) wif, public_key = _get_public_key(node) - self.assertEqual(hexlify(public_key), public_keys[index]) + self.assertEqual(public_key.hex(), public_keys[index]) self.assertEqual(wif, wif_keys[index]) self.assertEqual(public_key_to_wif(public_key), wif_keys[index]) diff --git a/core/tests/test_apps.ethereum.clear_signing.py b/core/tests/test_apps.ethereum.clear_signing.py index dd5220d69dd..8ddc11e49a8 100644 --- a/core/tests/test_apps.ethereum.clear_signing.py +++ b/core/tests/test_apps.ethereum.clear_signing.py @@ -5,8 +5,6 @@ if not utils.BITCOIN_ONLY: - from ubinascii import hexlify - from ethereum_common import * from trezor.enums import EthereumERC7730FieldFormatterType as FT from trezor.messages import ( @@ -69,7 +67,7 @@ def to_bytes(v: int) -> bytes: class TestEthereumClearSigning(unittest.TestCase): def test_address_parsing_valid(self): addr_hex = "d8da6bf26964af9d7eed9e03e53415d37aa96045" - addr_bytes = unhexlify(addr_hex) + addr_bytes = bytes.fromhex(addr_hex) valid_payload = b"\x00" * 12 + addr_bytes data = memoryview(valid_payload) @@ -82,7 +80,7 @@ def test_address_parsing_valid(self): def test_address_parsing_invalid_padding(self): addr_hex = "d8da6bf26964af9d7eed9e03e53415d37aa96045" - addr_bytes = unhexlify(addr_hex) + addr_bytes = bytes.fromhex(addr_hex) invalid_payload = b"\x01" + b"\x00" * 11 + addr_bytes # dirty padding data = memoryview(invalid_payload) @@ -165,7 +163,7 @@ def test_static_struct_valid(self): is_dynamic=False, ) - addr_bytes = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr_bytes = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") u160_val = 2**160 - 1 bool_val = 1 @@ -186,7 +184,7 @@ def test_static_struct_uint160_overflow(self): is_dynamic=False, ) - addr_bytes = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr_bytes = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") overflow_u160 = 2**160 bool_val = 1 @@ -204,7 +202,7 @@ def test_static_struct_uint160_overflow(self): def test_dynamic_struct_valid(self): dynamic_struct = Tuple((parse_address, parse_string), is_dynamic=True) - addr = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") # left padded with zeroes addr_bytes = b"\x00" * (32 - 20) + addr @@ -250,9 +248,9 @@ def test_dynamic_struct_out_of_bounds(self): def test_array_of_addresses_valid(self): address_array_parser = Array(Atomic(parse_address)) - addr1 = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr1 = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") addr1_bytes = b"\x00" * (32 - 20) + addr1 - addr2 = unhexlify("71c7656ec7ab88b098defb751b7401b5f6d8976f") + addr2 = bytes.fromhex("71c7656ec7ab88b098defb751b7401b5f6d8976f") addr2_bytes = b"\x00" * (32 - 20) + addr2 array_length = len([addr1, addr2]) @@ -276,13 +274,13 @@ def test_array_of_addresses_valid(self): def test_array_of_addresses_with_dirty_element(self): address_array_parser = Array(Atomic(parse_address)) - addr_valid_bytes = b"\x00" * 12 + unhexlify( + addr_valid_bytes = b"\x00" * 12 + bytes.fromhex( "d8da6bf26964af9d7eed9e03e53415d37aa96045" ) addr_dirty_bytes = ( b"\x01" + b"\x00" * 11 - + unhexlify("71c7656ec7ab88b098defb751b7401b5f6d8976f") + + bytes.fromhex("71c7656ec7ab88b098defb751b7401b5f6d8976f") ) payload = ( @@ -306,8 +304,8 @@ def test_array_of_dynamic_structs(self): ) ) - addr1 = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") - addr2 = unhexlify("71c7656ec7ab88b098defb751b7401b5f6d8976f") + addr1 = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr2 = bytes.fromhex("71c7656ec7ab88b098defb751b7401b5f6d8976f") text1 = "Hello first world!" text2 = "Hello second world!" @@ -358,10 +356,10 @@ def test_array_of_static_structs(self): ) ) - addr1 = unhexlify("6666666666666666666666666666666666666666") - addr2 = unhexlify("7777777777777777777777777777777777777777") - addr3 = unhexlify("8888888888888888888888888888888888888888") - addr4 = unhexlify("9999999999999999999999999999999999999999") + addr1 = bytes.fromhex("6666666666666666666666666666666666666666") + addr2 = bytes.fromhex("7777777777777777777777777777777777777777") + addr3 = bytes.fromhex("8888888888888888888888888888888888888888") + addr4 = bytes.fromhex("9999999999999999999999999999999999999999") def pad_addr(addr): return b"\x00" * (32 - 20) + addr @@ -786,8 +784,8 @@ class _Defs: network = make_eth_network() fmt = AddressNameFormatter() - addr1 = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") - addr2 = unhexlify("71c7656ec7ab88b098defb751b7401b5f6d8976f") + addr1 = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") + addr2 = bytes.fromhex("71c7656ec7ab88b098defb751b7401b5f6d8976f") formatted, _, _ = await_result( _format_field_value(fmt, [addr1, addr2], None, _Defs(), None) @@ -803,7 +801,7 @@ class _Defs: def test_multi_value_token_amount(self): # Multi-value with TokenAmountFormatter: every element shares the one # (constant) token, rendered one amount-per-line. - token_addr = unhexlify("ae7ab96520de3a18e5e111b5eaab095312d7fe84") + token_addr = bytes.fromhex("ae7ab96520de3a18e5e111b5eaab095312d7fe84") class _Defs: network = make_eth_network() @@ -935,7 +933,7 @@ class _Defs: addr_hex = "d8da6bf26964af9d7eed9e03e53415d37aa96045" flags = (1 << 255) | (1 << 160) - packed_address = flags | int.from_bytes(unhexlify(addr_hex), "big") + packed_address = flags | int.from_bytes(bytes.fromhex(addr_hex), "big") display_format = DisplayFormat( binding_context=None, @@ -989,7 +987,7 @@ def test_slice_of_negative_int_rejected(self): def test_from_proto_token_amount_constant_token(self): # Regression test for `from_proto` # Might use a .proto binary blob in future. - token_addr = unhexlify("ae7ab96520de3a18e5e111b5eaab095312d7fe84") # stETH + token_addr = bytes.fromhex("ae7ab96520de3a18e5e111b5eaab095312d7fe84") # stETH info = EthereumERC7730FieldInfo( path=EthereumERC7730Path(path=[0]), label="Amount", @@ -1004,7 +1002,7 @@ def test_from_proto_token_amount_constant_token(self): def test_token_amount_constant_token_format(self): # The token is resolved from `defs` by the constant address, without # touching the calldata - so `path_walker` is never called (passed None). - token_addr = unhexlify("ae7ab96520de3a18e5e111b5eaab095312d7fe84") # stETH + token_addr = bytes.fromhex("ae7ab96520de3a18e5e111b5eaab095312d7fe84") # stETH class _Defs: network = make_eth_network() @@ -1030,10 +1028,10 @@ def test_token_amount_no_token_source_rejected(self): # --- `calldata` fields (nested invocations) --- TRANSFER_SIG = b"\xa9\x05\x9c\xbb" - RECIPIENT = unhexlify("d8da6bf26964af9d7eed9e03e53415d37aa96045") + RECIPIENT = bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045") # stETH: mapped to "Lido" in KNOWN_ADDRESSES, exercising the provider / # callee name resolution. Will be updated once those definitions are removed. - CALLEE = unhexlify("ae7ab96520de3a18e5e111b5eaab095312d7fe84") + CALLEE = bytes.fromhex("ae7ab96520de3a18e5e111b5eaab095312d7fe84") @staticmethod def _msg(**kwargs): @@ -1116,7 +1114,7 @@ def _assert_raw_fallback(self, fields, blob, callee_str="Lido"): # the fallback is two rows: the callee, then the raw hex blob self.assertEqual(len(fields), 2) self.assertEqual(fields[0][0][:2], ("Subcall to", callee_str)) - self.assertEqual(fields[1][0][:2], ("Wrapped call", hexlify(blob).decode())) + self.assertEqual(fields[1][0][:2], ("Wrapped call", blob.hex())) for _, token, token_address in fields: self.assertIsNone(token) self.assertIsNone(token_address) @@ -1175,7 +1173,7 @@ def test_calldata_nested_transfer(self): self.assertEqual(fields[1][0][:2], ("(Subcall) Intent", "Send")) (label, formatted, _), _, _ = fields[2] self.assertEqual(label, "(Subcall) To") - self.assertEqual(formatted.lower(), "0x" + hexlify(self.RECIPIENT).decode()) + self.assertEqual(formatted.lower(), "0x" + self.RECIPIENT.hex()) (label, formatted, _), token, token_address = fields[3] self.assertEqual(label, "(Subcall) Amount") self.assertEqual(formatted, "2 TST") @@ -1243,9 +1241,7 @@ def test_calldata_scalars_descriptor(self): if value is not None: self.assertEqual(got_value, value) recipient_value = fields[2][0][1] - self.assertEqual( - recipient_value.lower(), "0x" + hexlify(self.RECIPIENT).decode() - ) + self.assertEqual(recipient_value.lower(), "0x" + self.RECIPIENT.hex()) def test_calldata_no_inner_format_raw_fallback(self): # No built-in matches and definition requests are unsupported -> the @@ -1300,10 +1296,10 @@ def test_calldata_depth_capped_at_one(self): # the middle format's calldata field degraded to callee + raw hex (label, formatted, _), _, _ = fields[2] self.assertEqual(label, "(Subcall) Subcall to") - self.assertEqual(formatted.lower(), "0x" + hexlify(innermost_callee).decode()) + self.assertEqual(formatted.lower(), "0x" + innermost_callee.hex()) self.assertEqual( fields[3][0][:2], - ("(Subcall) Inner call", hexlify(innermost_blob).decode()), + ("(Subcall) Inner call", innermost_blob.hex()), ) # the transfer was never resolved: no third-level formatting happened self.assertFalse(any("Send" == f[0][1] for f in fields)) @@ -1356,7 +1352,7 @@ def format_for(path): override_callee=override, ) ) - self.assertEqual(fields[0][0][1], hexlify(override).decode()) + self.assertEqual(fields[0][0][1], override.hex()) for path in (ContainerPath.From, ContainerPath.Value): with self.assertRaises(InvalidFormatDefinition): @@ -1450,7 +1446,7 @@ def test_calldata_array_of_subcalls(self): self.assertEqual(group[1][0][:2], (prefix + "Intent", "Send")) (label, formatted, _), _, _ = group[2] self.assertEqual(label, prefix + "To") - self.assertEqual(formatted.lower(), "0x" + hexlify(self.RECIPIENT).decode()) + self.assertEqual(formatted.lower(), "0x" + self.RECIPIENT.hex()) (label, formatted, _), token, token_address = group[3] self.assertEqual(label, prefix + "Amount") self.assertEqual(formatted, "2 TST") @@ -1471,7 +1467,7 @@ def test_calldata_array_parallel_callees(self): self.assertEqual(fields[0][0][:2], ("(Subcall #1) Provider", "Lido")) (label, provider, _), _, _ = fields[4] self.assertEqual(label, "(Subcall #2) Provider") - self.assertEqual(provider.lower(), "0x" + hexlify(other_callee).decode()) + self.assertEqual(provider.lower(), "0x" + other_callee.hex()) # each subcall's token resolves via its own callee self.assertEqual(defs.token_requests, [self.CALLEE, other_callee]) @@ -1486,7 +1482,7 @@ def test_calldata_array_raw_fallback(self): self.assertEqual(fields[0][0][:2], ("(Subcall #1) To", "Lido")) self.assertEqual( fields[1][0][:2], - ("(Subcall #1) Wrapped call", hexlify(bad_blob).decode()), + ("(Subcall #1) Wrapped call", bad_blob.hex()), ) self.assertEqual(fields[2][0][:2], ("(Subcall #2) Provider", "Lido")) diff --git a/core/tests/test_apps.ethereum.clear_signing_definitions.py b/core/tests/test_apps.ethereum.clear_signing_definitions.py index d7c109c95a7..1033991c419 100644 --- a/core/tests/test_apps.ethereum.clear_signing_definitions.py +++ b/core/tests/test_apps.ethereum.clear_signing_definitions.py @@ -81,7 +81,7 @@ def test_func_sigs_match_solidity_signatures(self): self.assertIn( func_sig, expected, - msg=f"selector {hexlify(func_sig).decode()} (intent {display_format.intent}) matches no known Solidity signature", + msg=f"selector {func_sig.hex()} (intent {display_format.intent}) matches no known Solidity signature", ) seen.add(func_sig) diff --git a/core/tests/test_apps.ethereum.helpers.py b/core/tests/test_apps.ethereum.helpers.py index 95de8cc44ae..9d80004b8d8 100644 --- a/core/tests/test_apps.ethereum.helpers.py +++ b/core/tests/test_apps.ethereum.helpers.py @@ -22,7 +22,7 @@ def test_address_from_bytes_eip55(self): "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb", ] for s in eip55: - b = unhexlify(s[2:]) + b = bytes.fromhex(s[2:]) h = address_from_bytes(b) self.assertEqual(h, s) @@ -43,13 +43,13 @@ def test_address_from_bytes_rskip60(self): n = make_eth_network(chain_id=30) for s in rskip60_chain_30: - b = unhexlify(s[2:]) + b = bytes.fromhex(s[2:]) h = address_from_bytes(b, n) self.assertEqual(h, s) n = make_eth_network(chain_id=31) for s in rskip60_chain_31: - b = unhexlify(s[2:]) + b = bytes.fromhex(s[2:]) h = address_from_bytes(b, n) self.assertEqual(h, s) diff --git a/core/tests/test_apps.ethereum.yielding.py b/core/tests/test_apps.ethereum.yielding.py index aa0ea0ccc42..99395f5c73a 100644 --- a/core/tests/test_apps.ethereum.yielding.py +++ b/core/tests/test_apps.ethereum.yielding.py @@ -34,7 +34,7 @@ def test_known_address(self): # https://etherscan.io/address/0x3ef3d8ba38ebe18db133cec108f4d14ce00dd9ae self.assertEqual( yielding._MERKL_XYZ_CLAIM_DISTRIBUTOR_ADDR, - unhexlify("3ef3d8ba38ebe18db133cec108f4d14ce00dd9ae"), + bytes.fromhex("3ef3d8ba38ebe18db133cec108f4d14ce00dd9ae"), ) diff --git a/core/tests/test_apps.ethereum.yielding_vaults.py b/core/tests/test_apps.ethereum.yielding_vaults.py index 0abfe28f766..d72bb06e52e 100644 --- a/core/tests/test_apps.ethereum.yielding_vaults.py +++ b/core/tests/test_apps.ethereum.yielding_vaults.py @@ -13,39 +13,39 @@ def test_known_vault_addresses(self): # route users to a wrong vault. self.assertEqual( yielding_vaults._TEST_SH_USDC_VAULT_ADDRESS, - unhexlify("a511d618cd0f9d7cad791009d7c5e3b19c9568da"), + bytes.fromhex("a511d618cd0f9d7cad791009d7c5e3b19c9568da"), ) # https://etherscan.io/address/0xde6c23E561F3e55846207EC45A91b777e0F7C889 self.assertEqual( yielding_vaults._SH_USDC_VAULT_ADDRESS, - unhexlify("de6c23e561f3e55846207ec45a91b777e0f7c889"), + bytes.fromhex("de6c23e561f3e55846207ec45a91b777e0f7c889"), ) # https://etherscan.io/address/0xE4DB1c5A1B709CE4d2adA6985D9D506e58F73829 self.assertEqual( yielding_vaults._SH_USDT_VAULT_ADDRESS, - unhexlify("e4db1c5a1b709ce4d2ada6985d9d506e58f73829"), + bytes.fromhex("e4db1c5a1b709ce4d2ada6985d9d506e58f73829"), ) # https://etherscan.io/address/0x704cFb08969048a8DFf298B214F959791d8Da509 self.assertEqual( yielding_vaults._SH_ETH_VAULT_ADDRESS, - unhexlify("704cfb08969048a8dff298b214f959791d8da509"), + bytes.fromhex("704cfb08969048a8dff298b214f959791d8da509"), ) def test_known_token_addresses(self): # https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 self.assertEqual( yielding_vaults._USDC_ADDRESS, - unhexlify("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), + bytes.fromhex("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), ) # https://etherscan.io/token/0xdAC17F958D2ee523a2206206994597C13D831ec7 self.assertEqual( yielding_vaults._USDT_ADDRESS, - unhexlify("dac17f958d2ee523a2206206994597c13d831ec7"), + bytes.fromhex("dac17f958d2ee523a2206206994597c13d831ec7"), ) # https://etherscan.io/token/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 self.assertEqual( yielding_vaults._WETH_ADDRESS, - unhexlify("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), + bytes.fromhex("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), ) diff --git a/core/tests/test_apps.evolu.check_evolu.py b/core/tests/test_apps.evolu.check_evolu.py index 8e8f4c4375b..0e81e74b0ef 100644 --- a/core/tests/test_apps.evolu.check_evolu.py +++ b/core/tests/test_apps.evolu.check_evolu.py @@ -7,7 +7,6 @@ class TestCheckEvoluCommandsRegistrationRequest(unittest.TestCase): def test_proof_sign_registration_request(self): from trezorutils import delegated_identity - from ubinascii import unhexlify from storage.device import get_delegated_identity_key_rotation_index from trezor.crypto.curve import nist256p1 @@ -22,7 +21,7 @@ def test_proof_sign_registration_request(self): sign_request_challenge: str = "1234" sign_request_size: int = 10 arguments = [ - unhexlify(sign_request_challenge), + bytes.fromhex(sign_request_challenge), sign_request_size.to_bytes(4, "big"), ] @@ -41,13 +40,11 @@ def test_proof_sign_registration_request(self): self.assertTrue(check_delegated_identity_proof(proof, header, arguments)) def test_proof_sign_registration_request_invalid_size(self): - from ubinascii import unhexlify - from trezor.wire import DataError from apps.evolu.sign_registration_request import _check_data - sign_request_challenge = unhexlify("1234") + sign_request_challenge = bytes.fromhex("1234") sign_request_size: int = 256**4 + 5 # invalid size with self.assertRaises(DataError): diff --git a/core/tests/test_apps.monero.bulletproof.py b/core/tests/test_apps.monero.bulletproof.py index 2035ddcae75..ebf00aeaf6a 100644 --- a/core/tests/test_apps.monero.bulletproof.py +++ b/core/tests/test_apps.monero.bulletproof.py @@ -23,8 +23,8 @@ def test_square_multiply(self): ) def test_dvct_skips(self): - z_sq = unhexlify( - b"e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" + z_sq = bytes.fromhex( + "e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" ) d_vct0 = bp.VctD(64, 8, z_sq, raw=True) d_vct1 = bp.VctD(64, 8, z_sq, raw=True) @@ -90,7 +90,7 @@ def test_dvct_skips(self): def test_pow_back_skips(self): MN = 128 - y = unhexlify( + y = bytes.fromhex( "60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e" ) y_sc = crypto.decodeint_into(None, y) @@ -144,11 +144,11 @@ def test_pow_back_skips(self): def test_bpp_bprime(self): N, M = 64, 4 MN = N * M - y = unhexlify( - b"60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e" + y = bytes.fromhex( + "60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e" ) - z = unhexlify( - b"e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" + z = bytes.fromhex( + "e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" ) zc = crypto.decodeint_into(None, z) z_sq = bp._sc_mul(None, z, z) @@ -199,64 +199,64 @@ def aR1_fnc(i, d): def bproof_plus_2(self): return BulletproofPlus( V=[ - unhexlify(b"e0dae61095ac728a15d4d9754f1f9f956c22d4fa2deee2c0ff1def031b083e02"), - unhexlify(b"5b424ecb1f8ea02351d324296a34a0608ecc104610feaad06e6002f61992bfe1"), + bytes.fromhex("e0dae61095ac728a15d4d9754f1f9f956c22d4fa2deee2c0ff1def031b083e02"), + bytes.fromhex("5b424ecb1f8ea02351d324296a34a0608ecc104610feaad06e6002f61992bfe1"), ], - A=unhexlify(b"6ae6f16a6b01cf494fb2cf368573365293f76c624cfc11152d648479238e9319"), - A1=unhexlify(b"33ad318a44df6f14a945e6d051911ab9a24841457d15d62bd1436fb3edc8a193"), - B=unhexlify(b"5f56531cb8e78dbb3450f1d599a6d4c7f5e4c04ee3e7015643c19a528bcbb109"), - - r1=unhexlify(b"40ad8a9c6b3bdd95c7fb8605e50135050e64f1ce29d1c4b37b1271e658354500"), - s1=unhexlify(b"aed959c770499134aaa7e099f566dac56ee12959d797b62a3d8d1037b790b806"), - d1=unhexlify(b"395a1e8d3df8e90e716fdeaa493090782c8db922337d09a36b50c1f02cd8e100"), - - L=[unhexlify(b"ed2d768bb9c8b5a9fa24c90b5831d3cceb3e78cef45eba90e52f89a2b3c859d2"), - unhexlify(b"7f25cc8e211783e9c1b80dd13ee286943da0ec07bd33291536639432758f6927"), - unhexlify(b"7bae3d31f4e2a6d78d74d2bcb6d0656e4222161423d635f7ce08805e96cec83e"), - unhexlify(b"c87f949f70cf569c4baa332612305733fd19a2262490c55ec88c16a68d7b5e7d"), - unhexlify(b"34d06caf0d02129ebcc8bf318da8f6a0ddfaf2c7cb85f4144726561cefc86dcd"), - unhexlify(b"ab3effd3a2706591774e013c76f5b8ece9e58abf7efc0a11b479f9d2a89d0c55"), - unhexlify(b"ebf8d34e6643533bf73b13d2dd56aeaf2113fb3017d39bc6db6a2f71bc1d53f1"), + A=bytes.fromhex("6ae6f16a6b01cf494fb2cf368573365293f76c624cfc11152d648479238e9319"), + A1=bytes.fromhex("33ad318a44df6f14a945e6d051911ab9a24841457d15d62bd1436fb3edc8a193"), + B=bytes.fromhex("5f56531cb8e78dbb3450f1d599a6d4c7f5e4c04ee3e7015643c19a528bcbb109"), + + r1=bytes.fromhex("40ad8a9c6b3bdd95c7fb8605e50135050e64f1ce29d1c4b37b1271e658354500"), + s1=bytes.fromhex("aed959c770499134aaa7e099f566dac56ee12959d797b62a3d8d1037b790b806"), + d1=bytes.fromhex("395a1e8d3df8e90e716fdeaa493090782c8db922337d09a36b50c1f02cd8e100"), + + L=[bytes.fromhex("ed2d768bb9c8b5a9fa24c90b5831d3cceb3e78cef45eba90e52f89a2b3c859d2"), + bytes.fromhex("7f25cc8e211783e9c1b80dd13ee286943da0ec07bd33291536639432758f6927"), + bytes.fromhex("7bae3d31f4e2a6d78d74d2bcb6d0656e4222161423d635f7ce08805e96cec83e"), + bytes.fromhex("c87f949f70cf569c4baa332612305733fd19a2262490c55ec88c16a68d7b5e7d"), + bytes.fromhex("34d06caf0d02129ebcc8bf318da8f6a0ddfaf2c7cb85f4144726561cefc86dcd"), + bytes.fromhex("ab3effd3a2706591774e013c76f5b8ece9e58abf7efc0a11b479f9d2a89d0c55"), + bytes.fromhex("ebf8d34e6643533bf73b13d2dd56aeaf2113fb3017d39bc6db6a2f71bc1d53f1"), ], - R=[unhexlify(b"27e146e61e88944246dcd90ddb4284923c7fdc6fd6a187ed2efa3dcb8c380346"), - unhexlify(b"fab99152d48d835b9a01cdbec46301db0f57ca091f6cbaa0b45c8498f18babe1"), - unhexlify(b"8467f87acd7be026a27ed798cca6cc1526b0f805ac534a9c5162a9cd75460011"), - unhexlify(b"f421fa4bda1dba042ca56c6bdce313dc8d18cee084d722af47447ce54b6ff8df"), - unhexlify(b"8dd5dabc0ad67c83f42668e96bf5ee6741bcd8e661eda1e8ce6a23d84cf0b5b5"), - unhexlify(b"fcf20a7775699b0456542930b2374b233fb3f8f79e1911428157631a20b3c3ad"), - unhexlify(b"66e477bd93dabb184e2738829320bf8e60f6b4b476ca0fbc1013af28e8de34c1"), + R=[bytes.fromhex("27e146e61e88944246dcd90ddb4284923c7fdc6fd6a187ed2efa3dcb8c380346"), + bytes.fromhex("fab99152d48d835b9a01cdbec46301db0f57ca091f6cbaa0b45c8498f18babe1"), + bytes.fromhex("8467f87acd7be026a27ed798cca6cc1526b0f805ac534a9c5162a9cd75460011"), + bytes.fromhex("f421fa4bda1dba042ca56c6bdce313dc8d18cee084d722af47447ce54b6ff8df"), + bytes.fromhex("8dd5dabc0ad67c83f42668e96bf5ee6741bcd8e661eda1e8ce6a23d84cf0b5b5"), + bytes.fromhex("fcf20a7775699b0456542930b2374b233fb3f8f79e1911428157631a20b3c3ad"), + bytes.fromhex("66e477bd93dabb184e2738829320bf8e60f6b4b476ca0fbc1013af28e8de34c1"), ], ) def bproof_plus_2_invalid(self): return BulletproofPlus( V=[ - unhexlify(b"e0dae61095ac728a15d4d9754f1f9f956c22d4fa2deee2c0ff1def031b083e02"), - unhexlify(b"5b424ecb1f8ea02351d324296a34a0608ecc104610feaad06e6002f61992bfe1"), + bytes.fromhex("e0dae61095ac728a15d4d9754f1f9f956c22d4fa2deee2c0ff1def031b083e02"), + bytes.fromhex("5b424ecb1f8ea02351d324296a34a0608ecc104610feaad06e6002f61992bfe1"), ], - A=unhexlify(b"6ae6f16a6b01cf494fb2cf368573365293f76c624cfc11152d648479238e9309"), - A1=unhexlify(b"33ad318a44df6f14a945e6d051911ab9a24841457d15d62bd1436fb3edc8a193"), - B=unhexlify(b"5f56531cb8e78dbb3450f1d599a6d4c7f5e4c04ee3e7015643c19a528bcbb109"), - - r1=unhexlify(b"40ad8a9c6b3bdd95c7fb8605e50135050e64f1ce29d1c4b37b1271e658354500"), - s1=unhexlify(b"aed959c770499134aaa7e099f566dac56ee12959d797b62a3d8d1037b790b806"), - d1=unhexlify(b"395a1e8d3df8e90e716fdeaa493090782c8db922337d09a36b50c1f02cd8e100"), - - L=[unhexlify(b"ed2d768bb9c8b5a9fa24c90b5831d3cceb3e78cef45eba90e52f89a2b3c859d2"), - unhexlify(b"7f25cc8e211783e9c1b80dd13ee286943da0ec07bd33291536639432758f6927"), - unhexlify(b"7bae3d31f4e2a6d78d74d2bcb6d0656e4222161423d635f7ce08805e96cec83e"), - unhexlify(b"c87f949f70cf569c4baa332612305733fd19a2262490c55ec88c16a68d7b5e7d"), - unhexlify(b"34d06caf0d02129ebcc8bf318da8f6a0ddfaf2c7cb85f4144726561cefc86dcd"), - unhexlify(b"ab3effd3a2706591774e013c76f5b8ece9e58abf7efc0a11b479f9d2a89d0c55"), - unhexlify(b"ebf8d34e6643533bf73b13d2dd56aeaf2113fb3017d39bc6db6a2f71bc1d53f1"), + A=bytes.fromhex("6ae6f16a6b01cf494fb2cf368573365293f76c624cfc11152d648479238e9309"), + A1=bytes.fromhex("33ad318a44df6f14a945e6d051911ab9a24841457d15d62bd1436fb3edc8a193"), + B=bytes.fromhex("5f56531cb8e78dbb3450f1d599a6d4c7f5e4c04ee3e7015643c19a528bcbb109"), + + r1=bytes.fromhex("40ad8a9c6b3bdd95c7fb8605e50135050e64f1ce29d1c4b37b1271e658354500"), + s1=bytes.fromhex("aed959c770499134aaa7e099f566dac56ee12959d797b62a3d8d1037b790b806"), + d1=bytes.fromhex("395a1e8d3df8e90e716fdeaa493090782c8db922337d09a36b50c1f02cd8e100"), + + L=[bytes.fromhex("ed2d768bb9c8b5a9fa24c90b5831d3cceb3e78cef45eba90e52f89a2b3c859d2"), + bytes.fromhex("7f25cc8e211783e9c1b80dd13ee286943da0ec07bd33291536639432758f6927"), + bytes.fromhex("7bae3d31f4e2a6d78d74d2bcb6d0656e4222161423d635f7ce08805e96cec83e"), + bytes.fromhex("c87f949f70cf569c4baa332612305733fd19a2262490c55ec88c16a68d7b5e7d"), + bytes.fromhex("34d06caf0d02129ebcc8bf318da8f6a0ddfaf2c7cb85f4144726561cefc86dcd"), + bytes.fromhex("ab3effd3a2706591774e013c76f5b8ece9e58abf7efc0a11b479f9d2a89d0c55"), + bytes.fromhex("ebf8d34e6643533bf73b13d2dd56aeaf2113fb3017d39bc6db6a2f71bc1d53f1"), ], - R=[unhexlify(b"27e146e61e88944246dcd90ddb4284923c7fdc6fd6a187ed2efa3dcb8c380346"), - unhexlify(b"fab99152d48d835b9a01cdbec46301db0f57ca091f6cbaa0b45c8498f18babe1"), - unhexlify(b"8467f87acd7be026a27ed798cca6cc1526b0f805ac534a9c5162a9cd75460011"), - unhexlify(b"f421fa4bda1dba042ca56c6bdce313dc8d18cee084d722af47447ce54b6ff8df"), - unhexlify(b"8dd5dabc0ad67c83f42668e96bf5ee6741bcd8e661eda1e8ce6a23d84cf0b5b5"), - unhexlify(b"fcf20a7775699b0456542930b2374b233fb3f8f79e1911428157631a20b3c3ad"), - unhexlify(b"66e477bd93dabb184e2738829320bf8e60f6b4b476ca0fbc1013af28e8de34c1"), + R=[bytes.fromhex("27e146e61e88944246dcd90ddb4284923c7fdc6fd6a187ed2efa3dcb8c380346"), + bytes.fromhex("fab99152d48d835b9a01cdbec46301db0f57ca091f6cbaa0b45c8498f18babe1"), + bytes.fromhex("8467f87acd7be026a27ed798cca6cc1526b0f805ac534a9c5162a9cd75460011"), + bytes.fromhex("f421fa4bda1dba042ca56c6bdce313dc8d18cee084d722af47447ce54b6ff8df"), + bytes.fromhex("8dd5dabc0ad67c83f42668e96bf5ee6741bcd8e661eda1e8ce6a23d84cf0b5b5"), + bytes.fromhex("fcf20a7775699b0456542930b2374b233fb3f8f79e1911428157631a20b3c3ad"), + bytes.fromhex("66e477bd93dabb184e2738829320bf8e60f6b4b476ca0fbc1013af28e8de34c1"), ], ) # fmt: on diff --git a/core/tests/test_apps.monero.clsag.py b/core/tests/test_apps.monero.clsag.py index c697fe4933b..931c1fd7d36 100644 --- a/core/tests/test_apps.monero.clsag.py +++ b/core/tests/test_apps.monero.clsag.py @@ -2,8 +2,6 @@ from common import * # isort:skip if not utils.BITCOIN_ONLY: - import ubinascii - from trezor.crypto import monero as tcry from trezor.crypto import random @@ -162,17 +160,15 @@ def gen_clsag_sig(self, ring_size=11, index=None): return msg, scalars, sc1, sI, sD, ring2, Cp def verify_monero_generated(self, clsag): - msg = ubinascii.unhexlify(clsag["msg"]) - sI = crypto_helpers.decodepoint(ubinascii.unhexlify(clsag["sI"])) - sD = crypto_helpers.decodepoint(ubinascii.unhexlify(clsag["sD"])) - sc1 = crypto_helpers.decodeint(ubinascii.unhexlify(clsag["sc1"])) - Cout = crypto_helpers.decodepoint(ubinascii.unhexlify(clsag["cout"])) - scalars = [ - crypto_helpers.decodeint(ubinascii.unhexlify(x)) for x in clsag["ss"] - ] + msg = bytes.fromhex(clsag["msg"]) + sI = crypto_helpers.decodepoint(bytes.fromhex(clsag["sI"])) + sD = crypto_helpers.decodepoint(bytes.fromhex(clsag["sD"])) + sc1 = crypto_helpers.decodeint(bytes.fromhex(clsag["sc1"])) + Cout = crypto_helpers.decodepoint(bytes.fromhex(clsag["cout"])) + scalars = [crypto_helpers.decodeint(bytes.fromhex(x)) for x in clsag["ss"]] ring = [] for e in clsag["ring"]: - ring.append(TmpKey(ubinascii.unhexlify(e[0]), ubinascii.unhexlify(e[1]))) + ring.append(TmpKey(bytes.fromhex(e[0]), bytes.fromhex(e[1]))) self.verify_clsag(msg, scalars, sc1, sI, sD, ring, Cout) diff --git a/core/tests/test_apps.monero.crypto.py b/core/tests/test_apps.monero.crypto.py index 9d98c80bc02..a92dbaee452 100644 --- a/core/tests/test_apps.monero.crypto.py +++ b/core/tests/test_apps.monero.crypto.py @@ -14,8 +14,8 @@ @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroCrypto(unittest.TestCase): def test_encoding(self): - point = unhexlify( - b"2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" + point = bytes.fromhex( + "2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" ) self.assertEqual( point, crypto_helpers.encodepoint(crypto_helpers.decodepoint(point)) @@ -31,12 +31,12 @@ def test_encoding(self): def test_scalarmult_base(self): scalar = crypto_helpers.decodeint( - unhexlify( - b"a0eea49140a3b036da30eacf64bd9d56ce3ef68ba82ef13571ec511edbcf8303" + bytes.fromhex( + "a0eea49140a3b036da30eacf64bd9d56ce3ef68ba82ef13571ec511edbcf8303" ) ) - exp = unhexlify( - b"16bb4a3c44e2ced511fc0d4cd86b13b3af21efc99fb0356199fac489f2544c09" + exp = bytes.fromhex( + "16bb4a3c44e2ced511fc0d4cd86b13b3af21efc99fb0356199fac489f2544c09" ) res = crypto.scalarmult_base_into(None, scalar) @@ -44,12 +44,12 @@ def test_scalarmult_base(self): self.assertTrue(crypto.point_eq(crypto_helpers.decodepoint(exp), res)) scalar = crypto_helpers.decodeint( - unhexlify( - b"fd290dce39f781aebbdbd24584ed6d48bd300de19d9c3decfda0a6e2c6751d0f" + bytes.fromhex( + "fd290dce39f781aebbdbd24584ed6d48bd300de19d9c3decfda0a6e2c6751d0f" ) ) - exp = unhexlify( - b"123daf90fc26f13c6529e6b49bfed498995ac383ef19c0db6771143f24ba8dd5" + exp = bytes.fromhex( + "123daf90fc26f13c6529e6b49bfed498995ac383ef19c0db6771143f24ba8dd5" ) res = crypto.scalarmult_base_into(None, scalar) @@ -57,14 +57,14 @@ def test_scalarmult_base(self): self.assertTrue(crypto.point_eq(crypto_helpers.decodepoint(exp), res)) def test_scalarmult(self): - priv = unhexlify( - b"3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" + priv = bytes.fromhex( + "3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" ) - pub = unhexlify( - b"2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" + pub = bytes.fromhex( + "2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" ) - exp = unhexlify( - b"adcd1f5881f46f254900a03c654e71950a88a0236fa0a3a946c9b8daed6ef43d" + exp = bytes.fromhex( + "adcd1f5881f46f254900a03c654e71950a88a0236fa0a3a946c9b8daed6ef43d" ) res = crypto.scalarmult_into( @@ -74,49 +74,49 @@ def test_scalarmult(self): self.assertTrue(crypto.point_eq(crypto_helpers.decodepoint(exp), res)) def test_cn_fast_hash(self): - inp = unhexlify( - b"259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff6405" + inp = bytes.fromhex( + "259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff6405" ) res = crypto.fast_hash_into(None, inp) self.assertEqual( res, - unhexlify( - b"86db87b83fb1246efca5f3b0db09ce3fa4d605b0d10e6507cac253dd31a3ec16" + bytes.fromhex( + "86db87b83fb1246efca5f3b0db09ce3fa4d605b0d10e6507cac253dd31a3ec16" ), ) def test_hash_to_scalar(self): - inp = unhexlify( - b"259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff6405" + inp = bytes.fromhex( + "259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff6405" ) res = crypto.hash_to_scalar_into(None, inp) exp = crypto_helpers.decodeint( - unhexlify( - b"9907925b254e12162609fc0dfd0fef2aa4d605b0d10e6507cac253dd31a3ec06" + bytes.fromhex( + "9907925b254e12162609fc0dfd0fef2aa4d605b0d10e6507cac253dd31a3ec06" ) ) self.assertTrue(crypto.sc_eq(res, exp)) def test_hash_to_point(self): - data = unhexlify( - b"42f6835bf83114a1f5f6076fe79bdfa0bd67c74b88f127d54572d3910dd09201" + data = bytes.fromhex( + "42f6835bf83114a1f5f6076fe79bdfa0bd67c74b88f127d54572d3910dd09201" ) res = crypto.hash_to_point_into(None, data) res_p = crypto_helpers.encodepoint(res) self.assertEqual( res_p, - unhexlify( - b"54863a0464c008acc99cffb179bc6cf34eb1bbdf6c29f7a070a7c6376ae30ab5" + bytes.fromhex( + "54863a0464c008acc99cffb179bc6cf34eb1bbdf6c29f7a070a7c6376ae30ab5" ), ) def test_derivation_to_scalar(self): - derivation = unhexlify( - b"e720a09f2e3a0bbf4e4ba7ad93653bb296885510121f806acb2a5f9168fafa01" + derivation = bytes.fromhex( + "e720a09f2e3a0bbf4e4ba7ad93653bb296885510121f806acb2a5f9168fafa01" ) - scalar = unhexlify( - b"25d08763414c379aa9cf989cdcb3cadd36bd5193b500107d6bf5f921f18e470e" + scalar = bytes.fromhex( + "25d08763414c379aa9cf989cdcb3cadd36bd5193b500107d6bf5f921f18e470e" ) sc_int = crypto_helpers.derivation_to_scalar( @@ -126,17 +126,17 @@ def test_derivation_to_scalar(self): def test_generate_key_derivation(self): key_pub = crypto_helpers.decodepoint( - unhexlify( - b"7739c95d3298e2f87362dba9e0e0b3980a692ae8e2f16796b0e382098cd6bd83" + bytes.fromhex( + "7739c95d3298e2f87362dba9e0e0b3980a692ae8e2f16796b0e382098cd6bd83" ) ) key_priv = crypto_helpers.decodeint( - unhexlify( - b"3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" + bytes.fromhex( + "3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" ) ) - deriv_exp = unhexlify( - b"fa188a45a0e4daccc0e6d4f6f6858fd46392104be74183ec0047e7e9f4eaf739" + deriv_exp = bytes.fromhex( + "fa188a45a0e4daccc0e6d4f6f6858fd46392104be74183ec0047e7e9f4eaf739" ) self.assertEqual( @@ -147,43 +147,43 @@ def test_generate_key_derivation(self): ) def test_h(self): - H = unhexlify( - b"8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94" + H = bytes.fromhex( + "8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94" ) self.assertEqual(crypto_helpers.encodepoint(crypto.xmr_H()), H) def test_sc_inversion(self): res = crypto.Scalar() inp = crypto_helpers.decodeint( - unhexlify( - b"3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" + bytes.fromhex( + "3482fb9735ef879fcae5ec7721b5d3646e155c4fb58d6cc11c732c9c9b76620a" ) ) crypto.sc_inv_into(res, inp) self.assertEqual( - hexlify(crypto_helpers.encodeint(res)), - b"bcf365a551e6358f3f281a6241d4a25eded60230b60a1d48c67b51a85e33d70e", + crypto_helpers.encodeint(res).hex(), + "bcf365a551e6358f3f281a6241d4a25eded60230b60a1d48c67b51a85e33d70e", ) def test_addr_encode(self): addr_exp = "4LL9oSLmtpccfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2bYXZKKQePHES9khPK" addr = tcry.xmr_base58_addr_encode_check( 19, - unhexlify( - b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d117113076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f098a125052fe6f3877" + bytes.fromhex( + "eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d117113076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f098a125052fe6f3877" ), ) addr2 = encode_addr( bytes([19]), - unhexlify( - b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d11711" + bytes.fromhex( + "eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d11711" ), - unhexlify( - b"3076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f09" + bytes.fromhex( + "3076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f09" ), - unhexlify(b"8a125052fe6f3877"), + bytes.fromhex("8a125052fe6f3877"), ) self.assertEqual(addr, addr_exp) @@ -192,11 +192,11 @@ def test_addr_encode(self): def test_wallet_addr(self): addr = encode_addr( net_version(), - unhexlify( - b"3bec484c5d7f0246af520aab550452b5b6013733feabebd681c4a60d457b7fc1" + bytes.fromhex( + "3bec484c5d7f0246af520aab550452b5b6013733feabebd681c4a60d457b7fc1" ), - unhexlify( - b"2d5918e31d3c003da3c778592c07b398ad6f961a67082a75fd49394d51e69bbe" + bytes.fromhex( + "2d5918e31d3c003da3c778592c07b398ad6f961a67082a75fd49394d51e69bbe" ), ) @@ -207,13 +207,13 @@ def test_wallet_addr(self): w = AccountCreds.new_wallet( crypto_helpers.decodeint( - unhexlify( - b"4ce88c168e0f5f8d6524f712d5f8d7d83233b1e7a2a60b5aba5206cc0ea2bc08" + bytes.fromhex( + "4ce88c168e0f5f8d6524f712d5f8d7d83233b1e7a2a60b5aba5206cc0ea2bc08" ) ), crypto_helpers.decodeint( - unhexlify( - b"f2644a3dd97d43e87887e74d1691d52baa0614206ad1b0c239ff4aa3b501750a" + bytes.fromhex( + "f2644a3dd97d43e87887e74d1691d52baa0614206ad1b0c239ff4aa3b501750a" ) ), network_type=MoneroNetworkType.TESTNET, @@ -225,13 +225,13 @@ def test_wallet_addr(self): def test_derive_subaddress_public_key(self): out_key = crypto_helpers.decodepoint( - unhexlify( - b"f4efc29da4ccd6bc6e81f52a6f47b2952966442a7efb49901cce06a7a3bef3e5" + bytes.fromhex( + "f4efc29da4ccd6bc6e81f52a6f47b2952966442a7efb49901cce06a7a3bef3e5" ) ) deriv = crypto_helpers.decodepoint( - unhexlify( - b"259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff64" + bytes.fromhex( + "259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff64" ) ) res = crypto_helpers.encodepoint( @@ -239,34 +239,34 @@ def test_derive_subaddress_public_key(self): ) self.assertEqual( res, - unhexlify( - b"5a10cca900ee47a7f412cd661b29f5ab356d6a1951884593bb170b5ec8b6f2e8" + bytes.fromhex( + "5a10cca900ee47a7f412cd661b29f5ab356d6a1951884593bb170b5ec8b6f2e8" ), ) def test_get_subaddress_secret_key(self): a = crypto_helpers.decodeint( - unhexlify( - b"4ce88c168e0f5f8d6524f712d5f8d7d83233b1e7a2a60b5aba5206cc0ea2bc08" + bytes.fromhex( + "4ce88c168e0f5f8d6524f712d5f8d7d83233b1e7a2a60b5aba5206cc0ea2bc08" ) ) m = monero.get_subaddress_secret_key(secret_key=a, major=0, minor=1) self.assertEqual( crypto_helpers.encodeint(m), - unhexlify( - b"b6ff4d689b95e3310efbf683850c075bcde46361923054e42ef30016b287ff0c" + bytes.fromhex( + "b6ff4d689b95e3310efbf683850c075bcde46361923054e42ef30016b287ff0c" ), ) def test_public_spend(self): - derivation = unhexlify( - b"e720a09f2e3a0bbf4e4ba7ad93653bb296885510121f806acb2a5f9168fafa01" + derivation = bytes.fromhex( + "e720a09f2e3a0bbf4e4ba7ad93653bb296885510121f806acb2a5f9168fafa01" ) - base = unhexlify( - b"7d996b0f2db6dbb5f2a086211f2399a4a7479b2c911af307fdc3f7f61a88cb0e" + base = bytes.fromhex( + "7d996b0f2db6dbb5f2a086211f2399a4a7479b2c911af307fdc3f7f61a88cb0e" ) - pkey_ex = unhexlify( - b"0846cae7405077b6b7800f0b932c10a186448370b6db318f8c9e13f781dab546" + pkey_ex = bytes.fromhex( + "0846cae7405077b6b7800f0b932c10a186448370b6db318f8c9e13f781dab546" ) pkey_comp = crypto_helpers.derive_public_key( @@ -279,17 +279,17 @@ def test_view_tags(self): test_vectors = [ ( - b"0fc47054f355ced4d67de73bfa12e4c78ff19089548fffa7d07a674741860f97", + "0fc47054f355ced4d67de73bfa12e4c78ff19089548fffa7d07a674741860f97", 0, b"\x76", ), ( - b"fe7770c4b076e95ddb8026affcfab39d31c7c4a2266e0e25e343bc4badc907d0", + "fe7770c4b076e95ddb8026affcfab39d31c7c4a2266e0e25e343bc4badc907d0", 15, b"\xeb", ), ( - b"ea9337d0ddf480abdc4fc56a0cb223702729cb230ae7b9de50243ad25ce90e8d", + "ea9337d0ddf480abdc4fc56a0cb223702729cb230ae7b9de50243ad25ce90e8d", 13, b"\x42", ), @@ -297,7 +297,8 @@ def test_view_tags(self): for key, idx, exp in test_vectors: self.assertEqual( - _derive_view_tags(crypto_helpers.decodepoint(unhexlify(key)), idx), exp + _derive_view_tags(crypto_helpers.decodepoint(bytes.fromhex(key)), idx), + exp, ) diff --git a/core/tests/test_apps.monero.proto.py b/core/tests/test_apps.monero.proto.py index 775eff5d6e4..3fd77702e1a 100644 --- a/core/tests/test_apps.monero.proto.py +++ b/core/tests/test_apps.monero.proto.py @@ -2,8 +2,6 @@ from common import * # isort:skip if not utils.BITCOIN_ONLY: - import ubinascii - from trezor.crypto import chacha20poly1305_decrypt, chacha20poly1305_encrypt from apps.monero.signing import offloading_keys, step_09_sign_input @@ -13,33 +11,33 @@ @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroProto(unittest.TestCase): def test_sign_keys(self): - mst = ubinascii.unhexlify( - b"ca3bbe08a178a4508c3992a47ba775799e7626a365ed136e803fe5f2df2ce01c" + mst = bytes.fromhex( + "ca3bbe08a178a4508c3992a47ba775799e7626a365ed136e803fe5f2df2ce01c" ) self.assertEqual( offloading_keys.key_signature(mst, 0, True)[:12], - ubinascii.unhexlify(b"bb665d97ac7c77995578e352"), + bytes.fromhex("bb665d97ac7c77995578e352"), ) self.assertEqual( offloading_keys.key_signature(mst, 0, False), - ubinascii.unhexlify( - b"87bb70af81bb7325f73e8b962167579454d126ff8ee51472922d7c103fc60f5f" + bytes.fromhex( + "87bb70af81bb7325f73e8b962167579454d126ff8ee51472922d7c103fc60f5f" ), ) self.assertEqual( offloading_keys.key_signature(mst, 3, True)[:12], - ubinascii.unhexlify(b"b2ef8e4e4eec72ce3096622a"), + bytes.fromhex("b2ef8e4e4eec72ce3096622a"), ) self.assertEqual( offloading_keys.key_signature(mst, 3, False), - ubinascii.unhexlify( - b"e4331602a83a68c892a83693a1b961564048d9349111b85b8b4b52a1adcf36da" + bytes.fromhex( + "e4331602a83a68c892a83693a1b961564048d9349111b85b8b4b52a1adcf36da" ), ) def test_sig_seal(self): - mst = ubinascii.unhexlify( - b"ca3bbe08a178a4508c3992a47ba775799e7626a365ed136e803fe5f2df2ce01c" + mst = bytes.fromhex( + "ca3bbe08a178a4508c3992a47ba775799e7626a365ed136e803fe5f2df2ce01c" ) st = State() st.last_step = st.STEP_SIGN @@ -62,7 +60,7 @@ def test_sig_seal(self): "03da465e27f7feec31353cb668f0e8965391f983b06c0684b35b00af38533603", ] - mg_buff = [ubinascii.unhexlify(x) for x in mg_buff] + mg_buff = [bytes.fromhex(x) for x in mg_buff] mg_buff_b = list(mg_buff) mg_res = step_09_sign_input._protect_signature(st, mg_buff) diff --git a/core/tests/test_apps.nem.address.py b/core/tests/test_apps.nem.address.py index 0a00938bb85..824ebc12031 100644 --- a/core/tests/test_apps.nem.address.py +++ b/core/tests/test_apps.nem.address.py @@ -17,13 +17,13 @@ @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemAddress(unittest.TestCase): def test_addresses(self): - pubkey = unhexlify( + pubkey = bytes.fromhex( "c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844" ) address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET) self.assertEqual(address, "NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4") - pubkey = unhexlify( + pubkey = bytes.fromhex( "114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810" ) address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET) diff --git a/core/tests/test_apps.nem.hdnode.py b/core/tests/test_apps.nem.hdnode.py index d6e79840c20..264cd63a40a 100644 --- a/core/tests/test_apps.nem.hdnode.py +++ b/core/tests/test_apps.nem.hdnode.py @@ -118,7 +118,7 @@ def test_addresses(self): ] for test in test_cases: - private_key = bytearray(reversed(unhexlify(test[0]))) + private_key = bytearray(reversed(bytes.fromhex(test[0]))) node = bip32.HDNode( depth=0, @@ -131,7 +131,7 @@ def test_addresses(self): self.assertEqual(node.nem_address(NEM_NETWORK_MAINNET), test[2]) # public key is prepended with 1, removing - self.assertEqual(node.public_key()[1:], unhexlify(test[1])) + self.assertEqual(node.public_key()[1:], bytes.fromhex(test[1])) def test_encryption(self): # test vectors from https://raw.githubusercontent.com/NemProject/nem-test-vectors/master/4.test-cipher.dat @@ -300,7 +300,7 @@ def test_encryption(self): ] for test in test_cases: - private_key = bytearray(reversed(unhexlify(test["private"]))) + private_key = bytearray(reversed(bytes.fromhex(test["private"]))) node = bip32.HDNode( depth=0, fingerprint=0, @@ -311,13 +311,13 @@ def test_encryption(self): ) encrypted = node.nem_encrypt( - unhexlify(test["public"]), - unhexlify(test["iv"]), - unhexlify(test["salt"]), - unhexlify(test["input"]), + bytes.fromhex(test["public"]), + bytes.fromhex(test["iv"]), + bytes.fromhex(test["salt"]), + bytes.fromhex(test["input"]), ) - self.assertEqual(encrypted, unhexlify(test["output"])) + self.assertEqual(encrypted, bytes.fromhex(test["output"])) if __name__ == "__main__": diff --git a/core/tests/test_apps.nem.mosaic_creation.py b/core/tests/test_apps.nem.mosaic_creation.py index 181d5e7a71e..fd66f78023e 100644 --- a/core/tests/test_apps.nem.mosaic_creation.py +++ b/core/tests/test_apps.nem.mosaic_creation.py @@ -45,20 +45,20 @@ def test_nem_transaction_mosaic_creation(self): t = serialize_mosaic_creation( m.transaction, m.mosaic_creation, - unhexlify( + bytes.fromhex( "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" ), ) self.assertEqual( t, - unhexlify( + bytes.fromhex( "014000000100009870b4d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd32400f36f060000000080c2d600de00000020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3241f0000001000000067696d72652e67616d65732e706f6e6707000000706164646c65731b000000506164646c657320666f722074686520626f6e672067616d652e0a04000000150000000c00000064697669736962696c69747901000000301a0000000d000000696e697469616c537570706c79050000003130303030190000000d000000737570706c794d757461626c650400000074727565180000000c0000007472616e7366657261626c650400000074727565000000002800000054424d4f534149434f443446353445453543444d523233434342474f414d3258534a4252354f4c4300743ba40b000000" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "68364353c29105e6d361ad1a42abbccbf419cfc7adb8b74c8f35d8f8bdaca3fa" ), ) @@ -89,14 +89,14 @@ def test_nem_transaction_mosaic_creation_with_levy(self): t = serialize_mosaic_creation( m.transaction, m.mosaic_creation, - unhexlify( + bytes.fromhex( "244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "b2f4a98113ff1f3a8f1e9d7197aa982545297fe0aa3fa6094af8031569953a55" ), ) @@ -126,19 +126,19 @@ def test_nem_transaction_mosaic_creation_with_levy(self): t = serialize_mosaic_creation( m.transaction, m.mosaic_creation, - unhexlify( + bytes.fromhex( "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" ), ) self.assertEqual( t, - unhexlify( + bytes.fromhex( "0140000001000068ccaf200420000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d3101000000004c0122040c01000020000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a0f0000000300000064696d04000000636f696e0800000044494d20434f494e04000000150000000c00000064697669736962696c69747901000000361f0000000d000000696e697469616c537570706c790a000000393030303030303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c6504000000747275654b00000002000000280000004e4347474c564f32473343554143564935474e58324b52424a5351434e3452444c325a574a3444500f0000000300000064696d04000000636f696e0a00000000000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d325853495558365452530065cd1d00000000" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "e8dc14821dbea4831d9051f86158ef348001447968fc22c01644fdaf2bda75c6" ), ) @@ -172,20 +172,20 @@ def test_nem_transaction_mosaic_creation_with_description(self): t = serialize_mosaic_creation( m.transaction, m.mosaic_creation, - unhexlify( + bytes.fromhex( "58956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f23" ), ) self.assertEqual( t, - unhexlify( + bytes.fromhex( "0140000001000068d2dd97012000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2300f36f0600000000e2eb9701c80100002000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2317000000060000006a61626f3338090000007265645f746f6b656e0c0100005468697320746f6b656e20697320746f2063656c656272617465207468652072656c65617365206f66204e616d6573706163657320616e64204d6f7361696373206f6e20746865204e454d2073797374656d2e205468697320746f6b656e207761732074686520666973742065766572206d6f736169632063726561746564206f74686572207468616e206e656d2e78656d2e20546865726520617265206f6e6c792031302c3030302052656420546f6b656e7320746861742077696c6c206576657220626520637265617465642e20497420686173206e6f206c65767920616e642063616e2062652074726164656420667265656c7920616d6f6e6720746869726420706172746965732e04000000150000000c00000064697669736962696c69747901000000321a0000000d000000696e697469616c537570706c790500000031303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c65040000007472756500000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d3258534955583654525300743ba40b000000" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "269c6fda657aba3053a0e5b138c075808cc20e244e1182d9b730798b60a1f77b" ), ) diff --git a/core/tests/test_apps.nem.mosaic_supply_change.py b/core/tests/test_apps.nem.mosaic_supply_change.py index 490a7a8a003..ec0a2f9cad4 100644 --- a/core/tests/test_apps.nem.mosaic_supply_change.py +++ b/core/tests/test_apps.nem.mosaic_supply_change.py @@ -29,14 +29,14 @@ def test_nem_transaction_create_mosaic_supply_change(self): t = serialize_mosaic_supply_change( m.transaction, m.supply_change, - unhexlify( + bytes.fromhex( "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "33a50fdd4a54913643a580b2af08b9a5b51b7cee922bde380e84c573a7969c50" ), ) @@ -55,14 +55,14 @@ def test_nem_transaction_create_mosaic_supply_change(self): t = serialize_mosaic_supply_change( m.transaction, m.supply_change, - unhexlify( + bytes.fromhex( "84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "1ce8e8894d077a66ff22294b000825d090a60742ec407efd80eb8b19657704f2" ), ) @@ -81,14 +81,14 @@ def test_nem_transaction_create_mosaic_supply_change(self): t = serialize_mosaic_supply_change( m.transaction, m.supply_change, - unhexlify( + bytes.fromhex( "b7ccc27b21ba6cf5c699a8dc86ba6ba98950442597ff9fa30e0abe0f5f4dd05d" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "694e493e9576d2bcf60d85747e302ac2e1cc27783187947180d4275a713ff1ff" ), ) @@ -100,14 +100,14 @@ def test_nem_transaction_create_mosaic_supply_change(self): t = serialize_mosaic_supply_change( m.transaction, m.supply_change, - unhexlify( + bytes.fromhex( "75f001a8641e2ce5c4386883dda561399ed346177411b492a677b73899502f13" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "09836334e123970e068d5b411e4d1df54a3ead10acf1ad5935a2cdd9f9680185" ), ) diff --git a/core/tests/test_apps.nem.multisig.aggregate_modification.py b/core/tests/test_apps.nem.multisig.aggregate_modification.py index b2e225ef340..a2dd652271c 100644 --- a/core/tests/test_apps.nem.multisig.aggregate_modification.py +++ b/core/tests/test_apps.nem.multisig.aggregate_modification.py @@ -24,7 +24,7 @@ def test_nem_transaction_aggregate_modification(self): t = serialize_aggregate_modification( m.transaction, m.aggregate_modification, - unhexlify( + bytes.fromhex( "462ee976890916e54fa825d26bdd0235f5eb5b6a143c199ab0ae5ee9328e08ce" ), ) @@ -32,21 +32,21 @@ def test_nem_transaction_aggregate_modification(self): write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "c54d6e33ed1446eedd7f7a80a588dd01857f723687a09200c1917d5524752f8b" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "6a55471b17159e5b6cd579c421e95a4e39d92e3f78b0a55ee337e785a601d3a2" ), ) @@ -56,7 +56,7 @@ def test_nem_transaction_aggregate_modification(self): t = serialize_aggregate_modification( m.transaction, m.aggregate_modification, - unhexlify( + bytes.fromhex( "f41b99320549741c5cce42d9e4bb836d98c50ed5415d0c3c2912d1bb50e6a0e5" ), ) @@ -64,42 +64,42 @@ def test_nem_transaction_aggregate_modification(self): write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "1fbdbdde28daf828245e4533765726f0b7790e0b7146e2ce205df3e86366980b" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "f94e8702eb1943b23570b1b83be1b81536df35538978820e98bfce8f999e2d37" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "826cedee421ff66e708858c17815fcd831a4bb68e3d8956299334e9e24380ba8" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "719862cd7d0f4e875a6a0274c9a1738f38f40ad9944179006a54c34724c1274d" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "43aa69177018fc3e2bdbeb259c81cddf24be50eef9c5386db51d82386c41475a" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "cc64ca69bfa95db2ff7ac1e21fe6d27ece189c603200ebc9778d8bb80ca25c3c" ), ) @@ -110,7 +110,7 @@ def test_nem_transaction_aggregate_modification_relative_change(self): t = serialize_aggregate_modification( m.transaction, m.aggregate_modification, - unhexlify( + bytes.fromhex( "6bf7849c1eec6a2002995cc457dc00c4e29bad5c88de63f51e42dfdcd7b2131d" ), ) @@ -118,28 +118,28 @@ def test_nem_transaction_aggregate_modification_relative_change(self): write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "5f53d076c8c3ec3110b98364bc423092c3ec2be2b1b3c40fd8ab68d54fa39295" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "9eb199c2b4d406f64cb7aa5b2b0815264b56ba8fe44d558a6cb423a31a33c4c2" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "94b2323dab23a3faba24fa6ddda0ece4fbb06acfedd74e76ad9fae38d006882b" ), ) write_cosignatory_modification( t, 1, - unhexlify( + bytes.fromhex( "d88c6ee2a2cd3929d0d76b6b14ecb549d21296ab196a2b3a4cb2536bcce32e87" ), ) @@ -147,7 +147,7 @@ def test_nem_transaction_aggregate_modification_relative_change(self): self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "1fbdae5ba753e68af270930413ae90f671eb8ab58988116684bac0abd5726584" ), ) diff --git a/core/tests/test_apps.nem.multisig.py b/core/tests/test_apps.nem.multisig.py index 3c02a8112ec..f5ae3764064 100644 --- a/core/tests/test_apps.nem.multisig.py +++ b/core/tests/test_apps.nem.multisig.py @@ -25,7 +25,7 @@ def test_nem_multisig(self): base_tx = serialize_aggregate_modification( m.transaction, m.aggregate_modification, - unhexlify( + bytes.fromhex( "abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac" ), ) @@ -33,14 +33,14 @@ def test_nem_multisig(self): write_cosignatory_modification( base_tx, 2, - unhexlify( + bytes.fromhex( "e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3" ), ) m = _create_common_msg(NEM_NETWORK_TESTNET, 3939039, 6000000, 3960639) multisig = serialize_multisig( m, - unhexlify( + bytes.fromhex( "59d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e" ), base_tx, @@ -48,18 +48,18 @@ def test_nem_multisig(self): self.assertEqual( multisig, - unhexlify( + bytes.fromhex( "0410000001000098df1a3c002000000059d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e808d5b00000000003f6f3c006c0000000110000001000098df1a3c0020000000abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac0024f400000000003f6f3c0001000000280000000200000020000000e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3" ), ) - address_pubkey = unhexlify( + address_pubkey = bytes.fromhex( "abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac" ) m = _create_common_msg(NEM_NETWORK_TESTNET, 3939891, 6000000, 3961491) multisig = serialize_multisig_signature( m, - unhexlify( + bytes.fromhex( "71cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4" ), base_tx, @@ -68,7 +68,7 @@ def test_nem_multisig(self): self.assertEqual( multisig, - unhexlify( + bytes.fromhex( "0210000001000098331e3c002000000071cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4808d5b000000000093723c0024000000200000008ec165580bdabfd31ce6007a1748ce5bdf30eab7a214743097de3bc822ac7e002800000054435258595551494d464137414f474c354c463359574c43375641424c59554d4a35414342554e4c" ), ) @@ -88,7 +88,7 @@ def test_nem_multisig_2(self): base_tx = serialize_provision_namespace( m.transaction, m.provision_namespace, - unhexlify( + bytes.fromhex( "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" ), ) @@ -97,25 +97,25 @@ def test_nem_multisig_2(self): multisig = serialize_multisig( m, - unhexlify( + bytes.fromhex( "cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9" ), base_tx, ) self.assertEqual( multisig, - unhexlify( + bytes.fromhex( "041000000100006800978a0320000000cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9808d5b000000000080e88b037b000000012000000100006800978a0320000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d31010000000080e88b03280000004e414d4553504143455748344d4b464d42435646455244504f4f5034464b374d54425844505a5a4100f2052a010000000300000064696dffffffff" ), ) m = _create_common_msg(NEM_NETWORK_MAINNET, 59414342, 6000000, 59500742) - address_pubkey = unhexlify( + address_pubkey = bytes.fromhex( "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" ) multisig = serialize_multisig_signature( m, - unhexlify( + bytes.fromhex( "1b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2" ), base_tx, @@ -123,7 +123,7 @@ def test_nem_multisig_2(self): ) self.assertEqual( multisig, - unhexlify( + bytes.fromhex( "021000000100006846978a03200000001b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2808d5b0000000000c6e88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56" ), ) @@ -131,7 +131,7 @@ def test_nem_multisig_2(self): m = _create_common_msg(NEM_NETWORK_MAINNET, 59414381, 6000000, 59500781) multisig = serialize_multisig_signature( m, - unhexlify( + bytes.fromhex( "7ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87" ), base_tx, @@ -139,7 +139,7 @@ def test_nem_multisig_2(self): ) self.assertEqual( multisig, - unhexlify( + bytes.fromhex( "02100000010000686d978a03200000007ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87808d5b0000000000ede88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56" ), ) diff --git a/core/tests/test_apps.nem.namespace.py b/core/tests/test_apps.nem.namespace.py index 3d28b69f250..603c7c529d4 100644 --- a/core/tests/test_apps.nem.namespace.py +++ b/core/tests/test_apps.nem.namespace.py @@ -29,13 +29,13 @@ def test_create_provision_namespace(self): t = serialize_provision_namespace( m.transaction, m.provision_namespace, - unhexlify( + bytes.fromhex( "84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "f7cab28da57204d01a907c697836577a4ae755e6c9bac60dcc318494a22debb3" ), ) @@ -54,14 +54,14 @@ def test_create_provision_namespace(self): t = serialize_provision_namespace( m.transaction, m.provision_namespace, - unhexlify( + bytes.fromhex( "244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "7ddd5fe607e1bfb5606e0ac576024c318c8300d237273117d4db32a60c49524d" ), ) @@ -80,14 +80,14 @@ def test_create_provision_namespace(self): t = serialize_provision_namespace( m.transaction, m.provision_namespace, - unhexlify( + bytes.fromhex( "9f3c14f304309c8b72b2821339c4428793b1518bea72d58dd01f19d523518614" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "57071aad93ca125dc231dc02c07ad8610cd243d35068f9b36a7d231383907569" ), ) diff --git a/core/tests/test_apps.nem.transfer.py b/core/tests/test_apps.nem.transfer.py index c368b8f0eb9..1db7ece99c7 100644 --- a/core/tests/test_apps.nem.transfer.py +++ b/core/tests/test_apps.nem.transfer.py @@ -29,7 +29,7 @@ def test_create_transfer(self): t = serialize_transfer( m.transaction, m.transfer, - unhexlify( + bytes.fromhex( "e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f" ), None, @@ -37,13 +37,13 @@ def test_create_transfer(self): ) self.assertEqual( t, - unhexlify( + bytes.fromhex( "01010000010000980000000020000000e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f00000000000000000000000028000000544247494d52453453424652554a584d48374456463249425933364c324544575a3337475653433400203d88792d000000000000" ), ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "0acbf8df91e6a65dc56c56c43d65f31ff2a6a48d06fc66e78c7f3436faf3e74f" ), ) @@ -63,15 +63,15 @@ def test_create_transfer_with_payload(self): t = serialize_transfer( m.transaction, m.transfer, - unhexlify( + bytes.fromhex( "8d07f90fb4bbe7715fa327c926770166a11be2e494a970605f2e12557f66c9b9" ), - bytearray("Good luck!"), + b"Good luck!", False, ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "e90e98614c7598fbfa4db5411db1b331d157c2f86b558fb7c943d013ed9f71cb" ), ) @@ -91,17 +91,17 @@ def test_create_transfer_with_encrypted_payload(self): t = serialize_transfer( m.transaction, m.transfer, - unhexlify( + bytes.fromhex( "f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01" ), - unhexlify( + bytes.fromhex( "4d9dcf9186967d30be93d6d5404ded22812dbbae7c3f0de501bcd7228cba45bded13000eec7b4c6215fc4d3588168c9218167cec98e6977359153a4132e050f594548e61e0dc61c153f0f53c5e65c595239c9eb7c4e7d48e0f4bb8b1dd2f5ddc" ), True, ) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "40e89160e6f83d37f7c82defc0afe2c1605ae8c919134570a51dd27ea1bb516c" ), ) @@ -122,16 +122,16 @@ def test_create_transfer_with_mosaic(self): t = serialize_transfer( m.transaction, m.transfer, - unhexlify( + bytes.fromhex( "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" ), - bytearray("sending you 3 pairs of paddles\n"), + b"sending you 3 pairs of paddles\n", False, ) self.assertEqual( t, - unhexlify( + bytes.fromhex( "010100000200009824b9d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3248034900b0000000034c7d6002800000054424c4f4f44504c574f574d5a3254415258345246504f534f574c554c48584d524f424e32575849c0c62d000000000027000000010000001f00000073656e64696e6720796f752033207061697273206f6620706164646c65730a02000000" ), ) @@ -141,7 +141,7 @@ def test_create_transfer_with_mosaic(self): self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "3409d9ece28d6296d6d5e220a7e3cb8641a3fb235ffcbd20c95da64f003ace6c" ), ) @@ -160,17 +160,17 @@ def test_create_transfer_with_mosaic(self): t = serialize_transfer( m.transaction, m.transfer, - unhexlify( + bytes.fromhex( "f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01" ), - bytearray("enjoy! :)"), + b"enjoy! :)", False, ) serialize_mosaic(t, "imre.g", "tokens", 1) self.assertEqual( hashlib.sha3_256(t, keccak=True).digest(), - unhexlify( + bytes.fromhex( "882dca18dcbe075e15e0ec5a1d7e6ccd69cc0f1309ffd3fde227bfbc107b3f6e" ), ) diff --git a/core/tests/test_apps.ripple.address.py b/core/tests/test_apps.ripple.address.py index c5cd1d73678..0cff512e492 100644 --- a/core/tests/test_apps.ripple.address.py +++ b/core/tests/test_apps.ripple.address.py @@ -9,21 +9,21 @@ class TestRippleAddress(unittest.TestCase): def test_pubkey_to_address(self): addr = address_from_public_key( - unhexlify( + bytes.fromhex( "ed9434799226374926eda3b54b1b461b4abf7237962eae18528fea67595397fa32" ) ) self.assertEqual(addr, "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN") addr = address_from_public_key( - unhexlify( + bytes.fromhex( "03e2b079e9b09ae8916da8f5ee40cbda9578dbe7c820553fe4d5f872eec7b1fdd4" ) ) self.assertEqual(addr, "rhq549rEtUrJowuxQC2WsHNGLjAjBQdAe8") addr = address_from_public_key( - unhexlify( + bytes.fromhex( "0282ee731039929e97db6aec242002e9aa62cd62b989136df231f4bb9b8b7c7eb2" ) ) diff --git a/core/tests/test_apps.ripple.serializer.py b/core/tests/test_apps.ripple.serializer.py index 837820f0bea..46e91a093c1 100644 --- a/core/tests/test_apps.ripple.serializer.py +++ b/core/tests/test_apps.ripple.serializer.py @@ -26,7 +26,7 @@ def test_transactions(self): ) self.assertEqual( serialize(common, source_address, pubkey=None), - unhexlify( + bytes.fromhex( "120000240000000161400000000bebc20068400000000000000a811450f97a072f1c4357f1ad84566a609479d927c9428314550fc62003e785dc231a1058a05e56e3f09cf4e6" ), ) @@ -45,7 +45,7 @@ def test_transactions(self): ) self.assertEqual( serialize(common, source_address, pubkey=None), - unhexlify( + bytes.fromhex( "12000024000000636140000000000000016840000000000000638114550fc62003e785dc231a1058a05e56e3f09cf4e6831450f97a072f1c4357f1ad84566a609479d927c942" ), ) @@ -65,7 +65,7 @@ def test_transactions(self): ) self.assertEqual( serialize(common, source_address, pubkey=None), - unhexlify( + bytes.fromhex( "120000220000000024000000026140000000017d784068400000000000000a81145ccb151f6e9d603f394ae778acf10d3bece874f68314e851bbbe79e328e43d68f43445368133df5fba5a" ), ) @@ -86,7 +86,7 @@ def test_transactions(self): # 201b005ee9ba removed from the test vector because last ledger sequence is not supported self.assertEqual( serialize(common, source_address, pubkey=None), - unhexlify( + bytes.fromhex( "12000022000000002400000090614000000000030d4068400000000000000f8114aa1bd19d9e87be8069fdbf6843653c43837c03c6831467fe6ec28e0464dd24fb2d62a492aac697cfad02" ), ) @@ -108,7 +108,7 @@ def test_transactions(self): ) self.assertEqual( serialize(common, source_address, pubkey=None), - unhexlify( + bytes.fromhex( "120000220000000024000000012ef72d50ca6140000000017d784068400000000000000c8114e851bbbe79e328e43d68f43445368133df5fba5a831476dac5e814cd4aa74142c3ab45e69a900e637aa2" ), ) @@ -131,30 +131,30 @@ def test_transactions_for_signing(self): tx = serialize( common, source_address, - pubkey=unhexlify( + pubkey=bytes.fromhex( "ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a" ), ) network_prefix = helpers.HASH_TX_SIGN.to_bytes(4, "big") tx = network_prefix + tx - self.assertEqual(tx[0:4], unhexlify("53545800")) # signing prefix - self.assertEqual(tx[4:7], unhexlify("120000")) # transaction type - self.assertEqual(tx[7:12], unhexlify("2280000000")) # flags - self.assertEqual(tx[12:17], unhexlify("2400000001")) # sequence - self.assertEqual(tx[17:26], unhexlify("6140000000000003e8")) # amount - self.assertEqual(tx[26:35], unhexlify("68400000000000000a")) # fee + self.assertEqual(tx[0:4], bytes.fromhex("53545800")) # signing prefix + self.assertEqual(tx[4:7], bytes.fromhex("120000")) # transaction type + self.assertEqual(tx[7:12], bytes.fromhex("2280000000")) # flags + self.assertEqual(tx[12:17], bytes.fromhex("2400000001")) # sequence + self.assertEqual(tx[17:26], bytes.fromhex("6140000000000003e8")) # amount + self.assertEqual(tx[26:35], bytes.fromhex("68400000000000000a")) # fee self.assertEqual( tx[35:70], - unhexlify( + bytes.fromhex( "7321ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a" ), ) # signing pub key self.assertEqual( - tx[70:92], unhexlify("81145b812c9d57731e27a2da8b1830195f88ef32a3b6") + tx[70:92], bytes.fromhex("81145b812c9d57731e27a2da8b1830195f88ef32a3b6") ) # account self.assertEqual( - tx[92:114], unhexlify("8314b5f762798a53d543a014caf8b297cff8f2f937e8") + tx[92:114], bytes.fromhex("8314b5f762798a53d543a014caf8b297cff8f2f937e8") ) # destination self.assertEqual(len(tx[114:]), 0) # that's it diff --git a/core/tests/test_apps.solana.offchain_message.py b/core/tests/test_apps.solana.offchain_message.py index 8751eafb7bb..4a8ab91828d 100644 --- a/core/tests/test_apps.solana.offchain_message.py +++ b/core/tests/test_apps.solana.offchain_message.py @@ -1,6 +1,4 @@ # flake8: noqa: F403,F405 -from ubinascii import unhexlify - from trezor.crypto import base58 from trezor.wire import DataError @@ -58,7 +56,7 @@ def test_vectors(self): for vector in TEST_VECTORS: signers = [base58.decode(signer) for signer in vector["signers"]] serialized = self.serialize(signers, vector["message"]) - self.assertEqual(serialized, unhexlify(vector["hex"])) + self.assertEqual(serialized, bytes.fromhex(vector["hex"])) def test_signers_empty(self): with self.assertRaises(DataError): diff --git a/core/tests/test_apps.stellar.address.py b/core/tests/test_apps.stellar.address.py index 7717e65d780..e53ff2523d7 100644 --- a/core/tests/test_apps.stellar.address.py +++ b/core/tests/test_apps.stellar.address.py @@ -24,7 +24,7 @@ def test_address_to_pubkey(self): public_key_from_address( "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V" ), - unhexlify( + bytes.fromhex( "5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0" ), ) @@ -33,14 +33,14 @@ def test_address_to_pubkey(self): public_key_from_address( "GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6" ), - unhexlify( + bytes.fromhex( "9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4" ), ) def test_pubkey_to_address(self): addr = address_from_public_key( - unhexlify( + bytes.fromhex( "5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0" ) ) @@ -49,7 +49,7 @@ def test_pubkey_to_address(self): ) addr = address_from_public_key( - unhexlify( + bytes.fromhex( "9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4" ) ) @@ -58,21 +58,21 @@ def test_pubkey_to_address(self): ) def test_both(self): - pubkey = unhexlify( + pubkey = bytes.fromhex( "dfcc77d08588601702e02de2dc603f5c5281bea23baa894ae3b3b4778e5bbe40" ) self.assertEqual( public_key_from_address(address_from_public_key(pubkey)), pubkey ) - pubkey = unhexlify( + pubkey = bytes.fromhex( "53214e6155469c32fb882b1b1d94930d5445a78202867b7ddc6a33ad42ff4464" ) self.assertEqual( public_key_from_address(address_from_public_key(pubkey)), pubkey ) - pubkey = unhexlify( + pubkey = bytes.fromhex( "5ed4690134e5ef79b290ea1e7a4b8f3b6b3bcf287463c18bfe36baa030e7efbd" ) self.assertEqual( @@ -91,7 +91,7 @@ def test_invalid_address(self): # and decode_strkey(strkey) -> (version, data). def test_strkey_account(self): # ED25519 public key (G... address) - pubkey = unhexlify( + pubkey = bytes.fromhex( "3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a" ) strkey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ" @@ -100,7 +100,7 @@ def test_strkey_account(self): def test_strkey_contract(self): # contract address (C... address) - contract_hash = unhexlify( + contract_hash = bytes.fromhex( "3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a" ) strkey = "CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA" @@ -129,13 +129,13 @@ def test_strkey_muxed_account(self): "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAEABLYI", ), ): - muxed_data = unhexlify(pubkey + muxed_id) + muxed_data = bytes.fromhex(pubkey + muxed_id) self.assertEqual(encode_strkey(STRKEY_MUXED_ACCOUNT, muxed_data), strkey) self.assertEqual(decode_strkey(strkey), (STRKEY_MUXED_ACCOUNT, muxed_data)) def test_strkey_claimable_balance(self): # claimable balance (B... address): 1 byte type (v0 = 0x00) + 32 bytes hash - balance_id = unhexlify( + balance_id = bytes.fromhex( "00" # type v0 "3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a" # hash ) @@ -145,7 +145,7 @@ def test_strkey_claimable_balance(self): def test_strkey_liquidity_pool(self): # liquidity pool (L... address): 32 bytes hash - pool_id = unhexlify( + pool_id = bytes.fromhex( "3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a" ) strkey = "LA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUPJN" diff --git a/core/tests/test_apps.stellar.writers.py b/core/tests/test_apps.stellar.writers.py index 82deca4a19c..5e655f70e49 100644 --- a/core/tests/test_apps.stellar.writers.py +++ b/core/tests/test_apps.stellar.writers.py @@ -24,7 +24,7 @@ def test_write_int32(self): for value, expected in TESTS: w = bytearray() write_int32(w, value) - self.assertEqual(w, unhexlify(expected), msg=f"write_int32({value})") + self.assertEqual(w, bytes.fromhex(expected), msg=f"write_int32({value})") def test_write_int32_out_of_range(self): TESTS = [ @@ -52,7 +52,7 @@ def test_write_int64(self): for value, expected in TESTS: w = bytearray() write_int64(w, value) - self.assertEqual(w, unhexlify(expected), msg=f"write_int64({value})") + self.assertEqual(w, bytes.fromhex(expected), msg=f"write_int64({value})") def test_write_int64_out_of_range(self): TESTS = [ diff --git a/core/tests/test_apps.tezos.address.py b/core/tests/test_apps.tezos.address.py index 748419e760b..27681a6c79d 100644 --- a/core/tests/test_apps.tezos.address.py +++ b/core/tests/test_apps.tezos.address.py @@ -14,19 +14,19 @@ def test_get_address_from_contract(self): contracts = [ TezosContractID( tag=TezosContractType.Implicit, - hash=unhexlify("0090ec585b4d5fa39b20213e46b232cc57a4cfab4b"), + hash=bytes.fromhex("0090ec585b4d5fa39b20213e46b232cc57a4cfab4b"), ), TezosContractID( tag=TezosContractType.Implicit, - hash=unhexlify("017dfb3fef44082eca8cd3eccebd77db44633ffc9e"), + hash=bytes.fromhex("017dfb3fef44082eca8cd3eccebd77db44633ffc9e"), ), TezosContractID( tag=TezosContractType.Implicit, - hash=unhexlify("02c1fc1b7e503825068ff4fe2f8916f98af981eab1"), + hash=bytes.fromhex("02c1fc1b7e503825068ff4fe2f8916f98af981eab1"), ), TezosContractID( tag=TezosContractType.Originated, - hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00"), + hash=bytes.fromhex("65671dedc69669f066f45d586a2ecdeddacc95af00"), ), ] diff --git a/core/tests/test_apps.tezos.encode.py b/core/tests/test_apps.tezos.encode.py index ad9d15b7af4..fd654f39252 100644 --- a/core/tests/test_apps.tezos.encode.py +++ b/core/tests/test_apps.tezos.encode.py @@ -30,7 +30,7 @@ def test_tezos_encode_zarith(self): for i, o in zip(inputs, outputs): w = bytearray() _encode_zarith(w, i) - self.assertEqual(bytes(w), unhexlify(o)) + self.assertEqual(bytes(w), bytes.fromhex(o)) def test_tezos_encode_data_with_bool_prefix(self): w = bytearray() @@ -39,8 +39,8 @@ def test_tezos_encode_data_with_bool_prefix(self): data = "afffeb1dc3c0" w = bytearray() - _encode_data_with_bool_prefix(w, unhexlify(data), 6) - self.assertEqual(bytes(w), unhexlify("ff" + data)) + _encode_data_with_bool_prefix(w, bytes.fromhex(data), 6) + self.assertEqual(bytes(w), bytes.fromhex("ff" + data)) def test_tezos_encode_bool(self): w = bytearray() @@ -54,26 +54,26 @@ def test_tezos_encode_bool(self): def test_tezos_encode_contract_id(self): implicit = TezosContractID( tag=TezosContractType.Implicit, - hash=unhexlify("00101368afffeb1dc3c089facbbe23f5c30b787ce9"), + hash=bytes.fromhex("00101368afffeb1dc3c089facbbe23f5c30b787ce9"), ) w = bytearray() _encode_contract_id(w, implicit) self.assertEqual( - bytes(w), unhexlify("0000101368afffeb1dc3c089facbbe23f5c30b787ce9") + bytes(w), bytes.fromhex("0000101368afffeb1dc3c089facbbe23f5c30b787ce9") ) originated = TezosContractID( tag=TezosContractType.Originated, - hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00"), + hash=bytes.fromhex("65671dedc69669f066f45d586a2ecdeddacc95af00"), ) w = bytearray() _encode_contract_id(w, originated) self.assertEqual( - bytes(w), unhexlify("0165671dedc69669f066f45d586a2ecdeddacc95af00") + bytes(w), bytes.fromhex("0165671dedc69669f066f45d586a2ecdeddacc95af00") ) def test_tezos_base58_encode_check(self): - pkh = unhexlify("101368afffeb1dc3c089facbbe23f5c30b787ce9") + pkh = bytes.fromhex("101368afffeb1dc3c089facbbe23f5c30b787ce9") self.assertEqual( base58_encode_check(pkh, prefix="tz1"), @@ -104,7 +104,7 @@ def test_tezos_encode_natural(self): for i, o in zip(inputs, outputs): w = bytearray() _encode_natural(w, i) - self.assertEqual(bytes(w), unhexlify(o)) + self.assertEqual(bytes(w), bytes.fromhex(o)) if __name__ == "__main__": diff --git a/core/tests/test_apps.tron.address.py b/core/tests/test_apps.tron.address.py index 136295750de..3e5b9b22c0f 100644 --- a/core/tests/test_apps.tron.address.py +++ b/core/tests/test_apps.tron.address.py @@ -15,21 +15,21 @@ def address_from_public_key(pubkey: bytes) -> str: class TestTronAddress(unittest.TestCase): def test_pubkey_to_address(self): addr = address_from_public_key( - unhexlify( + bytes.fromhex( "04aee772c640a56bfd434cc6c41b661467f0fac8ad922cd0d6f37a25a9faab506c9d687d8d4ad0957ca8a07b15db6b39ab2fa56cc81b49f2f92d44e1cdd2f4f266" ) ) self.assertEqual(addr, "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT") addr = address_from_public_key( - unhexlify( + bytes.fromhex( "041cc8ed55001c441a9ca7b42129f025f33ff30ea29dfe88fc9f8ad8826582c73b52d47c475c75da0cc9f64a6462ca57e70a8902a79cccc4e769cc0261c691ce4f" ) ) self.assertEqual(addr, "TVd6xm7E5vn9qnUQZbfoH5SAVZXZ15c4wC") addr = address_from_public_key( - unhexlify( + bytes.fromhex( "04d3df47d402249892f56295cf08cb70c2e37fc6b9eea01e1b163f4b5608f96c8449b3ea69541a33ff7961bb69af6f98bfca558fe53b9429de3fb8054d29f9c917" ) ) diff --git a/core/tests/test_apps.webauthn.credential.py b/core/tests/test_apps.webauthn.credential.py index d46ba163c88..09d7ebf58ca 100644 --- a/core/tests/test_apps.webauthn.credential.py +++ b/core/tests/test_apps.webauthn.credential.py @@ -23,40 +23,38 @@ def test_fido2_credential_decode(self): storage.device.is_initialized = lambda: True cred_id = ( - b"f1d0020013e65c865634ad8abddf7a66df56ae7d8c3afd356f76426801508b2e" - b"579bcb3496fe6396a6002e3cd6d80f6359dfa9961e24c544bfc2f26acec1b8d8" - b"78ba56727e1f6a7b5176c607552aea63a5abe5d826d69fab3063edfa0201d9a5" - b"1013d69eddb2eff37acdd5963f" + "f1d0020013e65c865634ad8abddf7a66df56ae7d8c3afd356f76426801508b2e" + "579bcb3496fe6396a6002e3cd6d80f6359dfa9961e24c544bfc2f26acec1b8d8" + "78ba56727e1f6a7b5176c607552aea63a5abe5d826d69fab3063edfa0201d9a5" + "1013d69eddb2eff37acdd5963f" ) rp_id = "example.com" rp_id_hash = sha256(rp_id).digest() - user_id = b"3082019330820138a0030201023082019330820138a003020102308201933082" + user_id = "3082019330820138a0030201023082019330820138a003020102308201933082" user_name = "johnpsmith@example.com" creation_time = 2 public_key = ( - b"a501020326200121582051f0d4c307bc737c90ac605c6279f7d01e451798aa7b" - b"74df550fdb43a7760c7c22582002b5107fef42094d00f52a9b1e90afb90e1b9d" - b"ecbf15a6f13d4f882de857e2f4" + "a501020326200121582051f0d4c307bc737c90ac605c6279f7d01e451798aa7b" + "74df550fdb43a7760c7c22582002b5107fef42094d00f52a9b1e90afb90e1b9d" + "ecbf15a6f13d4f882de857e2f4" ) - cred_random = ( - b"36a9b5d71c13ed54594474b54073af1fb03ea91cd056588909dae43ae2f35dbf" - ) + cred_random = "36a9b5d71c13ed54594474b54073af1fb03ea91cd056588909dae43ae2f35dbf" # Load credential. - cred = Fido2Credential.from_cred_id(unhexlify(cred_id), rp_id_hash) + cred = Fido2Credential.from_cred_id(bytes.fromhex(cred_id), rp_id_hash) self.assertIsNotNone(cred) # Check credential data. - self.assertEqual(hexlify(cred.id), cred_id) + self.assertEqual(cred.id.hex(), cred_id) self.assertEqual(cred.rp_id, rp_id) self.assertEqual(cred.rp_id_hash, rp_id_hash) - self.assertEqual(hexlify(cred.user_id), user_id) + self.assertEqual(cred.user_id.hex(), user_id) self.assertEqual(cred.user_name, user_name) self.assertEqual(cred.creation_time, creation_time) self.assertTrue(cred.hmac_secret) @@ -64,8 +62,8 @@ def test_fido2_credential_decode(self): self.assertIsNone(cred.user_display_name) # Check credential keys. - self.assertEqual(hexlify(cred.hmac_secret_key()), cred_random) - self.assertEqual(hexlify(cred.public_key()), public_key) + self.assertEqual(cred.hmac_secret_key().hex(), cred_random) + self.assertEqual(cred.public_key().hex(), public_key) def test_truncation(self): cred = Fido2Credential() diff --git a/core/tests/test_apps.zcash.f4jumble.py b/core/tests/test_apps.zcash.f4jumble.py index 215b64ffb7e..84a882392f1 100644 --- a/core/tests/test_apps.zcash.f4jumble.py +++ b/core/tests/test_apps.zcash.f4jumble.py @@ -10,42 +10,42 @@ def test_f4jumble(self): # source: https://github.com/zcash/librustzcash/blob/main/components/f4jumble/src/test_vectors.rs TEST_VECTORS = [ { - "jumbled": unhexlify( + "jumbled": bytes.fromhex( "0304d029141b995da5387c125970673504d6c764d91ea6c082123770c7139ccd88ee27368cd0c0921a0444c8e5858d22" ), - "normal": unhexlify( + "normal": bytes.fromhex( "5d7a8f739a2d9e945b0ce152a8049e294c4d6e66b164939daffa2ef6ee6921481cdd86b3cc4318d9614fc820905d042b" ), }, { - "jumbled": unhexlify( + "jumbled": bytes.fromhex( "5271fa3321f3adbcfb075196883d542b438ec6339176537daf859841fe6a56222bff76d1662b5509a9e1079e446eeedd2e683c31aae3ee1851d7954328526be1" ), - "normal": unhexlify( + "normal": bytes.fromhex( "b1ef9ca3f24988c7b3534201cfb1cd8dbf69b8250c18ef41294ca97993db546c1fe01f7e9c8e36d6a5e29d4e30a73594bf5098421c69378af1e40f64e125946f" ), }, { - "jumbled": unhexlify( + "jumbled": bytes.fromhex( "498cf1b1ba6f4577effe64151d67469adc30acc325e326207e7d78487085b4162669f82f02f9774c0cc26ae6e1a76f1e266c6a9a8a2f4ffe8d2d676b1ed71cc47195a3f19208998f7d8cdfc0b74d2a96364d733a62b4273c77d9828aa1fa061588a7c4c88dd3d3dde02239557acfaad35c55854f4541e1a1b3bc8c17076e7316" ), - "normal": unhexlify( + "normal": bytes.fromhex( "62c2fa7b2fecbcb64b6968912a6381ce3dc166d56a1d62f5a8d7551db5fd9313e8c7203d996af7d477083756d59af80d06a745f44ab023752cb5b406ed8985e18130ab33362697b0e4e4c763ccb8f676495c222f7fba1e31defa3d5a57efc2e1e9b01a035587d5fb1a38e01d94903d3c3e0ad3360c1d3710acd20b183e31d49f" ), }, { - "jumbled": unhexlify( + "jumbled": bytes.fromhex( "7508a3a146714f229db91b543e240633ed57853f6451c9db6d64c6e86af1b88b28704f608582c53c51ce7d5b8548827a971d2b98d41b7f6258655902440cd66ee11e84dbfac7d2a43696fd0468810a3d9637c3fa58e7d2d341ef250fa09b9fb71a78a41d389370138a55ea58fcde779d714a04e0d30e61dc2d8be0da61cd684509" ), - "normal": unhexlify( + "normal": bytes.fromhex( "25c9a138f49b1a537edcf04be34a9851a7af9db6990ed83dd64af3597c04323ea51b0052ad8084a8b9da948d320dadd64f5431e61ddf658d24ae67c22c8d1309131fc00fe7f235734276d38d47f1e191e00c7a1d48af046827591e9733a97fa6b679f3dc601d008285edcbdae69ce8fc1be4aac00ff2711ebd931de518856878f7" ), }, { - "jumbled": unhexlify( + "jumbled": bytes.fromhex( "5139912fe8b95492c12731995a0f4478dbeb81ec36653a21bc80d673f3c6a0feef70b6c566f9d34bb726c098648382d105afb19b2b8486b73cbd47a17a0d2d1fd593b14bb9826c5d114b850c6f0cf3083a6f61e38e42713a37ef7997ebd2b376c8a410d797b3932e5a6e39e726b2894ce79604b4ae3c00acaea3be2c1dfe697fa644755102cf9ad78794d0594585494fe38ab56fa6ef3271a68a33481015adf3944c115311421a7dc3ce73ef2abf47e18a6aca7f9dd25a85ce8dbd6f1ad89c8d" ), - "normal": unhexlify( + "normal": bytes.fromhex( "3476f21a482ec9378365c8f7393c94e2885315eb4671098b79535e790fe53e29fef2b3766697ac32b4f473f468a008e72389fc03880d780cb07fcfaabe3f1a84b27db59a4a153d882d2b2103596555ed9494c6ac893c49723833ec8926c1039586a7afcf4a0d9c731e985d99589c8bb838e8aaf745533ed9e8ae3a1cd074a51a20da8aba18d1dbebbc862ded42435e92476930d069896cff30eb414f727b89e001afa2fb8dc3436d75a4a6f26572504b192232ecb9f0c02411e52596bc5e9045" ), }, diff --git a/core/tests/test_apps.zcash.unified_addresses.py b/core/tests/test_apps.zcash.unified_addresses.py index 98f5110e3fa..c289cdab8a8 100644 --- a/core/tests/test_apps.zcash.unified_addresses.py +++ b/core/tests/test_apps.zcash.unified_addresses.py @@ -273,15 +273,15 @@ def __getattr__(self, name): def get_receivers(tv: ZcashTestVector): receivers = dict() if tv.p2pkh_bytes is not None: - receivers[P2PKH] = unhexlify(tv.p2pkh_bytes) + receivers[P2PKH] = bytes.fromhex(tv.p2pkh_bytes) if tv.p2sh_bytes is not None: - receivers[P2SH] = unhexlify(tv.p2sh_bytes) + receivers[P2SH] = bytes.fromhex(tv.p2sh_bytes) if tv.sapling_raw_addr is not None: - receivers[SAPLING] = unhexlify(tv.sapling_raw_addr) + receivers[SAPLING] = bytes.fromhex(tv.sapling_raw_addr) if tv.orchard_raw_addr is not None: - receivers[ORCHARD] = unhexlify(tv.orchard_raw_addr) + receivers[ORCHARD] = bytes.fromhex(tv.orchard_raw_addr) if tv.unknown_bytes is not None: - receivers[tv.unknown_typecode] = unhexlify(tv.unknown_bytes) + receivers[tv.unknown_typecode] = bytes.fromhex(tv.unknown_bytes) return receivers @@ -292,11 +292,11 @@ def test_encode_unified(self): for tv in map(ZcashTestVector, TESTVECTORS[2:]): receivers = get_receivers(tv) ua = unified_addresses.encode(receivers, COIN) - self.assertEqual(ua, unhexlify(tv.unified_addr).decode()) + self.assertEqual(ua, bytes.fromhex(tv.unified_addr).decode()) def test_decode_unified(self): for tv in map(ZcashTestVector, TESTVECTORS[2:]): - address = unhexlify(tv.unified_addr).decode() + address = bytes.fromhex(tv.unified_addr).decode() receivers = unified_addresses.decode(address, COIN) self.assertEqual(receivers, get_receivers(tv)) diff --git a/core/tests/test_apps.zcash.zip244.py b/core/tests/test_apps.zcash.zip244.py index b4947a14dd0..4cd49887438 100644 --- a/core/tests/test_apps.zcash.zip244.py +++ b/core/tests/test_apps.zcash.zip244.py @@ -43,7 +43,7 @@ def test_zcash_hasher(self): ) inputs = [ TxInput( - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "4f61d91843ccb386dd1c482169eef62efaaf9d9364b1666e4d4c299e04a852e1" ), prev_index=1569726664, @@ -51,12 +51,12 @@ def test_zcash_hasher(self): amount=1249971475008092, script_type=InputScriptType.SPENDADDRESS, sequence=0x8849F2A3, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a9149466817faf329208fc3c3ef42ce4513d22fc1f9b88ac" ), ), TxInput( - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "368e9c7e1fe01f6c54db9379a94c2941ef180c25b869bf8dcdb1cf014253b3c7" ), prev_index=2648876502, @@ -64,12 +64,12 @@ def test_zcash_hasher(self): amount=1353789347081201, script_type=InputScriptType.SPENDADDRESS, sequence=0x8A37691C, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a9142275979f97043edd9a6083ee27d136727ce5f42888ac" ), ), TxInput( - prev_hash=unhexlify( + prev_hash=bytes.fromhex( "f5621d6ad566c13dce81632a9168694bb6bcec2f7bfac2626f9425e1640fe4f1" ), prev_index=492165032, @@ -77,7 +77,7 @@ def test_zcash_hasher(self): amount=1672802384749611, script_type=InputScriptType.SPENDADDRESS, sequence=0x6A993D20, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914682c89bfc3940621bd4a4bfc349a79b46ce707e388ac" ), ), @@ -85,45 +85,45 @@ def test_zcash_hasher(self): outputs = [ PrevOutput( amount=865034086766210, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a9140d06a745f44ab023752cb5b406ed8985e18130ab88ac" ), ), PrevOutput( amount=2088955338922857, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a91463ccb8f676495c222f7fba1e31defa3d5a57efc288ac" ), ), PrevOutput( amount=1760123755646275, - script_pubkey=unhexlify( + script_pubkey=bytes.fromhex( "76a914fb1a38e01d94903d3c3e0ad3360c1d3710acd20b88ac" ), ), ] pubkeys = [ - unhexlify( + bytes.fromhex( "02ed9c769c787fda78a7da13764707d14217e74e26428b47a2a8fe6d5a0bc46196" ), - unhexlify( + bytes.fromhex( "0219ac5de9a45f76e7efede5259acd94bb047ab8e7cc60fe844cb32317072ebbf3" ), - unhexlify( + bytes.fromhex( "02829099a7cf1f617c956c0222e7b77ae331813d6a736eab3c5f6344d961843d39" ), ] - expected_txid = unhexlify( + expected_txid = bytes.fromhex( "c91d34ecc44484b07ee573f385d80e57e4e57571bb86aa6ec6c44d654123e4e9" ) expected_sighashes = [ - unhexlify( + bytes.fromhex( "4d82669c8c0e9b1f26d59bcb347212f2d044eeb839fce21e039d8bb082bbc343" ), - unhexlify( + bytes.fromhex( "2e2a27d78d117e28760d3c972f9614547ec57688c970f06c19c515cded6b030c" ), - unhexlify( + bytes.fromhex( "d0a92ffd4a4d262f5b84598bcfca741a42c17b8e9d26cf4fd87839df8f33e4ee" ), ] diff --git a/core/tests/test_trezor.crypto.aes.py b/core/tests/test_trezor.crypto.aes.py index 20957f89049..3287d136e63 100644 --- a/core/tests/test_trezor.crypto.aes.py +++ b/core/tests/test_trezor.crypto.aes.py @@ -9,11 +9,11 @@ class TestCryptoAes(unittest.TestCase): # test vectors from NIST Special Publication 800-38A (Appendix F) # https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf - iv = unhexlify("000102030405060708090a0b0c0d0e0f") - ctr = unhexlify("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff") - key128 = unhexlify("2b7e151628aed2a6abf7158809cf4f3c") - key192 = unhexlify("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b") - key256 = unhexlify( + iv = bytes.fromhex("000102030405060708090a0b0c0d0e0f") + ctr = bytes.fromhex("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff") + key128 = bytes.fromhex("2b7e151628aed2a6abf7158809cf4f3c") + key192 = bytes.fromhex("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b") + key256 = bytes.fromhex( "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" ) @@ -44,7 +44,7 @@ def test_ecb(self): ctx1 = aes(aes.ECB, key) ctx2 = aes(aes.ECB, key) for plain, cipher in vec: - plain, cipher = unhexlify(plain), unhexlify(cipher) + plain, cipher = bytes.fromhex(plain), bytes.fromhex(cipher) e = ctx1.encrypt(plain) self.assertEqual(e, cipher) d = ctx2.decrypt(cipher) @@ -77,7 +77,7 @@ def test_cbc(self): ctx1 = aes(aes.CBC, key, self.iv) ctx2 = aes(aes.CBC, key, self.iv) for plain, cipher in vec: - plain, cipher = unhexlify(plain), unhexlify(cipher) + plain, cipher = bytes.fromhex(plain), bytes.fromhex(cipher) e = ctx1.encrypt(plain) self.assertEqual(e, cipher) d = ctx2.decrypt(cipher) @@ -110,7 +110,7 @@ def test_cfb(self): ctx1 = aes(aes.CFB, key, self.iv) ctx2 = aes(aes.CFB, key, self.iv) for plain, cipher in vec: - plain, cipher = unhexlify(plain), unhexlify(cipher) + plain, cipher = bytes.fromhex(plain), bytes.fromhex(cipher) e = ctx1.encrypt(plain) self.assertEqual(e, cipher) d = ctx2.decrypt(cipher) @@ -143,7 +143,7 @@ def test_ofb(self): ctx1 = aes(aes.OFB, key, self.iv) ctx2 = aes(aes.OFB, key, self.iv) for plain, cipher in vec: - plain, cipher = unhexlify(plain), unhexlify(cipher) + plain, cipher = bytes.fromhex(plain), bytes.fromhex(cipher) e = ctx1.encrypt(plain) self.assertEqual(e, cipher) d = ctx2.decrypt(cipher) @@ -176,7 +176,7 @@ def test_ctr(self): ctx1 = aes(aes.CTR, key, self.ctr) ctx2 = aes(aes.CTR, key, self.ctr) for plain, cipher in vec: - plain, cipher = unhexlify(plain), unhexlify(cipher) + plain, cipher = bytes.fromhex(plain), bytes.fromhex(cipher) e = ctx1.encrypt(plain) self.assertEqual(e, cipher) d = ctx2.decrypt(cipher) diff --git a/core/tests/test_trezor.crypto.aesgcm.py b/core/tests/test_trezor.crypto.aesgcm.py index 55a2f32dd7e..1fcbe1855ef 100644 --- a/core/tests/test_trezor.crypto.aesgcm.py +++ b/core/tests/test_trezor.crypto.aesgcm.py @@ -46,7 +46,7 @@ class TestCryptoAes(unittest.TestCase): def test_gcm(self): for vector in self.vectors: - key, iv, pt, aad, ct, tag = map(unhexlify, vector) + key, iv, pt, aad, ct, tag = map(bytes.fromhex, vector) # Test encryption. ctx = aesgcm_encrypt(key, iv) @@ -64,7 +64,7 @@ def test_gcm(self): def test_gcm_in_place(self): for vector in self.vectors: - key, iv, pt, aad, ct, tag = map(unhexlify, vector) + key, iv, pt, aad, ct, tag = map(bytes.fromhex, vector) buffer = bytearray(pt) # Test encryption. @@ -87,7 +87,7 @@ def test_gcm_in_place(self): def test_gcm_chunks(self): for vector in self.vectors: - key, iv, pt, aad, ct, tag = map(unhexlify, vector) + key, iv, pt, aad, ct, tag = map(bytes.fromhex, vector) chunk1 = len(pt) // 3 @@ -109,7 +109,7 @@ def test_gcm_chunks(self): def test_gcm_chunks_in_place(self): for vector in self.vectors: - key, iv, pt, aad, ct, tag = map(unhexlify, vector) + key, iv, pt, aad, ct, tag = map(bytes.fromhex, vector) buffer = bytearray(ct) chunk1_length = len(pt) // 3 chunk2_length = len(pt) - chunk1_length @@ -138,7 +138,7 @@ def test_gcm_chunks_in_place(self): def test_gcm_invalid_tag_len(self): for vector in self.vectors: - key, iv, pt, aad, ct, _tag = map(unhexlify, vector) + key, iv, pt, aad, ct, _tag = map(bytes.fromhex, vector) invalid_tags = [ b"", b"\x00", @@ -164,7 +164,7 @@ def test_gcm_invalid_tag_len(self): def test_gcm_invalid_tag(self): invalid_tag = b"\xab" * 16 for vector in self.vectors: - key, iv, pt, aad, ct, _ = map(unhexlify, vector) + key, iv, pt, aad, ct, _ = map(bytes.fromhex, vector) ctx = aesgcm_decrypt(key, iv) if aad: ctx.auth(aad) diff --git a/core/tests/test_trezor.crypto.base58.py b/core/tests/test_trezor.crypto.base58.py index 63903b8e006..c3f31f6d226 100644 --- a/core/tests/test_trezor.crypto.base58.py +++ b/core/tests/test_trezor.crypto.base58.py @@ -236,18 +236,18 @@ class TestCryptoBase58(unittest.TestCase): def test_decode_check(self): for a, b in self.vectors: - self.assertEqual(base58.decode_check(b), unhexlify(a)) + self.assertEqual(base58.decode_check(b), bytes.fromhex(a)) for a, b in self.vectors_graphene: self.assertEqual( - base58.decode_check(b, digestfunc=digestfunc_graphene), unhexlify(a) + base58.decode_check(b, digestfunc=digestfunc_graphene), bytes.fromhex(a) ) def test_encode_check(self): for a, b in self.vectors: - self.assertEqual(base58.encode_check(unhexlify(a)), b) + self.assertEqual(base58.encode_check(bytes.fromhex(a)), b) for a, b in self.vectors_graphene: self.assertEqual( - base58.encode_check(unhexlify(a), digestfunc=digestfunc_graphene), b + base58.encode_check(bytes.fromhex(a), digestfunc=digestfunc_graphene), b ) diff --git a/core/tests/test_trezor.crypto.bech32.py b/core/tests/test_trezor.crypto.bech32.py index f8bb4dbd7af..84d3532dc04 100644 --- a/core/tests/test_trezor.crypto.bech32.py +++ b/core/tests/test_trezor.crypto.bech32.py @@ -207,7 +207,7 @@ def test_valid_address(self): witver, witprog = bech32.decode(hrp, address) self.assertIsNotNone(witver) scriptpubkey = segwit_scriptpubkey(witver, witprog) - self.assertEqual(scriptpubkey, unhexlify(hexscript)) + self.assertEqual(scriptpubkey, bytes.fromhex(hexscript)) addr = bech32.encode(hrp, witver, witprog) self.assertEqual(address.lower(), addr) diff --git a/core/tests/test_trezor.crypto.bip32.py b/core/tests/test_trezor.crypto.bip32.py index 46f21544c82..4137532a30c 100644 --- a/core/tests/test_trezor.crypto.bip32.py +++ b/core/tests/test_trezor.crypto.bip32.py @@ -19,7 +19,7 @@ def test_from_seed_invalid(self): bip32.from_seed(bytearray(), c) with self.assertRaises(TypeError): bip32.from_seed(1, c) - s = unhexlify("000102030405060708090a0b0c0d0e0f") + s = bytes.fromhex("000102030405060708090a0b0c0d0e0f") with self.assertRaises(ValueError): bip32.from_seed(s, "") with self.assertRaises(ValueError): @@ -35,26 +35,26 @@ def test_secp256k1_vector_1_derive(self): # init m n = bip32.from_seed( - unhexlify("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME + bytes.fromhex("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME ) # [Chain m] self.assertEqual(n.fingerprint(), 0x00000000) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2" ), ) @@ -69,19 +69,19 @@ def test_secp256k1_vector_1_derive(self): self.assertEqual(n.fingerprint(), 0x3442193E) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56" ), ) @@ -96,19 +96,19 @@ def test_secp256k1_vector_1_derive(self): self.assertEqual(n.fingerprint(), 0x5C1BD648) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c" ), ) @@ -123,19 +123,19 @@ def test_secp256k1_vector_1_derive(self): self.assertEqual(n.fingerprint(), 0xBEF5A2F9) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2" ), ) @@ -150,19 +150,19 @@ def test_secp256k1_vector_1_derive(self): self.assertEqual(n.fingerprint(), 0xEE7AB90C) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29" ), ) @@ -177,19 +177,19 @@ def test_secp256k1_vector_1_derive(self): self.assertEqual(n.fingerprint(), 0xD880D7D8) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011" ), ) @@ -205,7 +205,7 @@ def test_secp256k1_vector_2_derive(self): # init m n = bip32.from_seed( - unhexlify( + bytes.fromhex( "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" ), SECP256K1_NAME, @@ -215,19 +215,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0x00000000) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7" ), ) @@ -242,19 +242,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0xBD16BEE5) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea" ), ) @@ -269,19 +269,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0x5A61FF8E) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b" ), ) @@ -296,19 +296,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0xD8AB4937) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9" ), ) @@ -323,19 +323,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0x78412E3A) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0" ), ) @@ -350,19 +350,19 @@ def test_secp256k1_vector_2_derive(self): self.assertEqual(n.fingerprint(), 0x31A507B8) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" ), ) @@ -378,7 +378,7 @@ def test_secp256k1_vector_1_derive_path(self): # init m m = bip32.from_seed( - unhexlify("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME + bytes.fromhex("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME ) # [Chain m] @@ -386,19 +386,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0x00000000) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2" ), ) @@ -414,19 +414,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0x3442193E) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56" ), ) @@ -442,19 +442,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0x5C1BD648) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c" ), ) @@ -470,19 +470,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0xBEF5A2F9) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2" ), ) @@ -498,19 +498,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0xEE7AB90C) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29" ), ) @@ -526,19 +526,19 @@ def test_secp256k1_vector_1_derive_path(self): self.assertEqual(n.fingerprint(), 0xD880D7D8) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011" ), ) @@ -554,7 +554,7 @@ def test_secp256k1_vector_2_derive_path(self): # init m m = bip32.from_seed( - unhexlify( + bytes.fromhex( "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" ), SECP256K1_NAME, @@ -565,19 +565,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0x00000000) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7" ), ) @@ -593,19 +593,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0xBD16BEE5) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea" ), ) @@ -621,19 +621,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0x5A61FF8E) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b" ), ) @@ -649,19 +649,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0xD8AB4937) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9" ), ) @@ -677,19 +677,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0x78412E3A) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0" ), ) @@ -705,19 +705,19 @@ def test_secp256k1_vector_2_derive_path(self): self.assertEqual(n.fingerprint(), 0x31A507B8) self.assertEqual( n.chain_code(), - unhexlify( + bytes.fromhex( "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" ), ) self.assertEqual( n.private_key(), - unhexlify( + bytes.fromhex( "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23" ), ) self.assertEqual( n.public_key(), - unhexlify( + bytes.fromhex( "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" ), ) diff --git a/core/tests/test_trezor.crypto.bip39.py b/core/tests/test_trezor.crypto.bip39.py index 20a6f8d3aa9..57b25ba7285 100644 --- a/core/tests/test_trezor.crypto.bip39.py +++ b/core/tests/test_trezor.crypto.bip39.py @@ -129,8 +129,8 @@ def test_mnemonic(self): ), ] for d, m, s in v: - self.assertEqual(bip39.from_data(unhexlify(d)), m) - self.assertEqual(bip39.seed(m, "TREZOR"), unhexlify(s)) + self.assertEqual(bip39.from_data(bytes.fromhex(d)), m) + self.assertEqual(bip39.seed(m, "TREZOR"), bytes.fromhex(s)) def test_check_ok(self): v = [ diff --git a/core/tests/test_trezor.crypto.chacha20poly1305.py b/core/tests/test_trezor.crypto.chacha20poly1305.py index 1b42846c5e8..bcd263847bc 100644 --- a/core/tests/test_trezor.crypto.chacha20poly1305.py +++ b/core/tests/test_trezor.crypto.chacha20poly1305.py @@ -33,7 +33,7 @@ class TestCryptoChaCha20Poly1305(unittest.TestCase): def test_chacha20_encrypt(self): for vector in self.vectors: - plaintext, _, key, nonce, ciphertext, _ = map(unhexlify, vector) + plaintext, _, key, nonce, ciphertext, _ = map(bytes.fromhex, vector) ctx = chacha20poly1305_encrypt(key, nonce) out = ctx.encrypt(plaintext) @@ -41,14 +41,14 @@ def test_chacha20_encrypt(self): def test_chacha20_decrypt(self): for vector in self.vectors: - plaintext, _, key, nonce, ciphertext, _ = map(unhexlify, vector) + plaintext, _, key, nonce, ciphertext, _ = map(bytes.fromhex, vector) ctx = chacha20poly1305_decrypt(key, nonce) out = ctx.decrypt(ciphertext) self.assertEqual(out, plaintext) def test_chacha20poly1305_encrypt_mac(self): for vector in self.vectors: - plaintext, aad, key, nonce, ciphertext, tag = map(unhexlify, vector) + plaintext, aad, key, nonce, ciphertext, tag = map(bytes.fromhex, vector) ctx = chacha20poly1305_encrypt(key, nonce) ctx.auth(aad) @@ -59,7 +59,7 @@ def test_chacha20poly1305_encrypt_mac(self): def test_chacha20poly1305_decrypt_mac(self): for vector in self.vectors: - plaintext, aad, key, nonce, ciphertext, tag = map(unhexlify, vector) + plaintext, aad, key, nonce, ciphertext, tag = map(bytes.fromhex, vector) ctx = chacha20poly1305_decrypt(key, nonce) ctx.auth(aad) @@ -69,7 +69,7 @@ def test_chacha20poly1305_decrypt_mac(self): def test_chacha20poly1305_invalid_mac_len(self): for vector in self.vectors: - _, aad, key, nonce, ciphertext, _mac = map(unhexlify, vector) + _, aad, key, nonce, ciphertext, _mac = map(bytes.fromhex, vector) invalid_macs = [ b"", b"\x00", @@ -91,7 +91,7 @@ def test_chacha20poly1305_invalid_mac_len(self): def test_chacha20poly1305_invalid_mac(self): invalid_mac = b"\xab" * 16 for vector in self.vectors: - _, aad, key, nonce, ciphertext, _ = map(unhexlify, vector) + _, aad, key, nonce, ciphertext, _ = map(bytes.fromhex, vector) ctx = chacha20poly1305_decrypt(key, nonce) ctx.auth(aad) diff --git a/core/tests/test_trezor.crypto.crc.py b/core/tests/test_trezor.crypto.crc.py index a56bce4ebd7..cf97c76a90f 100644 --- a/core/tests/test_trezor.crypto.crc.py +++ b/core/tests/test_trezor.crypto.crc.py @@ -9,19 +9,19 @@ class TestCryptoCrc(unittest.TestCase): vectors_crc32 = [ ("123456789", 0xCBF43926), ( - unhexlify( + bytes.fromhex( "0000000000000000000000000000000000000000000000000000000000000000" ), 0x190A55AD, ), ( - unhexlify( + bytes.fromhex( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ), 0xFF6CAB0B, ), ( - unhexlify( + bytes.fromhex( "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" ), 0x91267E8A, diff --git a/core/tests/test_trezor.crypto.curve.bip340.py b/core/tests/test_trezor.crypto.curve.bip340.py index f2596a7cd23..cca0f4b6fb4 100644 --- a/core/tests/test_trezor.crypto.curve.bip340.py +++ b/core/tests/test_trezor.crypto.curve.bip340.py @@ -38,7 +38,7 @@ def test_generate_secret(self): def test_publickey(self): for sk, pk in self.vectors: - pk_computed = hexlify(bip340.publickey(unhexlify(sk))).decode() + pk_computed = bip340.publickey(bytes.fromhex(sk)).hex() self.assertEqual(str(pk_computed).upper(), pk) def test_sign_verify_random(self): diff --git a/core/tests/test_trezor.crypto.curve.curve25519.py b/core/tests/test_trezor.crypto.curve.curve25519.py index 9a99eea4960..b90a50e0c24 100644 --- a/core/tests/test_trezor.crypto.curve.curve25519.py +++ b/core/tests/test_trezor.crypto.curve.curve25519.py @@ -22,8 +22,8 @@ def test_generate_secret(self): def test_multiply(self): for sk, pk, session in self.vectors: - session2 = curve25519.multiply(unhexlify(sk), unhexlify(pk)) - self.assertEqual(session2, unhexlify(session)) + session2 = curve25519.multiply(bytes.fromhex(sk), bytes.fromhex(pk)) + self.assertEqual(session2, bytes.fromhex(session)) def test_multiply_random(self): for _ in range(100): diff --git a/core/tests/test_trezor.crypto.curve.ed25519.py b/core/tests/test_trezor.crypto.curve.ed25519.py index db19c2747cd..41e57718afb 100644 --- a/core/tests/test_trezor.crypto.curve.ed25519.py +++ b/core/tests/test_trezor.crypto.curve.ed25519.py @@ -53,20 +53,20 @@ class TestCryptoEd25519(unittest.TestCase): def test_publickey(self): for sk, pk, _ in self.vectors: - pk2 = ed25519.publickey(unhexlify(sk)) - self.assertEqual(pk2, unhexlify(pk)) + pk2 = ed25519.publickey(bytes.fromhex(sk)) + self.assertEqual(pk2, bytes.fromhex(pk)) def test_sign(self): for sk, pk, sig in self.vectors: # msg = pk - sig2 = ed25519.sign(unhexlify(sk), unhexlify(pk)) - self.assertEqual(sig2, unhexlify(sig)) + sig2 = ed25519.sign(bytes.fromhex(sk), bytes.fromhex(pk)) + self.assertEqual(sig2, bytes.fromhex(sig)) def test_verify(self): for _, pk, sig in self.vectors: # msg = pk self.assertTrue( - ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk)) + ed25519.verify(bytes.fromhex(pk), bytes.fromhex(sig), bytes.fromhex(pk)) ) pass diff --git a/core/tests/test_trezor.crypto.curve.nist256p1.py b/core/tests/test_trezor.crypto.curve.nist256p1.py index 0e893b34290..ac5e44a6f76 100644 --- a/core/tests/test_trezor.crypto.curve.nist256p1.py +++ b/core/tests/test_trezor.crypto.curve.nist256p1.py @@ -235,11 +235,9 @@ def test_publickey(self): if len(sk) < 64: sk = "0" * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify( - nist256p1.publickey(unhexlify(sk), False) - ).decode() # uncompressed + pk65 = nist256p1.publickey(bytes.fromhex(sk), False).hex() # uncompressed self.assertEqual(str(pk65), "04" + pk) - pk33 = hexlify(nist256p1.publickey(unhexlify(sk))).decode() + pk33 = nist256p1.publickey(bytes.fromhex(sk)).hex() if pk[-1] in "02468ace": self.assertEqual(pk33, "02" + pk[:64]) else: diff --git a/core/tests/test_trezor.crypto.curve.secp256k1.py b/core/tests/test_trezor.crypto.curve.secp256k1.py index 2075d8a9adc..231610adece 100644 --- a/core/tests/test_trezor.crypto.curve.secp256k1.py +++ b/core/tests/test_trezor.crypto.curve.secp256k1.py @@ -206,11 +206,9 @@ def test_publickey(self): if len(sk) < 64: sk = "0" * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify( - secp256k1.publickey(unhexlify(sk), False) - ).decode() # uncompressed + pk65 = secp256k1.publickey(bytes.fromhex(sk), False).hex() # uncompressed self.assertEqual(str(pk65), "04" + pk) - pk33 = hexlify(secp256k1.publickey(unhexlify(sk))).decode() + pk33 = secp256k1.publickey(bytes.fromhex(sk)).hex() if pk[-1] in "02468ace": self.assertEqual(pk33, "02" + pk[:64]) else: @@ -262,16 +260,16 @@ def test_ecdh(self): sk = hex(sk)[2:] if len(sk) < 64: sk = "0" * (64 - len(sk)) + sk - sk = unhexlify(sk) + sk = bytes.fromhex(sk) pk = pk.lower() pk33 = secp256k1.publickey(sk) pk65 = secp256k1.publickey(sk, False) - fixed_vector_hex = b"0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8" + fixed_vector_hex = "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8" fixed_vector1 = secp256k1.multiply(sk, pk65) fixed_vector2 = secp256k1.multiply(sk, pk33) self.assertEqual(fixed_vector1, fixed_vector2) - self.assertEqual(hexlify(fixed_vector1), fixed_vector_hex) + self.assertEqual(fixed_vector1.hex(), fixed_vector_hex) if __name__ == "__main__": diff --git a/core/tests/test_trezor.crypto.der.py b/core/tests/test_trezor.crypto.der.py index 948a3009592..f7dc70cb551 100644 --- a/core/tests/test_trezor.crypto.der.py +++ b/core/tests/test_trezor.crypto.der.py @@ -75,8 +75,8 @@ class TestCryptoDer(unittest.TestCase): def test_der_encode_decode_signature(self): for s, d in self.vectors_sig: - s = tuple(unhexlify(i) for i in s) - d = unhexlify(d) + s = tuple(bytes.fromhex(i) for i in s) + d = bytes.fromhex(d) sig = b"".join(s) d2 = der.encode_signature(sig) self.assertEqual(d2, d) diff --git a/core/tests/test_trezor.crypto.elligator2.py b/core/tests/test_trezor.crypto.elligator2.py index 11ecbf86159..b5e6dddf323 100644 --- a/core/tests/test_trezor.crypto.elligator2.py +++ b/core/tests/test_trezor.crypto.elligator2.py @@ -55,7 +55,7 @@ def test_map_to_curve25519(self): for input, output in vectors: self.assertEqual( - hexlify(elligator2.map_to_curve25519(unhexlify(input))).decode("ascii"), + elligator2.map_to_curve25519(bytes.fromhex(input)).hex(), output, ) diff --git a/core/tests/test_trezor.crypto.hashlib.blake256.py b/core/tests/test_trezor.crypto.hashlib.blake256.py index 4fe16160f12..94cafb0ef4f 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake256.py +++ b/core/tests/test_trezor.crypto.hashlib.blake256.py @@ -81,14 +81,16 @@ class TestCryptoBlake256(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.blake256(unhexlify(b)).digest(), unhexlify(d)) + self.assertEqual( + hashlib.blake256(bytes.fromhex(b)).digest(), bytes.fromhex(d) + ) def test_update(self): for b, d in self.vectors: x = hashlib.blake256() - x.update(unhexlify(b)) - self.assertEqual(x.digest(), unhexlify(d)) + x.update(bytes.fromhex(b)) + self.assertEqual(x.digest(), bytes.fromhex(d)) def test_digest_multi(self): x = hashlib.blake256() diff --git a/core/tests/test_trezor.crypto.hashlib.blake2b.py b/core/tests/test_trezor.crypto.hashlib.blake2b.py index ce2fa038a07..9f70ecbcd89 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake2b.py +++ b/core/tests/test_trezor.crypto.hashlib.blake2b.py @@ -35,58 +35,59 @@ class TestCryptoBlake2b(unittest.TestCase): ] def test_digest(self): - key = unhexlify( + key = bytes.fromhex( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" ) for d, h in self.vectors: self.assertEqual( - hashlib.blake2b(data=unhexlify(d), key=key).digest(), unhexlify(h) + hashlib.blake2b(data=bytes.fromhex(d), key=key).digest(), + bytes.fromhex(h), ) def test_update(self): - key = unhexlify( + key = bytes.fromhex( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" ) x = hashlib.blake2b(key=key) x.update(bytes(range(10))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "4fe181f54ad63a2983feaaf77d1e7235c2beb17fa328b6d9505bda327df19fc37f02c4b6f0368ce23147313a8e5738b5fa2a95b29de1c7f8264eb77b69f585cd" ), ) x.update(bytes(range(10, 30))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "c6dbc61dec6eaeac81e3d5f755203c8e220551534a0b2fd105a91889945a638550204f44093dd998c076205dffad703a0e5cd3c7f438a7e634cd59fededb539e" ), ) x.update(bytes(range(30, 80))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "fa1549c9796cd4d303dcf452c1fbd5744fd9b9b47003d920b92de34839d07ef2a29ded68f6fc9e6c45e071a2e48bd50c5084e96b657dd0404045a1ddefe282ed" ), ) x.update(bytes(range(80, 111))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "2620f687e8625f6a412460b42e2cef67634208ce10a0cbd4dff7044a41b7880077e9f8dc3b8d1216d3376a21e015b58fb279b521d83f9388c7382c8505590b9b" ), ) x.update(bytes(range(111, 127))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "76d2d819c92bce55fa8e092ab1bf9b9eab237a25267986cacf2b8ee14d214d730dc9a5aa2d7b596e86a1fd8fa0804c77402d2fcd45083688b218b1cdfa0dcbcb" ), ) x.update(bytes(range(127, 255))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461" ), ) diff --git a/core/tests/test_trezor.crypto.hashlib.blake2s.py b/core/tests/test_trezor.crypto.hashlib.blake2s.py index 91260b02838..c6cad0dea35 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake2s.py +++ b/core/tests/test_trezor.crypto.hashlib.blake2s.py @@ -30,58 +30,58 @@ class TestCryptoBlake2s(unittest.TestCase): ] def test_digest(self): - key = unhexlify( + key = bytes.fromhex( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ) for d, h in self.vectors: self.assertEqual( - hashlib.blake2s(unhexlify(d), key=key).digest(), unhexlify(h) + hashlib.blake2s(bytes.fromhex(d), key=key).digest(), bytes.fromhex(h) ) def test_update(self): - key = unhexlify( + key = bytes.fromhex( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ) x = hashlib.blake2s(b"", key=key) x.update(bytes(range(10))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "f5c4b2ba1a00781b13aba0425242c69cb1552f3f71a9a3bb22b4a6b4277b46dd" ), ) x.update(bytes(range(10, 30))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "3ca989de10cfe609909472c8d35610805b2f977734cf652cc64b3bfc882d5d89" ), ) x.update(bytes(range(30, 80))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "30f3548370cfdceda5c37b569b6175e799eef1a62aaa943245ae7669c227a7b5" ), ) x.update(bytes(range(80, 111))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "9fe03bbe69ab1834f5219b0da88a08b30a66c5913f0151963c360560db0387b3" ), ) x.update(bytes(range(111, 127))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "ddbfea75cc467882eb3483ce5e2e756a4f4701b76b445519e89f22d60fa86e06" ), ) x.update(bytes(range(127, 255))) self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd" ), ) diff --git a/core/tests/test_trezor.crypto.hashlib.groestl512.py b/core/tests/test_trezor.crypto.hashlib.groestl512.py index caad11c45ef..a519cfd3ffb 100644 --- a/core/tests/test_trezor.crypto.hashlib.groestl512.py +++ b/core/tests/test_trezor.crypto.hashlib.groestl512.py @@ -13,39 +13,39 @@ class TestCryptoGroestl512(unittest.TestCase): "6D3AD29D279110EEF3ADBD66DE2A0345A77BAEDE1557F5D099FCE0C03D6DC2BA8E6D4A6633DFBD66053C20FAA87D1A11F39A7FBE4A6C2F009801370308FC4AD8", ), ( - unhexlify("C1ECFDFC"), + bytes.fromhex("C1ECFDFC"), "4726D760203C1EAF847F6837C74C16ADCEF5B55EAD5768A7C13E21A33D0D7B740F52DE8C81356DA63DABA791DA6680AF015DEB81246550201F232822BB087CE5", ), ( - unhexlify("82E192E4043DDCD12ECF52969D0F807EED"), + bytes.fromhex("82E192E4043DDCD12ECF52969D0F807EED"), "8CD831960FE9726055F7B3693CC5639DB7D01EDDA045AE41E877853111C4CF53D26D5B4E135118571721C247ACA6607979A4DF73849D1477365F7DB0149FBC9F", ), ( - unhexlify( + bytes.fromhex( "F5961DFD2B1FFFFDA4FFBF30560C165BFEDAB8CE0BE525845DEB8DC61004B7DB38467205F5DCFB34A2ACFE96C0" ), "CE24486770D443B423274DD30AF746EA4080065393D13DF0535709E260CF14B033CCD190A9FA5F81705178EB656031A6F1465A5A993BE62BE8D43931950BD5DB", ), ( - unhexlify( + bytes.fromhex( "2B6DB7CED8665EBE9DEB080295218426BDAA7C6DA9ADD2088932CDFFBAA1C14129BCCDD70F369EFB149285858D2B1D155D14DE2FDB680A8B027284055182A0CAE275234CC9C92863C1B4AB66F304CF0621CD54565F5BFF461D3B461BD40DF28198E3732501B4860EADD503D26D6E69338F4E0456E9E9BAF3D827AE685FB1D817" ), "FF410B511135DBC0B8644C28EFA3EC632326FEB98E50EDC6390C441610D7C514ACDF0A61A0BF01AA9DC1F55D92E085248EBA1C24EE23978B4986AF41C13A6176", ), ( - unhexlify( + bytes.fromhex( "EECBB8FDFA4DA62170FD06727F697D81F83F601FF61E478105D3CB7502F2C89BF3E8F56EDD469D049807A38882A7EEFBC85FC9A950952E9FA84B8AFEBD3CE782D4DA598002827B1EB98882EA1F0A8F7AA9CE013A6E9BC462FB66C8D4A18DA21401E1B93356EB12F3725B6DB1684F2300A98B9A119E5D27FF704AFFB618E12708E77E6E5F34139A5A41131FD1D6336C272A8FC37080F041C71341BEE6AB550CB4A20A6DDB6A8E0299F2B14BC730C54B8B1C1C487B494BDCCFD3A53535AB2F231590BF2C4062FD2AD58F906A2D0D" ), "3AE2AABD659C5844C923FD171CA36431A7E606ECA52A21B96A0F5E8CD1FA24141BEDAADF58608781DFABC103FE929CD2EADE8D6FBD6185D4F4B855DCA610D7A0", ), ( - unhexlify( + bytes.fromhex( "724627916C50338643E6996F07877EAFD96BDF01DA7E991D4155B9BE1295EA7D21C9391F4C4A41C75F77E5D27389253393725F1427F57914B273AB862B9E31DABCE506E558720520D33352D119F699E784F9E548FF91BC35CA147042128709820D69A8287EA3257857615EB0321270E94B84F446942765CE882B191FAEE7E1C87E0F0BD4E0CD8A927703524B559B769CA4ECE1F6DBF313FDCF67C572EC4185C1A88E86EC11B6454B371980020F19633B6B95BD280E4FBCB0161E1A82470320CEC6ECFA25AC73D09F1536F286D3F9DACAFB2CD1D0CE72D64D197F5C7520B3CCB2FD74EB72664BA93853EF41EABF52F015DD591500D018DD162815CC993595B195" ), "F88E8E86FBE2200E90226A181E48348E06D1643270C079B8BDD3660E8D21CD0493C55051CBFA607B1CFACA2C5A2C9354CDD405C1D3AD1D8435B825884CC0559F", ), ( - unhexlify( + bytes.fromhex( "D0FF6E045F4B636F75A389799F314066644854821B6E7AE4047ADFDE2D0C0E02C250F0BE582BEC94011189B964A8AF430F5921ED9D9F4446E4C788515B89CA69E5F7CDFCCC9E83E8F9460145B43DDC41C07CC512B7E6FDD0E1E7AABA29A6C016CCB7BD54B145F3951EAB9BC4908F623E5A9B0C5B36056292540B79FD15C53457DC74A65FD773A34D6B313A056F79BC29A3FAC15F6A1446BFAEEAAFBAC8ECF8168DDE5F6AE6B6E579BD3CE74E7ABFADF361D0FD32D56586A8D2D4FF4CFDF8A750FAFDE4C2E9EB32B06847FA30B13CC273532D1A23C8257F80C60B8FA94FA976F534145CD61C41C0A511B62CADD5848CEFF643F83CE43F8E6969C5A559AFAD60E310599A34B2E5E029FBDDF2988FCE59269C7128A1FC79A74B154D8AA2850DCFDBF594684E74099E37882B440367C1DD3003F61CAFB46AC75D30E677AF54559A5DAB70C506CF61A9C35E0E56E1430746916DDEEC8D89B0C10DAA02C5D7E9F42621D2B312EAFFC9FF306297952A32D26C2148570AEC90501CA739CE5E689E7066D9580A4FC25E2023897C74C6856273133E1275A0D275DC5B75DB724CD12C9C01BB95AB5A227B7850020630506096878D289923177183EA9282A4C78EC212D2E898CB99D81A3364DF20927EE34D4475A5CF5CDB24088ED75B60201922E9C972D8556CA75F8274D15F3FB88A6B42C766DEF6B21329DEE7C457446DDE8C26405FE5D0309A04229F449E8490CF9000EE8DF400CB7C7EE831BD7059D24088FB42D61681CDE45050FCA78FF64D9C8D1F58B55F802FA5D2F2E723F3E4EED4338B060D31C8ACC46D26870BD45D0DE0798D48E32AAD1A6D4322E69F5E72309B9D7FA1F24BB1D63FF09ED47391C232497BF222C542A70975C8292D275197A4CA" ), "27AB9EA01D8FD80ED14990761ED6BC329DC842770F83FDD1CE95C0A074D6D7495C7C85297CC73F3A695377E4211F897F68C1A7F910F6BF440264FB63F120ABA2", @@ -54,19 +54,19 @@ class TestCryptoGroestl512(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.groestl512(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.groestl512(b).digest(), bytes.fromhex(d)) def test_update(self): for b, d in self.vectors: x = hashlib.groestl512() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) # Test from ExtremelyLongMsgKAT_512.txt, disabled by default because it resource-expensive # x = hashlib.groestl512() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994')) + # self.assertEqual(x.digest(), bytes.fromhex('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994')) def test_digest_multi(self): x = hashlib.groestl512() diff --git a/core/tests/test_trezor.crypto.hashlib.ripemd160.py b/core/tests/test_trezor.crypto.hashlib.ripemd160.py index 6ab0131eafd..2650818c703 100644 --- a/core/tests/test_trezor.crypto.hashlib.ripemd160.py +++ b/core/tests/test_trezor.crypto.hashlib.ripemd160.py @@ -29,19 +29,19 @@ class TestCryptoRipemd160(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.ripemd160(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.ripemd160(b).digest(), bytes.fromhex(d)) def test_update(self): for b, d in self.vectors: x = hashlib.ripemd160() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.ripemd160() for _ in range(8): x.update(b"1234567890") self.assertEqual( - x.digest(), unhexlify("9b752e45573d4b39f4dbd3323cab82bf63326bfb") + x.digest(), bytes.fromhex("9b752e45573d4b39f4dbd3323cab82bf63326bfb") ) def test_digest_multi(self): diff --git a/core/tests/test_trezor.crypto.hashlib.sha1.py b/core/tests/test_trezor.crypto.hashlib.sha1.py index 04871c2e61a..5a290cbcc28 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha1.py +++ b/core/tests/test_trezor.crypto.hashlib.sha1.py @@ -22,25 +22,25 @@ class TestCryptoSha1(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.sha1(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.sha1(b).digest(), bytes.fromhex(d)) def test_update(self): for b, d in self.vectors: x = hashlib.sha1() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.sha1() for _ in range(1000000): x.update(b"a") self.assertEqual( - x.digest(), unhexlify("34aa973cd4c4daa4f61eeb2bdbad27316534016f") + x.digest(), bytes.fromhex("34aa973cd4c4daa4f61eeb2bdbad27316534016f") ) # x = hashlib.sha1() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592')) + # self.assertEqual(x.digest(), bytes.fromhex('7789f0c9ef7bfc40d93311143dfbe69e2017f592')) def test_digest_multi(self): x = hashlib.sha1() diff --git a/core/tests/test_trezor.crypto.hashlib.sha256.py b/core/tests/test_trezor.crypto.hashlib.sha256.py index 928949a04d2..660a5b708b5 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha256.py @@ -22,20 +22,20 @@ class TestCryptoSha256(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.sha256(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.sha256(b).digest(), bytes.fromhex(d)) def test_update(self): for b, d in self.vectors: x = hashlib.sha256() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.sha256() for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" ), ) @@ -43,7 +43,7 @@ def test_update(self): # x = hashlib.sha256() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e')) + # self.assertEqual(x.digest(), bytes.fromhex('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e')) def test_digest_multi(self): x = hashlib.sha256() diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_256.py b/core/tests/test_trezor.crypto.hashlib.sha3_256.py index 4b7f990c0d4..cc5806c74a7 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_256.py @@ -35,24 +35,26 @@ class TestCryptoSha3_256(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.sha3_256(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.sha3_256(b).digest(), bytes.fromhex(d)) def test_digest_keccak(self): for b, d in self.vectors_keccak: - self.assertEqual(hashlib.sha3_256(b, keccak=True).digest(), unhexlify(d)) + self.assertEqual( + hashlib.sha3_256(b, keccak=True).digest(), bytes.fromhex(d) + ) def test_update(self): for b, d in self.vectors: x = hashlib.sha3_256() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.sha3_256() for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "5c8875ae474a3634ba4fd55ec85bffd661f32aca75c6d699d0cdcb6c115891c1" ), ) @@ -60,13 +62,13 @@ def test_update(self): # x = hashlib.sha3_256() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b')) + # self.assertEqual(x.digest(), bytes.fromhex('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b')) def test_update_keccak(self): for b, d in self.vectors_keccak: x = hashlib.sha3_256(keccak=True) x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) def test_digest_multi(self): x = hashlib.sha3_256() diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_512.py b/core/tests/test_trezor.crypto.hashlib.sha3_512.py index 3c55ac70584..56d28e50c7d 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_512.py @@ -47,24 +47,26 @@ class TestCryptoSha3_512(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.sha3_512(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.sha3_512(b).digest(), bytes.fromhex(d)) def test_digest_keccak(self): for b, d in self.vectors_keccak: - self.assertEqual(hashlib.sha3_512(b, keccak=True).digest(), unhexlify(d)) + self.assertEqual( + hashlib.sha3_512(b, keccak=True).digest(), bytes.fromhex(d) + ) def test_update(self): for b, d in self.vectors: x = hashlib.sha3_512() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.sha3_512() for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "3c3a876da14034ab60627c077bb98f7e120a2a5370212dffb3385a18d4f38859ed311d0a9d5141ce9cc5c66ee689b266a8aa18ace8282a0e0db596c90b0a7b87" ), ) @@ -72,13 +74,13 @@ def test_update(self): # x = hashlib.sha3_512() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c')) + # self.assertEqual(x.digest(), bytes.fromhex('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c')) def test_update_keccak(self): for b, d in self.vectors_keccak: x = hashlib.sha3_512(keccak=True) x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) def test_digest_multi(self): x = hashlib.sha3_512() diff --git a/core/tests/test_trezor.crypto.hashlib.sha512.py b/core/tests/test_trezor.crypto.hashlib.sha512.py index 4a5c4209428..fea5dcd65f2 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha512.py @@ -28,20 +28,20 @@ class TestCryptoSha512(unittest.TestCase): def test_digest(self): for b, d in self.vectors: - self.assertEqual(hashlib.sha512(b).digest(), unhexlify(d)) + self.assertEqual(hashlib.sha512(b).digest(), bytes.fromhex(d)) def test_update(self): for b, d in self.vectors: x = hashlib.sha512() x.update(b) - self.assertEqual(x.digest(), unhexlify(d)) + self.assertEqual(x.digest(), bytes.fromhex(d)) x = hashlib.sha512() for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b" ), ) @@ -49,7 +49,7 @@ def test_update(self): # x = hashlib.sha512() # for i in range(16777216): # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - # self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086')) + # self.assertEqual(x.digest(), bytes.fromhex('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086')) def test_digest_multi(self): x = hashlib.sha512() diff --git a/core/tests/test_trezor.crypto.hmac.py b/core/tests/test_trezor.crypto.hmac.py index 4e27567df1c..9799cd0522a 100644 --- a/core/tests/test_trezor.crypto.hmac.py +++ b/core/tests/test_trezor.crypto.hmac.py @@ -15,13 +15,13 @@ def test_digest(self): msg = b"Hi There" self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854" ), ) @@ -31,13 +31,13 @@ def test_digest(self): msg = b"what do ya want for nothing?" self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737" ), ) @@ -47,13 +47,13 @@ def test_digest(self): msg = b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb" ), ) @@ -63,13 +63,13 @@ def test_digest(self): msg = b"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd" ), ) @@ -79,13 +79,13 @@ def test_digest(self): msg = b"Test Using Larger Than Block-Size Key - Hash Key First" self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598" ), ) @@ -95,13 +95,13 @@ def test_digest(self): msg = b"This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." self.assertEqual( hmac(hmac.SHA256, key, msg).digest(), - unhexlify( + bytes.fromhex( "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2" ), ) self.assertEqual( hmac(hmac.SHA512, key, msg).digest(), - unhexlify( + bytes.fromhex( "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58" ), ) @@ -115,7 +115,7 @@ def test_update(self): x.update(b"\xdd") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe" ), ) @@ -124,7 +124,7 @@ def test_update(self): x.update(b"\xdd") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb" ), ) @@ -136,7 +136,7 @@ def test_update(self): x.update(b"\xcd") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b" ), ) @@ -145,7 +145,7 @@ def test_update(self): x.update(b"\xcd") self.assertEqual( x.digest(), - unhexlify( + bytes.fromhex( "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd" ), ) diff --git a/core/tests/test_trezor.crypto.pbkdf2.py b/core/tests/test_trezor.crypto.pbkdf2.py index fe7a349dc96..c96e3025614 100644 --- a/core/tests/test_trezor.crypto.pbkdf2.py +++ b/core/tests/test_trezor.crypto.pbkdf2.py @@ -14,21 +14,21 @@ def test_pbkdf2_hmac_sha256(self): dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 1).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b" ), ) dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 2).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43" ), ) dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 4096).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a" ), ) @@ -37,7 +37,7 @@ def test_pbkdf2_hmac_sha256(self): dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 4096).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1" ), ) @@ -50,7 +50,7 @@ def test_pbkdf2_hmac_sha256_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b" ), ) @@ -60,7 +60,7 @@ def test_pbkdf2_hmac_sha256_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43" ), ) @@ -70,7 +70,7 @@ def test_pbkdf2_hmac_sha256_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a" ), ) @@ -82,7 +82,7 @@ def test_pbkdf2_hmac_sha256_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1" ), ) @@ -95,21 +95,21 @@ def test_pbkdf2_hmac_sha512(self): dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 1).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce" ), ) dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 2).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e" ), ) dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 4096).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5" ), ) @@ -118,7 +118,7 @@ def test_pbkdf2_hmac_sha512(self): dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 4096).key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8" ), ) @@ -131,7 +131,7 @@ def test_pbkdf2_hmac_sha512_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce" ), ) @@ -141,7 +141,7 @@ def test_pbkdf2_hmac_sha512_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e" ), ) @@ -151,7 +151,7 @@ def test_pbkdf2_hmac_sha512_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5" ), ) @@ -163,7 +163,7 @@ def test_pbkdf2_hmac_sha512_update(self): dk = p.key() self.assertEqual( dk, - unhexlify( + bytes.fromhex( "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8" ), ) diff --git a/core/tests/test_trezor.crypto.random.py b/core/tests/test_trezor.crypto.random.py index 890f92cc705..f666a8760f2 100644 --- a/core/tests/test_trezor.crypto.random.py +++ b/core/tests/test_trezor.crypto.random.py @@ -31,8 +31,8 @@ def test_bytes_uniform(self): c[h] = 0 for _ in range(8): b = random.bytes(1000) - for h in hexlify(b): - c[chr(h)] += 1 + for h in b.hex(): + c[h] += 1 for h in "0123456789abcdef": self.assertAlmostEqual(c[h], 1000, delta=200) diff --git a/core/tests/test_trezor.crypto.rlp.py b/core/tests/test_trezor.crypto.rlp.py index be852e9f099..f20cecdc52f 100644 --- a/core/tests/test_trezor.crypto.rlp.py +++ b/core/tests/test_trezor.crypto.rlp.py @@ -128,7 +128,7 @@ class TestCryptoRlp(unittest.TestCase): def test_rlp_write(self): for i, o in self.vectors: - o = unhexlify(o) + o = bytes.fromhex(o) w = bytearray() rlp.write(w, i) self.assertEqual(w, o) diff --git a/core/tests/test_trezor.crypto.slip39.py b/core/tests/test_trezor.crypto.slip39.py index ff0d840b86d..3b6059e13f5 100644 --- a/core/tests/test_trezor.crypto.slip39.py +++ b/core/tests/test_trezor.crypto.slip39.py @@ -209,7 +209,7 @@ def test_vectors(self): identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) self.assertEqual( slip39.decrypt(ems, b"TREZOR", exponent, identifier, extendable), - unhexlify(secret), + bytes.fromhex(secret), ) else: with self.assertRaises(slip39.MnemonicError): diff --git a/core/tests/test_trezor.wire.codec.codec_v1.py b/core/tests/test_trezor.wire.codec.codec_v1.py index 08be380727a..46c5e305aa1 100644 --- a/core/tests/test_trezor.wire.codec.codec_v1.py +++ b/core/tests/test_trezor.wire.codec.codec_v1.py @@ -1,7 +1,7 @@ # flake8: noqa: F403,F405 from common import * # isort:skip -import ustruct +import struct from mock_wire_interface import MockHID from trezor import io @@ -11,11 +11,11 @@ MESSAGE_TYPE = 0x4242 -HEADER_PAYLOAD_LENGTH = MockHID.RX_PACKET_LEN - 3 - ustruct.calcsize(">HL") +HEADER_PAYLOAD_LENGTH = MockHID.RX_PACKET_LEN - 3 - struct.calcsize(">HL") def make_header(mtype, length): - return b"?##" + ustruct.pack(">HL", mtype, length) + return b"?##" + struct.pack(">HL", mtype, length) class TestWireCodecV1(unittest.TestCase): diff --git a/core/tests/test_trezor.wire.thp.cpace.py b/core/tests/test_trezor.wire.thp.cpace.py index 856214e2710..d0dafa2e9e5 100644 --- a/core/tests/test_trezor.wire.thp.cpace.py +++ b/core/tests/test_trezor.wire.thp.cpace.py @@ -58,15 +58,17 @@ class TestTrezorHostProtocolCPace(unittest.TestCase): def test_compute_shared_secret(self): ctx = cpace.Cpace(b"") - s = unhexlify( + s = bytes.fromhex( "af46e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449aff" ) ctx.trezor_private_key = s for _, input in self.vectors_raise: - self.assertRaises(ValueError, ctx.compute_shared_secret, unhexlify(input)) + self.assertRaises( + ValueError, ctx.compute_shared_secret, bytes.fromhex(input) + ) for _, input, expected_out in self.vectors_valid: - ctx.compute_shared_secret(unhexlify(input)) - self.assertEqual(hexlify(ctx.shared_secret).decode(), expected_out) + ctx.compute_shared_secret(bytes.fromhex(input)) + self.assertEqual(ctx.shared_secret.hex(), expected_out) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 693e2dfca17..de76d314d39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,16 +91,15 @@ profile = "black" extra_standard_library = [ "buffer_types", "micropython", - "ubinascii", - "ustruct", "uctypes", "utime", - "utimeq", + "timeq", "trezorio", "trezorui", "trezorutils", "trezorconfig", "trezorcrypto", + "vfs", ] known_first_party = ["trezorlib", "apps", "coin_info", "marketcap", "ui_tests"] known_third_party = ["trezor", "storage"] diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index c80685b2d41..f33e4ae5e08 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -942,9 +942,9 @@ "T2T1_en_test_autolock.py::test_dryrun_enter_word_slowly": "b180199eadc4f4a26138671b08db171c0569e0e399d3be2f0e6dd237546f697b", "T2T1_en_test_autolock.py::test_dryrun_locks_at_number_of_words": "03804d3c7559d0c1ff91462e982cf22573c577013c8954fe954a3d146b8aec38", "T2T1_en_test_autolock.py::test_dryrun_locks_at_word_entry": "43ece7c42bef74232c2b2974c2aae65e6aa127321f21b5a3f982d555a5e98915", -"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "1591ffbecb10eebecda268e693670887e79111a8bd22b12f382894b435bcebc0", -"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "2effb32d59e1988a540ceb181858656c9e385beff3d490746270256caad06321", -"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "3da7a82db168c3bd9ae4c953c291c3253734bb6ba79aa694decc82c7b4170470", +"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "b08ccd5ba1767052b2852aac062d39c8e600e0301f0f9a05d9cc46ab3b64b501", +"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "cfddd12892a751a93398d8c0d9bcd9c5e22af76d7b3607c6a4f7b2268c07d136", +"T2T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "3dc731a5c37d6bbb1fdf3ab0dd4e9e2b3f85e388d282c2b234ff4951a71635cd", "T2T1_en_test_lock.py::test_hold_to_lock": "0b8af13ed9617c60bd9a9a0af3f2a5e8bd6aac45b4aa02095ef5aa31414525c4", "T2T1_en_test_passphrase_bde.py::test_cycle_through_last_character": "39664383f651224563ed5f502cb65b7521d3361c9c5d84278a97e8089b35346b", "T2T1_en_test_passphrase_bde.py::test_passphrase_click_same_button_many_times": "22da61afdaa52632397202f2841f8ce2d8624ff01379da9d5b5673f44501898c", @@ -982,13 +982,13 @@ "T2T1_en_test_recovery.py::test_recovery_cancel_number_of_words": "c875c62a9ec6a483fe860324f1eb628f195d5c884458e462a6400488b1c29b5f", "T2T1_en_test_recovery.py::test_recovery_slip39_basic": "ddffd50945b48aa401365d4d82d3890852d28a650c6e0a2f5d2cbc7533366df8", "T2T1_en_test_recovery.py::test_recovery_slip39_issue5306": "e12b2eb8c8c66c6071697e089fc37de86940c1604be80feee25d1785c2cd400c", -"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_device": "91bdd4fbf7f0489cb71776cfd637d0072cdf953a584e8d5f4f38cab1fd99c1a3", -"T2T1_en_test_reset_bip39.py::test_reset_bip39": "ec1650457a73b9b8adbe3c09a39e3861ebdb86acd0b6b2382676f20971055458", -"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "87415e9147381d9bc8632bc1714309066f2df9bd01f629082e7440b4ebf0a79d", -"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "18bbdcdac6e57035d6ebacfabeb535e866c19829c7a8e5e19c6a68f98a934353", -"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "a41a9a0b06cc1e582a95bd20936377c7a37e3c18fcb399d33e55f214e52365dd", -"T2T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "1e499491a5c94ce350d1815be00ba2fb5786c6c8e4823e805f07c6dcb0ece381", -"T2T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "1c20bd915fd7c8bbc85046e330b188b7fc5518ba7ce2f3a479ac8ea9019bad0b", +"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_device": "0257808085fefd7e9c21236893a9faf173fcf50d9ce303e132c6fc8b1c6b6881", +"T2T1_en_test_reset_bip39.py::test_reset_bip39": "4773baf5dff4c087418b2bad81f26cad2873ab94e0ebf84565d9806416e7e23b", +"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "e8ffa9602806c276aad17e74d24abccf0b3f0bbd1c90ca9a9e16fc27739e3767", +"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "872197f41fce8d4503010398b0cf6d631ddcd80f380fcc50b350546d7513dae7", +"T2T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "a16df694a7eca2c7e712b49e59c2753882d98f9fdcdc245306516eb776c4e928", +"T2T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "a61ddcb2b294d7af5fe8d575b0adff34cf3009f959006e1e0ab0be6e2517fda3", +"T2T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "54d452a5179fbcaa8fb34671aee64fd2694963f26977041e96c8a9c3bd24b470", "T2T1_es_test_autolock.py::test_autolock_does_not_interrupt_preauthorized": "48100caacb16bc93265270b5b5768808aeb40f7a10895f4be7c41f62905fb666", "T2T1_es_test_autolock.py::test_autolock_does_not_interrupt_signing": "ee9be166a6ee8688bb566801d8fe9093695d076109f5b7abc3f54d2d7520839c", "T2T1_es_test_autolock.py::test_autolock_interrupts_passphrase": "6ddcd7cbb2d14cf14e3affcd095e77d5766ea6db59d6b41cee49d67f517a956f", @@ -6176,34 +6176,34 @@ "T2T1_en_reset_recovery-test_recovery_slip39_basic.py::test_wrong_nth_word[2]": "baa001a4423285cd3ddb20f40f4d15fa3289761f20353031d302ceeee5824d5d", "T2T1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_dryrun[Display]": "43a5511cc3f00f297bfd371e0d8effd74c3a088e7ab77076eb44391d515d2002", "T2T1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_invalid_seed_dryrun[Display]": "b2e12f15f0fd2a8dd4d23ef0852eae0acd061d776ebb6a509b71dcbf2437c772", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "d67fdd104597802e3d88178fcb58b3281ffa543aeec865b7aa09ea39ca9b4ba2", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "a54b68ba7034dd49b2de36505605520981e9af8debbc98a2f8ef945c4f022343", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "21727bd7fa1a39d418e4f6a338f2f10ddd83623ba0b34e4f1ba7056a8dafee7e", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "4c5cfebe165e144b19447feea33a01d4dd43e2f03b0b639519534290a7a61235", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "71f8a9675a0af28550280b5bf844e61a92abdb9eb8d35d58e73b6675e113dfac", -"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "56cc6a233ae686dbb82f81fb37bbe10c14b0eef2c45d5637e73680a93042f5ea", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "3bde02b3e16f03c2820a1a25a37632eb7a7b5aaeee2863d01c3d3d98c69756f2", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "ae14bd2b9f911f9dfc0dee920f74bbd30fe60254faad59d877f211f126930326", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "98fea395ea81dd40bc501f183fbc48b06cdd8da9a6a3c158a4366ac18941850e", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "277755cae19af6ea856e5a767e2cff9512166cd5502ecb426e81ddb85693f933", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "66a8e7223be6c71e01529a2800043a4bf321427d8374fc41cb33f7d904bf23f7", +"T2T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "57187ef808bce454fe98e9a603da784499903ffe5bb185b0cc27c4cf70536c15", "T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_already_initialized": "8aa7c68cd09e700e8c6903dcfc39c4a66214481c12c34dc56762829478399b79", "T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_entropy_check": "7ab9b15c2c71b7353cd8201f3bf273ae1720ef8fd841829427afa18c996e0d4d", "T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "df7b18621e1a9cacb05b7ebedab5976ba3a02d356900ef28749fed011524c59f", "T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_no_entropy_check": "7ab9b15c2c71b7353cd8201f3bf273ae1720ef8fd841829427afa18c996e0d4d", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "fd2f831b263475bcc59b7b84ceb8d292b57ba9c920e8d18d591423248ec50433", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "fd2f831b263475bcc59b7b84ceb8d292b57ba9c920e8d18d591423248ec50433", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "d8e8bc15853bf8ff6c05bc97958a6f8e100f3d99400cb292d37e9c173dfb7435", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "d8e8bc15853bf8ff6c05bc97958a6f8e100f3d99400cb292d37e9c173dfb7435", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "8213bdcd28581899860de14ba5bb03e3244b08b3811e5888dd8a093be8f77701", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "6ae16f37a515a9a247bb92c4df644058369cc10ea95ae036a268021562f4c858", -"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "fcfcf9383cab1242c8e670e38f0f9b9abefebc343c4ffc80759d17322f2dc771", -"T2T1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "cbb43f5932f81343db3fb5c8cedada6a023f1854f86ca4ee08bc705040a19eaa", -"T2T1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "0cb315af20a8b11995d0ba7cb54291d6db3c44c029c3dc83eadedde39584c6e8", -"T2T1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "901dad6856b676c303dedc9b10e19bad68e0bc3e9468fa10b60398f8370ad6e4", -"T2T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "b5aace4a7074ff2bbf22b87644530bb949d74eff05662c3bec0ba2928b5ddb12", -"T2T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "b5aace4a7074ff2bbf22b87644530bb949d74eff05662c3bec0ba2928b5ddb12", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "e872c2c6876a8063ba77f02a76aae596479096af42b9a00daa4cb440cb575018", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "e872c2c6876a8063ba77f02a76aae596479096af42b9a00daa4cb440cb575018", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "e73841e987535f44a43067a242b076a8388e20f8642f70342b47975b2accd420", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "e73841e987535f44a43067a242b076a8388e20f8642f70342b47975b2accd420", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "f98e92ec95bee98dfb977efd53e71eaef6ac47213656ada97f56ee58f802fe7b", -"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "f98e92ec95bee98dfb977efd53e71eaef6ac47213656ada97f56ee58f802fe7b", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "08ca82a70e631304668103f97021fe5f473e42f4e9eb3ceeeffa4f0f64deca16", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "08ca82a70e631304668103f97021fe5f473e42f4e9eb3ceeeffa4f0f64deca16", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "8c7d5a2a16a5c80aaf003d46813a4e4e9e0a75d3ea7299f3fdbf79a15993343b", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "8c7d5a2a16a5c80aaf003d46813a4e4e9e0a75d3ea7299f3fdbf79a15993343b", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "2a1f80429e66ba14feea925d243b85e7d9376be916481a9aa1c988fafbd5d55b", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "ded5e201cd2be6fdece11436cc4b7166acc39f997f4fab0343cda2d958b057fb", +"T2T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "24c722b37edb4d0f29674ee3c61e51d0b4395256d2e5602f281073594a1eb0df", +"T2T1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "a366d1c2790db0fd29c63859a5fb4af347251fa95128c0df4a17078a02706b4b", +"T2T1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "cb1f2cd526f48d97663b86b53a9762bc86cf46975a301d6d86addf2e7381197a", +"T2T1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "68d700c962e936e305a8167e9b31167465bbd858483ea5323b33c55bf8aa4019", +"T2T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "90bd344867f6c067f8b753c493fa12c1d79cd802a9eed2228d48e75a1ae9e763", +"T2T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "90bd344867f6c067f8b753c493fa12c1d79cd802a9eed2228d48e75a1ae9e763", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "fb7fd69702eccebaa8c9934a2b2774e80a79c2998593642b5139c4a5210f3814", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "fb7fd69702eccebaa8c9934a2b2774e80a79c2998593642b5139c4a5210f3814", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "e758192cbb59ae0790569904c1cd38c237372bf973e408600c038a21650a6ca2", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "e758192cbb59ae0790569904c1cd38c237372bf973e408600c038a21650a6ca2", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "56ece9c1766e57acc21a0aa9f52d225da7f71544d9045ecc5cdd4efa15e52313", +"T2T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "56ece9c1766e57acc21a0aa9f52d225da7f71544d9045ecc5cdd4efa15e52313", "T2T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-0-rNaqKtKrMSwpwZSzRckPf-3321e5d1": "33d52f2589cb068cb1b86ba509a227659cec0b20707c875ea6561c977e06112e", "T2T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-1-rBKz5MC2iXdoS3XgnNSYm-fd75b415": "a993bfcda273fedef3b3bd890d4e752bfac3a2ac0974d0736f85a6c62ceed267", "T2T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-1h-0-0-rJX2KwzaLJDyFhhtXKi3h-af5daf0f": "e7edd1f1cbc26e23663eed486fdd374d92da0df6589b892325492425c243b532", @@ -6468,24 +6468,24 @@ "T2T1_en_test_msg_applysettings.py::test_set_brightness_negative": "8aa7c68cd09e700e8c6903dcfc39c4a66214481c12c34dc56762829478399b79", "T2T1_en_test_msg_applysettings.py::test_set_label[empty]": "628a9906a6f009a3666a35998b71caa2085623593e8672d9fcc335732fcb2d37", "T2T1_en_test_msg_applysettings.py::test_set_label[max_len]": "08181d6d327a1441f9be3418ebe25f2c7169ab561fccca86f738dd68ec256ec7", -"T2T1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "c49a4143d0bbf27586fdd167b277d7c3909f274c5e3ac8038c2079a3fa224f6b", -"T2T1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "c49a4143d0bbf27586fdd167b277d7c3909f274c5e3ac8038c2079a3fa224f6b", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "05b8703f3c7e9e54548c9a38a94f76f160c5699d3a3388523e86dda3b637200b", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "05b8703f3c7e9e54548c9a38a94f76f160c5699d3a3388523e86dda3b637200b", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "4275c73dbe88d089bcd8b8af38ecf64477198ddf995f03771ec6ba0d1bbb3851", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "4275c73dbe88d089bcd8b8af38ecf64477198ddf995f03771ec6ba0d1bbb3851", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "2e6e2e4fe1b684a800d74a7a4e2f0d22ccecad6f7f2b5635c3b5cd91727a9565", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "2e6e2e4fe1b684a800d74a7a4e2f0d22ccecad6f7f2b5635c3b5cd91727a9565", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "ef3a45281394fd41b8ffcc40724142cede85d0ce294ece33188d8370b51461aa", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "ef3a45281394fd41b8ffcc40724142cede85d0ce294ece33188d8370b51461aa", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "42a8b67a9dafa852af72bfbb174affba1cf006873077c35408eb33c21b70e835", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "42a8b67a9dafa852af72bfbb174affba1cf006873077c35408eb33c21b70e835", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "97a039ce474b2515d87bb748eb4b1987dc1af672ceef2ba3bf8214907d3ec970", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "97a039ce474b2515d87bb748eb4b1987dc1af672ceef2ba3bf8214907d3ec970", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "c06856494a14af75fa1b8313dcf641fc30cc3ba6e63509c9b188ca099c4368dc", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "c06856494a14af75fa1b8313dcf641fc30cc3ba6e63509c9b188ca099c4368dc", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "9c743e97ec888daf3a265a44c1e05d36c03c933539af8d29120997091477c776", -"T2T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "9c743e97ec888daf3a265a44c1e05d36c03c933539af8d29120997091477c776", +"T2T1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "30146ba5ff98bebea088ddc1263fdb6a1a0b848f78f396617d24baf362433d1b", +"T2T1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "30146ba5ff98bebea088ddc1263fdb6a1a0b848f78f396617d24baf362433d1b", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "8a189bdaebbaa5791afac7d981af243fc4e4f7d966312585425c5873e492b148", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "8a189bdaebbaa5791afac7d981af243fc4e4f7d966312585425c5873e492b148", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "95ba61e64c4a311838e29f626e840a58aa98825f6476c0c5d4845a713a7894c1", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "95ba61e64c4a311838e29f626e840a58aa98825f6476c0c5d4845a713a7894c1", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "95c0d69ba4a27105d0cef0b0dc7cfeb1acb2f1b0dc80346f9bd7d69a800fd8c9", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "95c0d69ba4a27105d0cef0b0dc7cfeb1acb2f1b0dc80346f9bd7d69a800fd8c9", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "c3905c2b1491c3eb4445250a7f773c362dd001720be29069bea3430072a3f2e4", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "c3905c2b1491c3eb4445250a7f773c362dd001720be29069bea3430072a3f2e4", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "e6af35a6acb48b2ea7f8f41724e90617ce3e401a9ac248bcdf0426445f015f71", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "e6af35a6acb48b2ea7f8f41724e90617ce3e401a9ac248bcdf0426445f015f71", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "00c935fa1a9369f3b616ec5c4fe16a6e4fb7a39fa62c20ada96eecbd4593329f", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "00c935fa1a9369f3b616ec5c4fe16a6e4fb7a39fa62c20ada96eecbd4593329f", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "7c7ff52ab5b6c21e08ffa197c65e01f48115c6c7bbe19e4d308d2ff513e373e9", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "7c7ff52ab5b6c21e08ffa197c65e01f48115c6c7bbe19e4d308d2ff513e373e9", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "bbd0eec7258d3902fe661e6b6bb9691631b68f27ec5e7584312c454253acf321", +"T2T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "bbd0eec7258d3902fe661e6b6bb9691631b68f27ec5e7584312c454253acf321", "T2T1_en_test_msg_backup_device.py::test_interrupt_backup_fails[Display]": "3106d22b3518e2cd671ba8ebc41c944068b72460a0ab6dfce61424cfa355f65e", "T2T1_en_test_msg_backup_device.py::test_no_backup_fails[Display]": "27354fec0c2803e9d46a3aef50a22cb6e6e5b4dfd8d788be63835ce513de5b4f", "T2T1_en_test_msg_change_wipe_code_t2.py::test_set_remove_pin_without_removing_wipe_code": "634f9f3e470cbd0d50ec07ae70dfabb69fe3b505ecb67ccb56f89d19580b05ba", @@ -6501,9 +6501,9 @@ "T2T1_en_test_msg_changepin_t2.py::test_set_failed": "e437fde2fea07f0deff2a429c4f12d3680762a1d1dd7463e7a211ca5c3436686", "T2T1_en_test_msg_changepin_t2.py::test_set_pin": "944bbaf7914a074f99fabc1744821689e22759a1c29d94695753148a4f07a69c", "T2T1_en_test_msg_delayed_ack.py::test_abort": "e65a3557c4f1d3ebd2e16c361b3851aa5c4f902ede28b60626fb48bdce714f28", -"T2T1_en_test_msg_delayed_ack.py::test_backup_no_acks": "b29dbaa021a4cc288b53ed9830c9291dc43219ae766be6557cefb29b75d92e4a", +"T2T1_en_test_msg_delayed_ack.py::test_backup_no_acks": "6f1624d09250ac72be9618d00f1b746cf433312ca973a02a6eec323a5b762d7c", "T2T1_en_test_msg_delayed_ack.py::test_delayed_ack": "e65a3557c4f1d3ebd2e16c361b3851aa5c4f902ede28b60626fb48bdce714f28", -"T2T1_en_test_msg_delayed_ack.py::test_setup_no_acks": "19307288dc82035be5cacf0fcaabe91b342b6f3284d1530349b781b1c7ae361f", +"T2T1_en_test_msg_delayed_ack.py::test_setup_no_acks": "7797ea097757fdf4838776b6be798f5e1088755e8703f2dd11b3880c9ee647d4", "T2T1_en_test_msg_loaddevice.py::test_load_device_1": "571d7a69e955b455ce947edbd90d7ae404afac736cddd02e17dfcc7830759117", "T2T1_en_test_msg_loaddevice.py::test_load_device_2": "a4bc906bbcb42d93a29b548e44ad82c91e09fa49b2423748328bb1d65b2a9c12", "T2T1_en_test_msg_loaddevice.py::test_load_device_slip39_advanced": "571d7a69e955b455ce947edbd90d7ae404afac736cddd02e17dfcc7830759117", @@ -6541,10 +6541,10 @@ "T2T1_en_test_protection_levels.py::test_unlocked": "7f0ae95ad6b7d0cad3b40d638b9d323d880640fd895a15b9be8cc7fa4d4649e0", "T2T1_en_test_protection_levels.py::test_verify_message_t2": "0080f1b013f28fe50c07b5752a9e8a0a994838c6bbfd70733f79b01c7d6ec0c0", "T2T1_en_test_protection_levels.py::test_wipe_device": "6bdbc57f1442f94a96f78c6052642547221ca08ff0f183eb8a74efb36710a681", -"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "0afa5d3f4cc00d434be413b9b82fdde70c44fbd51be44a78762df99b852fc862", -"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "67a3f7e6f1ea0cb971446cbf4fc09cefbd080d834297a623fd6551bf86f38fba", -"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "67a3f7e6f1ea0cb971446cbf4fc09cefbd080d834297a623fd6551bf86f38fba", -"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "da16bb7fec4650a98a7cf5f8517cab17fea64d399448f6225ec8ffccdb56149b", +"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "8173366a9d9600814c24214d79fabe92f3a6874c054f085ee9a13d97cb0b74e9", +"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "fbeaf527f0034fa64198cbb178a3a0340a74fada3dcbd664107f4ff310d15266", +"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "fbeaf527f0034fa64198cbb178a3a0340a74fada3dcbd664107f4ff310d15266", +"T2T1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "a99db8d8e2995d0a1f238b84d9f4f78305ae4aa47ee685be36f6412cf37294a5", "T2T1_en_test_sdcard.py::test_sd_format": "1c0e37c8e38da56a979cf162475abeca84beb5095bd78024931bfd0163974327", "T2T1_en_test_sdcard.py::test_sd_no_format": "2723724828f549bfbdf0a5b7aa92b7df256e0eadb6b1f074fad824da8b398409", "T2T1_en_test_sdcard.py::test_sd_protect_lock[auto_lock]": "136227acaaef1c90cf7d1541fd406d589ed8f030f49300149c30d6dba932b09e", @@ -12274,9 +12274,9 @@ "T3B1_en_test_autolock.py::test_dryrun_enter_word_slowly": "977d48ecfa74d1a7501910e5608b7d3209516082239d8dd70f5063518ba6bf43", "T3B1_en_test_autolock.py::test_dryrun_locks_at_number_of_words": "0cee170bbe8a66b4709457c8e5b7f78b5dbea4247aacc3cefd6c3be41e0aed87", "T3B1_en_test_autolock.py::test_dryrun_locks_at_word_entry": "022cf931952dff5aa5ee2b0da833ee1060577c498c3d639fb62f6ce39b50cd95", -"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "deb552190504e012c8eb6d27629b3059331dacf95c7dfd97530b54adb616a7c8", -"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "dcab09d135877b43a41dde613b721ee98d7350e2e2f1457ccb1d106ca6291254", -"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "4223ddef779df21cf306213d9856f0d095255ae96ae7f5319b4ece1ea440413c", +"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "bca7c46d0cc94e3b86d87a9c760d8c95dfeb6611bf672471d5aa4805731e406e", +"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "e8d4d88c8c2e2ab897e7a296de7d4ec54c802c86a8faf65a97ecdc422a575186", +"T3B1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "e76b1fa04360931121e0bb50147f91ae2b9481f800fcc0ec1bd8df79293e455c", "T3B1_en_test_lock.py::test_hold_to_lock": "f2a4d5d83b19c04a235003137ff5f1b35ba36b36971dcc82d2911039753380b9", "T3B1_en_test_passphrase_caesar.py::test_cancel": "01a843febf11800dcec1efc1fbde99ef83dc654816a3e2fb8d80188eb6b89f53", "T3B1_en_test_passphrase_caesar.py::test_passphrase_delete": "ec6468b03b6e424688596167bf19fc6db1fadbca381e2d9ee1272f0ff13fbbc4", @@ -12304,13 +12304,13 @@ "T3B1_en_test_recovery.py::test_recovery_cancel_issue4613": "2b9c9188fcde9ce82c2fcaaf918e9e1b755e0999f30a332c1b6eaa4891cef845", "T3B1_en_test_recovery.py::test_recovery_cancel_number_of_words": "b56656c8f2f31d96cc371a7a54cdaa6c4501905ecedce251e9e06cae308173a2", "T3B1_en_test_recovery.py::test_recovery_slip39_basic": "eca12dbbb83a1b76bfee74a2315344c4de92620781597b6125c867bbfa81b391", -"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_device": "fa62364e7cf538ec33061fbb4c531bdb7dc460253f9b8d195d7ab2ffb885c992", -"T3B1_en_test_reset_bip39.py::test_reset_bip39": "ff7753a6a5c1afe46dfea1ed41a2dd63fec4a4fab82fce68e2ffa18d0915b625", -"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "6f5d8dba20cafa82bb0da1309d6a2597215d23873e303bad672142b1dbb4c5b4", -"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "e5f538df2e438fbf56ed15a334c5ec86f811fcddeea2a44fcdaf0caadc64a52a", -"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "8c7a6b3ac9a6011fcbe7212f4edbe1d786b267ec892d959e45ee0e38bcbb805b", -"T3B1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "d7e5615d747f375d9fd7fdd50019970813bbe8d85a0dc8d739287a8176b4d8a2", -"T3B1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "f0a4a91fa92b8a4a94ff53bdada54c94bcef24b1a9e0b53841ad083467914c67", +"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_device": "5d470fd46b992dec26b3e0beb9086b646be6acb54cd6385bc68d3104affde2f7", +"T3B1_en_test_reset_bip39.py::test_reset_bip39": "cb40bbb32e2d5e4040bc36053a2ca2207d4b3d95c06fc8e276c3b113bc9f7625", +"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "cc4a55070b643f1cdf5cdd37a58ab49969c865138e2d71622f4d8f34fd9d5b46", +"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "c7fed665d2978fd4df363316243ff70d198fb2edc381393a39a364b38dc5dae5", +"T3B1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "b775ecdbe51bffd24bfe7367cfe15d3334d9a4e66f746a5d6c838da701288d33", +"T3B1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "bc94958cbb10c0668a6fc7b962b9e78c7c40951e3933cf5c19e73305b652f3f8", +"T3B1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "5e630bb6354e4502780d67d38086d358ab9561d630ce83d6e50d80560fc80093", "T3B1_en_test_tutorial_caesar.py::test_tutorial_again_and_skip": "3b222e024b64b14bc0cdf38ad14e0893f577e4dd5971a4596e51f772b838b250", "T3B1_en_test_tutorial_caesar.py::test_tutorial_finish": "cd123234604a7ac5909fddf166c41d678682b245b266ba12dace3466495d3e9d", "T3B1_en_test_tutorial_caesar.py::test_tutorial_skip": "17cc0f156c9930392316710f2ded598151f292238ca947a844c3963b9ad496d7", @@ -17292,34 +17292,34 @@ "T3B1_en_reset_recovery-test_recovery_slip39_basic.py::test_wrong_nth_word[2]": "e8f62bc3af7bdf998cec98681735b13eff8398d17a47189d0436a988bf2850c7", "T3B1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_dryrun[Display]": "50bd69798ea98f5e7f222a7dc2576d6ba896008955ea3fac3e8a6b323bdf1c53", "T3B1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_invalid_seed_dryrun[Display]": "f2f409b48ed48847e7f95cec95b633654d151bf94f9f806fc3b812afa758a561", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "b88e213c5883b8b8939fa26251ad83248716a16e6d00b11d0589bb7e15869f07", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "a2a50c06aac999fd774633d2c7bf114be0fb55b295c78c780b20e0097b61d091", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "7891b590c7f541b04367206f6e1abe2c4407cccc3e1ed56e8f5997b67de2f0a5", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "2f23b5708987da7f8adb0ca2a13c3124375a5154422cd31beac9a488435ca91e", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "3cae5a0ade4e7370801fe09be699fe14f871b1773dde9b7f3b9afd608661ab32", -"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "3061473f59f33240bc014c74973b776489895b58d8b35ec413bd87b6c77f0339", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "2c9ec7b7fde965bbcf1be1c0a474bd381b6f0dd726a3fadf99ee1fccbec2d390", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "b62880a9671536f499932721a58630c8d3239c7735daf5dadfcfb252c8fd3213", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "84935fc8a37cb3e3f83cf761057dd70ac6a333cd7f03e9b5c19ab6b749b67b19", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "76e7294bc70cafe8a4b2bdd0c02078334e80a23e9a4b20bd6b008a4bcf74fdf1", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "ba47e078d4519e13f39bc14f40825d3b131f25f8e9e34e35be2fa1efa51b43e0", +"T3B1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "ba1ade7cd46e9993f0e6721c9c246372235757b615d7c9c02310c88e72212d80", "T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_already_initialized": "7945fdf0623a34efada654fe62a57fa06c6ab0cf4383bc14c6b7acd594b10596", "T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_entropy_check": "5405190d95ef5eebdac4783e1c199cb1cf45b7dfb6ef1d38ab356bf9b676f7ed", "T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "7573e5fdcf90b4fd4e1f14aec29d40d05eff1599f6143dd92589e0ba5f1cd1b9", "T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_no_entropy_check": "5405190d95ef5eebdac4783e1c199cb1cf45b7dfb6ef1d38ab356bf9b676f7ed", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "4abfc8e31cb723066ec189aff1944b5705a860ceb4d0dc2279a9e3c156a95ef8", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "4abfc8e31cb723066ec189aff1944b5705a860ceb4d0dc2279a9e3c156a95ef8", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "6a87245acbfcc0edc5c98035416a747dc279fb5a48bf23ab59981308656af133", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "6a87245acbfcc0edc5c98035416a747dc279fb5a48bf23ab59981308656af133", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "9e3afdbda574a89666c3844815a48ffb52626c83e0871b89130844dbf3d912b8", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "532946b8d9b2c0d7403d7c209e1342a6bb56327769f0c7e67c779a633afd20db", -"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "dfebacc6e66c6df6be4989ae80666f314de58d48ed243692088e637dae0705db", -"T3B1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "67f0d272b63d4cc0fa08d963afce63ca49fc004348df162f783368ba38c2e748", -"T3B1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "d2a3452d5dcd4eeae1654a665b269a053182f3b7bb7593bda83d52895bc73bb4", -"T3B1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "40e8ef83f8136405e1de3afc00182124013bcff51fdb411ed5dc2b86708bffd8", -"T3B1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "074acefbe9f39129771889b6a4b0884b2de0dcd65b3f9a129b838dbde0302a89", -"T3B1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "074acefbe9f39129771889b6a4b0884b2de0dcd65b3f9a129b838dbde0302a89", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "33e19293a71f331c677b47ed23eb85782ed52392d07a0c41ef40622b5923cf8f", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "33e19293a71f331c677b47ed23eb85782ed52392d07a0c41ef40622b5923cf8f", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "e223c0e310bb816a208e92478b116d237831320075622075b965e12c21b65544", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "e223c0e310bb816a208e92478b116d237831320075622075b965e12c21b65544", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "3aa25f606d964244326606a6ad46702916d3dfbe46c9a1fc5fa26742b0fb1860", -"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "3aa25f606d964244326606a6ad46702916d3dfbe46c9a1fc5fa26742b0fb1860", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "f3a3af4dc52e38f8c10e39e2a650a21151ebedee292351c093dcce1659d194ac", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "f3a3af4dc52e38f8c10e39e2a650a21151ebedee292351c093dcce1659d194ac", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "7e2e16e49b8aefa3d677b2c9c4b21fbb8ac880cbee74d9326905ff1630d6fcf3", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "7e2e16e49b8aefa3d677b2c9c4b21fbb8ac880cbee74d9326905ff1630d6fcf3", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "a6dbd381fb8ceb126f817228d303e1e2613aa5c2764d911874c717ab36cd251a", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "eef559a4442e3e148c28630e44c84fdcb1587b361827956204f57f348119fbaa", +"T3B1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "3cca7c4aa66c2ff2ca751eba6f06e3c6073a471c2eebc0689578fb44533474fd", +"T3B1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "a9ff404884569350e130560e811d8aa34117e753776ab568e15ca4f99287cb84", +"T3B1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "d7e2356db085e1a0e9d0ab1be66ff79aef080ac8f00cc2da714dbb25797110fe", +"T3B1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "7e76ae282d27ad73b7d64cb42f53bf69324029ffaf2192b8ddc6ba4112193a77", +"T3B1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "ce95b341f8d4fd13dfb7f5714e3695da9f4218148461415b719871b0f433f2ea", +"T3B1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "ce95b341f8d4fd13dfb7f5714e3695da9f4218148461415b719871b0f433f2ea", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "3f61db831e67e518fffa0f03b990762af04e262bfa76d87e51f0e154107247e3", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "3f61db831e67e518fffa0f03b990762af04e262bfa76d87e51f0e154107247e3", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "617a8b72624c2b6d847572f98e35a7c8be0fc5eaf38af248be8f0fc3a0f6403f", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "617a8b72624c2b6d847572f98e35a7c8be0fc5eaf38af248be8f0fc3a0f6403f", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "922fba149a3051fbb2d8e2a94c04305592dcb2f50217809f7cf5614367d37c81", +"T3B1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "922fba149a3051fbb2d8e2a94c04305592dcb2f50217809f7cf5614367d37c81", "T3B1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-0-rNaqKtKrMSwpwZSzRckPf-3321e5d1": "467be98fc1563466b63747097017bab05f283e8f685bae98043bf9caadf2adf9", "T3B1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-1-rBKz5MC2iXdoS3XgnNSYm-fd75b415": "07fe720f2c2ecdaafac8b72e26e393aeb6f7ef0f9e72b3d1ce76c4e640a954be", "T3B1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-1h-0-0-rJX2KwzaLJDyFhhtXKi3h-af5daf0f": "af343cbe91c4a9fef5ac24feef5b091130380707c55a8659d6ffa1dccdfa896b", @@ -17597,24 +17597,24 @@ "T3B1_en_test_msg_applysettings.py::test_safety_checks": "a6d992dd20fa98a95f5ce9d5b0330d54fe74f386dd203db0b2034e7301ec7038", "T3B1_en_test_msg_applysettings.py::test_set_label[empty]": "4212e27bf4a188b9687ca5c02d3643f23955c36d1b12f859b90d875b63c47751", "T3B1_en_test_msg_applysettings.py::test_set_label[max_len]": "80fcf3fc6d9f76d74e8ce47ee4f4d0867a6ac32a6551685a833d0ade324ce190", -"T3B1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "a6d4c598a718ddc116afb26fa4445135328ec8a61f834d3c84f8ddb7d18f4994", -"T3B1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "a6d4c598a718ddc116afb26fa4445135328ec8a61f834d3c84f8ddb7d18f4994", +"T3B1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "b181b96415000faae290408a46b8a2520bb03e021060cd621737c077d8b979ed", +"T3B1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "b181b96415000faae290408a46b8a2520bb03e021060cd621737c077d8b979ed", "T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "e6a99b6fda271dc96d9d5c7c496524f0142e4d02527e3097b21f427d25b50b2d", "T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "e6a99b6fda271dc96d9d5c7c496524f0142e4d02527e3097b21f427d25b50b2d", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "cdf4cf89ba81fa2e245ed292082ea948f10e6ed51efc45d33527acc8fe82cadb", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "cdf4cf89ba81fa2e245ed292082ea948f10e6ed51efc45d33527acc8fe82cadb", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "b392b00e1abb48ac7f394734384e1d0a567446e7cc9832bd2c8c84ecc5b0ac55", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "b392b00e1abb48ac7f394734384e1d0a567446e7cc9832bd2c8c84ecc5b0ac55", "T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "e6a99b6fda271dc96d9d5c7c496524f0142e4d02527e3097b21f427d25b50b2d", "T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "e6a99b6fda271dc96d9d5c7c496524f0142e4d02527e3097b21f427d25b50b2d", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "82654e87f295cc0071dcb88cfb9e696628e24e37aaa1848cd98638793833fda6", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "82654e87f295cc0071dcb88cfb9e696628e24e37aaa1848cd98638793833fda6", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "6dcea1879742e5eae33dbc5099bf9aac7b6b68464a9f06ed8efd3039288b31da", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "6dcea1879742e5eae33dbc5099bf9aac7b6b68464a9f06ed8efd3039288b31da", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "40a4a06c9196922a484800efe098eec6be86118163d5c9c38089220f0d9eba3a", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "40a4a06c9196922a484800efe098eec6be86118163d5c9c38089220f0d9eba3a", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "5bf32049a938ad3221fae05b9ac6606494bf31a14a14e46caff6aeb314fe79b8", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "5bf32049a938ad3221fae05b9ac6606494bf31a14a14e46caff6aeb314fe79b8", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "54b6c05e545210771584303f80fcb6f8760f3413a6f82785cde7697840b4738a", -"T3B1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "54b6c05e545210771584303f80fcb6f8760f3413a6f82785cde7697840b4738a", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "ec6d91f670d5f6363680688ce28cae8a5d66a0f7fde520a56c0475931cd2bff8", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "ec6d91f670d5f6363680688ce28cae8a5d66a0f7fde520a56c0475931cd2bff8", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "980f43ab5295a067bf0d6ce39b98201f0bfb23dcc3623c522ae19a40274fb885", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "980f43ab5295a067bf0d6ce39b98201f0bfb23dcc3623c522ae19a40274fb885", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "4594803dd1b69c3d4685893bf22fb16dea3b56d7a4ed46491663cbc8e8c877ac", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "4594803dd1b69c3d4685893bf22fb16dea3b56d7a4ed46491663cbc8e8c877ac", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "1abca5e916998cf434e346174e1d073100a58a4aec900c887f9befe34d7cbd7c", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "1abca5e916998cf434e346174e1d073100a58a4aec900c887f9befe34d7cbd7c", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "defcab96fc50591bc38794f5fe070738f6c644dabed73107e5b75fe38cf14100", +"T3B1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "defcab96fc50591bc38794f5fe070738f6c644dabed73107e5b75fe38cf14100", "T3B1_en_test_msg_backup_device.py::test_interrupt_backup_fails[Display]": "7cbb759dcca46c3cbca4845d1f717c732c9ff79111db125d74235d3c33ede8cd", "T3B1_en_test_msg_backup_device.py::test_no_backup_fails[Display]": "54344b55b5e4df4843b8508830f10321cad111192232fedc05fd3c6fd33c2951", "T3B1_en_test_msg_change_wipe_code_t2.py::test_set_remove_pin_without_removing_wipe_code": "98aadf032bc184a8ff51fc56a735a8b4c9e767e5d3c0a80aa47e9dababe6dfaf", @@ -17630,9 +17630,9 @@ "T3B1_en_test_msg_changepin_t2.py::test_set_failed": "326b2d556644f06cab06dfaf72b3da703b9b0d003e67a5b842569bf92972fa64", "T3B1_en_test_msg_changepin_t2.py::test_set_pin": "0c2e421774b2e90c4b2e029017ea3a65b138717ba9bfd6a02112adbcfaca266d", "T3B1_en_test_msg_delayed_ack.py::test_abort": "5eb2fa358b8e0a199b48e9ab34dd41d4c40ba87355c17c4a61d97c026abb3027", -"T3B1_en_test_msg_delayed_ack.py::test_backup_no_acks": "0f32bf4a43f3620a346b8907bb7ca3b1ec034e757667503cbf37cdc2ef1ba150", +"T3B1_en_test_msg_delayed_ack.py::test_backup_no_acks": "77f441b491bc4abc9eab04f7c78bd6406c25e62c5289ac98e65714319e51d510", "T3B1_en_test_msg_delayed_ack.py::test_delayed_ack": "5eb2fa358b8e0a199b48e9ab34dd41d4c40ba87355c17c4a61d97c026abb3027", -"T3B1_en_test_msg_delayed_ack.py::test_setup_no_acks": "5b4fea9fc530b2a0c6c9bf5bc980fbd7f1cd2e5da7d4cfdfa3be868e28472ab5", +"T3B1_en_test_msg_delayed_ack.py::test_setup_no_acks": "dc798a707cf881651ad30721a230e325080744a89a14a305a390db8f0a109136", "T3B1_en_test_msg_loaddevice.py::test_load_device_1": "d5b26ad520e0a3b0010356dd85a854aeff2770dc9d5a807037248eb433c32f53", "T3B1_en_test_msg_loaddevice.py::test_load_device_2": "01f804470023bc2c686b13425098a3f16bcc081fb3337ced64b916a51c6d09e7", "T3B1_en_test_msg_loaddevice.py::test_load_device_slip39_advanced": "d5b26ad520e0a3b0010356dd85a854aeff2770dc9d5a807037248eb433c32f53", @@ -17668,10 +17668,10 @@ "T3B1_en_test_protection_levels.py::test_unlocked": "da37880e17049cad50f2ef7e3375bb2140fd7efc8c0f979381016b4997031532", "T3B1_en_test_protection_levels.py::test_verify_message_t2": "27732702d8241c1b650280db1019fb061b446ef67c2d3cb72a4887587c7eb20d", "T3B1_en_test_protection_levels.py::test_wipe_device": "44a95969711c9fb85e9f8458ba5ba9fc4d3f65280f4c39172cead0f88dada438", -"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "3edacc362e507e4c25e932e56e62f53d0229d77b4bbd44ee08a9f3a056418956", -"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "88fd7c70dd66f47c2f0650ce1209507c9b87c741b4fa278a32228628dca2f150", -"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "88fd7c70dd66f47c2f0650ce1209507c9b87c741b4fa278a32228628dca2f150", -"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "b0b2e4cc027910b29f9b0a891a91564acd7e5cee1bf19718ca47c3016abdbd73", +"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "72c71c8ea4bd15080a9f1d3159cb4773c8c73c45cc9932f7b9b434f05652fc35", +"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "472b44753a1024cd445a703e449f305e44b7899bec09e1d9273f99562c2056e6", +"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "472b44753a1024cd445a703e449f305e44b7899bec09e1d9273f99562c2056e6", +"T3B1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "9a671296bf37357e9c32b52279ff5c5444363f74ef50d077446708640c936b3c", "T3B1_en_test_session.py::test_cannot_resume_ended_session": "7945fdf0623a34efada654fe62a57fa06c6ab0cf4383bc14c6b7acd594b10596", "T3B1_en_test_session.py::test_clear_session": "32e62ad94fbb31db7986b17265b8817c1a5c42fd4acfa0c3d88c2781e390a5a0", "T3B1_en_test_session.py::test_derive_cardano_empty_session": "7945fdf0623a34efada654fe62a57fa06c6ab0cf4383bc14c6b7acd594b10596", @@ -23216,9 +23216,9 @@ "T3T1_en_test_autolock.py::test_dryrun_enter_word_slowly": "9526feaf8aa56b584e5fb74cc626f96ad953e0c41c0275a94a7693b646039860", "T3T1_en_test_autolock.py::test_dryrun_locks_at_number_of_words": "d07a7489796d3e84c7a991bac07de90a107fee1f2172c75134df8e97f905b4c0", "T3T1_en_test_autolock.py::test_dryrun_locks_at_word_entry": "0d1ee8f0b905052933787e2e010d78f3f885b62abd674f23b4ec88146ac65768", -"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "7d9f1913f85c57a71ee7989254e2e3d3c177eb966a06e3ea9a24359bb21b7aeb", -"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "5d6c2a1347c8cc856116466943a7468238eb300f4540c4ac9ec238b5fb6ee84d", -"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "c30454833172f336c28eb29ebba0e17dda9700a5ff6b5b9f10fe05aeeaddce30", +"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "209c8bd8cf4af66da748cf666089b0be7a8fedcfba1dee6dad072962d0303f3b", +"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "7888b03f5a59759596d1cdbf99251abb5f91c307ac7522179824b930c6880dad", +"T3T1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "727b5238422b379bc94b4b9191ce2510d23d1959b38890befd816d9c2a62bb32", "T3T1_en_test_lock.py::test_hold_to_lock": "f26fa6e0a3ba2cb603b92ac8a1b342c140e0d08d6813943fedcfe7a6f214365a", "T3T1_en_test_passphrase_bde.py::test_cycle_through_last_character": "3a11829a07e2d0a120a9962af89305895b912bfa1a309a7eb4187efc9e87bc69", "T3T1_en_test_passphrase_bde.py::test_passphrase_click_same_button_many_times": "7f1debe8da6ef368c73f29148664683ab9e5bd019c47d2afce12b8ae6f250af9", @@ -23256,13 +23256,13 @@ "T3T1_en_test_recovery.py::test_recovery_cancel_number_of_words": "488839d82e57dc778d6ba53fc8d1015a3e859d5e6e112554c5d1f8efea57fea9", "T3T1_en_test_recovery.py::test_recovery_slip39_basic": "87205a0eb073e3b091424f4019d3427113515081afabc8d60b69ddd65f8221b3", "T3T1_en_test_recovery.py::test_recovery_slip39_issue5306": "b2a726440dc451cfc1a89105f6c3c72294d6512eb3f5baa98ef848ca3ebc394a", -"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_device": "193bb51ac3eace05dafe526846889d95f8a59633065b1501b41dcf55894417ef", -"T3T1_en_test_reset_bip39.py::test_reset_bip39": "ed48d52541d13060df9eecf5da280594a7c2533bca108b4043c8b0427be62aba", -"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "e4946dcebed859c3777c28c959db86fc31bdaec9cb328908d3c6f7b17f85bbfd", -"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "970d309cb1883b56c4bcecc62571addbcdf9b95dc8614a669aa74eef5ec9c05d", -"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "198f9e2ff6a0657c1be37f7ef682061d1913b42f136d097ebb748ec9e8eb3a62", -"T3T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "3c342839be041864b1b124b0bc4c130d2e03b99fd8322992a8b367be07c755b1", -"T3T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "19f4736f409da3149b0c6d25c1f78d9d8bc247267dca6bc3db583f6832fb0729", +"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_device": "7904929c13b81f1bc2b140b477d3df466541a60e50852293a4690831429b988f", +"T3T1_en_test_reset_bip39.py::test_reset_bip39": "00efba970ce16925aacf60ea56982d5e18807d80c8f00b5a3aeb2440f61d46b4", +"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "5880191340be0b3e82374ea6871a2e2414b28f50e499616975d6edcf33c28a71", +"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "a9fca1cac296f22dc9a0d5a9cb10d4bfacbd428547af7ecb3cbf89c50f5df539", +"T3T1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "baa8e148ef8f69e5d4ae942986d229f40e0f18cef4d18d16bc9be4cbf6d37442", +"T3T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "066e0a964bc1f42718c8e884bce62029cfcfcb0921a615790eac7f4399f8977a", +"T3T1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "9bdef3232df73395ac748338f1acc5b67d72817d81773c619c1fd70814ea8433", "T3T1_en_test_tutorial_delizia.py::test_tutorial_ignore_menu": "92baa3eea5efb8e12837a992bb26ea49452a584c79415fecdbce1bcfe7532440", "T3T1_en_test_tutorial_delizia.py::test_tutorial_menu_exit": "c28a20fece461959cb08f90b4013a56c7c4537740685bf372a3375f1d29ee644", "T3T1_en_test_tutorial_delizia.py::test_tutorial_menu_funfact": "4df0575fb66c7e627d44ddccbb89490fb7ac0ba15cc2606d84d93d4f5f925d51", @@ -28373,34 +28373,34 @@ "T3T1_en_reset_recovery-test_recovery_slip39_basic.py::test_wrong_nth_word[2]": "08fd5bdade429f2cdc74eac74eaea3c0ce5771ca6ac1546b84ae3edc38243ffa", "T3T1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_dryrun[Display]": "94aafc91bcd675d1e3e555c5197566270c51da999961434023a360b9fbc50901", "T3T1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_invalid_seed_dryrun[Display]": "e64f6c1bffab1b27b0ca74171900b55c9a586ae835fbc7a6a4508d397c9342d0", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "786fb545b43be259bf647aaeb38e1860b1c150332266d8c2f136bfe396b2608f", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "aa03ac113877000e9baec05318ed6b544754778f31fb326ea709651d66c68d4d", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "7e95194d55853e53233dc34832bbd901e6841c639c074ba4dc3c32374c0579d2", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "fea4faabd87aa7914b841cbe85e2a1cdcaafd5226ba22a46522eeba178351370", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "45ed6c8dbeefe2076f9ebb1431b47548eda02d6485108de3d84ced0c8d70ef2f", -"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "6834038a095d66295b062c7b4ca9f4425e0d218719039fcec9ae41eafb4af65d", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "d200e1543b39038d4e87252f753112c03fb4b3df80a0a7f25de49c3b84ac7502", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "4a919d2075e589724a1cabddc8fd6a7dafba8caf05ff4c42e5f2d462de93d4e5", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "fdbb1a3c945bfe50f1b5ce4fa81bfa51b3929cdb73ee1339244675f24df32f4a", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "d15d690da90ec755d9915f9ed929474931e89272a22234d087aa1ab239af368f", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "9b035c41f92bc20bea6897be216872797388d4d8b8a4534895a6bceb31c822d0", +"T3T1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "2e384627afafb3c8125534b0ebe6879c5ea0fb25fe1b44e3a415e1f4b339d11c", "T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_already_initialized": "0064e8a52b9bff0c2a31432fa781b800afb21e8910d60f303671bdfc8d8425fc", "T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_entropy_check": "5336136eeaa51563b4796135d438c3a7e8e51c7e0dcb223894df322a30a222ea", "T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "7b5fb22b304d7be58de633faa3d31a1d66bbe894bed0b19762a2f106301767ae", "T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_no_entropy_check": "5336136eeaa51563b4796135d438c3a7e8e51c7e0dcb223894df322a30a222ea", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "2d0cc7546dd9f6423510554300ee33421df1f67ad339f7cd811ff4ba172fb6d4", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "2d0cc7546dd9f6423510554300ee33421df1f67ad339f7cd811ff4ba172fb6d4", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "550376c65f6f44f1e36e2b46143901ec4c1f8aeee3871559a85ada6f6a923e94", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "550376c65f6f44f1e36e2b46143901ec4c1f8aeee3871559a85ada6f6a923e94", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "94021156526bc4af6790e27fae01382eefd663264831fde24ceff5c85840c2dc", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "6a14582535639a2996843c505654a6eb50f3b355bf367b5a3059acbf21207a2d", -"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "8c44c92969b1844934e4e3a9a905be2787031bb9d13fe2e3e984c99154ab5a86", -"T3T1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "961d04e03e7b0d0223d84e640ca34e8d4f7e2ad70c08db5819532028dd35dac1", -"T3T1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "76dcbb2f948a85a98d51b2011edcb956f83c9d668865f09829dcebe7db5f2898", -"T3T1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "fae980e00f7b79fe480631f0b5a5d6faa152c799a26a710de3e221fb9e50b450", -"T3T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "1ea6fdad5445f6523c9835035fbe23c6eb0d88f287073a9368150cc09644c21b", -"T3T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "1ea6fdad5445f6523c9835035fbe23c6eb0d88f287073a9368150cc09644c21b", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "bba55ebcf37dc6c5f0472eed893ea984d002b526d11bbf54c801d8bcb91c4eb2", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "bba55ebcf37dc6c5f0472eed893ea984d002b526d11bbf54c801d8bcb91c4eb2", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "650354b29ee4cc2a79460274180a994300450fda1248f2c8ee1269c930034e6b", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "650354b29ee4cc2a79460274180a994300450fda1248f2c8ee1269c930034e6b", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "2b42f4307deadfc62bb1f33fe58236b7065db47d25984327d34b8c3ae3418fc2", -"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "2b42f4307deadfc62bb1f33fe58236b7065db47d25984327d34b8c3ae3418fc2", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "d3061516b41564feaaf9e74396bc5319ba3e23bba040e053cdcb2b9d904e0703", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "d3061516b41564feaaf9e74396bc5319ba3e23bba040e053cdcb2b9d904e0703", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "c115ab8d6759eb6470be7fd2e40de55167d46f0bb9128a6a49dc53cc2de40754", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "c115ab8d6759eb6470be7fd2e40de55167d46f0bb9128a6a49dc53cc2de40754", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "886fb0045df00b4a33c8248e6cdaa7f918ac17e13467f945c5662cb2ed85f118", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "7c3e274bbf1ada6d55415cc57f96572deee24345deecd49509320ffcef90aae7", +"T3T1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "c68bfdeddf1d2b62a5ead14479ca0e55cb2c29c10a9b6caf53d9c7fcdd06990d", +"T3T1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "70ff1a3d294224e2a9f1c32cc2ea4010695d2722ba81361349384820c6919b1b", +"T3T1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "d28865c12b42a645b00bf87b3e19baaf28e4c8fe44351f1d4a1818238d17ed3c", +"T3T1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "bd020800d0df4d260275584aae9e3a217e1bafd6648a99020e55dd5a4a50ab31", +"T3T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "5d17f06123ce94dd6ea4e3b2249dc5f5a8c9b44f485b09120e1a4a9d97fdc47f", +"T3T1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "5d17f06123ce94dd6ea4e3b2249dc5f5a8c9b44f485b09120e1a4a9d97fdc47f", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "fe98f85b588655d631494956792505fafcd2882166490a8ad0754f702f7184a1", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "fe98f85b588655d631494956792505fafcd2882166490a8ad0754f702f7184a1", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "f9d118087ed2420bc57f831bdc5d412d0a8563c6c6b879390c92a9ae0df87009", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "f9d118087ed2420bc57f831bdc5d412d0a8563c6c6b879390c92a9ae0df87009", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "ae9624cfb5fd6ffed9b0eb4216c9422609143bb39af0de2e9e7a4a0958e39ef3", +"T3T1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "ae9624cfb5fd6ffed9b0eb4216c9422609143bb39af0de2e9e7a4a0958e39ef3", "T3T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-0-rNaqKtKrMSwpwZSzRckPf-3321e5d1": "853834754a9872d8006f9cd3e892ae166ca245e2c4c9344b96a92717d40c7e23", "T3T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-1-rBKz5MC2iXdoS3XgnNSYm-fd75b415": "45b703560d401a4948caf15daa24eef1bef45082752082e06b98cad9d9ada0ed", "T3T1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-1h-0-0-rJX2KwzaLJDyFhhtXKi3h-af5daf0f": "3b2419d806472f9c0c2e0b038d027719492b3d614d22dd9f62b6dc3b8343ccba", @@ -28682,24 +28682,24 @@ "T3T1_en_test_msg_applysettings.py::test_set_brightness_negative": "0064e8a52b9bff0c2a31432fa781b800afb21e8910d60f303671bdfc8d8425fc", "T3T1_en_test_msg_applysettings.py::test_set_label[empty]": "9db081602bd168cdb194b1c2839305ab9cf66fccea5424668b07e843586f495f", "T3T1_en_test_msg_applysettings.py::test_set_label[max_len]": "1ab607f9d2a5c15140e66e1e51ca9ce19f20a3573ac7cc4d89ceaeaa622db040", -"T3T1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "6b372dd2ad7a64c415f2cc7310d9841843726ad3fa350fd18da82ad374258347", -"T3T1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "6b372dd2ad7a64c415f2cc7310d9841843726ad3fa350fd18da82ad374258347", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "2d183800be79f204b7d968d2fb495ed9ec26fa60e470620e4bf9ae905773546f", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "2d183800be79f204b7d968d2fb495ed9ec26fa60e470620e4bf9ae905773546f", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "a92b0d4d6fa63435371b50d86ec90d6af1af0b552f65228a4cf0ce91126a95df", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "a92b0d4d6fa63435371b50d86ec90d6af1af0b552f65228a4cf0ce91126a95df", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "6711dedca13b341562f9dedd3f80bc1124bf6884ee1b9460d5beca705cfaaa2b", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "6711dedca13b341562f9dedd3f80bc1124bf6884ee1b9460d5beca705cfaaa2b", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "d44941d3935793291d0239bcc803ab293ab3af85757f32cc2101e9859de49eb8", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "d44941d3935793291d0239bcc803ab293ab3af85757f32cc2101e9859de49eb8", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "0aacffc086a3b64c481ea984212c766c578488c0f542aee28d217f3344305bb4", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "0aacffc086a3b64c481ea984212c766c578488c0f542aee28d217f3344305bb4", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "0bd2c1a66939c95853c67031c51d32b0cd726003acb1f1f1c4c7942f8f57344f", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "0bd2c1a66939c95853c67031c51d32b0cd726003acb1f1f1c4c7942f8f57344f", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "c7a78d559c006a0b1dea01fd9db7e53bd52ace475752021579aa7af56a761791", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "c7a78d559c006a0b1dea01fd9db7e53bd52ace475752021579aa7af56a761791", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "8abf8af3f4574a970d442b855512eabff01dde0f3fcc27de7dab63feb556f486", -"T3T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "8abf8af3f4574a970d442b855512eabff01dde0f3fcc27de7dab63feb556f486", +"T3T1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "78d823817cf5c51d1025e2629253c8e4ded48bef00e2b4ae6e7f3dac6b83320a", +"T3T1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "78d823817cf5c51d1025e2629253c8e4ded48bef00e2b4ae6e7f3dac6b83320a", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "7218304114f5f42a347dbc6644f83336d755c1d45fc065f9a994533eb7c38196", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "7218304114f5f42a347dbc6644f83336d755c1d45fc065f9a994533eb7c38196", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "248af9b0cd715bfc555d452d0e712877911854e05baaa8f02ff261dcdc59cbf3", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "248af9b0cd715bfc555d452d0e712877911854e05baaa8f02ff261dcdc59cbf3", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "940378ea04049474c121ed191fd006ecf41d757184194195f26c5481673c5c37", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "940378ea04049474c121ed191fd006ecf41d757184194195f26c5481673c5c37", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "2363481ad2e2de72788e445442918bb8eae7e34a64f306f0c5731103c5ae0430", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "2363481ad2e2de72788e445442918bb8eae7e34a64f306f0c5731103c5ae0430", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "f278cd2fc1095dca43bbe98471932571a4dff487f3972c8e6cf3a222fd04f411", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "f278cd2fc1095dca43bbe98471932571a4dff487f3972c8e6cf3a222fd04f411", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "fc7299fede6e223ab2a9771e9429237f80e424211df735d4bed7069e2ab91caa", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "fc7299fede6e223ab2a9771e9429237f80e424211df735d4bed7069e2ab91caa", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "012550676fd05d19215d8d1692ff16bedb0f98d8f8a2c44b291fa9c71a5ed741", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "012550676fd05d19215d8d1692ff16bedb0f98d8f8a2c44b291fa9c71a5ed741", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "d57820c0b7170008bf902e26171f9438a6b561fb69c24fc7b7823dbe43ebf4c1", +"T3T1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "d57820c0b7170008bf902e26171f9438a6b561fb69c24fc7b7823dbe43ebf4c1", "T3T1_en_test_msg_backup_device.py::test_interrupt_backup_fails[Display]": "b3de26886fa9066a692e730de7b5e9d5da3c397e230354f0927c77179426163f", "T3T1_en_test_msg_backup_device.py::test_no_backup_fails[Display]": "365368aab9f2864feaa56ca19319131e06e3db4856b79417a42e7b0385c3ca37", "T3T1_en_test_msg_change_wipe_code_t2.py::test_set_remove_pin_without_removing_wipe_code": "c73e0cf4edbee7958079fb275e3dd0a9196420a67e47b29b64e7df184f134d8a", @@ -28716,9 +28716,9 @@ "T3T1_en_test_msg_changepin_t2.py::test_set_failed": "fd0d3f63cb81c4e1e0cee3b02dc18e0fa846e8bf392b4af4d81913e82b223c3f", "T3T1_en_test_msg_changepin_t2.py::test_set_pin": "999b46a983bc5244c53b831ee2cb51c8b5b59219d98fd84f44de3ba17ed3b72b", "T3T1_en_test_msg_delayed_ack.py::test_abort": "a609953f7ce56226eb94d3569126a1e641cb3773f16479baf3ba6492c36171fa", -"T3T1_en_test_msg_delayed_ack.py::test_backup_no_acks": "3e895b72553d2337383c656a6cbca2634b1b42d7dd47b1c2e16ad9d1bc13240b", +"T3T1_en_test_msg_delayed_ack.py::test_backup_no_acks": "98c6f0b7696ca3eb42e9d45f4f3b75525acdb245225b65cc359cba521b8b21eb", "T3T1_en_test_msg_delayed_ack.py::test_delayed_ack": "a609953f7ce56226eb94d3569126a1e641cb3773f16479baf3ba6492c36171fa", -"T3T1_en_test_msg_delayed_ack.py::test_setup_no_acks": "737db43ddfb08f4b2330a4c3726f354f9d26e4073aea3a380cb97a3349ab7c82", +"T3T1_en_test_msg_delayed_ack.py::test_setup_no_acks": "0f2f3f93b2fdefd4ba17daab2d5f6e96a7231638bee9691f2eabcc09156677e0", "T3T1_en_test_msg_loaddevice.py::test_load_device_1": "a1629d90e08f23a83dec1f47b0992bafea1ca1adb4f72b18ce4263e796e65109", "T3T1_en_test_msg_loaddevice.py::test_load_device_2": "6d691085eed4ef2a73ea0c514965ca7290160e9797f48922d4dba7e7243bcc35", "T3T1_en_test_msg_loaddevice.py::test_load_device_slip39_advanced": "a1629d90e08f23a83dec1f47b0992bafea1ca1adb4f72b18ce4263e796e65109", @@ -28757,10 +28757,10 @@ "T3T1_en_test_protection_levels.py::test_unlocked": "a8a2c71d62d18c17aadbf38e93f65b4f32056d334c7785f5ad8579788badfc81", "T3T1_en_test_protection_levels.py::test_verify_message_t2": "cd6e174cd4a79710947e2f9847b4e9f87a14628f69a6e793ba4cdd042fd32320", "T3T1_en_test_protection_levels.py::test_wipe_device": "2499a48f54880cb72e39a194f4079fe1d207755eac59a16d03e3b72f45a80fc8", -"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "5876a224bf22c14bbc838e2abdb969e37499b9ab5d2373150b17f04afb03f263", -"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "44392722f1c4acc53caf2abf89913d0563a40ff958a0fc4ae1f8ba6ba0718ac9", -"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "44392722f1c4acc53caf2abf89913d0563a40ff958a0fc4ae1f8ba6ba0718ac9", -"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "1f985d01dd2154514ab24ac042b250ed1678778f00582c25791cccf2bc73dbfe", +"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "23f2cf9d6a4a5ca8cd27299e1da58c7d6511682d53bbed607fc2a0d293d40aa4", +"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "5d1f39ed39f85dbc7f3469768f8a33e04d7d601eccba7cc2108361a5974a7a66", +"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "5d1f39ed39f85dbc7f3469768f8a33e04d7d601eccba7cc2108361a5974a7a66", +"T3T1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "1a69ae6f00d0bf406b811e77df691e766291641782cda324c60b9e86cbd0eb98", "T3T1_en_test_sdcard.py::test_sd_format": "9a8c4fd7b59dbb24350131fb0476daf59794522931b7f7fd9010e1453c5690aa", "T3T1_en_test_sdcard.py::test_sd_no_format": "0edc58610ac21bb7fb8027bbd5b91ffb331363cda3f716b3f41d59a98946c1db", "T3T1_en_test_sdcard.py::test_sd_protect_lock[auto_lock]": "c435b24560b53f265bb8e1e782e6e41393c8c1d591d3fd645dd90e87b2399207", @@ -34553,9 +34553,9 @@ "T3W1_en_test_autolock.py::test_dryrun_enter_word_slowly": "a6af3598a11f4faded366d71edb9516b163f5d90d79ba9d3501c769851b6090b", "T3W1_en_test_autolock.py::test_dryrun_locks_at_number_of_words": "618929594f3754d87dbcc7b0a613e25eabb85c4cc718d4aaf42554e8d2c45c97", "T3W1_en_test_autolock.py::test_dryrun_locks_at_word_entry": "eb385fe53a78a226357fbc426e2e369a14dc4a60efe52c8fe77fd0160667fcad", -"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "f1a7aa7f1238cb7148db3be3f33de2133b8141c39cb910f62a2148106421c327", -"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "32c9ac0f08570c88cde99e28c44ea1cdca0105c5f038c25efadd37fe21f3929b", -"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "c682b22a1bfb345c5eb7911323e2d34326a1a4dc7070c1ba3916f636bd5d0c87", +"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[1of1]": "8e0b1b8c31c8737a58c26274a9c43e2186e81208429ab28747e00dfedcb88d74", +"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[2of3]": "c3dda114045cf49595f32122d798e4b2fc8e65147d4be0eeaf7de78fb5c3adfa", +"T3W1_en_test_backup_slip39_custom.py::test_backup_slip39_custom[5of5]": "f5dfc5510cba3e2319538168940e11b8ecf48f79d4f62dc026c39322232b4bf4", "T3W1_en_test_passphrase_bde.py::test_cycle_through_last_character": "549f5df01a778aa16ce89954174e9859c3ad17d1ca5b2ad6fd1dfd147b51459b", "T3W1_en_test_passphrase_bde.py::test_passphrase_click_same_button_many_times": "367501fb01bad68d4731d341169be7ecba72a5392c3f736400aa8671d72e90ce", "T3W1_en_test_passphrase_bde.py::test_passphrase_delete": "caba4c2ad317cf3c305165a318bb9d957bf4cbd3cd90035567885e542af85485", @@ -34593,13 +34593,13 @@ "T3W1_en_test_recovery.py::test_recovery_slip39_basic": "2fb68b5695b6a0f6a4ce0e1c439418be296818bcae6170e4902d34537ff09687", "T3W1_en_test_recovery.py::test_recovery_slip39_issue5306": "fae3303a452f339e980bccd0d3dd32d56b23adcc367beba2e0a2a5ebd37c5476", "T3W1_en_test_recovery.py::test_recovery_slip39_reenter_second": "5784d28ac5de004539ee5ad4c90c845f9dc517a3813531f9fef719c116588f98", -"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_device": "20d505240482b91b97d6e3aa72a05222641a3b7d8388686c4406dddde60d2a98", -"T3W1_en_test_reset_bip39.py::test_reset_bip39": "c2a074c40115ae1fd4be3ff38521887028d80c6aa755cee511ef51c2c9aa656c", -"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "d84a8fe8d494810ba71883fdf220eb3ddaf3d003afc3ac2efe5cb056963185fc", -"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "e30a475e36d64877210cde59f9f0b9b6ee04ce088ac4c78f1ce987aee576ac40", -"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "ac48a3610a874dd1de9aa9fb22d4bc41ffb8a2b98fb7924ee258bba0ee609d57", -"T3W1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "dc213a9a92970e39812f72877c8b1f265e6fc05831a51ea7d8d2b01c380c787a", -"T3W1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "838f78adf061c9422a8546037066519d831912d4a10e017f8a6c5f857b04ef68", +"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_device": "c519e1fdd484560840f9fd8299b06f2657d152f8e81b34df81266f1f5ff3c8f8", +"T3W1_en_test_reset_bip39.py::test_reset_bip39": "570c411d4d77b7f823ff0748f17a0fe0377c9756718137afebb4cfdf23fa083e", +"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[16of16]": "d9b0a579f75f55680d8e1ff1cdb1ecc98c4f07e7e613651e1b664ce9bd769f59", +"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[2of2]": "e0812f46c31fecf8f3162228bb0de3a7465a667b7085713cfbd872f99e497817", +"T3W1_en_test_reset_slip39_advanced.py::test_reset_slip39_advanced[small-16of16]": "d430f847c6c5afc0d8d7556d52316b5f8b727b390c8cbdb39c6b7d8ed4b93b19", +"T3W1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[16of16]": "401ce4c3afbc4437adcfa21f06386ce8b5dba6bd79a8604a8b878e39d8802ee8", +"T3W1_en_test_reset_slip39_basic.py::test_reset_slip39_basic[1of1]": "697d7f198fe158fec87758b96d2323b6c29bb3e7dd67d15f82919d9076285a6d", "T3W1_en_test_tutorial_eckhart.py::test_tutorial_cancel_from_confirm_menu": "2b59c30dbcf32ecce592e89e22d2f56d703c30b5fc0de34a016445cebf7e9db9", "T3W1_en_test_tutorial_eckhart.py::test_tutorial_cancel_from_main_menu": "ac0e8d064afd1c6a578e9efc39cfc4edce0c5dc3dcd890cdabdc3d361e43f701", "T3W1_en_test_tutorial_eckhart.py::test_tutorial_full_completion": "e19bc074dddd20706a80bb360865212eca5af4d0e11fdc1b8a772a48bf876365", @@ -39922,34 +39922,34 @@ "T3W1_en_reset_recovery-test_recovery_slip39_basic.py::test_wrong_nth_word[2]": "29d0da80b8875ee3e5e7328cdf3181a58783039684278c0dfee9a1f536434ed2", "T3W1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_dryrun[Display]": "527cdb4090eb4266ba6b0cdb73f73e336ceed10dfbd288e36105a6343fa57ffe", "T3W1_en_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_invalid_seed_dryrun[Display]": "1563392ccd0da8d6163a76c7c00ec9b61440bf5eb73746fa9be4682243d21073", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "016fdb868d15b79f07281ad60ad108fe0e011cf412d7c1e08c93e58b9c6a3eb3", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "ea305af5ca8d60a4aaa1580168d5e85b91946e227e73f8b2aab3b76fec8bb7aa", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "df61da9314eb79ae086c03e32a8e65f2d62e1c92be7dac3ee5e419326ba865a9", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "fb6e11287585132d5b80ee6c349226e1dcd8e666b595fbd0d0d12d98f5f7ed05", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "6d42a77864e914290961a60bdff6e341807d2ed63c18e2d7cb015e7e9855c54f", -"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "bcb98e2526ce5bd4eb02edb3cd69d3937599eda81d3743b8777aa7ea6494c03b", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Bip39-backu-b86ee80b": "ab9495443e0016408818e2b1947d27ca97a7154ccaa33eb54714e99300cec603", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Adva-ad86bb51": "5adb07c11b09221ec22208cc23734f3144ad6d689563f1d6d42dc21962e1f4c4", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_manual[Display-BackupType.Slip39_Basi-a506aa60": "24f816eb115f1096ba4cd71a1960b77720b7e7e16dc64311bcf466516b243af8", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Bip39-backup_f-c9bf60d2": "7bd2b044d06d338ecc0e877de736db1a5b83fb0a0dd9490ff22a6ff298986cd5", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Advance-14f66ed1": "adb07c9232ccd20f41b4b8764877538ebe811651dbe64634186e76c8db4b1fdf", +"T3W1_en_reset_recovery-test_reset_backup.py::test_skip_backup_msg[Display-BackupType.Slip39_Basic_E-38f118f4": "2c28238fcd0f5d4f16ee2d3516bafb875e1e4d1e416f7002655da4c9053ef8f3", "T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_already_initialized": "90812f196e8c35dc7f35cb5a9a0e553c8fc6a610812d85b9f166e90b3f1c8b59", "T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_entropy_check": "64c637f77f70878c2564e08de2e18e796e47100c48851e2c5c3bd27087f6cc0a", "T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "c99ff7ebe61b2f3268a43acee57fe1ea31b92929c8bebb4b54e1cae0c52a8f76", "T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_no_entropy_check": "64c637f77f70878c2564e08de2e18e796e47100c48851e2c5c3bd27087f6cc0a", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "a359f7d3423cce0f854636908bb988adf65d49fca5f97479a1b4fa4a26a4e9ac", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "a359f7d3423cce0f854636908bb988adf65d49fca5f97479a1b4fa4a26a4e9ac", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "9a46d33ef106a5efa776125dfe32c9526a6043ea600f9215bd893003b4dd0fa2", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "9a46d33ef106a5efa776125dfe32c9526a6043ea600f9215bd893003b4dd0fa2", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "fba920937d1222cf4b1f690b93dbc77101739c5d8e2f92d4f82320aeb18a771b", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "6d5ce1ed47a839b22e351b4de6f2068670a223881c1de7f0f1204f2b3050e1f5", -"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "c9212100a6acedc533813ddf9ca9d22a06946f724b75e273a464d816710b4be7", -"T3W1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "69e2dbe3baebe0e76c3346d4e5f183bcdf7aa34a4047fc14d0782c2bfc66b33d", -"T3W1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "3500955722e0bf69de91030f88b13e217c293e2000af93f118102b129a5b53ce", -"T3W1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "b1a73b02d021b45fdd2347a5f906237675d181ad75dade74a1b4f40d4c420514", -"T3W1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "6bddcf42c1c68ba4821a8844ab7d545d57b616564e137d6ead8d0cdf124a46dc", -"T3W1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "6bddcf42c1c68ba4821a8844ab7d545d57b616564e137d6ead8d0cdf124a46dc", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "88067b06b5c955dae9390f171a9c52d8e2b6567351e2272158df8d839c37a7b6", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "88067b06b5c955dae9390f171a9c52d8e2b6567351e2272158df8d839c37a7b6", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "31292c4c8855e98cf1018c8bdbc2c1374dd42da9d30c27f568e184b31090e3f1", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "31292c4c8855e98cf1018c8bdbc2c1374dd42da9d30c27f568e184b31090e3f1", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "bb089661c274a67bb5dfff8cd85151d4bb0cba00f409d23ec107d9c06e7bc481", -"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "bb089661c274a67bb5dfff8cd85151d4bb0cba00f409d23ec107d9c06e7bc481", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[_try_to_cancel]": "8534ee8aa6585454b04c043df7729fa55ba354b7ad83dc2ca546fb2302b7cdcd", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device[normal]": "8534ee8aa6585454b04c043df7729fa55ba354b7ad83dc2ca546fb2302b7cdcd", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[_try_to_cancel]": "e76c0f520c3bb5bf23ba1ed00079a11dd4b041a096d51059d0491a31898d3245", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192[normal]": "e76c0f520c3bb5bf23ba1ed00079a11dd4b041a096d51059d0491a31898d3245", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "eb7eb2ea86418f508b20a5797a1d51954af36b5cc3891312c6b3db7ae6494b59", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_entropy_check": "3a1631191ad382f860e2fdc3ffdbccea5d19821b86cba70a3c8da087b93c8565", +"T3W1_en_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "a1b420c95c97a7ad54849b236489795927f2cb17dd7613c77ce8501c5e7583ba", +"T3W1_en_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery[Display]": "291cda170a0b729e032ab5ad7b158438cce5969872a189fe09efdd3aa7f176a6", +"T3W1_en_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery[Display]": "7c35fe121abb35a6b12fa863394f2225e0e784f757fa96e4ffcfbabd20551bcb", +"T3W1_en_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery[Display]": "d0ed5234a26d74e5f8feab99d27c1c08d3f29f6f12e6bd3b976343de6696c65b", +"T3W1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-_tr-18d84664": "b39cae725ed185a7a4897b9e8ca2694600440a4c0e64ed652dae72794fd0454d", +"T3W1_en_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced[Display-normal]": "b39cae725ed185a7a4897b9e8ca2694600440a4c0e64ed652dae72794fd0454d", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-_try_to_cancel]": "ebf1fb67039b5e5a213d4a99edb2a991cbf4a218d237143352af81476c0892da", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic[Display-normal]": "ebf1fb67039b5e5a213d4a99edb2a991cbf4a218d237143352af81476c0892da", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-_try_-613691e1": "0ee39d61ffe3eb8fb7b84b3c93a4b00f9f5f83162a4bdfd9e3cbc8f07098f941", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256[Display-normal]": "0ee39d61ffe3eb8fb7b84b3c93a4b00f9f5f83162a4bdfd9e3cbc8f07098f941", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-_try_to_cancel]": "b827f02c2cebe1e1995b11e30d4ce9a7721c690c1cb9ff935f04f1dc6652fe40", +"T3W1_en_reset_recovery-test_reset_slip39_basic.py::test_reset_entropy_check[Display-normal]": "b827f02c2cebe1e1995b11e30d4ce9a7721c690c1cb9ff935f04f1dc6652fe40", "T3W1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-0-rNaqKtKrMSwpwZSzRckPf-3321e5d1": "2c13da7599a2e6a67fbadac5883009e336170f2f0a974413cc3d5882cded9080", "T3W1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-0h-0-1-rBKz5MC2iXdoS3XgnNSYm-fd75b415": "b92affa8d346b930dde0e52a3bf4838673abe83008d75478e4d86ce84af8867a", "T3W1_en_ripple-test_get_address.py::test_ripple_get_address[m-44h-144h-1h-0-0-rJX2KwzaLJDyFhhtXKi3h-af5daf0f": "5d03b2ef49cf6616da91a39c63638e25dcd629d01167877db6f26cac1839f7ad", @@ -40252,24 +40252,24 @@ "T3W1_en_test_msg_applysettings.py::test_set_brightness_negative": "90812f196e8c35dc7f35cb5a9a0e553c8fc6a610812d85b9f166e90b3f1c8b59", "T3W1_en_test_msg_applysettings.py::test_set_label[empty]": "911657c027283e163c85d6b1e2c8ab4a9be66d0dccd8657fc919ad1902cf3c39", "T3W1_en_test_msg_applysettings.py::test_set_label[max_len]": "09da9ea56201b0c328997c9b1296af61177a5971955b785a006286358b7d5127", -"T3W1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "aee5ba68292d116b9effec617693aada49bb66eb50849839f73b2344271b5202", -"T3W1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "aee5ba68292d116b9effec617693aada49bb66eb50849839f73b2344271b5202", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "e02cf1bef3a0b920bc3b1bad58869c2fac950478105318d8798a06d6d183ebc6", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "e02cf1bef3a0b920bc3b1bad58869c2fac950478105318d8798a06d6d183ebc6", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "97a7d695bf5aff354d7940ec5a03d89cb77a2faa1c6c11dff53a899c544d8a45", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "97a7d695bf5aff354d7940ec5a03d89cb77a2faa1c6c11dff53a899c544d8a45", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "7e2c69e029313f04e2645089fd768c05163ce9023131941ea96d3f54a4e45fa5", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "7e2c69e029313f04e2645089fd768c05163ce9023131941ea96d3f54a4e45fa5", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "c67d55c53bf132c00f426431d0398c350c58c6a4fa49c996f3b45de20fabc001", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "c67d55c53bf132c00f426431d0398c350c58c6a4fa49c996f3b45de20fabc001", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "a40473e625a280c4807a6116be0eab24a62455c703764a5834ce92db216afeeb", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "a40473e625a280c4807a6116be0eab24a62455c703764a5834ce92db216afeeb", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "ff9fa09fe8b137190c8dab16b29b519531af8d1f97f80a518610998d98e1547a", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "ff9fa09fe8b137190c8dab16b29b519531af8d1f97f80a518610998d98e1547a", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "78af1a95e114462ec72361b27420b8890c6826446d4395ad9378d9fb73e80281", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "78af1a95e114462ec72361b27420b8890c6826446d4395ad9378d9fb73e80281", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "907e40d0c74f1a286ba83e8677b77fb0d9639a6280d849dcbdd8da11b93ad6c2", -"T3W1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "907e40d0c74f1a286ba83e8677b77fb0d9639a6280d849dcbdd8da11b93ad6c2", +"T3W1_en_test_msg_backup_device.py::test_backup_bip39[Display-_try_to_cancel]": "2f218453d1c94ef8db9813f1d7ff29cf10b9e7dc5fff45de181cae616c6db771", +"T3W1_en_test_msg_backup_device.py::test_backup_bip39[Display-normal]": "2f218453d1c94ef8db9813f1d7ff29cf10b9e7dc5fff45de181cae616c6db771", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info__try_to_cancel]": "d4f935b00a3c6064ebd33178c636ea26da3cdab58a41f999f3d3bec476cdfbf5", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-click_info_normal]": "d4f935b00a3c6064ebd33178c636ea26da3cdab58a41f999f3d3bec476cdfbf5", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info__try_to_cancel]": "6dffe163012be18f7fe07bcaee742b74b3e02d104675e3cec9f37ac509ad239b", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_advanced[Display-no_click_info_normal]": "6dffe163012be18f7fe07bcaee742b74b3e02d104675e3cec9f37ac509ad239b", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info__try_to_cancel]": "a0f371b59cfc1831ab8f6cbfc6b01a85112e8b0da609b95f4f21a519ef00aee2", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-click_info_normal]": "a0f371b59cfc1831ab8f6cbfc6b01a85112e8b0da609b95f4f21a519ef00aee2", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info__try_to_cancel]": "ef15b214472c8490870a077fce30d2eab315b04bd04db3a97da1488e731c80bb", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_basic[Display-no_click_info_normal]": "ef15b214472c8490870a077fce30d2eab315b04bd04db3a97da1488e731c80bb", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1__try_to_cancel]": "ff841e42cb6bf6bb00f5490faa584b78f2dd1541cc4bb886aafd4af5dad3cb08", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-1_of_1_normal]": "ff841e42cb6bf6bb00f5490faa584b78f2dd1541cc4bb886aafd4af5dad3cb08", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2__try_to_cancel]": "95f7e4a992050f193a02a0f8b4234550ef35afee1f7301609b404b4c6239d68d", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-2_of_2_normal]": "95f7e4a992050f193a02a0f8b4234550ef35afee1f7301609b404b4c6239d68d", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5__try_to_cancel]": "c4e54dbda5cc12fece501c0b180eea1817de49b358963a7a415bbdc42ffa3cf6", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_custom[Display-3_of_5_normal]": "c4e54dbda5cc12fece501c0b180eea1817de49b358963a7a415bbdc42ffa3cf6", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-_try_to_cancel]": "69445e570e80640229d8c226512a7d3c769ecc157da67e66ef29e8742a3eb515", +"T3W1_en_test_msg_backup_device.py::test_backup_slip39_single[Display-normal]": "69445e570e80640229d8c226512a7d3c769ecc157da67e66ef29e8742a3eb515", "T3W1_en_test_msg_backup_device.py::test_interrupt_backup_fails[Display]": "cd47873afb0e8231dc98afcf6d9ad9f80878b37dc078a65497b0fcf6e3a669e2", "T3W1_en_test_msg_backup_device.py::test_no_backup_fails[Display]": "b120b6a914412ad038de0ebae75e1d3b58fc348f26d6254f6cfcb60a229c95a4", "T3W1_en_test_msg_change_wipe_code_t2.py::test_set_remove_pin_without_removing_wipe_code": "8b5fd7946c9c5218c2aebbb12cc78b734fed3e76b9ca070a7124973ef391ad59", @@ -40286,9 +40286,9 @@ "T3W1_en_test_msg_changepin_t2.py::test_set_failed": "eb562c9dae8fb623488cddc6c242b2e2c532dfe9c080bb86b2959049e589f89a", "T3W1_en_test_msg_changepin_t2.py::test_set_pin": "2d01e9102afd3aca2a0749230b156828b11a4996fe52c49fce40a6fa071e3fd9", "T3W1_en_test_msg_delayed_ack.py::test_abort": "78a1810e94b2870feff593e6fe5c1a7fe71077573400180956de31cd3e303b2b", -"T3W1_en_test_msg_delayed_ack.py::test_backup_no_acks": "983ad6a9fcb91896f7321a0f87a40a663ffcfb7859add9021ad57ce80a07d0fe", +"T3W1_en_test_msg_delayed_ack.py::test_backup_no_acks": "af572336f97b399f513ae7404b324e4533be5d62266abbf03eaa009e00cab563", "T3W1_en_test_msg_delayed_ack.py::test_delayed_ack": "78a1810e94b2870feff593e6fe5c1a7fe71077573400180956de31cd3e303b2b", -"T3W1_en_test_msg_delayed_ack.py::test_setup_no_acks": "17d293a730e193157d7e53091016930d2b65f0a2c3ec0b4fa704bc76dd68ea3b", +"T3W1_en_test_msg_delayed_ack.py::test_setup_no_acks": "d5870b4d38a0db998539d563e07020036eda834b3ee7d336dcb08ae2a91de5e1", "T3W1_en_test_msg_loaddevice.py::test_load_device_1": "6f931fe0947718c1a506348a9f8f4d3f8255b6240803cd0e2e36b8e4a26147a4", "T3W1_en_test_msg_loaddevice.py::test_load_device_2": "7ad122ad47c99d25489e8dd291d85f9032c1aebcb6afd876bfe0ab5e868b0472", "T3W1_en_test_msg_loaddevice.py::test_load_device_slip39_advanced": "6f931fe0947718c1a506348a9f8f4d3f8255b6240803cd0e2e36b8e4a26147a4", @@ -40323,10 +40323,10 @@ "T3W1_en_test_protection_levels.py::test_unlocked": "3a12bd0346756ba61ea33ac6d37a900d125b235944b225b143cb13e51ab676d6", "T3W1_en_test_protection_levels.py::test_verify_message_t2": "ae647b87358a37b18e1ae9210b5995d32f1ec7650b2e4a824d20454af6bf0fc3", "T3W1_en_test_protection_levels.py::test_wipe_device": "5f69916576b65e4d352455d955251122b5d0dad8ecf55ee053983de7d42028d7", -"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "5c5e338cdadaeab2961cc0c8359d9c1cd6b3dc3133c899b8696e8b40189b425a", -"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "052f2574715d34a3cb5ff21374ef876979d54adbc98a2475a07b0da46dfea609", -"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "052f2574715d34a3cb5ff21374ef876979d54adbc98a2475a07b0da46dfea609", -"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "7a25697af0f53a26995799b84b4786ed806d47d55e3cc801b9134a28ba2c69e3", +"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host[Display]": "51a19b09f09f6a0d801834038e31aec6fe968fb07024e4d18692725380df5963", +"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_cancel[Display]": "183772d3aa3c0dda485a5b8065e31910f410d02d36b7584d8214b8b64c96d263", +"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_send_disallowed_message[Display]": "183772d3aa3c0dda485a5b8065e31910f410d02d36b7584d8214b8b64c96d263", +"T3W1_en_test_repeated_backup.py::test_repeated_backup_via_host_upgrade_single[Display]": "6c702df5546811d9640354353c37b4fa60cff1a41f6a692dd4e50ca403fab6c2", "T3W1_en_test_serialnumber.py::test_cancel": "8f3ba246d05b9b084027bdff7da34b7f867632e413e36f3a2cfef703a3f50e63", "T3W1_en_test_serialnumber.py::test_same": "0ca28c86b20a8b4aab5ba2406d3796461aa538e3bf0ed297cfbca1a215ca6164", "T3W1_en_test_session.py::test_clear_session": "e2d0124ba07c71ac846340a1cd04f1718f030b1128124708c171515dd4c8a293", diff --git a/vendor/micropython b/vendor/micropython index f5ec033a280..dac0a232ff4 160000 --- a/vendor/micropython +++ b/vendor/micropython @@ -1 +1 @@ -Subproject commit f5ec033a28017a0b698e28c908abff0efd598607 +Subproject commit dac0a232ff40dd64a4a865d928765a749a221e00