Squashed commit of the following: commit 84d3486f59bda063f06521c8b695ea4b07781ec6 Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:17:15 2019 +0200 mocks: complete commit d538133a6d0fb4af06c7c81f80b8675869fb5908 Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:12:26 2019 +0200 mocks part 3 commit 9f0b868d41dafaf487df6fc844db7f3368eabe1b Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:09:20 2019 +0200 mocks: update generated mocks commit 5d80c18a7824ed16fc11cde4cdb8ebca7ed33400 Author: matejcik <ja@matejcik.cz> Date: Thu May 16 15:49:40 2019 +0200 mocks wip 2 commit 4b576eb796136a61eb88cb0d281fa4e21eadada8 Author: matejcik <ja@matejcik.cz> Date: Tue May 7 17:02:51 2019 +0200 WIP mocks part 1 commit cf3f0d4471ab74b478d2970b0bb178feae7c86a3 Author: matejcik <ja@matejcik.cz> Date: Fri May 3 17:07:53 2019 +0200 core: add package to secp256k1_zkp for mocking commit 8a12f26c8c0d99363c8df96012426abbbb3ff6cb Author: matejcik <ja@matejcik.cz> Date: Fri May 3 17:04:05 2019 +0200 core: blackify extmod docstring quotes commit b6f239676dde8b60b001fcae4e5de80a71dbacf2 Author: matejcik <ja@matejcik.cz> Date: Fri May 3 16:52:27 2019 +0200 core: make build_mocks directory agnostic mocks: detect bad packages mocks: revert noqa in favor of setup.cfg mocks: fix broken comment formattingpull/160/head
parent
ffcb5e99cc
commit
482b4569f5
@ -1,82 +1,99 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def init(ui_wait_callback: (int, int -> None)=None) -> None:
|
||||
'''
|
||||
def init(ui_wait_callback: Tuple[int, Callable[int, None]] = None) -> None:
|
||||
"""
|
||||
Initializes the storage. Must be called before any other method is
|
||||
called from this module!
|
||||
'''
|
||||
"""
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def check_pin(pin: int) -> bool:
|
||||
'''
|
||||
Check the given PIN. Returns True on success, False on failure.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def unlock(pin: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Attempts to unlock the storage with given PIN. Returns True on
|
||||
success, False on failure.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def check_pin(pin: int) -> bool:
|
||||
"""
|
||||
Check the given PIN. Returns True on success, False on failure.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def lock() -> None:
|
||||
'''
|
||||
"""
|
||||
Locks the storage.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def has_pin() -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns True if storage has a configured PIN, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def get_pin_rem() -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the number of remaining PIN entry attempts.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def change_pin(pin: int, newpin: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Change PIN. Returns True on success, False on failure.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def get(app: int, key: int, public: bool=False) -> bytes:
|
||||
'''
|
||||
def get(app: int, key: int, public: bool = False) -> bytes:
|
||||
"""
|
||||
Gets the value of the given key for the given app (or None if not set).
|
||||
Raises a RuntimeError if decryption or authentication of the stored value fails.
|
||||
'''
|
||||
Raises a RuntimeError if decryption or authentication of the stored
|
||||
value fails.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def set(app: int, key: int, value: bytes, public: bool=False) -> None:
|
||||
'''
|
||||
def set(app: int, key: int, value: bytes, public: bool = False) -> None:
|
||||
"""
|
||||
Sets a value of given key for given app.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def delete(app: int, key: int, public: bool=False) -> bool:
|
||||
'''
|
||||
def delete(app: int, key: int, public: bool = False) -> bool:
|
||||
"""
|
||||
Deletes the given key of the given app.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def set_counter(app: int, key: int, count: int, writable_locked: bool=False) -> bool:
|
||||
'''
|
||||
def set_counter(
|
||||
app: int, key: int, count: int, writable_locked: bool = False
|
||||
) -> bool:
|
||||
"""
|
||||
Sets the given key of the given app as a counter with the given value.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def next_counter(app: int, key: int, writable_locked: bool=False) -> bool:
|
||||
'''
|
||||
Increments the counter stored under the given key of the given app and returns the new value.
|
||||
'''
|
||||
def next_counter(app: int, key: int, writable_locked: bool = False) -> bool:
|
||||
"""
|
||||
Increments the counter stored under the given key of the given app and
|
||||
returns the new value.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def wipe() -> None:
|
||||
'''
|
||||
"""
|
||||
Erases the whole config. Use with caution!
|
||||
'''
|
||||
"""
|
||||
|
@ -1,312 +1,347 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||
class AES:
|
||||
'''
|
||||
"""
|
||||
AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def encrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Encrypt data and update AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def decrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Decrypt data and update AES context.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake256.h
|
||||
class Blake256:
|
||||
'''
|
||||
"""
|
||||
Blake256 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-blake2b.h
|
||||
class Blake2b:
|
||||
'''
|
||||
"""
|
||||
Blake2b context.
|
||||
'''
|
||||
|
||||
def __init__(self, data: bytes = None, outlen: int = Blake2b.digest_size, personal: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: bytes = None,
|
||||
outlen: int = Blake2b.digest_size,
|
||||
personal: 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, outlen: int = Blake2s.digest_size, key: bytes = None, personal: bytes = None) -> None:
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: bytes = None,
|
||||
outlen: int = Blake2s.digest_size,
|
||||
key: bytes = None,
|
||||
personal: 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-chacha20poly1305.h
|
||||
class ChaCha20Poly1305:
|
||||
'''
|
||||
"""
|
||||
ChaCha20Poly1305 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, key: bytes, nonce: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Initialize the ChaCha20 + Poly1305 context for encryption or decryption
|
||||
using a 32 byte key and 12 byte nonce as in the RFC 7539 style.
|
||||
'''
|
||||
"""
|
||||
|
||||
def encrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
Encrypt data (length of data must be divisible by 64 except for the final value).
|
||||
'''
|
||||
"""
|
||||
Encrypt data (length of data must be divisible by 64 except for the
|
||||
final value).
|
||||
"""
|
||||
|
||||
def decrypt(self, data: bytes) -> bytes:
|
||||
'''
|
||||
Decrypt data (length of data must be divisible by 64 except for the final value).
|
||||
'''
|
||||
"""
|
||||
Decrypt data (length of data must be divisible by 64 except for the
|
||||
final value).
|
||||
"""
|
||||
|
||||
def auth(self, data: bytes) -> None:
|
||||
'''
|
||||
"""
|
||||
Include authenticated data in the Poly1305 MAC using the RFC 7539
|
||||
style with 16 byte padding. This must only be called once and prior
|
||||
to encryption or decryption.
|
||||
'''
|
||||
"""
|
||||
|
||||
def finish(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Compute RFC 7539-style Poly1305 MAC.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-groestl.h
|
||||
class Groestl512:
|
||||
'''
|
||||
"""
|
||||
GROESTL512 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-pbkdf2.h
|
||||
class Pbkdf2:
|
||||
'''
|
||||
"""
|
||||
PBKDF2 context.
|
||||
'''
|
||||
|
||||
def __init__(self, prf: int, password: bytes, salt: bytes, iterations: int = None, blocknr: int = 1) -> None:
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
prf: int,
|
||||
password: bytes,
|
||||
salt: bytes,
|
||||
iterations: int = None,
|
||||
blocknr: int = 1,
|
||||
) -> 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-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-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, keccak = False) -> None:
|
||||
'''
|
||||
def __init__(self, data: bytes = None, keccak: bool = False) -> 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def copy(self) -> sha3:
|
||||
'''
|
||||
"""
|
||||
Returns the copy of the digest object with the current state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
class Sha3_512:
|
||||
'''
|
||||
"""
|
||||
SHA3_512 context.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, data: bytes = None, keccak = False) -> None:
|
||||
'''
|
||||
def __init__(self, data: bytes = None, keccak: bool = False) -> 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def copy(self) -> sha3:
|
||||
'''
|
||||
"""
|
||||
Returns the copy of the digest object with the current state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,118 +1,126 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
class HDNode:
|
||||
'''
|
||||
"""
|
||||
BIP0032 HD node structure.
|
||||
'''
|
||||
|
||||
def __init__(self,
|
||||
depth: int,
|
||||
fingerprint: int,
|
||||
child_num: int,
|
||||
chain_code: bytes,
|
||||
private_key: bytes = None,
|
||||
public_key: bytes = None,
|
||||
curve_name: str = None) -> None:
|
||||
'''
|
||||
'''
|
||||
|
||||
def derive(self, index: int, public: bool=False) -> None:
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
depth: int,
|
||||
fingerprint: int,
|
||||
child_num: int,
|
||||
chain_code: bytes,
|
||||
private_key: bytes = None,
|
||||
public_key: bytes = None,
|
||||
curve_name: str = None,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def derive(self, index: int, public: bool = False) -> None:
|
||||
"""
|
||||
Derive a BIP0032 child node in place.
|
||||
'''
|
||||
"""
|
||||
|
||||
def derive_cardano(self, index: int) -> None:
|
||||
'''
|
||||
"""
|
||||
Derive a BIP0032 child node in place using Cardano algorithm.
|
||||
'''
|
||||
"""
|
||||
|
||||
def derive_path(self, path: List[int]) -> None:
|
||||
'''
|
||||
Go through a list of indexes and iteratively derive a child node in place.
|
||||
'''
|
||||
"""
|
||||
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 private_key_ext(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Returns a private key extension 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
def nem_address(self, network: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Compute a NEM address string from the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def nem_encrypt(self, transfer_public_key: bytes, iv: bytes, salt: bytes, payload: bytes) -> bytes:
|
||||
'''
|
||||
def nem_encrypt(
|
||||
self, transfer_public_key: bytes, iv: bytes, salt: bytes, payload: bytes
|
||||
) -> bytes:
|
||||
"""
|
||||
Encrypts payload using the transfer's public key
|
||||
'''
|
||||
"""
|
||||
|
||||
def ethereum_pubkeyhash(self) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Compute an Ethereum pubkeyhash (aka address) from the HD node.
|
||||
'''
|
||||
"""
|
||||
|
||||
def deserialize(self, 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.
|
||||
'''
|
||||
"""
|
||||
|
||||
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
|
||||
'''
|
||||
"""
|
||||
|
@ -1,38 +1,47 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def find_word(prefix: str) -> Optional[str]:
|
||||
'''
|
||||
"""
|
||||
Return the first word from the wordlist starting with prefix.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def complete_word(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.
|
||||
'''
|
||||
Result is a bitmask, with 'a' on the lowest bit, 'b' on the second
|
||||
lowest, etc.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def generate(strength: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def from_data(data: bytes) -> str:
|
||||
'''
|
||||
"""
|
||||
Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def check(mnemonic: str) -> bool:
|
||||
'''
|
||||
"""
|
||||
Check whether given mnemonic is valid.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def seed(mnemonic: str, passphrase: str, callback: (int, int -> None)=None) -> bytes:
|
||||
'''
|
||||
def seed(
|
||||
mnemonic: str, passphrase: str, callback: Tuple[int, int, None] = None
|
||||
) -> bytes:
|
||||
"""
|
||||
Generate seed from mnemonic and passphrase.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,20 +1,23 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def multiply(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.
|
||||
"""
|
||||
|
@ -1,50 +1,66 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def sign(secret_key: bytes, message: bytes, hasher: str='') -> bytes:
|
||||
'''
|
||||
def sign(secret_key: bytes, message: bytes, hasher: str = "") -> bytes:
|
||||
"""
|
||||
Uses secret key to produce the signature of message.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def sign_ext(secret_key: bytes, secret_extension: bytes, message: bytes) -> bytes:
|
||||
'''
|
||||
def sign_ext(
|
||||
secret_key: bytes, secret_extension: bytes, message: bytes
|
||||
) -> bytes:
|
||||
"""
|
||||
Uses secret key to produce the cardano signature of message.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def verify(public_key: bytes, signature: bytes, message: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the message.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_combine_publickeys(public_keys: List[bytes]) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Combines a list of public keys used in COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_combine_signatures(R: bytes, signatures: List[bytes]) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Combines a list of signatures used in COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def cosi_sign(secret_key: bytes, message: bytes, nonce: bytes, sigR: bytes, combined_pubkey: bytes) -> bytes:
|
||||
'''
|
||||
def cosi_sign(
|
||||
secret_key: bytes,
|
||||
message: bytes,
|
||||
nonce: bytes,
|
||||
sigR: bytes,
|
||||
combined_pubkey: bytes,
|
||||
) -> bytes:
|
||||
"""
|
||||
Produce signature of message using COSI cosigning scheme.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,313 +1,407 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point on ED25519
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[Union[Ge25519, bytes]] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Sc25519:
|
||||
'''
|
||||
"""
|
||||
EC scalar on SC25519
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[Union[Sc25519, bytes, int]] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
class Hasher:
|
||||
'''
|
||||
"""
|
||||
XMR hasher
|
||||
'''
|
||||
"""
|
||||
def __init__(x: Optional[bytes] = None):
|
||||
'''
|
||||
"""
|
||||
Constructor
|
||||
'''
|
||||
def update(buffer: bytes):
|
||||
'''
|
||||
"""
|
||||
def update(buffer: bytes):
|
||||
"""
|
||||
Update hasher
|
||||
'''
|
||||
def digest() -> bytes:
|
||||
'''
|
||||
"""
|
||||
def digest() -> bytes:
|
||||
"""
|
||||
Computes digest
|
||||
'''
|
||||
def copy() -> Hasher:
|
||||
'''
|
||||
"""
|
||||
def copy() -> Hasher:
|
||||
"""
|
||||
Creates copy of the hasher, preserving the state
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def init256_modm(dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]) -> Sc25519:
|
||||
'''
|
||||
def init256_modm(
|
||||
dst: Optional[Sc25519], val: Union[int, bytes, Sc25519]
|
||||
) -> Sc25519:
|
||||
"""
|
||||
Initializes Sc25519 scalar
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def check256_modm(val: Sc25519):
|
||||
'''
|
||||
"""
|
||||
Throws exception if scalar is invalid
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def iszero256_modm(val: Sc25519) -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns False if the scalar is zero
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def eq256_modm(a: Sc25519, b: Sc25519) -> int:
|
||||
'''
|
||||
"""
|
||||
Compares scalars, returns 1 on the same value
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def get256_modm(a: Sc25519) -> int:
|
||||
'''
|
||||
Extracts 64bit integer from the scalar. Raises exception if scalar is bigger than 2^64
|
||||
'''
|
||||
"""
|
||||
Extracts 64bit integer from the scalar. Raises exception if scalar is
|
||||
bigger than 2^64
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def add256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar addition
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def sub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar subtraction
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def mul256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar multiplication
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def mulsub256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) -> Sc25519:
|
||||
'''
|
||||
def mulsub256_modm(
|
||||
r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
|
||||
) -> Sc25519:
|
||||
"""
|
||||
c - a*b
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def muladd256_modm(r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519) -> Sc25519:
|
||||
'''
|
||||
def muladd256_modm(
|
||||
r: Optional[Sc25519], a: Sc25519, b: Sc25519, c: Sc25519
|
||||
) -> Sc25519:
|
||||
"""
|
||||
c + a*b
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def inv256_modm(r: Optional[Sc25519], a: Sc25519) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Scalar modular inversion
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def pack256_modm(r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0) -> bytes:
|
||||
'''
|
||||
def pack256_modm(
|
||||
r: Optional[bytes], a: Sc25519, offset: Optional[int] = 0
|
||||
) -> bytes:
|
||||
"""
|
||||
Scalar compression
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def unpack256_modm(r: Optional[Sc25519], a: bytes, offset: int = 0) -> Sc25519:
|
||||
'''
|
||||
def unpack256_modm(
|
||||
r: Optional[Sc25519], a: bytes, offset: int = 0
|
||||
) -> Sc25519:
|
||||
"""
|
||||
Scalar decompression
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def unpack256_modm_noreduce(r: Optional[Sc25519], a: bytes, offset: int = 0) -> Sc25519:
|
||||
'''
|
||||
def unpack256_modm_noreduce(
|
||||
r: Optional[Sc25519], a: bytes, offset: int = 0
|
||||
) -> Sc25519:
|
||||
"""
|
||||
Scalar decompression, raw, without modular reduction
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_set_neutral(r: Optional[Ge25519]) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Sets neutral point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_set_xmr_h(r: Optional[Ge25519]) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Sets H point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_check(r: Ge25519):
|
||||
'''
|
||||
"""
|
||||
Checks point, throws if not on curve
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_eq(a: Ge25519, b: Ge25519) -> bool:
|
||||
'''
|
||||
"""
|
||||
Compares EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_add(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Adds EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_sub(r: Optional[Ge25519], a: Ge25519, b: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
Subtracts EC points
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_double(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point doubling
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_mul8(r: Optional[Ge25519], p: Ge25519) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
EC point * 8
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_double_scalarmult_vartime(r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, s2: Sc25519) -> Ge25519:
|
||||
'''
|
||||
def ge25519_double_scalarmult_vartime(
|
||||
r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, s2: Sc25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
s1 * G + s2 * p1
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_double_scalarmult_vartime2(r: Optional[Ge25519], p1: Ge25519, s1: Sc25519, p2: Ge25519, s2: Sc25519) -> Ge25519:
|
||||
'''
|
||||
def ge25519_double_scalarmult_vartime2(
|
||||
r: Optional[Ge25519],
|
||||
p1: Ge25519,
|
||||
s1: Sc25519,
|
||||
p2: Ge25519,
|
||||
s2: Sc25519,
|
||||
) -> Ge25519:
|
||||
"""
|
||||
s1 * p1 + s2 * p2
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_scalarmult_base(r: Optional[Ge25519], s: Union[Sc25519, int]) -> Ge25519:
|
||||
'''
|
||||
def ge25519_scalarmult_base(
|
||||
r: Optional[Ge25519], s: Union[Sc25519, int]
|
||||
) -> Ge25519:
|
||||
"""
|
||||
s * G
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_scalarmult(r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, int]) -> Ge25519:
|
||||
'''
|
||||
def ge25519_scalarmult(
|
||||
r: Optional[Ge25519], p: Ge25519, s: Union[Sc25519, int]
|
||||
) -> Ge25519:
|
||||
"""
|
||||
s * p
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_pack(r: bytes, p: Ge25519, offset: int = 0) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Point compression
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ge25519_unpack_vartime(r: Optional[Ge25519], buff: bytes, offset: int = 0) -> Ge25519:
|
||||
'''
|
||||
def ge25519_unpack_vartime(
|
||||
r: Optional[Ge25519], buff: bytes, offset: int = 0
|
||||
) -> Ge25519:
|
||||
"""
|
||||
Point decompression
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def base58_addr_encode_check(tag: int, buff: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Monero block base 58 encoding
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def base58_addr_decode_check(buff: bytes) -> Tuple[bytes, int]:
|
||||
'''
|
||||
Monero block base 58 decoding, returning (decoded, tag) or raising on error.
|
||||
'''
|
||||
"""
|
||||
Monero block base 58 decoding, returning (decoded, tag) or raising on
|
||||
error.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_random_scalar(r: Optional[Sc25519] = None) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
Generates a random scalar
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_fast_hash(r: Optional[bytes], buff: bytes) -> bytes:
|
||||
'''
|
||||
"""
|
||||
XMR fast hash
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_hash_to_ec(r: Optional[Ge25519], buff: bytes) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
XMR hashing to EC point
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_hash_to_scalar(r: Optional[Sc25519], buff: bytes) -> Sc25519:
|
||||
'''
|
||||
"""
|
||||
XMR hashing to EC scalar
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_derivation_to_scalar(r: Optional[Sc25519], p: Ge25519, output_index: int) -> Sc25519:
|
||||
'''
|
||||
def xmr_derivation_to_scalar(
|
||||
r: Optional[Sc25519], p: Ge25519, output_index: int
|
||||
) -> Sc25519:
|
||||
"""
|
||||
H_s(derivation || varint(output_index))
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_generate_key_derivation(r: Optional[Ge25519], A: Ge25519, b: Sc25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_generate_key_derivation(
|
||||
r: Optional[Ge25519], A: Ge25519, b: Sc25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
8*(key2*key1)
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_derive_private_key(r: Optional[Sc25519], deriv: Ge25519, idx: int, base: Sc25519) -> Sc25519:
|
||||
'''
|
||||
def xmr_derive_private_key(
|
||||
r: Optional[Sc25519], deriv: Ge25519, idx: int, base: Sc25519
|
||||
) -> Sc25519:
|
||||
"""
|
||||
base + H_s(derivation || varint(output_index))
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_derive_public_key(r: Optional[Ge25519], deriv: Ge25519, idx: int, base: Ge25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_derive_public_key(
|
||||
r: Optional[Ge25519], deriv: Ge25519, idx: int, base: Ge25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
H_s(derivation || varint(output_index))G + base
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_add_keys2(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_add_keys2(
|
||||
r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
aG + bB, G is basepoint
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_add_keys2_vartime(r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_add_keys2_vartime(
|
||||
r: Optional[Ge25519], a: Sc25519, b: Sc25519, B: Ge25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
aG + bB, G is basepoint
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_add_keys3(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_add_keys3(
|
||||
r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
aA + bB
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_add_keys3_vartime(r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519) -> Ge25519:
|
||||
'''
|
||||
def xmr_add_keys3_vartime(
|
||||
r: Optional[Ge25519], a: Sc25519, A: Ge25519, b: Sc25519, B: Ge25519
|
||||
) -> Ge25519:
|
||||
"""
|
||||
aA + bB
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_get_subaddress_secret_key(r: Optional[Sc25519], major: int, minor: int, m: Sc25519) -> Sc25519:
|
||||
'''
|
||||
def xmr_get_subaddress_secret_key(
|
||||
r: Optional[Sc25519], major: int, minor: int, m: Sc25519
|
||||
) -> Sc25519:
|
||||
"""
|
||||
Hs(SubAddr || a || index_major || index_minor)
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def xmr_gen_c(r: Optional[Ge25519], a: Sc25519, amount: int) -> Ge25519:
|
||||
'''
|
||||
"""
|
||||
aG + amount * H
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-monero.h
|
||||
def ct_equals(a: bytes, b: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Constant time buffer comparison
|
||||
'''
|
||||
"""
|
||||
|
@ -1,13 +1,15 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h
|
||||
def validate_address(address: str, network: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Validate a NEM address
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nem.h
|
||||
def compute_address(public_key: bytes, network: int) -> str:
|
||||
'''
|
||||
"""
|
||||
Compute a NEM address from a public key
|
||||
'''
|
||||
"""
|
||||
|
@ -1,40 +1,48 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def sign(secret_key: bytes, digest: bytes, compressed: bool = True) -> bytes:
|
||||
'''
|
||||
def sign(
|
||||
secret_key: bytes, digest: bytes, compressed: bool = True
|
||||
) -> bytes:
|
||||
"""
|
||||
Uses secret key to produce the signature of the digest.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the digest.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def verify_recover(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.
|
||||
'''
|
||||
"""
|
||||
Uses signature of the digest to verify the digest and recover the public
|
||||
key. Returns public key on success, None if the signature is invalid.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def multiply(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.
|
||||
"""
|
||||
|
@ -1,19 +1,22 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def uniform(n: int) -> int:
|
||||
'''
|
||||
"""
|
||||
Compute uniform random number from interval 0 ... n - 1.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def bytes(len: int) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate random bytes sequence of length len.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def shuffle(data: list) -> None:
|
||||
'''
|
||||
"""
|
||||
Shuffles items of given list (in-place).
|
||||
'''
|
||||
"""
|
||||
|
@ -1,40 +1,51 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
"""
|
||||
Generate secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
'''
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def sign(secret_key: bytes, digest: bytes, compressed: bool = True, canonical: int = None) -> bytes:
|
||||
'''
|
||||
def sign(
|
||||
secret_key: bytes,
|
||||
digest: bytes,
|
||||
compressed: bool = True,
|
||||
canonical: int = None,
|
||||
) -> bytes:
|
||||
"""
|
||||
Uses secret key to produce the signature of the digest.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Uses public key to verify the signature of the digest.
|
||||
Returns True on success.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def verify_recover(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.
|
||||
'''
|
||||
"""
|
||||
Uses signature of the digest to verify the digest and recover the public
|
||||
key. Returns public key on success, None if the signature is invalid.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def multiply(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.
|
||||
"""
|
||||
|
@ -0,0 +1,48 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def generate_secret() -> bytes:
|
||||
"""
|
||||
Generate secret key.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def publickey(secret_key: bytes, compressed: bool = True) -> bytes:
|
||||
"""
|
||||
Computes public key from secret key.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def sign(
|
||||
secret_key: bytes, digest: bytes, compressed: bool = True
|
||||
) -> bytes:
|
||||
"""
|
||||
Uses secret key to produce the signature of the digest.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
||||
"""
|
||||
Uses public key to verify the signature of the digest.
|
||||
Returns True on success.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def verify_recover(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 if the signature is invalid.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1_zkp.h
|
||||
def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
||||
"""
|
||||
Multiplies point defined by public_key with scalar defined by
|
||||
secret_key. Useful for ECDH.
|
||||
"""
|
@ -1,206 +1,223 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-flash.h
|
||||
class FlashOTP:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def FlashOTP.write(self, block: int, offset: int, data: bytes) -> None:
|
||||
'''
|
||||
def write(self, block: int, offset: int, data: bytes) -> None:
|
||||
"""
|
||||
Writes data to OTP flash
|
||||
'''
|
||||
"""
|
||||
|
||||
def FlashOTP.read(self, block: int, offset: int, data: bytearray) -> None:
|
||||
'''
|
||||
def read(self, block: int, offset: int, data: bytearray) -> None:
|
||||
"""
|
||||
Reads data from OTP flash
|
||||
'''
|
||||
"""
|
||||
|
||||
def FlashOTP.lock(self, block: int) -> None:
|
||||
'''
|
||||
def lock(self, block: int) -> None:
|
||||
"""
|
||||
Lock OTP flash block
|
||||
'''
|
||||
"""
|
||||
|
||||
def FlashOTP.is_locked(self, block: int) -> bool:
|
||||
'''
|
||||
def is_locked(self, block: int) -> bool:
|
||||
"""
|
||||
Is OTP flash block locked?
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-hid.h
|
||||
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:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
|
||||
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:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
def write(self, msg: bytes) -> int:
|
||||
'''
|
||||
"""
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-poll.h
|
||||
def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool:
|
||||
'''
|
||||
"""
|
||||
Wait until one of `ifaces` is ready to read or write (using masks
|
||||
`list_ref`:
|
||||
`list_ref[0]` - the interface number, including the mask
|
||||
`list_ref[1]` - for touch event, tuple of (event_type, x_position, y_position)
|
||||
`list_ref[1]` - for touch event, tuple of (event_type, x_position,
|
||||
y_position)
|
||||
- for USB read event, received bytes
|
||||
If timeout occurs, False is returned, True otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-sbu.h
|
||||
class SBU:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def set(self, sbu1: bool, sbu2: bool) -> None:
|
||||
'''
|
||||
"""
|
||||
Sets SBU wires to sbu1 and sbu2 values respectively
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-sdcard.h
|
||||
class SDCard:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
"""
|
||||
|
||||
def present(self) -> bool:
|
||||
'''
|
||||
"""
|
||||
Returns True if SD card is detected, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
def power(self, state: bool) -> bool:
|
||||
'''
|
||||
"""
|
||||
Power on or power off the SD card interface.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
"""
|
||||
|
||||
def capacity(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns capacity of the SD card in bytes, or zero if not present.
|
||||
'''
|
||||
"""
|
||||
|
||||
def read(self, block_num: int, buf: bytearray) -> bool:
|
||||
'''
|
||||
"""
|
||||
Reads blocks starting with block_num from the SD card into buf.
|
||||
Number of bytes read is length of buf rounded down to multiply of SDCARD_BLOCK_SIZE.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
Number of bytes read is length of buf rounded down to multiply of
|
||||
SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
|
||||
"""
|
||||
|
||||
def write(self, block_num: int, buf: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Writes blocks starting with block_num from buf to the SD card.
|
||||
Number of bytes written is length of buf rounded down to multiply of SDCARD_BLOCK_SIZE.
|
||||
Returns True if in case of success, False otherwise.
|
||||
'''
|
||||
Number of bytes written is length of buf rounded down to multiply of
|
||||
SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-usb.h
|
||||
class USB:
|
||||
'''
|
||||
"""
|
||||
USB device configuration.
|
||||
'''
|
||||
|
||||
def __init__(self,
|
||||
device_class: int=0,
|
||||
device_subclass: int=0,
|
||||
device_protocol: int=0,
|
||||
vendor_id: int,
|
||||
product_id: int,
|
||||
release_num: int,
|
||||
manufacturer: str='',
|
||||
product: str='',
|
||||
serial_number: str='',
|
||||
interface: str='',
|
||||
usb21_enabled: bool=True,
|
||||
usb21_landing: bool=True) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vendor_id: int,
|
||||
product_id: int,
|
||||
release_num: int,
|
||||
device_class: int = 0,
|
||||
device_subclass: int = 0,
|
||||
device_protocol: int = 0,
|
||||
manufacturer: str = "",
|
||||
product: str = "",
|
||||
serial_number: str = "",
|
||||
interface: str = "",
|
||||
usb21_enabled: bool = True,
|
||||
usb21_landing: bool = True,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def add(self, iface: Union[HID, VCP, WebUSB]) -> None:
|
||||
'''
|
||||
"""
|
||||
Registers passed interface into the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
def open(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Initializes the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
def close(self) -> None:
|
||||
'''
|
||||
"""
|
||||
Cleans up the USB stack.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-vcp.h
|
||||
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:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
iface_num: int,
|
||||
data_iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
ep_cmd: int,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-webusb.h
|
||||
class WebUSB:
|
||||
'''
|
||||
"""
|
||||
USB WebUSB interface configuration.
|
||||
'''
|
||||
|
||||
def __init__(self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64) -> None:
|
||||
'''
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
iface_num: int,
|
||||
ep_in: int,
|
||||
ep_out: int,
|
||||
subclass: int = 0,
|
||||
protocol: int = 0,
|
||||
polling_interval: int = 1,
|
||||
max_packet_len: int = 64,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
|
||||
def iface_num(self) -> int:
|
||||
'''
|
||||
"""
|
||||
Returns the configured number of this interface.
|
||||
'''
|
||||
"""
|
||||
|
||||
def write(self, msg: bytes) -> int:
|
||||
'''
|
||||
"""
|
||||
Sends message using USB WebUSB (device) or UDP (emulator).
|
||||
'''
|
||||
"""
|
||||
|
@ -1,124 +1,182 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# 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.
|
||||
'''
|
||||
"""
|
||||
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 avatar(self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int) -> None:
|
||||
'''
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) -
|
||||
full-color mode.
|
||||
"""
|
||||
|
||||
def avatar(
|
||||
self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int
|
||||
) -> None:
|
||||
"""
|
||||
Renders an avatar at position (x,y).
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode.
|
||||
Image needs to be of exactly AVATAR_IMAGE_SIZE x AVATAR_IMAGE_SIZE pixels size.
|
||||
'''
|
||||
|
||||
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 icon needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode.
|
||||
'''
|
||||
|
||||
def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None:
|
||||
'''
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) -
|
||||
full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
|
||||
AVATAR_IMAGE_SIZE pixels size.
|
||||
"""
|
||||
|
||||
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 icon needs to be in TREZOR Optimized Image
|
||||
Format (TOIF) - gray-scale mode.
|
||||
"""
|
||||
|
||||
def loader(
|
||||
self,
|
||||
progress: int,
|
||||
indeterminate: bool,
|
||||
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.
|
||||
'''
|
||||
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 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, minwidth: int=None) -> int:
|
||||
'''
|
||||
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.
|
||||
Fills at least minwidth pixels with bgcolor.
|
||||
Returns width of rendered text in pixels.
|
||||
'''
|
||||
|
||||
def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
|
||||
'''
|
||||
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.
|
||||
Fills at least minwidth pixels with bgcolor.
|
||||
Returns width of rendered text in pixels.
|
||||
'''
|
||||
|
||||
def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
|
||||
'''
|
||||
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.
|
||||
Fills at least minwidth pixels with bgcolor.
|
||||
Returns width of rendered text in pixels.
|
||||
'''
|
||||
"""
|
||||
|
||||
def text(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
minwidth: int = None,
|
||||
) -> int:
|
||||
"""
|
||||
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. Fills at least minwidth pixels
|
||||
with bgcolor. Returns width of rendered text in pixels.
|
||||
"""
|
||||
|
||||
def text_center(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
minwidth: int = None,
|
||||
) -> int:
|
||||
"""
|
||||
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. Fills at least minwidth pixels with
|
||||
bgcolor. Returns width of rendered text in pixels.
|
||||
"""
|
||||
|
||||
def text_right(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
minwidth: int = None,
|
||||
) -> int:
|
||||
"""
|
||||
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. Fills at least minwidth pixels
|
||||
with bgcolor. Returns width of rendered text in pixels.
|
||||
"""
|
||||
|
||||
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 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.
|
||||
'''
|
||||
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, prefix: str) -> None:
|
||||
'''
|
||||
"""
|
||||
Saves current display contents to PNG file with given prefix.
|
||||
'''
|
||||
"""
|
||||
|
@ -1,32 +1,36 @@
|
||||
from typing import *
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def consteq(sec: bytes, pub: bytes) -> bool:
|
||||
'''
|
||||
"""
|
||||
Compares the private information in `sec` with public, user-provided
|
||||
information in `pub`. Runs in constant time, corresponding to a length
|
||||
of `pub`. Can access memory behind valid length of `sec`, caller is
|
||||
expected to avoid any invalid memory access.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def 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
|
||||
copied bytes.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def halt(msg: str = None) -> None:
|
||||
'''
|
||||
"""
|
||||
Halts execution.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def set_mode_unprivileged() -> None:
|
||||
'''
|
||||
"""
|
||||
Set unprivileged mode.
|
||||
'''
|
||||
"""
|
||||
|
Loading…
Reference in new issue