From 5a5c4f11b9567267d6e98fa97f4e324a831abc42 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 14 Jun 2017 17:40:50 +0200 Subject: [PATCH] extmod: doc comments describe internal apis --- .../extmod/modtrezorconfig/modtrezorconfig.c | 16 +++-- .../modtrezorcrypto/modtrezorcrypto-aes.h | 12 +++- .../modtrezorcrypto/modtrezorcrypto-bip32.h | 38 ++++++---- .../modtrezorcrypto/modtrezorcrypto-bip39.h | 30 ++++---- .../modtrezorcrypto/modtrezorcrypto-blake2b.h | 10 ++- .../modtrezorcrypto/modtrezorcrypto-blake2s.h | 10 ++- .../modtrezorcrypto-curve25519.h | 16 +++-- .../modtrezorcrypto/modtrezorcrypto-ed25519.h | 26 ++++--- .../modtrezorcrypto-nist256p1.h | 18 +++-- .../modtrezorcrypto/modtrezorcrypto-pbkdf2.h | 16 +++-- .../modtrezorcrypto/modtrezorcrypto-random.h | 12 +++- .../modtrezorcrypto/modtrezorcrypto-rfc6979.h | 14 +++- .../modtrezorcrypto-ripemd160.h | 10 ++- .../modtrezorcrypto-secp256k1.h | 22 +++--- .../modtrezorcrypto/modtrezorcrypto-sha1.h | 10 ++- .../modtrezorcrypto/modtrezorcrypto-sha256.h | 10 ++- .../modtrezorcrypto-sha3-256.h | 10 ++- .../modtrezorcrypto-sha3-512.h | 10 ++- .../modtrezorcrypto/modtrezorcrypto-sha512.h | 10 ++- .../modtrezorcrypto/modtrezorcrypto-ssss.h | 14 ++-- .../extmod/modtrezormsg/modtrezormsg.c | 71 +++++++++++++------ .../extmod/modtrezorui/modtrezorui-display.h | 48 +++++++------ .../extmod/modtrezorutils/modtrezorutils.c | 10 +-- 23 files changed, 296 insertions(+), 147 deletions(-) diff --git a/micropython/extmod/modtrezorconfig/modtrezorconfig.c b/micropython/extmod/modtrezorconfig/modtrezorconfig.c index db4285a9f..37c4cb995 100644 --- a/micropython/extmod/modtrezorconfig/modtrezorconfig.c +++ b/micropython/extmod/modtrezorconfig/modtrezorconfig.c @@ -15,10 +15,18 @@ #if MICROPY_PY_TREZORCONFIG +/// class Config: +/// ''' +/// Persistent key-value storage, with 16-bit keys and bytes values. +/// ''' typedef struct _mp_obj_Config_t { mp_obj_base_t base; } mp_obj_Config_t; +/// def __init__(self): +/// ''' +/// Initializes the storage. +/// ''' STATIC mp_obj_t mod_TrezorConfig_Config_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); mp_obj_Config_t *o = m_new_obj(mp_obj_Config_t); @@ -30,7 +38,7 @@ STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size return MP_OBJ_FROM_PTR(o); } -/// def trezor.config.get(app: int, key: int) -> bytes: +/// def get(self, app: int, key: int) -> bytes: /// ''' /// Gets a value of given key for given app (or empty bytes if not set). /// ''' @@ -50,7 +58,7 @@ STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_ } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorConfig_Config_get_obj, mod_TrezorConfig_Config_get); -/// def trezor.config.set(app: int, key: int, value: bytes) -> None: +/// def set(self, app: int, key: int, value: bytes) -> None: /// ''' /// Sets a value of given key for given app. /// Returns True on success. @@ -69,9 +77,9 @@ STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorConfig_Config_set_obj, 4, 4, mod_TrezorConfig_Config_set); -/// def trezor.config.wipe() -> None: +/// def wipe(self) -> None: /// ''' -/// Erases the whole config (use with caution!) +/// Erases the whole config. Use with caution! /// ''' STATIC mp_obj_t mod_TrezorConfig_Config_wipe(mp_obj_t self) { bool r = norcow_wipe(); diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-aes.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-aes.h index 1aaee252d..5df260f7a 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-aes.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-aes.h @@ -9,6 +9,10 @@ #include "trezor-crypto/aes/aes.h" +/// class AES: +/// ''' +/// AES context. +/// ''' typedef struct _mp_obj_AES_t { mp_obj_base_t base; union { @@ -33,6 +37,10 @@ enum { #define AESModeMask 0x3F #define AESDirMask 0xC0 +/// def __init__(self, mode: int, key: bytes, iv: bytes = ...) -> None: +/// ''' +/// Initialize AES context. +/// ''' 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); mp_obj_AES_t *o = m_new_obj(mp_obj_AES_t); @@ -83,9 +91,9 @@ STATIC mp_obj_t mod_TrezorCrypto_AES_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.aes.AES.update(self, data: bytes) -> bytes: +/// def update(self, data: bytes) -> bytes: /// ''' -/// Update AES context +/// Update AES context with data. /// ''' STATIC mp_obj_t mod_TrezorCrypto_AES_update(mp_obj_t self, mp_obj_t data) { mp_buffer_info_t buf; diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h index 6953353a2..b74e0f5d0 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h @@ -9,6 +9,10 @@ #include "trezor-crypto/bip32.h" +/// class HDNode: +/// ''' +/// BIP0032 HD node structure. +/// ''' typedef struct _mp_obj_HDNode_t { mp_obj_base_t base; uint32_t fingerprint; @@ -20,7 +24,7 @@ STATIC const mp_obj_type_t mod_TrezorCrypto_HDNode_type; #define XPUB_MAXLEN 128 #define ADDRESS_MAXLEN 36 -/// def trezor.crypto.HDNode.derive(index: int) -> None: +/// def derive(self, index: int) -> None: /// ''' /// Derive a BIP0032 child node in place. /// ''' @@ -39,7 +43,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_derive_obj, mod_TrezorCrypto_HDNode_derive); -/// def trezor.crypto.HDNode.derive_path(path: list) -> None: +/// def derive_path(self, path: List[int]) -> None: /// ''' /// Go through a list of indexes and iteratively derive a child node in place. /// ''' @@ -96,7 +100,7 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_ return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } -/// def trezor.crypto.HDNode.serialize_public(version: int) -> str: +/// def serialize_public(self, version: int) -> str: /// ''' /// Serialize the public info from HD node to base58 string. /// ''' @@ -106,7 +110,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_public(mp_obj_t self, mp_obj_t } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_public_obj, mod_TrezorCrypto_HDNode_serialize_public); -/// def trezor.crypto.HDNode.serialize_private(version: int) -> str: +/// def serialize_private(self, version: int) -> str: /// ''' /// Serialize the private info HD node to base58 string. /// ''' @@ -116,7 +120,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_private(mp_obj_t self, mp_obj_ } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_private_obj, mod_TrezorCrypto_HDNode_serialize_private); -/// def trezor.crypto.HDNode.clone() -> HDNode: +/// def clone(self) -> HDNode: /// ''' /// Returns a copy of the HD node. /// ''' @@ -130,7 +134,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_clone(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_clone_obj, mod_TrezorCrypto_HDNode_clone); -/// def trezor.crypto.HDNode.depth() -> int: +/// def depth(self) -> int: /// ''' /// Returns a depth of the HD node. /// ''' @@ -140,7 +144,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_depth(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_depth_obj, mod_TrezorCrypto_HDNode_depth); -/// def trezor.crypto.HDNode.fingerprint() -> int: +/// def fingerprint(self) -> int: /// ''' /// Returns a fingerprint of the HD node (hash of the parent public key). /// ''' @@ -150,7 +154,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_fingerprint(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_fingerprint_obj, mod_TrezorCrypto_HDNode_fingerprint); -/// def trezor.crypto.HDNode.child_num() -> int: +/// def child_num(self) -> int: /// ''' /// Returns a child index of the HD node. /// ''' @@ -160,7 +164,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_child_num(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_child_num_obj, mod_TrezorCrypto_HDNode_child_num); -/// def trezor.crypto.HDNode.chain_code() -> bytes: +/// def chain_code(self) -> bytes: /// ''' /// Returns a chain code of the HD node. /// ''' @@ -170,7 +174,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_chain_code(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_chain_code_obj, mod_TrezorCrypto_HDNode_chain_code); -/// def trezor.crypto.HDNode.private_key() -> bytes: +/// def private_key(self) -> bytes: /// ''' /// Returns a private key of the HD node. /// ''' @@ -180,7 +184,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_private_key(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_private_key_obj, mod_TrezorCrypto_HDNode_private_key); -/// def trezor.crypto.HDNode.public_key() -> bytes: +/// def public_key(self) -> bytes: /// ''' /// Returns a public key of the HD node. /// ''' @@ -191,7 +195,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_public_key(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_public_key_obj, mod_TrezorCrypto_HDNode_public_key); -/// def trezor.crypto.HDNode.address(version: int) -> str: +/// def address(self, version: int) -> str: /// ''' /// Compute a base58-encoded address string from the HD node. /// ''' @@ -231,10 +235,16 @@ STATIC const mp_obj_type_t mod_TrezorCrypto_HDNode_type = { .locals_dict = (void*)&mod_TrezorCrypto_HDNode_locals_dict, }; +/// class Bip32: +/// ''' +/// ''' typedef struct _mp_obj_Bip32_t { mp_obj_base_t base; } mp_obj_Bip32_t; +/// def __init__(self): +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip32_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); mp_obj_Bip32_t *o = m_new_obj(mp_obj_Bip32_t); @@ -242,7 +252,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_make_new(const mp_obj_type_t *type, size_ return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.bip32.deserialize(value:str, version_public: int, version_private: int) -> HDNode: +/// def deserialize(self, value: str, version_public: int, version_private: int) -> HDNode: /// ''' /// Construct a BIP0032 HD node from a base58-serialized value. /// ''' @@ -268,7 +278,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(size_t n_args, const mp_obj_t } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Bip32_deserialize_obj, 4, 4, mod_TrezorCrypto_Bip32_deserialize); -/// def trezor.crypto.bip32.from_seed(seed: bytes, curve_name: str) -> HDNode: +/// def from_seed(self, seed: bytes, curve_name: str) -> HDNode: /// ''' /// Construct a BIP0032 HD node from a BIP0039 seed value. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h index c15be06fe..a0d4f4bbe 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h @@ -9,10 +9,16 @@ #include "trezor-crypto/bip39.h" +/// class Bip39: +/// ''' +/// ''' typedef struct _mp_obj_Bip39_t { mp_obj_base_t base; } mp_obj_Bip39_t; +/// def __init__(self): +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_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); mp_obj_Bip39_t *o = m_new_obj(mp_obj_Bip39_t); @@ -20,9 +26,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_make_new(const mp_obj_type_t *type, size_ return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.bip39.find_word(prefix: str) -> str: +/// def find_word(self, prefix: str) -> Optional[str]: /// ''' -/// Return the first word from the wordlist starting with prefix +/// Return the first word from the wordlist starting with prefix. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_find_word(mp_obj_t self, mp_obj_t prefix) { @@ -40,9 +46,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_find_word(mp_obj_t self, mp_obj_t prefix) } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_find_word_obj, mod_TrezorCrypto_Bip39_find_word); -/// def trezor.crypto.bip39.complete_word(prefix: str) -> int: +/// def complete_word(self, prefix: str) -> int: /// ''' -/// Return possible 1-letter suffixes for given word prefix +/// Return possible 1-letter suffixes for given word prefix. /// Result is a bitmask, with 'a' on the lowest bit, 'b' on the second lowest, etc. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_complete_word(mp_obj_t self, mp_obj_t prefix) @@ -67,9 +73,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_complete_word(mp_obj_t self, mp_obj_t pre } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_complete_word_obj, mod_TrezorCrypto_Bip39_complete_word); -/// def trezor.crypto.bip39.generate(strength: int) -> str: +/// def generate(self, strength: int) -> str: /// ''' -/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits) +/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits). /// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength) { int bits = mp_obj_get_int(strength); @@ -81,9 +87,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_generate_obj, mod_TrezorCrypto_Bip39_generate); -/// def trezor.crypto.bip39.from_data(data: bytes) -> str: +/// def from_data(self, data: bytes) -> str: /// ''' -/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes) +/// 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 self, mp_obj_t data) { mp_buffer_info_t bin; @@ -96,9 +102,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_from_data_obj, mod_TrezorCrypto_Bip39_from_data); -/// def trezor.crypto.bip39.check(mnemonic: str) -> bool: +/// def check(self, mnemonic: str) -> bool: /// ''' -/// Check whether given mnemonic is valid +/// Check whether given mnemonic is valid. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) { mp_buffer_info_t text; @@ -107,9 +113,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_check_obj, mod_TrezorCrypto_Bip39_check); -/// def trezor.crypto.bip39.seed(mnemonic: str, passphrase: str) -> bytes: +/// def seed(self, mnemonic: str, passphrase: str) -> bytes: /// ''' -/// Generate seed from mnemonic and passphrase +/// Generate seed from mnemonic and passphrase. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Bip39_seed(mp_obj_t self, mp_obj_t mnemonic, mp_obj_t passphrase) { mp_buffer_info_t mnemo; diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h index a4ac43cef..0adbabc2e 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h @@ -9,6 +9,10 @@ #include "trezor-crypto/blake2b.h" +/// class Blake2b: +/// ''' +/// Blake2b context. +/// ''' typedef struct _mp_obj_Blake2b_t { mp_obj_base_t base; BLAKE2B_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Blake2b_t { STATIC mp_obj_t mod_TrezorCrypto_Blake2b_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.blake2b(data: bytes=None, key: bytes=None) -> Blake2b: +/// def __init__(self, data: bytes = None, key: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -39,7 +43,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_make_new(const mp_obj_type_t *type, siz return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.blake2b.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -54,7 +58,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2b_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Blake2b_update_obj, mod_TrezorCrypto_Blake2b_update); -/// def trezor.crypto.hashlib.blake2b.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h index c16f3996b..7a0bd906b 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h @@ -9,6 +9,10 @@ #include "trezor-crypto/blake2s.h" +/// class Blake2s: +/// ''' +/// Blake2s context. +/// ''' typedef struct _mp_obj_Blake2s_t { mp_obj_base_t base; BLAKE2S_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Blake2s_t { STATIC mp_obj_t mod_TrezorCrypto_Blake2s_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.blake2s(data: bytes=None, key: bytes=None) -> Blake2s: +/// def __init__(self, data: bytes = None, key: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -39,7 +43,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_make_new(const mp_obj_type_t *type, siz return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.blake2s.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -54,7 +58,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Blake2s_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Blake2s_update_obj, mod_TrezorCrypto_Blake2s_update); -/// def trezor.crypto.hashlib.blake2s.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h index 5e14baa41..cf7461ac2 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h @@ -11,10 +11,16 @@ #include "rand.h" +/// class Curve25519: +/// ''' +/// ''' typedef struct _mp_obj_Curve25519_t { mp_obj_base_t base; } mp_obj_Curve25519_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Curve25519_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); mp_obj_Curve25519_t *o = m_new_obj(mp_obj_Curve25519_t); @@ -22,7 +28,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.curve.curve25519.generate_secret() -> bytes: +/// def generate_secret(self) -> bytes: /// ''' /// Generate secret key. /// ''' @@ -38,7 +44,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_generate_secret(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Curve25519_generate_secret_obj, mod_TrezorCrypto_Curve25519_generate_secret); -/// def trezor.crypto.curve.curve25519.publickey(secret_key: bytes) -> bytes: +/// def publickey(self, secret_key: bytes) -> bytes: /// ''' /// Computes public key from secret key. /// ''' @@ -55,10 +61,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Curve25519_publickey(mp_obj_t self, mp_obj_t se } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Curve25519_publickey_obj, mod_TrezorCrypto_Curve25519_publickey); -/// def trezor.crypto.curve.curve25519.multiply(secret_key: bytes, public_key: bytes) -> bytes: +/// def multiply(self, secret_key: bytes, public_key: bytes) -> bytes: /// ''' -/// Multiplies point defined by public_key with scalar defined by secret_key -/// Useful for ECDH +/// 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 self, mp_obj_t secret_key, mp_obj_t public_key) { mp_buffer_info_t sk, pk; diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h index dd2da3247..83d2caf7f 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h @@ -11,10 +11,16 @@ #include "rand.h" +/// class Ed25519: +/// ''' +/// ''' typedef struct _mp_obj_Ed25519_t { mp_obj_base_t base; } mp_obj_Ed25519_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Ed25519_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); mp_obj_Ed25519_t *o = m_new_obj(mp_obj_Ed25519_t); @@ -22,7 +28,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, siz return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.curve.ed25519.generate_secret() -> bytes: +/// def generate_secret(self) -> bytes: /// ''' /// Generate secret key. /// ''' @@ -38,7 +44,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_generate_secret(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ed25519_generate_secret_obj, mod_TrezorCrypto_Ed25519_generate_secret); -/// def trezor.crypto.curve.ed25519.publickey(secret_key: bytes) -> bytes: +/// def publickey(self, secret_key: bytes) -> bytes: /// ''' /// Computes public key from secret key. /// ''' @@ -55,7 +61,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secre } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_publickey_obj, mod_TrezorCrypto_Ed25519_publickey); -/// def trezor.crypto.curve.ed25519.sign(secret_key: bytes, message: bytes) -> bytes: +/// def sign(self, secret_key: bytes, message: bytes) -> bytes: /// ''' /// Uses secret key to produce the signature of message. /// ''' @@ -78,7 +84,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_sign_obj, mod_TrezorCrypto_Ed25519_sign); -/// def trezor.crypto.curve.ed25519.verify(public_key: bytes, signature: bytes, message: bytes) -> bool: +/// def verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool: /// ''' /// Uses public key to verify the signature of the message. /// Returns True on success. @@ -101,9 +107,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_verify(size_t n_args, const mp_obj_t *a } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Ed25519_verify_obj, 4, 4, mod_TrezorCrypto_Ed25519_verify); -/// def trezor.crypto.curve.ed25519.cosi_combine_publickeys(public_keys: list) -> bytes: +/// def cosi_combine_publickeys(self, public_keys: List[bytes]) -> bytes: /// ''' -/// Combines a list of public keys used in COSI cosigning scheme +/// Combines a list of public keys used in COSI cosigning scheme. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_publickeys(mp_obj_t self, mp_obj_t public_keys) { size_t pklen; @@ -130,9 +136,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_publickeys(mp_obj_t self, } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_cosi_combine_publickeys_obj, mod_TrezorCrypto_Ed25519_cosi_combine_publickeys); -/// def trezor.crypto.curve.ed25519.cosi_combine_signatures(R: bytes, signatures: list) -> bytes: +/// def cosi_combine_signatures(self, R: bytes, signatures: List[bytes]) -> bytes: /// ''' -/// Combines a list of signatures used in COSI cosigning scheme +/// Combines a list of signatures used in COSI cosigning scheme. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_signatures(mp_obj_t self, mp_obj_t R, mp_obj_t signatures) { mp_buffer_info_t sigR; @@ -162,9 +168,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_combine_signatures(mp_obj_t self, } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_cosi_combine_signatures_obj, mod_TrezorCrypto_Ed25519_cosi_combine_signatures); -/// def trezor.crypto.curve.ed25519.cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes: +/// def cosi_sign(self, secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes: /// ''' -/// Produce signature of message using COSI cosigning scheme +/// Produce signature of message using COSI cosigning scheme. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Ed25519_cosi_sign(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t sk, msg, nonce, sigR, pk; diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h index 1a25e39a0..46f529509 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h @@ -10,10 +10,16 @@ #include "trezor-crypto/ecdsa.h" #include "trezor-crypto/nist256p1.h" +/// class Nist256p1: +/// ''' +/// ''' typedef struct _mp_obj_Nist256p1_t { mp_obj_base_t base; } mp_obj_Nist256p1_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_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); mp_obj_Nist256p1_t *o = m_new_obj(mp_obj_Nist256p1_t); @@ -21,7 +27,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, s return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.curve.nist256p1.generate_secret() -> bytes: +/// def generate_secret(self) -> bytes: /// ''' /// Generate secret key. /// ''' @@ -39,7 +45,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_generate_secret(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Nist256p1_generate_secret_obj, mod_TrezorCrypto_Nist256p1_generate_secret); -/// def trezor.crypto.curve.nist256p1.publickey(secret_key: bytes, compressed: bool=True) -> bytes: +/// def publickey(self, secret_key: bytes, compressed: bool = True) -> bytes: /// ''' /// Computes public key from secret key. /// ''' @@ -62,7 +68,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_publickey_obj, 2, 3, mod_TrezorCrypto_Nist256p1_publickey); -/// def trezor.crypto.curve.nist256p1.sign(secret_key: bytes, digest: bytes, compressed: bool=True) -> bytes: +/// def sign(self, secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes: /// ''' /// Uses secret key to produce the signature of the digest. /// ''' @@ -88,7 +94,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(size_t n_args, const mp_obj_t *a } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_sign_obj, 3, 4, mod_TrezorCrypto_Nist256p1_sign); -/// def trezor.crypto.curve.nist256p1.verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: +/// def verify(self, public_key: bytes, signature: bytes, digest: bytes) -> bool: /// ''' /// Uses public key to verify the signature of the digest. /// Returns True on success. @@ -112,7 +118,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify(size_t n_args, const mp_obj_t } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_verify_obj, 4, 4, mod_TrezorCrypto_Nist256p1_verify); -/// def trezor.crypto.curve.nist256p1.verify_recover(signature: bytes, digest: bytes) -> bytes: +/// def verify_recover(self, signature: bytes, digest: bytes) -> bytes: /// ''' /// Uses signature of the digest to verify the digest and recover the public key. /// Returns public key on success, None on failure. @@ -147,7 +153,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify_recover(mp_obj_t self, mp_obj_ } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Nist256p1_verify_recover_obj, mod_TrezorCrypto_Nist256p1_verify_recover); -/// def trezor.crypto.curve.nist256p1.multiply(secret_key: bytes, public_key: bytes) -> bytes: +/// def multiply(self, secret_key: bytes, public_key: bytes) -> bytes: /// ''' /// Multiplies point defined by public_key with scalar defined by secret_key /// Useful for ECDH diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h index 676276f75..f47d1d596 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h @@ -9,6 +9,10 @@ #include "trezor-crypto/pbkdf2.h" +/// class Pbkdf2: +/// ''' +/// PBKDF2 context. +/// ''' typedef struct _mp_obj_Pbkdf2_t { mp_obj_base_t base; union { @@ -20,9 +24,9 @@ typedef struct _mp_obj_Pbkdf2_t { STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2: +/// def __init__(self, prf: str, password: bytes, salt: bytes, iterations: int = None) -> None: /// ''' -/// Create a PBKDF2 context +/// Create a PBKDF2 context. /// ''' 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); @@ -62,9 +66,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_make_new(const mp_obj_type_t *type, size return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.pbkdf2.update(self, iterations: int) -> None: +/// def update(self, iterations: int) -> None: /// ''' -/// Update a PBKDF2 context +/// Update a PBKDF2 context. /// ''' 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); @@ -79,9 +83,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t iteration } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Pbkdf2_update_obj, mod_TrezorCrypto_Pbkdf2_update); -/// def trezor.crypto.pbkdf2.key(self) -> bytes: +/// def key(self) -> bytes: /// ''' -/// Retreive derived key +/// Retrieve derived key. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_key(mp_obj_t self) { mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self); diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-random.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-random.h index 743eac593..7feb000a9 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-random.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-random.h @@ -9,10 +9,16 @@ #include "rand.h" +/// class Random: +/// ''' +/// ''' typedef struct _mp_obj_Random_t { mp_obj_base_t base; } mp_obj_Random_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Random_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); mp_obj_Random_t *o = m_new_obj(mp_obj_Random_t); @@ -20,7 +26,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_make_new(const mp_obj_type_t *type, size return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.random.uniform(n: int) -> int: +/// def uniform(self, n: int) -> int: /// ''' /// Compute uniform random number from interval 0 ... n - 1 /// ''' @@ -33,7 +39,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_uniform(mp_obj_t self, mp_obj_t n) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_uniform_obj, mod_TrezorCrypto_Random_uniform); -/// def trezor.crypto.random.bytes(len: int) -> bytes: +/// def bytes(self, len: int) -> bytes: /// ''' /// Generate random bytes sequence of length len /// ''' @@ -49,7 +55,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_bytes(mp_obj_t self, mp_obj_t len) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_bytes_obj, mod_TrezorCrypto_Random_bytes); -/// def trezor.crypto.random.shuffle(data: list) -> None: +/// def shuffle(self, data: list) -> None: /// ''' /// Shuffles items of given list (in-place) /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h index 681481a89..bc3573e88 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h @@ -9,11 +9,19 @@ #include "trezor-crypto/rfc6979.h" +/// class Rfc6979: +/// ''' +/// RFC6979 context. +/// ''' typedef struct _mp_obj_Rfc6979_t { mp_obj_base_t base; rfc6979_state rng; } mp_obj_Rfc6979_t; +/// def __init__(self, secret_key: bytes, hash: bytes) -> None: +/// ''' +/// Initialize RFC6979 context from secret key and a hash. +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_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); mp_obj_Rfc6979_t *o = m_new_obj(mp_obj_Rfc6979_t); @@ -22,7 +30,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_make_new(const mp_obj_type_t *type, siz mp_get_buffer_raise(args[0], &pkey, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &hash, MP_BUFFER_READ); if (pkey.len != 32) { - mp_raise_ValueError("Private key has to be 32 bytes long"); + mp_raise_ValueError("Secret key has to be 32 bytes long"); } if (hash.len != 32) { mp_raise_ValueError("Hash has to be 32 bytes long"); @@ -31,9 +39,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_make_new(const mp_obj_type_t *type, siz return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.rfc6979.next() -> bytes: +/// def next(self) -> bytes: /// ''' -/// Compute next 32-bytes of pseudorandom data +/// Compute next 32-bytes of pseudorandom data. /// ''' STATIC mp_obj_t mod_TrezorCrypto_Rfc6979_next(mp_obj_t self) { mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self); diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h index b1df88f61..8f2eb78fe 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h @@ -9,6 +9,10 @@ #include "trezor-crypto/ripemd160.h" +/// class Ripemd160: +/// ''' +/// RIPEMD160 context. +/// ''' typedef struct _mp_obj_Ripemd160_t { mp_obj_base_t base; RIPEMD160_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Ripemd160_t { STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.ripemd160(data: bytes=None) -> Ripemd160: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -32,7 +36,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, s return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.ripemd160.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -47,7 +51,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update); -/// def trezor.crypto.hashlib.ripemd160.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h index 5205c7dc0..a4aceff81 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h @@ -10,10 +10,16 @@ #include "trezor-crypto/ecdsa.h" #include "trezor-crypto/secp256k1.h" +/// class Secp256k1: +/// ''' +/// ''' typedef struct _mp_obj_Secp256k1_t { mp_obj_base_t base; } mp_obj_Secp256k1_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_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); mp_obj_Secp256k1_t *o = m_new_obj(mp_obj_Secp256k1_t); @@ -21,7 +27,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, s return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.curve.secp256k1.generate_secret() -> bytes: +/// def generate_secret(self, ) -> bytes: /// ''' /// Generate secret key. /// ''' @@ -39,7 +45,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_generate_secret(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Secp256k1_generate_secret_obj, mod_TrezorCrypto_Secp256k1_generate_secret); -/// def trezor.crypto.curve.secp256k1.publickey(secret_key: bytes, compressed: bool=True) -> bytes: +/// def publickey(self, secret_key: bytes, compressed: bool = True) -> bytes: /// ''' /// Computes public key from secret key. /// ''' @@ -62,7 +68,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_publickey_obj, 2, 3, mod_TrezorCrypto_Secp256k1_publickey); -/// def trezor.crypto.curve.secp256k1.sign(secret_key: bytes, digest: bytes, compressed: bool=True) -> bytes: +/// def sign(self, secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes: /// ''' /// Uses secret key to produce the signature of the digest. /// ''' @@ -88,7 +94,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(size_t n_args, const mp_obj_t *a } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_sign_obj, 3, 4, mod_TrezorCrypto_Secp256k1_sign); -/// def trezor.crypto.curve.secp256k1.verify(public_key: bytes, signature: bytes, digest: bytes) -> bool: +/// def verify(self, public_key: bytes, signature: bytes, digest: bytes) -> bool: /// ''' /// Uses public key to verify the signature of the digest. /// Returns True on success. @@ -112,7 +118,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify(size_t n_args, const mp_obj_t } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_verify_obj, 4, 4, mod_TrezorCrypto_Secp256k1_verify); -/// def trezor.crypto.curve.secp256k1.verify_recover(signature: bytes, digest: bytes) -> bytes: +/// def verify_recover(self, signature: bytes, digest: bytes) -> bytes: /// ''' /// Uses signature of the digest to verify the digest and recover the public key. /// Returns public key on success, None on failure. @@ -147,10 +153,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify_recover(mp_obj_t self, mp_obj_ } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Secp256k1_verify_recover_obj, mod_TrezorCrypto_Secp256k1_verify_recover); -/// def trezor.crypto.curve.secp256k1.multiply(secret_key: bytes, public_key: bytes) -> bytes: +/// def multiply(self, secret_key: bytes, public_key: bytes) -> bytes: /// ''' -/// Multiplies point defined by public_key with scalar defined by secret_key -/// Useful for ECDH +/// 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 self, mp_obj_t secret_key, mp_obj_t public_key) { mp_buffer_info_t sk, pk; diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h index b5293c6f0..f3ffddd2f 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h @@ -9,6 +9,10 @@ #include "trezor-crypto/sha2.h" +/// class Sha1: +/// ''' +/// SHA1 context. +/// ''' typedef struct _mp_obj_Sha1_t { mp_obj_base_t base; SHA1_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Sha1_t { STATIC mp_obj_t mod_TrezorCrypto_Sha1_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.sha1(data: bytes=None) -> Sha1: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -32,7 +36,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha1_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.sha1.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -47,7 +51,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha1_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha1_update_obj, mod_TrezorCrypto_Sha1_update); -/// def trezor.crypto.hashlib.sha1.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h index 69fc1f289..1d8063ab8 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h @@ -9,6 +9,10 @@ #include "trezor-crypto/sha2.h" +/// class Sha256: +/// ''' +/// SHA256 context. +/// ''' typedef struct _mp_obj_Sha256_t { mp_obj_base_t base; SHA256_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Sha256_t { STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.sha256(data: bytes=None) -> Sha256: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -32,7 +36,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.sha256.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -47,7 +51,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update); -/// def trezor.crypto.hashlib.sha256.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h index 9c56cba6f..277d02ad2 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h @@ -9,6 +9,10 @@ #include "trezor-crypto/sha3.h" +/// class Sha3_256: +/// ''' +/// SHA3_256 context. +/// ''' typedef struct _mp_obj_Sha3_256_t { mp_obj_base_t base; SHA3_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Sha3_256_t { STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.sha3_256(data: bytes=None) -> Sha3_256: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -32,7 +36,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, si return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.sha3_256.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -47,7 +51,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update); -/// def trezor.crypto.hashlib.sha3_256.digest(self, keccak: bool=False) -> bytes: +/// def digest(self, keccak: bool = False) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h index a6f53140d..ac7e9e5e5 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h @@ -9,6 +9,10 @@ #include "trezor-crypto/sha3.h" +/// class Sha3_512: +/// ''' +/// SHA3_512 context. +/// ''' typedef struct _mp_obj_Sha3_512_t { mp_obj_base_t base; SHA3_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Sha3_512_t { STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.sha3_512(data: bytes=None) -> Sha3_512: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -32,7 +36,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, si return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.sha3_512.update(self, data: bytes) -> None: +/// def update(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -47,7 +51,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update); -/// def trezor.crypto.hashlib.sha3_512.digest(self, keccak: bool=False) -> bytes: +/// def digest(self, keccak: bool = False) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h index 01a8c686e..dd574cda7 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h @@ -9,6 +9,10 @@ #include "trezor-crypto/sha2.h" +/// class Sha512: +/// ''' +/// SHA512 context. +/// ''' typedef struct _mp_obj_Sha512_t { mp_obj_base_t base; SHA512_CTX ctx; @@ -16,7 +20,7 @@ typedef struct _mp_obj_Sha512_t { STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data); -/// def trezor.crypto.hashlib.sha512(data: bytes=None) -> Sha512: +/// def __init__(self, data: bytes = None) -> None: /// ''' /// Creates a hash context object. /// ''' @@ -31,7 +35,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.hashlib.sha512.hash(self, data: bytes) -> None: +/// def hash(self, data: bytes) -> None: /// ''' /// Update the hash context with hashed data. /// ''' @@ -46,7 +50,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update); -/// def trezor.crypto.hashlib.sha512.digest(self) -> bytes: +/// def digest(self) -> bytes: /// ''' /// Returns the digest of hashed data. /// ''' diff --git a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h index 091edcb83..df93130cc 100644 --- a/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h +++ b/micropython/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h @@ -10,10 +10,16 @@ #include "trezor-crypto/bignum.h" #include "ssss.h" +/// class SSSS: +/// ''' +/// ''' typedef struct _mp_obj_SSSS_t { mp_obj_base_t base; } mp_obj_SSSS_t; +/// def __init__(self) -> None: +/// ''' +/// ''' STATIC mp_obj_t mod_TrezorCrypto_SSSS_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); mp_obj_SSSS_t *o = m_new_obj(mp_obj_SSSS_t); @@ -21,9 +27,9 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(o); } -/// def trezor.crypto.ssss.split(m: int, n: int, secret: bytes) -> tuple: +/// def split(self, m: int, n: int, secret: bytes) -> tuple: /// ''' -/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme +/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme. /// ''' STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args) { mp_int_t m = mp_obj_get_int(args[1]); @@ -53,9 +59,9 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_SSSS_split_obj, 4, 4, mod_TrezorCrypto_SSSS_split); -/// def trezor.crypto.ssss.combine(shares: tuple) -> bytes: +/// def combine(self, shares: tuple) -> bytes: /// ''' -/// Combine M shares of Shamir's Secret Sharing Scheme into secret +/// Combine M shares of Shamir's Secret Sharing Scheme into secret. /// ''' STATIC mp_obj_t mod_TrezorCrypto_SSSS_combine(mp_obj_t self, mp_obj_t shares) { size_t n; diff --git a/micropython/extmod/modtrezormsg/modtrezormsg.c b/micropython/extmod/modtrezormsg/modtrezormsg.c index f819d52a1..790acf038 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg.c +++ b/micropython/extmod/modtrezormsg/modtrezormsg.c @@ -24,15 +24,25 @@ #error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. #endif -/* - * USB HID interface configuration - */ - +/// class HID: +/// ''' +/// USB HID interface configuration. +/// ''' typedef struct _mp_obj_HID_t { mp_obj_base_t base; usb_hid_info_t info; } mp_obj_HID_t; +/// def __init__(self, +/// iface_num: int, +/// ep_in: int, +/// ep_out: int, +/// report_desc: bytes, +/// subclass: int = 0, +/// protocol: int = 0, +/// polling_interval: int = 1, +/// max_packet_len: int = 64) -> None: +/// pass STATIC mp_obj_t mod_TrezorMsg_HID_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[] = { @@ -110,15 +120,22 @@ STATIC const mp_obj_type_t mod_TrezorMsg_HID_type = { .locals_dict = (void*)&mod_TrezorMsg_HID_locals_dict, }; -/* - * USB VCP interface configuration - */ - +/// class VCP: +/// ''' +/// USB VCP interface configuration. +/// ''' typedef struct _mp_obj_VCP_t { mp_obj_base_t base; usb_vcp_info_t info; } mp_obj_VCP_t; +/// def __init__(self, +/// iface_num: int, +/// data_iface_num: int, +/// ep_in: int, +/// ep_out: int, +/// ep_cmd: int) -> None: +/// pass STATIC mp_obj_t mod_TrezorMsg_VCP_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[] = { @@ -188,10 +205,10 @@ STATIC const mp_obj_type_t mod_TrezorMsg_VCP_type = { .locals_dict = (void*)&mod_TrezorMsg_VCP_locals_dict, }; -/* - * USB device configuration - */ - +/// class USB: +/// ''' +/// USB device configuration. +/// ''' typedef struct _mp_obj_USB_t { mp_obj_base_t base; usb_dev_info_t info; @@ -211,6 +228,16 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) { } } +/// def __init__(self, +/// vendor_id: int, +/// product_id: int, +/// release_num: int, +/// manufacturer_str: str, +/// product_str: str, +/// serial_number_str: str, +/// configuration_str: str = '', +/// interface_str: str = '') -> None: +/// pass STATIC mp_obj_t mod_TrezorMsg_USB_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[] = { @@ -282,16 +309,18 @@ STATIC const mp_obj_type_t mod_TrezorMsg_USB_type = { .locals_dict = (void*)&mod_TrezorMsg_USB_locals_dict, }; -/* - * Msg class - */ - +/// class Msg: +/// ''' +/// Interface with USB and touch events. +/// ''' typedef struct _mp_obj_Msg_t { mp_obj_base_t base; mp_obj_t usb_info; mp_obj_t usb_ifaces; } mp_obj_Msg_t; +/// def __init__(self) -> None: +/// pass STATIC mp_obj_t mod_TrezorMsg_Msg_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); msg_init(); @@ -302,9 +331,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(o); } -/// def trezor.msg.init_usb(usb_info, usb_ifaces) -> None: +/// def init_usb(self, usb_info: USB, usb_ifaces: List[Union[HID, VCP]]) -> None: /// ''' -/// Registers passed interfaces and initializes the USB stack +/// Registers passed interfaces and initializes the USB stack. /// ''' STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_obj_t usb_ifaces) { @@ -369,7 +398,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_ } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_init_usb_obj, mod_TrezorMsg_Msg_init_usb); -/// def trezor.msg.deinit_usb() -> None: +/// def deinit_usb(self) -> None: /// ''' /// Cleans up the USB stack /// ''' @@ -386,7 +415,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_deinit_usb(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorMsg_Msg_deinit_usb_obj, mod_TrezorMsg_Msg_deinit_usb); -/// def trezor.msg.send(iface: int, message: bytes) -> int: +/// def send(self, iface: int, message: bytes) -> int: /// ''' /// Sends message using USB HID (device) or UDP (emulator). /// ''' @@ -404,7 +433,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s #define TOUCH_IFACE 255 extern uint32_t touch_read(void); // defined in HAL -/// def trezor.msg.select(timeout_us: int) -> tuple: +/// def select(self, timeout_us: int) -> tuple: /// ''' /// Polls the event queue and returns the event object. /// Function returns None if timeout specified in microseconds is reached. diff --git a/micropython/extmod/modtrezorui/modtrezorui-display.h b/micropython/extmod/modtrezorui/modtrezorui-display.h index 8126edebe..32e53fac1 100644 --- a/micropython/extmod/modtrezorui/modtrezorui-display.h +++ b/micropython/extmod/modtrezorui/modtrezorui-display.h @@ -9,10 +9,18 @@ #include "display.h" +/// class Display: +/// ''' +/// Provide access to device display. +/// ''' typedef struct _mp_obj_Display_t { mp_obj_base_t base; } mp_obj_Display_t; +/// def __init__(self) -> None: +/// ''' +/// Initialize the display. +/// ''' 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); display_init(); @@ -21,9 +29,9 @@ STATIC mp_obj_t mod_TrezorUI_Display_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(o); } -/// def trezor.ui.display.clear() -> None +/// def clear(self) -> None: /// ''' -/// Clear display (with black color) +/// Clear display with black color. /// ''' STATIC mp_obj_t mod_TrezorUI_Display_clear(mp_obj_t self) { display_clear(); @@ -31,9 +39,9 @@ STATIC mp_obj_t mod_TrezorUI_Display_clear(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorUI_Display_clear_obj, mod_TrezorUI_Display_clear); -/// def trezor.ui.display.refresh() -> None +/// def refresh(self) -> None: /// ''' -/// Refresh display (update screen) +/// Refresh display (update screen). /// ''' STATIC mp_obj_t mod_TrezorUI_Display_refresh(mp_obj_t self) { display_refresh(); @@ -41,7 +49,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_refresh(mp_obj_t self) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorUI_Display_refresh_obj, mod_TrezorUI_Display_refresh); -/// def trezor.ui.display.bar(x: int, y: int, w: int, h: int, color: int) -> None: +/// def bar(self, x: int, y: int, w: int, h: int, color: int) -> None: /// ''' /// Renders a bar at position (x,y = upper left corner) with width w and height h of color color. /// ''' @@ -56,7 +64,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_bar(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_bar_obj, 6, 6, mod_TrezorUI_Display_bar); -/// def trezor.ui.display.bar_radius(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None: +/// def bar_radius(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int = None, radius: int = None) -> None: /// ''' /// Renders a rounded bar at position (x,y = upper left corner) with width w and height h of color fgcolor. /// Background is set to bgcolor and corners are drawn with radius radius. @@ -74,7 +82,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_bar_radius(size_t n_args, const mp_obj_t *a } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_bar_radius_obj, 8, 8, mod_TrezorUI_Display_bar_radius); -/// def trezor.ui.display.image(x: int, y: int, image: bytes) -> None: +/// def image(self, x: int, y: int, image: bytes) -> None: /// ''' /// Renders an image at position (x,y). /// The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode. @@ -99,7 +107,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_image(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_image_obj, 4, 4, mod_TrezorUI_Display_image); -/// def trezor.ui.display.icon(x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None: +/// def icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None: /// ''' /// Renders an icon at position (x,y), fgcolor is used as foreground color, bgcolor as background. /// The image needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode. @@ -126,9 +134,9 @@ STATIC mp_obj_t mod_TrezorUI_Display_icon(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_icon_obj, 6, 6, mod_TrezorUI_Display_icon); -/// def trezor.ui.display.print(text: str) -> None: +/// def print(self, text: str) -> None: /// ''' -/// Renders text using 5x8 bitmap font (using special text mode) +/// Renders text using 5x8 bitmap font (using special text mode). /// ''' STATIC mp_obj_t mod_TrezorUI_Display_print(mp_obj_t self, mp_obj_t text) { mp_buffer_info_t buf; @@ -140,7 +148,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_print(mp_obj_t self, mp_obj_t text) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUI_Display_print_obj, mod_TrezorUI_Display_print); -/// def trezor.ui.display.text(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: +/// def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: /// ''' /// Renders left-aligned text at position (x,y) where x is left position and y is baseline. /// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. @@ -160,7 +168,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_text(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_obj, 7, 7, mod_TrezorUI_Display_text); -/// def trezor.ui.display.text_center(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: +/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: /// ''' /// Renders text centered at position (x,y) where x is text center and y is baseline. /// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. @@ -180,7 +188,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_center(size_t n_args, const mp_obj_t * } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_center_obj, 7, 7, mod_TrezorUI_Display_text_center); -/// def trezor.ui.display.text_right(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: +/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None: /// ''' /// Renders right-aligned text at position (x,y) where x is right position and y is baseline. /// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background. @@ -200,7 +208,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_right(size_t n_args, const mp_obj_t *a } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_text_right_obj, 7, 7, mod_TrezorUI_Display_text_right); -/// def trezor.ui.display.text_width(text: str, font: int) -> int: +/// def text_width(self, text: str, font: int) -> int: /// ''' /// Returns a width of text in pixels. Font font is used for rendering. /// ''' @@ -216,7 +224,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_text_width(mp_obj_t self, mp_obj_t text, mp } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUI_Display_text_width_obj, mod_TrezorUI_Display_text_width); -/// def trezor.ui.display.qrcode(x: int, y: int, data: bytes, scale: int) -> None: +/// def qrcode(self, x: int, y: int, data: bytes, scale: int) -> None: /// ''' /// Renders data encoded as a QR code centered at position (x,y). /// Scale determines a zoom factor. @@ -237,7 +245,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_qrcode(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_qrcode_obj, 5, 5, mod_TrezorUI_Display_qrcode); -/// def trezor.ui.display.loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None: +/// def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None: /// ''' /// Renders a rotating loader graphic. /// Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background. @@ -279,7 +287,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_loader(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_loader_obj, 5, 7, mod_TrezorUI_Display_loader); -/// def trezor.ui.display.orientation(degrees: int=None) -> int: +/// def orientation(self, degrees: int = None) -> int: /// ''' /// Sets display orientation to 0, 90, 180 or 270 degrees. /// Everything needs to be redrawn again when this function is used. @@ -300,7 +308,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_orientation(size_t n_args, const mp_obj_t * } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_orientation_obj, 1, 2, mod_TrezorUI_Display_orientation); -/// def trezor.ui.display.backlight(val: int=None) -> int: +/// def backlight(self, val: int = None) -> int: /// ''' /// Sets backlight intensity to the value specified in val. /// Call without the val parameter to just perform the read of the value. @@ -320,7 +328,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_backlight(size_t n_args, const mp_obj_t *ar } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_backlight_obj, 1, 2, mod_TrezorUI_Display_backlight); -/// def trezor.ui.display.offset(xy: tuple=None) -> tuple: +/// def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]: /// ''' /// Sets offset (x, y) for all subsequent drawing calls. /// Call without the xy parameter to just perform the read of the value. @@ -352,7 +360,7 @@ STATIC mp_obj_t mod_TrezorUI_Display_offset(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUI_Display_offset_obj, 1, 2, mod_TrezorUI_Display_offset); -/// def trezor.ui.display.save(filename: string) -> None: +/// def save(self, filename: str) -> None: /// ''' /// Saves current display contents to file filename. /// ''' diff --git a/micropython/extmod/modtrezorutils/modtrezorutils.c b/micropython/extmod/modtrezorutils/modtrezorutils.c index a66ec71e6..bd996a5bc 100644 --- a/micropython/extmod/modtrezorutils/modtrezorutils.c +++ b/micropython/extmod/modtrezorutils/modtrezorutils.c @@ -12,9 +12,9 @@ #include #include "common.h" -/// def trezor.utils.memcpy(dst: bytearray, dst_ofs: int, -/// src: bytearray, src_ofs: int, -// n: int) -> int: +/// def memcpy(dst: bytearray, dst_ofs: int, +/// src: bytearray, src_ofs: int, +/// n: int) -> int: /// ''' /// Copies at most `n` bytes from `src` at offset `src_ofs` to /// `dst` at offset `dst_ofs`. Returns the number of actually @@ -51,9 +51,9 @@ STATIC mp_obj_t mod_TrezorUtils_memcpy(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_memcpy_obj, 5, 5, mod_TrezorUtils_memcpy); -/// def trezor.utils.halt(msg: str=None) -> None: +/// def halt(msg: str = None) -> None: /// ''' -/// Halts execution +/// Halts execution. /// ''' STATIC mp_obj_t mod_TrezorUtils_halt(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t msg;