diff --git a/mocks/generated/.mock-generated b/mocks/generated/.mock-generated new file mode 100644 index 000000000..e69de29bb diff --git a/mocks/generated/__init__.py b/mocks/generated/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/mocks/generated/trezorconfig.py b/mocks/generated/trezorconfig.py new file mode 100644 index 000000000..a3eb8f7bb --- /dev/null +++ b/mocks/generated/trezorconfig.py @@ -0,0 +1,27 @@ + +# extmod/modtrezorconfig/modtrezorconfig.c +class Config: + ''' + Persistent key-value storage, with 16-bit keys and bytes values. + ''' + + def __init__(self): + ''' + Initializes the storage. + ''' + + def get(self, app: int, key: int) -> bytes: + ''' + Gets a value of given key for given app (or empty bytes if not set). + ''' + + def set(self, app: int, key: int, value: bytes) -> None: + ''' + Sets a value of given key for given app. + Returns True on success. + ''' + + def wipe(self) -> None: + ''' + Erases the whole config. Use with caution! + ''' diff --git a/mocks/generated/trezorcrypto.py b/mocks/generated/trezorcrypto.py new file mode 100644 index 000000000..c41bfdcb9 --- /dev/null +++ b/mocks/generated/trezorcrypto.py @@ -0,0 +1,543 @@ + +# extmod/modtrezorcrypto/modtrezorcrypto-aes.h +class AES: + ''' + AES context. + ''' + + def __init__(self, mode: int, key: bytes, iv: bytes = ...) -> None: + ''' + Initialize AES context. + ''' + + def update(self, data: bytes) -> bytes: + ''' + Update AES context with data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +class HDNode: + ''' + BIP0032 HD node structure. + ''' + + def derive(self, index: int) -> None: + ''' + Derive a BIP0032 child node in place. + ''' + + def derive_path(self, path: List[int]) -> None: + ''' + Go through a list of indexes and iteratively derive a child node in place. + ''' + + def serialize_public(self, version: int) -> str: + ''' + Serialize the public info from HD node to base58 string. + ''' + + def serialize_private(self, version: int) -> str: + ''' + Serialize the private info HD node to base58 string. + ''' + + def clone(self) -> HDNode: + ''' + Returns a copy of the HD node. + ''' + + def depth(self) -> int: + ''' + Returns a depth of the HD node. + ''' + + def fingerprint(self) -> int: + ''' + Returns a fingerprint of the HD node (hash of the parent public key). + ''' + + def child_num(self) -> int: + ''' + Returns a child index of the HD node. + ''' + + def chain_code(self) -> bytes: + ''' + Returns a chain code of the HD node. + ''' + + def private_key(self) -> bytes: + ''' + Returns a private key of the HD node. + ''' + + def public_key(self) -> bytes: + ''' + Returns a public key of the HD node. + ''' + + def address(self, version: int) -> str: + ''' + Compute a base58-encoded address string from the HD node. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +class Bip32: + ''' + ''' + + def __init__(self): + ''' + ''' + + def deserialize(self, value: str, version_public: int, version_private: int) -> HDNode: + ''' + Construct a BIP0032 HD node from a base58-serialized value. + ''' + + def from_seed(self, seed: bytes, curve_name: str) -> HDNode: + ''' + Construct a BIP0032 HD node from a BIP0039 seed value. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +class Bip39: + ''' + ''' + + def __init__(self): + ''' + ''' + + def find_word(self, prefix: str) -> Optional[str]: + ''' + Return the first word from the wordlist starting with prefix. + ''' + + def complete_word(self, prefix: str) -> int: + ''' + 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. + ''' + + def generate(self, strength: int) -> str: + ''' + Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits). + ''' + + def from_data(self, data: bytes) -> str: + ''' + Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes). + ''' + + def check(self, mnemonic: str) -> bool: + ''' + Check whether given mnemonic is valid. + ''' + + def seed(self, mnemonic: str, passphrase: str) -> bytes: + ''' + Generate seed from mnemonic and passphrase. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +class Blake2b: + ''' + Blake2b context. + ''' + + def __init__(self, data: bytes = None, key: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +class Blake2s: + ''' + Blake2s context. + ''' + + def __init__(self, data: bytes = None, key: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h +class Curve25519: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def generate_secret(self) -> bytes: + ''' + Generate secret key. + ''' + + def publickey(self, secret_key: bytes) -> bytes: + ''' + Computes public key from secret key. + ''' + + 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. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h +class Ed25519: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def generate_secret(self) -> bytes: + ''' + Generate secret key. + ''' + + def publickey(self, secret_key: bytes) -> bytes: + ''' + Computes public key from secret key. + ''' + + def sign(self, secret_key: bytes, message: bytes) -> bytes: + ''' + Uses secret key to produce the signature of message. + ''' + + 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. + ''' + + def cosi_combine_publickeys(self, public_keys: List[bytes]) -> bytes: + ''' + Combines a list of public keys used in COSI cosigning scheme. + ''' + + def cosi_combine_signatures(self, R: bytes, signatures: List[bytes]) -> bytes: + ''' + Combines a list of signatures used in COSI cosigning scheme. + ''' + + 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. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +class Nist256p1: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def generate_secret(self) -> bytes: + ''' + Generate secret key. + ''' + + def publickey(self, secret_key: bytes, compressed: bool = True) -> bytes: + ''' + Computes public key from secret key. + ''' + + def sign(self, secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes: + ''' + Uses secret key to produce the signature of the digest. + ''' + + 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. + ''' + + 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. + ''' + + 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 + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +class Pbkdf2: + ''' + PBKDF2 context. + ''' + + def __init__(self, prf: str, password: bytes, salt: bytes, iterations: int = None) -> None: + ''' + Create a PBKDF2 context. + ''' + + def update(self, iterations: int) -> None: + ''' + Update a PBKDF2 context. + ''' + + def key(self) -> bytes: + ''' + Retrieve derived key. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-random.h +class Random: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def uniform(self, n: int) -> int: + ''' + Compute uniform random number from interval 0 ... n - 1 + ''' + + def bytes(self, len: int) -> bytes: + ''' + Generate random bytes sequence of length len + ''' + + def shuffle(self, data: list) -> None: + ''' + Shuffles items of given list (in-place) + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h +class Rfc6979: + ''' + RFC6979 context. + ''' + + def __init__(self, secret_key: bytes, hash: bytes) -> None: + ''' + Initialize RFC6979 context from secret key and a hash. + ''' + + def next(self) -> bytes: + ''' + Compute next 32-bytes of pseudorandom data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +class Ripemd160: + ''' + RIPEMD160 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +class Secp256k1: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def generate_secret(self, ) -> bytes: + ''' + Generate secret key. + ''' + + def publickey(self, secret_key: bytes, compressed: bool = True) -> bytes: + ''' + Computes public key from secret key. + ''' + + def sign(self, secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes: + ''' + Uses secret key to produce the signature of the digest. + ''' + + 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. + ''' + + 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. + ''' + + 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. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +class Sha1: + ''' + SHA1 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +class Sha256: + ''' + SHA256 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +class Sha3_256: + ''' + SHA3_256 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self, keccak: bool = False) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +class Sha3_512: + ''' + SHA3_512 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def update(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self, keccak: bool = False) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +class Sha512: + ''' + SHA512 context. + ''' + + def __init__(self, data: bytes = None) -> None: + ''' + Creates a hash context object. + ''' + + def hash(self, data: bytes) -> None: + ''' + Update the hash context with hashed data. + ''' + + def digest(self) -> bytes: + ''' + Returns the digest of hashed data. + ''' + +# extmod/modtrezorcrypto/modtrezorcrypto-ssss.h +class SSSS: + ''' + ''' + + def __init__(self) -> None: + ''' + ''' + + def split(self, m: int, n: int, secret: bytes) -> tuple: + ''' + Split secret to (M of N) shares using Shamir's Secret Sharing Scheme. + ''' + + def combine(self, shares: tuple) -> bytes: + ''' + Combine M shares of Shamir's Secret Sharing Scheme into secret. + ''' diff --git a/mocks/generated/trezormsg.py b/mocks/generated/trezormsg.py new file mode 100644 index 000000000..32c8ae8a8 --- /dev/null +++ b/mocks/generated/trezormsg.py @@ -0,0 +1,78 @@ + +# extmod/modtrezormsg/modtrezormsg.c +class HID: + ''' + USB HID interface configuration. + ''' + + 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 + +# extmod/modtrezormsg/modtrezormsg.c +class VCP: + ''' + USB VCP interface configuration. + ''' + + def __init__(self, + iface_num: int, + data_iface_num: int, + ep_in: int, + ep_out: int, + ep_cmd: int) -> None: + pass + +# extmod/modtrezormsg/modtrezormsg.c +class USB: + ''' + USB device configuration. + ''' + + 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 + +# extmod/modtrezormsg/modtrezormsg.c +class Msg: + ''' + Interface with USB and touch events. + ''' + + def __init__(self) -> None: + pass + + def init_usb(self, usb_info: USB, usb_ifaces: List[Union[HID, VCP]]) -> None: + ''' + Registers passed interfaces and initializes the USB stack. + ''' + + def deinit_usb(self) -> None: + ''' + Cleans up the USB stack + ''' + + def send(self, iface: int, message: bytes) -> int: + ''' + Sends message using USB HID (device) or UDP (emulator). + ''' + + 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/mocks/generated/trezorui.py b/mocks/generated/trezorui.py new file mode 100644 index 000000000..2e63d82be --- /dev/null +++ b/mocks/generated/trezorui.py @@ -0,0 +1,110 @@ + +# extmod/modtrezorui/modtrezorui-display.h +class Display: + ''' + Provide access to device display. + ''' + + def __init__(self) -> None: + ''' + Initialize the display. + ''' + + def clear(self) -> None: + ''' + Clear display with black color. + ''' + + def refresh(self) -> None: + ''' + Refresh display (update screen). + ''' + + 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. + ''' + + 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. + ''' + + 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. + ''' + + 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. + ''' + + def print(self, text: str) -> None: + ''' + Renders text using 5x8 bitmap font (using special text mode). + ''' + + 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. + ''' + + 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. + ''' + + 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. + ''' + + def text_width(self, text: str, font: int) -> int: + ''' + Returns a width of text in pixels. Font font is used for rendering. + ''' + + 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. + ''' + + 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. + When icon and iconfgcolor are provided, an icon is drawn in the middle using the color specified in iconfgcolor. + Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size. + ''' + + 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. + Call without the degrees parameter to just perform the read of the value. + ''' + + 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. + ''' + + 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. + ''' + + def save(self, filename: str) -> None: + ''' + Saves current display contents to file filename. + ''' diff --git a/mocks/generated/trezorutils.py b/mocks/generated/trezorutils.py new file mode 100644 index 000000000..4f6704441 --- /dev/null +++ b/mocks/generated/trezorutils.py @@ -0,0 +1,16 @@ + +# extmod/modtrezorutils/modtrezorutils.c +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 + copied bytes. + ''' + +# extmod/modtrezorutils/modtrezorutils.c +def halt(msg: str = None) -> None: + ''' + Halts execution. + '''