mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
core/typing: improve extmod types
This commit is contained in:
parent
f5299456a9
commit
3af75c0b8b
@ -47,7 +47,9 @@ STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
|
||||
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
|
||||
/// called from this module!
|
||||
|
@ -32,7 +32,7 @@ enum AESMode {
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class AES:
|
||||
/// class aes:
|
||||
/// """
|
||||
/// AES context.
|
||||
/// """
|
||||
|
@ -489,6 +489,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
|
||||
mod_trezorcrypto_HDNode_ethereum_pubkeyhash_obj,
|
||||
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) {
|
||||
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
|
||||
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,
|
||||
};
|
||||
|
||||
/// mock:global
|
||||
|
||||
/// def deserialize(
|
||||
/// self, value: str, version_public: int, version_private: int
|
||||
/// value: str, version_public: int, version_private: int
|
||||
/// ) -> HDNode:
|
||||
/// """
|
||||
/// Construct a BIP0032 HD node from a base58-serialized value.
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake256:
|
||||
/// class blake256:
|
||||
/// """
|
||||
/// Blake256 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Blake256_t {
|
||||
mp_obj_base_t base;
|
||||
BLAKE256_CTX ctx;
|
||||
|
@ -26,10 +26,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake2b:
|
||||
/// class blake2b:
|
||||
/// """
|
||||
/// Blake2b context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Blake2b_t {
|
||||
mp_obj_base_t base;
|
||||
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__(
|
||||
/// self,
|
||||
/// data: bytes = None,
|
||||
/// outlen: int = Blake2b.digest_size,
|
||||
/// outlen: int = blake2b.digest_size,
|
||||
/// personal: bytes = None,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
|
@ -26,10 +26,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Blake2s:
|
||||
/// class blake2s:
|
||||
/// """
|
||||
/// Blake2s context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Blake2s_t {
|
||||
mp_obj_base_t base;
|
||||
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__(
|
||||
/// self,
|
||||
/// data: bytes = None,
|
||||
/// outlen: int = Blake2s.digest_size,
|
||||
/// outlen: int = blake2s.digest_size,
|
||||
/// key: bytes = None,
|
||||
/// personal: bytes = None,
|
||||
/// ) -> None:
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class ChaCha20Poly1305:
|
||||
/// class chacha20poly1305:
|
||||
/// """
|
||||
/// ChaCha20Poly1305 context.
|
||||
/// """
|
||||
|
@ -23,6 +23,12 @@
|
||||
|
||||
#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_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
|
||||
|
@ -27,10 +27,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Groestl512:
|
||||
/// class groestl512:
|
||||
/// """
|
||||
/// GROESTL512 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Groestl512_t {
|
||||
mp_obj_base_t base;
|
||||
GROESTL512_CTX ctx;
|
||||
|
@ -180,7 +180,7 @@ STATIC void mp_unpack_scalar(bignum256modm r, const mp_obj_t arg,
|
||||
/// EC point on ED25519
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[Union[Ge25519, bytes]] = None):
|
||||
/// def __init__(self, x: Optional[Union[Ge25519, bytes]] = None):
|
||||
/// """
|
||||
/// Constructor
|
||||
/// """
|
||||
@ -218,7 +218,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_ge25519___del___obj,
|
||||
/// EC scalar on SC25519
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
|
||||
/// def __init__(self, x: Optional[Union[Sc25519, bytes, int]] = None):
|
||||
/// """
|
||||
/// Constructor
|
||||
/// """
|
||||
@ -261,22 +261,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
|
||||
/// XMR hasher
|
||||
/// """
|
||||
///
|
||||
/// def __init__(x: Optional[bytes] = None):
|
||||
/// def __init__(self, x: Optional[bytes] = None):
|
||||
/// """
|
||||
/// Constructor
|
||||
/// """
|
||||
///
|
||||
/// def update(buffer: bytes):
|
||||
/// def update(self, buffer: bytes) -> None:
|
||||
/// """
|
||||
/// Update hasher
|
||||
/// """
|
||||
///
|
||||
/// def digest() -> bytes:
|
||||
/// def digest(self) -> bytes:
|
||||
/// """
|
||||
/// Computes digest
|
||||
/// """
|
||||
///
|
||||
/// def copy() -> Hasher:
|
||||
/// def copy(self) -> Hasher:
|
||||
/// """
|
||||
/// 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);
|
||||
|
||||
/// def check256_modm(val: Sc25519):
|
||||
/// def check256_modm(val: Sc25519) -> None:
|
||||
/// """
|
||||
/// 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);
|
||||
|
||||
/// def ge25519_check(r: Ge25519):
|
||||
/// def ge25519_check(r: Ge25519) -> None:
|
||||
/// """
|
||||
/// Checks point, throws if not on curve
|
||||
/// """
|
||||
|
@ -27,10 +27,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Pbkdf2:
|
||||
/// class pbkdf2:
|
||||
/// """
|
||||
/// PBKDF2 context.
|
||||
/// """
|
||||
/// HMAC_SHA256: int
|
||||
/// HMAC_SHA512: int
|
||||
typedef struct _mp_obj_Pbkdf2_t {
|
||||
mp_obj_base_t base;
|
||||
union {
|
||||
|
@ -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,
|
||||
mod_trezorcrypto_random_uniform);
|
||||
|
||||
/// def bytes(len: int) -> bytes:
|
||||
/// import builtins
|
||||
/// def bytes(len: int) -> builtins.bytes:
|
||||
/// """
|
||||
/// Generate random bytes sequence of length len.
|
||||
/// """
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Rfc6979:
|
||||
/// class rfc6979:
|
||||
/// """
|
||||
/// RFC6979 context.
|
||||
/// """
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Ripemd160:
|
||||
/// class ripemd160:
|
||||
/// """
|
||||
/// RIPEMD160 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Ripemd160_t {
|
||||
mp_obj_base_t base;
|
||||
RIPEMD160_CTX ctx;
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha1:
|
||||
/// class sha1:
|
||||
/// """
|
||||
/// SHA1 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Sha1_t {
|
||||
mp_obj_base_t base;
|
||||
SHA1_CTX ctx;
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha256:
|
||||
/// class sha256:
|
||||
/// """
|
||||
/// SHA256 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Sha256_t {
|
||||
mp_obj_base_t base;
|
||||
SHA256_CTX ctx;
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha3_256:
|
||||
/// class sha3_256:
|
||||
/// """
|
||||
/// SHA3_256 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Sha3_256_t {
|
||||
mp_obj_base_t base;
|
||||
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,
|
||||
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
|
||||
/// """
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha3_512:
|
||||
/// class sha3_512:
|
||||
/// """
|
||||
/// SHA3_512 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Sha3_512_t {
|
||||
mp_obj_base_t base;
|
||||
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,
|
||||
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
|
||||
/// """
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
/// package: trezorcrypto.__init__
|
||||
|
||||
/// class Sha512:
|
||||
/// class sha512:
|
||||
/// """
|
||||
/// SHA512 context.
|
||||
/// """
|
||||
/// block_size: int
|
||||
/// digest_size: int
|
||||
typedef struct _mp_obj_Sha512_t {
|
||||
mp_obj_base_t base;
|
||||
SHA512_CTX ctx;
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
/// 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)).
|
||||
/// :param shares: The Shamir shares.
|
||||
|
@ -44,6 +44,16 @@
|
||||
#include "modtrezorio-usb.h"
|
||||
// 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[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)},
|
||||
|
||||
|
@ -25,6 +25,15 @@
|
||||
/// """
|
||||
/// 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 {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_Display_t;
|
||||
|
@ -58,7 +58,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj,
|
||||
mod_trezorutils_consteq);
|
||||
|
||||
/// 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:
|
||||
/// """
|
||||
/// 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 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[] = {
|
||||
{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)},
|
||||
|
@ -2,7 +2,9 @@ from typing import *
|
||||
|
||||
|
||||
# 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
|
||||
called from this module!
|
@ -2,7 +2,7 @@ from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||
class AES:
|
||||
class aes:
|
||||
"""
|
||||
AES context.
|
||||
"""
|
||||
@ -24,10 +24,12 @@ class AES:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake256.h
|
||||
class Blake256:
|
||||
class blake256:
|
||||
"""
|
||||
Blake256 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
||||
@ -46,15 +48,17 @@ class Blake256:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
|
||||
class Blake2b:
|
||||
class blake2b:
|
||||
"""
|
||||
Blake2b context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: bytes = None,
|
||||
outlen: int = Blake2b.digest_size,
|
||||
outlen: int = blake2b.digest_size,
|
||||
personal: bytes = None,
|
||||
) -> None:
|
||||
"""
|
||||
@ -73,15 +77,17 @@ class Blake2b:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
class Blake2s:
|
||||
class blake2s:
|
||||
"""
|
||||
Blake2s context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: bytes = None,
|
||||
outlen: int = Blake2s.digest_size,
|
||||
outlen: int = blake2s.digest_size,
|
||||
key: bytes = None,
|
||||
personal: bytes = None,
|
||||
) -> None:
|
||||
@ -101,7 +107,7 @@ class Blake2s:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-chacha20poly1305.h
|
||||
class ChaCha20Poly1305:
|
||||
class chacha20poly1305:
|
||||
"""
|
||||
ChaCha20Poly1305 context.
|
||||
"""
|
||||
@ -138,10 +144,12 @@ class ChaCha20Poly1305:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-groestl.h
|
||||
class Groestl512:
|
||||
class groestl512:
|
||||
"""
|
||||
GROESTL512 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
||||
@ -160,10 +168,12 @@ class Groestl512:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
class Pbkdf2:
|
||||
class pbkdf2:
|
||||
"""
|
||||
PBKDF2 context.
|
||||
"""
|
||||
HMAC_SHA256: int
|
||||
HMAC_SHA512: int
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -189,7 +199,7 @@ class Pbkdf2:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h
|
||||
class Rfc6979:
|
||||
class rfc6979:
|
||||
"""
|
||||
RFC6979 context.
|
||||
"""
|
||||
@ -206,10 +216,12 @@ class Rfc6979:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
class Ripemd160:
|
||||
class ripemd160:
|
||||
"""
|
||||
RIPEMD160 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
||||
@ -228,10 +240,12 @@ class Ripemd160:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
class Sha1:
|
||||
class sha1:
|
||||
"""
|
||||
SHA1 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
||||
@ -250,10 +264,12 @@ class Sha1:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
class Sha256:
|
||||
class sha256:
|
||||
"""
|
||||
SHA256 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
||||
@ -272,10 +288,12 @@ class Sha256:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
class Sha3_256:
|
||||
class sha3_256:
|
||||
"""
|
||||
SHA3_256 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None, keccak: bool = False) -> None:
|
||||
"""
|
||||
@ -292,17 +310,19 @@ class Sha3_256:
|
||||
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
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
class Sha3_512:
|
||||
class sha3_512:
|
||||
"""
|
||||
SHA3_512 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None, keccak: bool = False) -> None:
|
||||
"""
|
||||
@ -319,17 +339,19 @@ class Sha3_512:
|
||||
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
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
class Sha512:
|
||||
class sha512:
|
||||
"""
|
||||
SHA512 context.
|
||||
"""
|
||||
block_size: int
|
||||
digest_size: int
|
||||
|
||||
def __init__(self, data: bytes = None) -> None:
|
||||
"""
|
@ -108,19 +108,30 @@ class HDNode:
|
||||
Compute an Ethereum pubkeyhash (aka address) from the HD node.
|
||||
"""
|
||||
|
||||
def deserialize(
|
||||
self, value: str, version_public: int, version_private: int
|
||||
) -> HDNode:
|
||||
def __del__(self) -> None:
|
||||
"""
|
||||
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:
|
||||
"""
|
||||
Convert mnemonic to hdnode
|
||||
"""
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def deserialize(
|
||||
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
|
||||
"""
|
8
core/mocks/generated/trezorcrypto/crc.pyi
Normal file
8
core/mocks/generated/trezorcrypto/crc.pyi
Normal 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`.
|
||||
"""
|
@ -6,7 +6,7 @@ class Ge25519:
|
||||
"""
|
||||
EC point on ED25519
|
||||
"""
|
||||
def __init__(x: Optional[Union[Ge25519, bytes]] = None):
|
||||
def __init__(self, x: Optional[Union[Ge25519, bytes]] = None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
@ -17,7 +17,7 @@ class 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
|
||||
"""
|
||||
@ -28,19 +28,19 @@ class Hasher:
|
||||
"""
|
||||
XMR hasher
|
||||
"""
|
||||
def __init__(x: Optional[bytes] = None):
|
||||
def __init__(self, x: Optional[bytes] = None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
def update(buffer: bytes):
|
||||
def update(self, buffer: bytes) -> None:
|
||||
"""
|
||||
Update hasher
|
||||
"""
|
||||
def digest() -> bytes:
|
||||
def digest(self) -> bytes:
|
||||
"""
|
||||
Computes digest
|
||||
"""
|
||||
def copy() -> Hasher:
|
||||
def copy(self) -> Hasher:
|
||||
"""
|
||||
Creates copy of the hasher, preserving the state
|
||||
"""
|
||||
@ -56,7 +56,7 @@ def init256_modm(
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def check256_modm(val: Sc25519):
|
||||
def check256_modm(val: Sc25519) -> None:
|
||||
"""
|
||||
Throws exception if scalar is invalid
|
||||
"""
|
||||
@ -172,7 +172,7 @@ def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_check(r: Ge25519):
|
||||
def ge25519_check(r: Ge25519) -> None:
|
||||
"""
|
||||
Checks point, throws if not on curve
|
||||
"""
|
@ -6,10 +6,11 @@ def uniform(n: int) -> int:
|
||||
"""
|
||||
Compute uniform random number from interval 0 ... n - 1.
|
||||
"""
|
||||
import builtins
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def bytes(len: int) -> bytes:
|
||||
def bytes(len: int) -> builtins.bytes:
|
||||
"""
|
||||
Generate random bytes sequence of length len.
|
||||
"""
|
@ -2,7 +2,7 @@ from typing import *
|
||||
|
||||
|
||||
# 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)).
|
||||
:param shares: The Shamir shares.
|
@ -221,3 +221,10 @@ class WebUSB:
|
||||
"""
|
||||
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]
|
@ -6,6 +6,13 @@ class 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:
|
||||
"""
|
@ -13,7 +13,7 @@ def consteq(sec: bytes, pub: bytes) -> bool:
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
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:
|
||||
"""
|
||||
Copies at most `n` bytes from `src` at offset `src_ofs` to
|
||||
@ -34,3 +34,9 @@ def set_mode_unprivileged() -> None:
|
||||
"""
|
||||
Set unprivileged mode.
|
||||
"""
|
||||
GITREV: str
|
||||
VERSION_MAJOR: int
|
||||
VERSION_MINOR: int
|
||||
VERSION_PATCH: int
|
||||
MODEL: str
|
||||
EMULATOR: bool
|
@ -1,5 +1,7 @@
|
||||
def const(c):
|
||||
def const(c: int) -> int:
|
||||
return c
|
||||
|
||||
def mem_info() -> None: ...
|
||||
def mem_current() -> int: ...
|
||||
def mem_total() -> int: ...
|
||||
def mem_peak() -> int: ...
|
@ -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
1
core/mocks/uos.pyi
Normal file
@ -0,0 +1 @@
|
||||
def getenv(env: str) -> str: ...
|
@ -60,7 +60,7 @@ def store_to_file(dest, parts):
|
||||
for package, line in parts:
|
||||
package = package.replace(".", "/")
|
||||
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)
|
||||
|
||||
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()))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if not os.path.exists(filepath):
|
||||
with open(filepath, "a") as f:
|
||||
f.write("from typing import *\n")
|
||||
|
Loading…
Reference in New Issue
Block a user