mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-26 08:08:51 +00:00
mocks: update build script, refresh
This commit is contained in:
parent
62ad4d6a39
commit
fd1718f8b6
@ -1,18 +1,18 @@
|
||||
|
||||
# ../extmod/modtrezorconfig/modtrezorconfig.c
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def get(app: int, key: int) -> bytes:
|
||||
'''
|
||||
Gets a value of given key for given app (or None if not set).
|
||||
Gets a value of given key for given app (or empty bytes if not set).
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorconfig/modtrezorconfig.c
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def set(app: int, key: int, value: bytes) -> None:
|
||||
'''
|
||||
Sets a value of given key for given app.
|
||||
Returns True on success.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorconfig/modtrezorconfig.c
|
||||
# extmod/modtrezorconfig/modtrezorconfig.c
|
||||
def wipe() -> None:
|
||||
'''
|
||||
Erases the whole config (use with caution!)
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
def pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2:
|
||||
'''
|
||||
Create a PBKDF2 context
|
||||
|
@ -1,71 +1,71 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def derive(index: int) -> None:
|
||||
'''
|
||||
Derive a BIP0032 child node in place.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def derive_path(path: list) -> None:
|
||||
'''
|
||||
Go through a list of indexes and iteratively derive a child node in place.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def serialize_public() -> str:
|
||||
'''
|
||||
Serialize the public info from HD node to base58 string.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def serialize_private() -> str:
|
||||
'''
|
||||
Serialize the private info HD node to base58 string.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def clone() -> HDNode:
|
||||
'''
|
||||
Returns a copy of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def depth() -> int:
|
||||
'''
|
||||
Returns a depth of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def fingerprint() -> int:
|
||||
'''
|
||||
Returns a fingerprint of the HD node (hash of the parent public key).
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def child_num() -> int:
|
||||
'''
|
||||
Returns a child index of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def chain_code() -> bytes:
|
||||
'''
|
||||
Returns a chain code of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def private_key() -> bytes:
|
||||
'''
|
||||
Returns a private key of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def public_key() -> bytes:
|
||||
'''
|
||||
Returns a public key of the HD node.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def address(version: int) -> str:
|
||||
'''
|
||||
Compute a base58-encoded address string from the HD node.
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||
def update(self, data: bytes) -> bytes:
|
||||
'''
|
||||
Update AES context
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def deserialize(value: str) -> HDNode:
|
||||
'''
|
||||
Construct a BIP0032 HD node from a base58-serialized value.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
|
||||
def from_seed(seed: bytes, curve_name: str) -> HDNode:
|
||||
'''
|
||||
Construct a BIP0032 HD node from a BIP0039 seed value.
|
||||
|
@ -1,23 +1,36 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def find_word(prefix: str) -> 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.
|
||||
'''
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def check(mnemonic: str) -> bool:
|
||||
'''
|
||||
Check whether given mnemonic is valid
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
def seed(mnemonic: str, passphrase: str) -> bytes:
|
||||
'''
|
||||
Generate seed from mnemonic and passphrase
|
||||
|
@ -1,17 +1,17 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
Generate secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-curve25519.h
|
||||
# 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
|
||||
|
@ -1,25 +1,43 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
Generate secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def publickey(secret_key: bytes) -> bytes:
|
||||
'''
|
||||
Computes public key from secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
def sign(secret_key: bytes, message: bytes) -> bytes:
|
||||
'''
|
||||
Uses secret key to produce the signature of message.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
# 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:
|
||||
'''
|
||||
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:
|
||||
'''
|
||||
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:
|
||||
'''
|
||||
Produce signature of message using COSI cosigning scheme
|
||||
'''
|
||||
|
@ -1,30 +1,37 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
Generate secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
# 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) -> bytes:
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.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-nist256p1.h
|
||||
# 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
|
||||
# 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.
|
||||
'''
|
||||
|
||||
# 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
|
||||
|
@ -1,30 +1,37 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
def generate_secret() -> bytes:
|
||||
'''
|
||||
Generate secret key.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
# 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) -> bytes:
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.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.h
|
||||
# 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
|
||||
# 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.
|
||||
'''
|
||||
|
||||
# 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
|
||||
|
@ -1,41 +1,48 @@
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
def blake2s(data: bytes=None, key: bytes=None) -> Blake2s:
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
|
||||
def blake2b(data: bytes=None, key: bytes=None) -> Blake2b:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
def sha1(data: bytes=None) -> Sha1:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
def ripemd160(data: bytes=None) -> Ripemd160:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
def sha256(data: bytes=None) -> Sha256:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
def sha512(data: bytes=None) -> Sha512:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
def sha3_256(data: bytes=None) -> Sha3_256:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
def sha512(data: bytes=None) -> Sha512:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
def sha256(data: bytes=None) -> Sha256:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
def ripemd160(data: bytes=None) -> Ripemd160:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
def sha3_512(data: bytes=None) -> Sha3_512:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
def sha1(data: bytes=None) -> Sha1:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
def blake2s(data: bytes=None, key: bytes=None) -> Blake2s:
|
||||
'''
|
||||
Creates a hash context object.
|
||||
'''
|
||||
|
12
mocks/trezor/crypto/hashlib/blake2b.py
Normal file
12
mocks/trezor/crypto/hashlib/blake2b.py
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
'''
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha1.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
def digest(self, keccak: bool=False) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
def update(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
def digest(self, keccak: bool=False) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
def hash(self, data: bytes) -> None:
|
||||
'''
|
||||
Update the hash context with hashed data.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
def digest(self) -> bytes:
|
||||
'''
|
||||
Returns the digest of hashed data.
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
def update(self, iterations: int) -> None:
|
||||
'''
|
||||
Update a PBKDF2 context
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||
def key(self) -> bytes:
|
||||
'''
|
||||
Retreive derived key
|
||||
|
@ -1,17 +1,17 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def uniform(n: int) -> int:
|
||||
'''
|
||||
Compute uniform random number from interval 0 ... n - 1
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def bytes(len: int) -> bytes:
|
||||
'''
|
||||
Generate random bytes sequence of length len
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
def shuffle(data: list) -> None:
|
||||
'''
|
||||
Shuffles items of given list (in-place)
|
||||
|
6
mocks/trezor/crypto/rfc6979.py
Normal file
6
mocks/trezor/crypto/rfc6979.py
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h
|
||||
def next() -> bytes:
|
||||
'''
|
||||
Compute next 32-bytes of pseudorandom data
|
||||
'''
|
@ -1,11 +1,11 @@
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ssss.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ssss.h
|
||||
def split(m: int, n: int, secret: bytes) -> tuple:
|
||||
'''
|
||||
Split secret to (M of N) shares using Shamir's Secret Sharing Scheme
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorcrypto/modtrezorcrypto-ssss.h
|
||||
# extmod/modtrezorcrypto/modtrezorcrypto-ssss.h
|
||||
def combine(shares: tuple) -> bytes:
|
||||
'''
|
||||
Combine M shares of Shamir's Secret Sharing Scheme into secret
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# ../extmod/modtrezordebug/modtrezordebug.c
|
||||
# extmod/modtrezordebug/modtrezordebug.c
|
||||
def memaccess(address: int, length: int) -> bytes:
|
||||
'''
|
||||
Creates a bytes object that can be used to access certain memory location.
|
||||
|
@ -1,23 +1,23 @@
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
# extmod/modtrezormsg/modtrezormsg.c
|
||||
def set_interfaces(ifaces: list/tuple) -> None:
|
||||
'''
|
||||
Configures USB interfaces with a list/tuple of (usage_page, ...)
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
# extmod/modtrezormsg/modtrezormsg.c
|
||||
def get_interfaces() -> tuple:
|
||||
'''
|
||||
Reads a tuple (of usage pages) of configured USB interfaces
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
# extmod/modtrezormsg/modtrezormsg.c
|
||||
def send(usage_page: int, message: bytes) -> int:
|
||||
'''
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
# extmod/modtrezormsg/modtrezormsg.c
|
||||
def select(timeout_us: int) -> tuple:
|
||||
'''
|
||||
Polls the event queue and returns the event object.
|
||||
|
@ -1,78 +1,84 @@
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def clear() -> None
|
||||
'''
|
||||
Clear display (with black color)
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def refresh() -> None
|
||||
'''
|
||||
Refresh display (update screen)
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def bar(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def bar_radius(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def image(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def icon(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def text(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def print(text: str, fgcolor: int, bgcolor: int) -> None:
|
||||
'''
|
||||
Renders text using 5x8 bitmap font (using special text mode)
|
||||
'''
|
||||
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def text(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_center(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_center(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_right(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_right(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_width(text: bytes, font: int) -> int:
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def text_width(text: str, font: int) -> int:
|
||||
'''
|
||||
Returns a width of text in pixels. Font font is used for rendering.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def qrcode(x: int, y: int, data: bytes, scale: int) -> None:
|
||||
'''
|
||||
Renders data encoded as a QR code at position (x,y).
|
||||
Renders data encoded as a QR code centered at position (x,y).
|
||||
Scale determines a zoom factor.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None:
|
||||
'''
|
||||
Renders a rotating loader graphic.
|
||||
@ -81,7 +87,7 @@ def loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=
|
||||
Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def orientation(degrees: int=None) -> int:
|
||||
'''
|
||||
Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
@ -89,27 +95,21 @@ def orientation(degrees: int=None) -> int:
|
||||
Call without the degrees parameter to just perform the read of the value.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def backlight(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.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def offset(xy: tuple=None) -> tuple:
|
||||
'''
|
||||
Sets offset (x, y) for all subsequent drawing calls.
|
||||
Call without the xy parameter to just perform the read of the value.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def raw(reg: int, data: bytes=None) -> None:
|
||||
'''
|
||||
Performs a raw command on the display. Read the datasheet to learn more.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
# extmod/modtrezorui/modtrezorui-display.h
|
||||
def save(filename: string) -> None:
|
||||
'''
|
||||
Saves current display contents to file filename.
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# ../extmod/modtrezorutils/modtrezorutils.c
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def memcpy(dst: bytearray, dst_ofs: int,
|
||||
src: bytearray, src_ofs: int,
|
||||
'''
|
||||
@ -7,3 +7,9 @@ def memcpy(dst: bytearray, dst_ofs: int,
|
||||
`dst` at offset `dst_ofs`. Returns the number of actually
|
||||
copied bytes.
|
||||
'''
|
||||
|
||||
# extmod/modtrezorutils/modtrezorutils.c
|
||||
def halt(msg: str=None) -> None:
|
||||
'''
|
||||
Halts execution
|
||||
'''
|
||||
|
@ -6,7 +6,7 @@ COMMENT_PREFIX = '/// '
|
||||
current_method = None
|
||||
current_package = None
|
||||
|
||||
def split_to_parts(line, mod_file=None):
|
||||
def split_to_parts(line, mod_desc=None):
|
||||
global current_method
|
||||
global current_package
|
||||
# Line is beginning of method
|
||||
@ -18,7 +18,7 @@ def split_to_parts(line, mod_file=None):
|
||||
*current_package, method_name = current_method.split('.')
|
||||
|
||||
yield (current_package, "\n")
|
||||
yield (current_package, '# ' + mod_file + "\n")
|
||||
yield (current_package, '# ' + mod_desc + "\n")
|
||||
line = line.replace(current_method, method_name)
|
||||
|
||||
yield (current_package, line)
|
||||
@ -46,13 +46,13 @@ def build_module(mod_file, dest):
|
||||
if not (mod_file.endswith('.h') or mod_file.endswith('.c')):
|
||||
return
|
||||
|
||||
#print(mod_file)
|
||||
mod_desc = mod_file.replace('../micropython/extmod', 'extmod')
|
||||
for l in open(mod_file):
|
||||
if not l.startswith(COMMENT_PREFIX):
|
||||
continue
|
||||
|
||||
l = l[len(COMMENT_PREFIX):]#.strip()
|
||||
store_to_file(dest, split_to_parts(l, mod_file))
|
||||
store_to_file(dest, split_to_parts(l, mod_desc))
|
||||
|
||||
def build_directory(dir, dest):
|
||||
print("Building mocks for", dir, "to", dest)
|
||||
@ -80,4 +80,4 @@ def clear_directory(top_dir):
|
||||
|
||||
if __name__ == '__main__':
|
||||
clear_directory('../mocks')
|
||||
build_directory('../extmod', '../mocks')
|
||||
build_directory('../micropython/extmod', '../mocks')
|
||||
|
Loading…
Reference in New Issue
Block a user