1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-16 17:42:02 +00:00

core/typing: improve extmod types

This commit is contained in:
Jan Pochyla 2019-06-09 11:24:06 +02:00
parent f5299456a9
commit 3af75c0b8b
53 changed files with 205 additions and 145 deletions

View File

@ -47,7 +47,9 @@ STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
return secfalse; return secfalse;
} }
/// def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None: /// def init(
/// ui_wait_callback: Callable[[int, int, str], bool] = None
/// ) -> None:
/// """ /// """
/// Initializes the storage. Must be called before any other method is /// Initializes the storage. Must be called before any other method is
/// called from this module! /// called from this module!

View File

@ -32,7 +32,7 @@ enum AESMode {
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class AES: /// class aes:
/// """ /// """
/// AES context. /// AES context.
/// """ /// """

View File

@ -489,6 +489,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj, mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj,
mod_trezorcrypto_HDNode_ethereum_pubkeyhash); mod_trezorcrypto_HDNode_ethereum_pubkeyhash);
/// def __del__(self) -> None:
/// """
/// 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); mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
o->fingerprint = 0; o->fingerprint = 0;
@ -547,8 +551,10 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type = {
.locals_dict = (void *)&mod_trezorcrypto_HDNode_locals_dict, .locals_dict = (void *)&mod_trezorcrypto_HDNode_locals_dict,
}; };
/// mock:global
/// def deserialize( /// def deserialize(
/// self, value: str, version_public: int, version_private: int /// value: str, version_public: int, version_private: int
/// ) -> HDNode: /// ) -> HDNode:
/// """ /// """
/// Construct a BIP0032 HD node from a base58-serialized value. /// Construct a BIP0032 HD node from a base58-serialized value.

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake256: /// class blake256:
/// """ /// """
/// Blake256 context. /// Blake256 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Blake256_t { typedef struct _mp_obj_Blake256_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE256_CTX ctx; BLAKE256_CTX ctx;

View File

@ -26,10 +26,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake2b: /// class blake2b:
/// """ /// """
/// Blake2b context. /// Blake2b context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Blake2b_t { typedef struct _mp_obj_Blake2b_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE2B_CTX ctx; BLAKE2B_CTX ctx;
@ -40,7 +42,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data);
/// def __init__( /// def __init__(
/// self, /// self,
/// data: bytes = None, /// data: bytes = None,
/// outlen: int = Blake2b.digest_size, /// outlen: int = blake2b.digest_size,
/// personal: bytes = None, /// personal: bytes = None,
/// ) -> None: /// ) -> None:
/// """ /// """

View File

@ -26,10 +26,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Blake2s: /// class blake2s:
/// """ /// """
/// Blake2s context. /// Blake2s context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Blake2s_t { typedef struct _mp_obj_Blake2s_t {
mp_obj_base_t base; mp_obj_base_t base;
BLAKE2S_CTX ctx; BLAKE2S_CTX ctx;
@ -40,7 +42,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data);
/// def __init__( /// def __init__(
/// self, /// self,
/// data: bytes = None, /// data: bytes = None,
/// outlen: int = Blake2s.digest_size, /// outlen: int = blake2s.digest_size,
/// key: bytes = None, /// key: bytes = None,
/// personal: bytes = None, /// personal: bytes = None,
/// ) -> None: /// ) -> None:

View File

@ -24,7 +24,7 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class ChaCha20Poly1305: /// class chacha20poly1305:
/// """ /// """
/// ChaCha20Poly1305 context. /// ChaCha20Poly1305 context.
/// """ /// """

View File

@ -23,6 +23,12 @@
#include "crc.h" #include "crc.h"
/// package: trezorcrypto.crc
/// def crc32(data: bytes, crc: int = 0) -> int:
/// """
/// Computes a CRC32 checksum of `data`.
/// """
mp_obj_t mod_trezorcrypto_crc_crc32(size_t n_args, const mp_obj_t *args) { mp_obj_t mod_trezorcrypto_crc_crc32(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);

View File

@ -27,10 +27,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Groestl512: /// class groestl512:
/// """ /// """
/// GROESTL512 context. /// GROESTL512 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Groestl512_t { typedef struct _mp_obj_Groestl512_t {
mp_obj_base_t base; mp_obj_base_t base;
GROESTL512_CTX ctx; GROESTL512_CTX ctx;

View File

@ -180,7 +180,7 @@ STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg,
/// EC point on ED25519 /// EC point on ED25519
/// """ /// """
/// ///
/// def __init__(x: Optional[Union[Ge25519, bytes]] = None): /// def __init__(self, x: Optional[Union[Ge25519, bytes]] = None):
/// """ /// """
/// Constructor /// Constructor
/// """ /// """
@ -218,7 +218,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj,
/// EC scalar on SC25519 /// EC scalar on SC25519
/// """ /// """
/// ///
/// def __init__(x: Optional[Union[Sc25519, bytes, int]] = None): /// def __init__(self, x: Optional[Union[Sc25519, bytes, int]] = None):
/// """ /// """
/// Constructor /// Constructor
/// """ /// """
@ -261,22 +261,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
/// XMR hasher /// XMR hasher
/// """ /// """
/// ///
/// def __init__(x: Optional[bytes] = None): /// def __init__(self, x: Optional[bytes] = None):
/// """ /// """
/// Constructor /// Constructor
/// """ /// """
/// ///
/// def update(buffer: bytes): /// def update(self, buffer: bytes) -> None:
/// """ /// """
/// Update hasher /// Update hasher
/// """ /// """
/// ///
/// def digest() -> bytes: /// def digest(self) -> bytes:
/// """ /// """
/// Computes digest /// Computes digest
/// """ /// """
/// ///
/// def copy() -> Hasher: /// def copy(self) -> Hasher:
/// """ /// """
/// Creates copy of the hasher, preserving the state /// Creates copy of the hasher, preserving the state
/// """ /// """
@ -343,7 +343,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_init256_modm_obj, 0, 2, mod_trezorcrypto_monero_init256_modm_obj, 0, 2,
mod_trezorcrypto_monero_init256_modm); mod_trezorcrypto_monero_init256_modm);
/// def check256_modm(val: Sc25519): /// def check256_modm(val: Sc25519) -> None:
/// """ /// """
/// Throws exception if scalar is invalid /// Throws exception if scalar is invalid
/// """ /// """
@ -640,7 +640,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mod_trezorcrypto_monero_ge25519_set_xmr_h_obj, 0, 1, mod_trezorcrypto_monero_ge25519_set_xmr_h_obj, 0, 1,
mod_trezorcrypto_monero_ge25519_set_xmr_h); mod_trezorcrypto_monero_ge25519_set_xmr_h);
/// def ge25519_check(r: Ge25519): /// def ge25519_check(r: Ge25519) -> None:
/// """ /// """
/// Checks point, throws if not on curve /// Checks point, throws if not on curve
/// """ /// """

View File

@ -27,10 +27,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Pbkdf2: /// class pbkdf2:
/// """ /// """
/// PBKDF2 context. /// PBKDF2 context.
/// """ /// """
/// HMAC_SHA256: int
/// HMAC_SHA512: int
typedef struct _mp_obj_Pbkdf2_t { typedef struct _mp_obj_Pbkdf2_t {
mp_obj_base_t base; mp_obj_base_t base;
union { union {

View File

@ -39,7 +39,8 @@ STATIC mp_obj_t mod_trezorcrypto_random_uniform(mp_obj_t n) {
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); mod_trezorcrypto_random_uniform);
/// def bytes(len: int) -> bytes: /// import builtins
/// def bytes(len: int) -> builtins.bytes:
/// """ /// """
/// Generate random bytes sequence of length len. /// Generate random bytes sequence of length len.
/// """ /// """

View File

@ -23,7 +23,7 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Rfc6979: /// class rfc6979:
/// """ /// """
/// RFC6979 context. /// RFC6979 context.
/// """ /// """

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Ripemd160: /// class ripemd160:
/// """ /// """
/// RIPEMD160 context. /// RIPEMD160 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Ripemd160_t { typedef struct _mp_obj_Ripemd160_t {
mp_obj_base_t base; mp_obj_base_t base;
RIPEMD160_CTX ctx; RIPEMD160_CTX ctx;

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha1: /// class sha1:
/// """ /// """
/// SHA1 context. /// SHA1 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Sha1_t { typedef struct _mp_obj_Sha1_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA1_CTX ctx; SHA1_CTX ctx;

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha256: /// class sha256:
/// """ /// """
/// SHA256 context. /// SHA256 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Sha256_t { typedef struct _mp_obj_Sha256_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA256_CTX ctx; SHA256_CTX ctx;

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha3_256: /// class sha3_256:
/// """ /// """
/// SHA3_256 context. /// SHA3_256 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Sha3_256_t { typedef struct _mp_obj_Sha3_256_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA3_CTX ctx; SHA3_CTX ctx;
@ -102,7 +104,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_digest(mp_obj_t self) {
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); mod_trezorcrypto_Sha3_256_digest);
/// def copy(self) -> sha3: /// def copy(self) -> sha3_256:
/// """ /// """
/// Returns the copy of the digest object with the current state /// Returns the copy of the digest object with the current state
/// """ /// """

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha3_512: /// class sha3_512:
/// """ /// """
/// SHA3_512 context. /// SHA3_512 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Sha3_512_t { typedef struct _mp_obj_Sha3_512_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA3_CTX ctx; SHA3_CTX ctx;
@ -102,7 +104,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_digest(mp_obj_t self) {
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); mod_trezorcrypto_Sha3_512_digest);
/// def copy(self) -> sha3: /// def copy(self) -> sha3_512:
/// """ /// """
/// Returns the copy of the digest object with the current state /// Returns the copy of the digest object with the current state
/// """ /// """

View File

@ -24,10 +24,12 @@
/// package: trezorcrypto.__init__ /// package: trezorcrypto.__init__
/// class Sha512: /// class sha512:
/// """ /// """
/// SHA512 context. /// SHA512 context.
/// """ /// """
/// block_size: int
/// digest_size: int
typedef struct _mp_obj_Sha512_t { typedef struct _mp_obj_Sha512_t {
mp_obj_base_t base; mp_obj_base_t base;
SHA512_CTX ctx; SHA512_CTX ctx;

View File

@ -27,7 +27,7 @@
/// package: trezorcrypto.shamir /// package: trezorcrypto.shamir
/// def interpolate(shares, x) -> bytes: /// def interpolate(shares: List[Tuple[int, bytes]], x: int) -> bytes:
/// """ /// """
/// Returns f(x) given the Shamir shares (x_1, f(x_1)), ... , (x_k, f(x_k)). /// Returns f(x) given the Shamir shares (x_1, f(x_1)), ... , (x_k, f(x_k)).
/// :param shares: The Shamir shares. /// :param shares: The Shamir shares.

View File

@ -44,6 +44,16 @@
#include "modtrezorio-usb.h" #include "modtrezorio-usb.h"
// clang-format on // clang-format on
/// POLL_READ: int # wait until interface is readable and return read data
/// POLL_WRITE: int # wait until interface is writable
///
/// TOUCH: int # interface id of the touch events
/// TOUCH_START: int # event id of touch start event
/// TOUCH_MOVE: int # event id of touch move event
/// TOUCH_END: int # event id of touch end event
/// WireInterface = Union[HID, WebUSB]
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)}, {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)},

View File

@ -25,6 +25,15 @@
/// """ /// """
/// Provide access to device display. /// Provide access to device display.
/// """ /// """
///
/// WIDTH: int # display width in pixels
/// HEIGHT: int # display height in pixels
/// FONT_SIZE: int # font height in pixels
/// FONT_MONO: int # id of monospace font
/// FONT_NORMAL: int # id of normal-width font
/// FONT_BOLD: int # id of bold-width font
/// FONT_MONO_BOLD: int # id of monospace bold-width font
///
typedef struct _mp_obj_Display_t { typedef struct _mp_obj_Display_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_Display_t; } mp_obj_Display_t;

View File

@ -58,7 +58,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj,
mod_trezorutils_consteq); mod_trezorutils_consteq);
/// def memcpy( /// def memcpy(
/// dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int /// dst: bytearray, dst_ofs: int, src: bytes, src_ofs: int, n: int
/// ) -> int: /// ) -> int:
/// """ /// """
/// Copies at most `n` bytes from `src` at offset `src_ofs` to /// Copies at most `n` bytes from `src` at offset `src_ofs` to
@ -122,6 +122,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_set_mode_unprivileged_obj,
#define PASTER(s) MP_QSTR_##s #define PASTER(s) MP_QSTR_##s
#define MP_QSTR(s) PASTER(s) #define MP_QSTR(s) PASTER(s)
/// GITREV: str
/// VERSION_MAJOR: int
/// VERSION_MINOR: int
/// VERSION_PATCH: int
/// MODEL: str
/// EMULATOR: bool
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___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_consteq), MP_ROM_PTR(&mod_trezorutils_consteq_obj)},

View File

@ -2,7 +2,9 @@ from typing import *
# extmod/modtrezorconfig/modtrezorconfig.c # extmod/modtrezorconfig/modtrezorconfig.c
def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None: def init(
ui_wait_callback: Callable[[int, int, str], bool] = None
) -> None:
""" """
Initializes the storage. Must be called before any other method is Initializes the storage. Must be called before any other method is
called from this module! called from this module!

View File

@ -2,7 +2,7 @@ from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h # extmod/modtrezorcrypto/modtrezorcrypto-aes.h
class AES: class aes:
""" """
AES context. AES context.
""" """
@ -24,10 +24,12 @@ class AES:
# extmod/modtrezorcrypto/modtrezorcrypto-blake256.h # extmod/modtrezorcrypto/modtrezorcrypto-blake256.h
class Blake256: class blake256:
""" """
Blake256 context. Blake256 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """
@ -46,15 +48,17 @@ class Blake256:
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h # extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
class Blake2b: class blake2b:
""" """
Blake2b context. Blake2b context.
""" """
block_size: int
digest_size: int
def __init__( def __init__(
self, self,
data: bytes = None, data: bytes = None,
outlen: int = Blake2b.digest_size, outlen: int = blake2b.digest_size,
personal: bytes = None, personal: bytes = None,
) -> None: ) -> None:
""" """
@ -73,15 +77,17 @@ class Blake2b:
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h # extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
class Blake2s: class blake2s:
""" """
Blake2s context. Blake2s context.
""" """
block_size: int
digest_size: int
def __init__( def __init__(
self, self,
data: bytes = None, data: bytes = None,
outlen: int = Blake2s.digest_size, outlen: int = blake2s.digest_size,
key: bytes = None, key: bytes = None,
personal: bytes = None, personal: bytes = None,
) -> None: ) -> None:
@ -101,7 +107,7 @@ class Blake2s:
# extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h # extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h
class ChaCha20Poly1305: class chacha20poly1305:
""" """
ChaCha20Poly1305 context. ChaCha20Poly1305 context.
""" """
@ -138,10 +144,12 @@ class ChaCha20Poly1305:
# extmod/modtrezorcrypto/modtrezorcrypto-groestl.h # extmod/modtrezorcrypto/modtrezorcrypto-groestl.h
class Groestl512: class groestl512:
""" """
GROESTL512 context. GROESTL512 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """
@ -160,10 +168,12 @@ class Groestl512:
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h # extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
class Pbkdf2: class pbkdf2:
""" """
PBKDF2 context. PBKDF2 context.
""" """
HMAC_SHA256: int
HMAC_SHA512: int
def __init__( def __init__(
self, self,
@ -189,7 +199,7 @@ class Pbkdf2:
# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h # extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h
class Rfc6979: class rfc6979:
""" """
RFC6979 context. RFC6979 context.
""" """
@ -206,10 +216,12 @@ class Rfc6979:
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h # extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
class Ripemd160: class ripemd160:
""" """
RIPEMD160 context. RIPEMD160 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """
@ -228,10 +240,12 @@ class Ripemd160:
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h # extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
class Sha1: class sha1:
""" """
SHA1 context. SHA1 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """
@ -250,10 +264,12 @@ class Sha1:
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h # extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
class Sha256: class sha256:
""" """
SHA256 context. SHA256 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """
@ -272,10 +288,12 @@ class Sha256:
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h # extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
class Sha3_256: class sha3_256:
""" """
SHA3_256 context. SHA3_256 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None, keccak: bool = False) -> None: def __init__(self, data: bytes = None, keccak: bool = False) -> None:
""" """
@ -292,17 +310,19 @@ class Sha3_256:
Returns the digest of hashed data. Returns the digest of hashed data.
""" """
def copy(self) -> sha3: def copy(self) -> sha3_256:
""" """
Returns the copy of the digest object with the current state Returns the copy of the digest object with the current state
""" """
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h # extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
class Sha3_512: class sha3_512:
""" """
SHA3_512 context. SHA3_512 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None, keccak: bool = False) -> None: def __init__(self, data: bytes = None, keccak: bool = False) -> None:
""" """
@ -319,17 +339,19 @@ class Sha3_512:
Returns the digest of hashed data. Returns the digest of hashed data.
""" """
def copy(self) -> sha3: def copy(self) -> sha3_512:
""" """
Returns the copy of the digest object with the current state Returns the copy of the digest object with the current state
""" """
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h # extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
class Sha512: class sha512:
""" """
SHA512 context. SHA512 context.
""" """
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None: def __init__(self, data: bytes = None) -> None:
""" """

View File

@ -108,19 +108,30 @@ class HDNode:
Compute an Ethereum pubkeyhash (aka address) from the HD node. Compute an Ethereum pubkeyhash (aka address) from the HD node.
""" """
def deserialize( def __del__(self) -> None:
self, value: str, version_public: int, version_private: int
) -> HDNode:
""" """
Construct a BIP0032 HD node from a base58-serialized value. Cleans up sensitive memory.
""" """
def from_seed(seed: bytes, curve_name: str) -> HDNode:
"""
Construct a BIP0032 HD node from a BIP0039 seed value.
"""
def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes: # extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
""" def deserialize(
Convert mnemonic to hdnode value: str, version_public: int, version_private: int
""" ) -> HDNode:
"""
Construct a BIP0032 HD node from a base58-serialized value.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
def from_seed(seed: bytes, curve_name: str) -> HDNode:
"""
Construct a BIP0032 HD node from a BIP0039 seed value.
"""
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
"""
Convert mnemonic to hdnode
"""

View File

@ -0,0 +1,8 @@
from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-crc.h
def crc32(data: bytes, crc: int = 0) -> int:
"""
Computes a CRC32 checksum of `data`.
"""

View File

@ -6,7 +6,7 @@ class Ge25519:
""" """
EC point on ED25519 EC point on ED25519
""" """
def __init__(x: Optional[Union[Ge25519, bytes]] = None): def __init__(self, x: Optional[Union[Ge25519, bytes]] = None):
""" """
Constructor Constructor
""" """
@ -17,7 +17,7 @@ class Sc25519:
""" """
EC scalar on SC25519 EC scalar on SC25519
""" """
def __init__(x: Optional[Union[Sc25519, bytes, int]] = None): def __init__(self, x: Optional[Union[Sc25519, bytes, int]] = None):
""" """
Constructor Constructor
""" """
@ -28,19 +28,19 @@ class Hasher:
""" """
XMR hasher XMR hasher
""" """
def __init__(x: Optional[bytes] = None): def __init__(self, x: Optional[bytes] = None):
""" """
Constructor Constructor
""" """
def update(buffer: bytes): def update(self, buffer: bytes) -> None:
""" """
Update hasher Update hasher
""" """
def digest() -> bytes: def digest(self) -> bytes:
""" """
Computes digest Computes digest
""" """
def copy() -> Hasher: def copy(self) -> Hasher:
""" """
Creates copy of the hasher, preserving the state Creates copy of the hasher, preserving the state
""" """
@ -56,7 +56,7 @@ def init256_modm(
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def check256_modm(val: Sc25519): def check256_modm(val: Sc25519) -> None:
""" """
Throws exception if scalar is invalid Throws exception if scalar is invalid
""" """
@ -172,7 +172,7 @@ def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h # extmod/modtrezorcrypto/modtrezorcrypto-monero.h
def ge25519_check(r: Ge25519): def ge25519_check(r: Ge25519) -> None:
""" """
Checks point, throws if not on curve Checks point, throws if not on curve
""" """

View File

@ -6,10 +6,11 @@ def uniform(n: int) -> int:
""" """
Compute uniform random number from interval 0 ... n - 1. Compute uniform random number from interval 0 ... n - 1.
""" """
import builtins
# extmod/modtrezorcrypto/modtrezorcrypto-random.h # extmod/modtrezorcrypto/modtrezorcrypto-random.h
def bytes(len: int) -> bytes: def bytes(len: int) -> builtins.bytes:
""" """
Generate random bytes sequence of length len. Generate random bytes sequence of length len.
""" """

View File

@ -2,7 +2,7 @@ from typing import *
# extmod/modtrezorcrypto/modtrezorcrypto-shamir.h # extmod/modtrezorcrypto/modtrezorcrypto-shamir.h
def interpolate(shares, x) -> bytes: def interpolate(shares: List[Tuple[int, bytes]], x: int) -> bytes:
""" """
Returns f(x) given the Shamir shares (x_1, f(x_1)), ... , (x_k, f(x_k)). Returns f(x) given the Shamir shares (x_1, f(x_1)), ... , (x_k, f(x_k)).
:param shares: The Shamir shares. :param shares: The Shamir shares.

View File

@ -221,3 +221,10 @@ class WebUSB:
""" """
Sends message using USB WebUSB (device) or UDP (emulator). Sends message using USB WebUSB (device) or UDP (emulator).
""" """
POLL_READ: int # wait until interface is readable and return read data
POLL_WRITE: int # wait until interface is writable
TOUCH: int # interface id of the touch events
TOUCH_START: int # event id of touch start event
TOUCH_MOVE: int # event id of touch move event
TOUCH_END: int # event id of touch end event
WireInterface = Union[HID, WebUSB]

View File

@ -6,6 +6,13 @@ class Display:
""" """
Provide access to device display. Provide access to device display.
""" """
WIDTH: int # display width in pixels
HEIGHT: int # display height in pixels
FONT_SIZE: int # font height in pixels
FONT_MONO: int # id of monospace font
FONT_NORMAL: int # id of normal-width font
FONT_BOLD: int # id of bold-width font
FONT_MONO_BOLD: int # id of monospace bold-width font
def __init__(self) -> None: def __init__(self) -> None:
""" """

View File

@ -13,7 +13,7 @@ def consteq(sec: bytes, pub: bytes) -> bool:
# extmod/modtrezorutils/modtrezorutils.c # extmod/modtrezorutils/modtrezorutils.c
def memcpy( def memcpy(
dst: bytearray, dst_ofs: int, src: bytearray, src_ofs: int, n: int dst: bytearray, dst_ofs: int, src: bytes, src_ofs: int, n: int
) -> int: ) -> int:
""" """
Copies at most `n` bytes from `src` at offset `src_ofs` to Copies at most `n` bytes from `src` at offset `src_ofs` to
@ -34,3 +34,9 @@ def set_mode_unprivileged() -> None:
""" """
Set unprivileged mode. Set unprivileged mode.
""" """
GITREV: str
VERSION_MAJOR: int
VERSION_MINOR: int
VERSION_PATCH: int
MODEL: str
EMULATOR: bool

View File

@ -1,5 +1,7 @@
def const(c): def const(c: int) -> int:
return c return c
def mem_info() -> None: ...
def mem_current() -> int: ... def mem_current() -> int: ...
def mem_total() -> int: ... def mem_total() -> int: ...
def mem_peak() -> int: ... def mem_peak() -> int: ...

View File

@ -1,69 +0,0 @@
__names_get = [
'AbstractSet',
'AsyncIterable',
'AsyncIterator',
'Awaitable',
'ByteString',
'Callable',
'Container',
'DefaultDict',
'Dict',
'Generator',
'Generic',
'ItemsView',
'Iterable',
'Iterator',
'KeysView',
'List',
'Mapping',
'MappingView',
'MutableMapping',
'MutableSequence',
'MutableSet',
'Optional',
'Reversible',
'Sequence',
'Set',
'Tuple',
'Type',
'Union',
'ValuesView',
]
__names_obj = [
'Any',
'AnyStr',
'Hashable',
'Sized',
'SupportsAbs',
'SupportsFloat',
'SupportsInt',
'SupportsRound',
'Text',
]
class __dummy:
def __getitem__(self, *args):
return object
__t = __dummy()
for __n in __names_get:
globals()[__n] = __t
for __n in __names_obj:
globals()[__n] = object
def TypeVar(*args):
return object
def NewType(*args):
return lambda x: x
TYPE_CHECKING = False

1
core/mocks/uos.pyi Normal file
View File

@ -0,0 +1 @@
def getenv(env: str) -> str: ...

View File

@ -60,7 +60,7 @@ def store_to_file(dest, parts):
for package, line in parts: for package, line in parts:
package = package.replace(".", "/") package = package.replace(".", "/")
dirpath = os.path.join(dest, os.path.dirname(package)) dirpath = os.path.join(dest, os.path.dirname(package))
filename = os.path.basename(package) + ".py" filename = os.path.basename(package) + ".pyi"
filepath = os.path.join(dirpath, filename) filepath = os.path.join(dirpath, filename)
os.makedirs(dirpath, exist_ok=True) os.makedirs(dirpath, exist_ok=True)
@ -72,7 +72,6 @@ def store_to_file(dest, parts):
print("You should set 'package:' in {}".format(line.strip())) print("You should set 'package:' in {}".format(line.strip()))
sys.exit(1) sys.exit(1)
if not os.path.exists(filepath): if not os.path.exists(filepath):
with open(filepath, "a") as f: with open(filepath, "a") as f:
f.write("from typing import *\n") f.write("from typing import *\n")