mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-15 09:50:57 +00:00
Mocks generated from Core's C modules
This commit is contained in:
parent
d87e4e683d
commit
eea88f9bae
0
mocks/trezor/.mock-generated
Normal file
0
mocks/trezor/.mock-generated
Normal file
0
mocks/trezor/__init__.py
Normal file
0
mocks/trezor/__init__.py
Normal file
13
mocks/trezor/config.py
Normal file
13
mocks/trezor/config.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
# ../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).
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorconfig/modtrezorconfig.c
|
||||||
|
def set(app: int, key: int) -> bool:
|
||||||
|
'''
|
||||||
|
Sets a value of given key for given app.
|
||||||
|
Returns True on success.
|
||||||
|
'''
|
4
mocks/trezor/crypto.py
Normal file
4
mocks/trezor/crypto.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||||
|
def pbkdf2(prf: str, password: bytes, salt: bytes, iterations: int=None) -> Pbkdf2:
|
||||||
|
pass
|
0
mocks/trezor/crypto/.mock-generated
Normal file
0
mocks/trezor/crypto/.mock-generated
Normal file
0
mocks/trezor/crypto/__init__.py
Normal file
0
mocks/trezor/crypto/__init__.py
Normal file
0
mocks/trezor/crypto/aes/.mock-generated
Normal file
0
mocks/trezor/crypto/aes/.mock-generated
Normal file
6
mocks/trezor/crypto/aes/AES.py
Normal file
6
mocks/trezor/crypto/aes/AES.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-aes.h
|
||||||
|
def update(self, data: bytes) -> bytes:
|
||||||
|
'''
|
||||||
|
Update AES context
|
||||||
|
'''
|
0
mocks/trezor/crypto/aes/__init__.py
Normal file
0
mocks/trezor/crypto/aes/__init__.py
Normal file
24
mocks/trezor/crypto/bip39.py
Normal file
24
mocks/trezor/crypto/bip39.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
# ../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) -> bytes:
|
||||||
|
'''
|
||||||
|
Generate seed from mnemonic and passphrase
|
||||||
|
'''
|
0
mocks/trezor/crypto/curve/.mock-generated
Normal file
0
mocks/trezor/crypto/curve/.mock-generated
Normal file
0
mocks/trezor/crypto/curve/__init__.py
Normal file
0
mocks/trezor/crypto/curve/__init__.py
Normal file
19
mocks/trezor/crypto/curve/ed25519.py
Normal file
19
mocks/trezor/crypto/curve/ed25519.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
# ../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) -> bytes:
|
||||||
|
'''
|
||||||
|
Uses secret key to produce the 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.
|
||||||
|
'''
|
19
mocks/trezor/crypto/curve/nist256p1.py
Normal file
19
mocks/trezor/crypto/curve/nist256p1.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
# ../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, message: bytes) -> bytes:
|
||||||
|
'''
|
||||||
|
Uses secret key to produce the signature of message.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.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.
|
||||||
|
'''
|
19
mocks/trezor/crypto/curve/secp256k1.py
Normal file
19
mocks/trezor/crypto/curve/secp256k1.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
# ../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, message: bytes) -> bytes:
|
||||||
|
'''
|
||||||
|
Uses secret key to produce the signature of message.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.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.
|
||||||
|
'''
|
30
mocks/trezor/crypto/hashlib.py
Normal file
30
mocks/trezor/crypto/hashlib.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
# ../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-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-sha3-256.h
|
||||||
|
def sha3_256(data: bytes=None) -> Sha3_256:
|
||||||
|
'''
|
||||||
|
Creates a hash context object.
|
||||||
|
'''
|
0
mocks/trezor/crypto/hashlib/.mock-generated
Normal file
0
mocks/trezor/crypto/hashlib/.mock-generated
Normal file
12
mocks/trezor/crypto/hashlib/Ripemd160.py
Normal file
12
mocks/trezor/crypto/hashlib/Ripemd160.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||||
|
def update(self, data: bytes) -> None:
|
||||||
|
'''
|
||||||
|
Update the hash context with hashed data.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||||
|
def digest(self) -> bytes:
|
||||||
|
'''
|
||||||
|
Returns the digest of hashed data.
|
||||||
|
'''
|
12
mocks/trezor/crypto/hashlib/Sha256.py
Normal file
12
mocks/trezor/crypto/hashlib/Sha256.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||||
|
def update(self, data: bytes) -> None:
|
||||||
|
'''
|
||||||
|
Update the hash context with hashed data.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||||
|
def digest(self) -> bytes:
|
||||||
|
'''
|
||||||
|
Returns the digest of hashed data.
|
||||||
|
'''
|
12
mocks/trezor/crypto/hashlib/Sha3_256.py
Normal file
12
mocks/trezor/crypto/hashlib/Sha3_256.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../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
|
||||||
|
def digest(self) -> bytes:
|
||||||
|
'''
|
||||||
|
Returns the digest of hashed data.
|
||||||
|
'''
|
12
mocks/trezor/crypto/hashlib/Sha3_512.py
Normal file
12
mocks/trezor/crypto/hashlib/Sha3_512.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../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
|
||||||
|
def digest(self) -> bytes:
|
||||||
|
'''
|
||||||
|
Returns the digest of hashed data.
|
||||||
|
'''
|
12
mocks/trezor/crypto/hashlib/Sha512.py
Normal file
12
mocks/trezor/crypto/hashlib/Sha512.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||||
|
def hash(self, data: bytes) -> None:
|
||||||
|
'''
|
||||||
|
Update the hash context with hashed data.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||||
|
def digest(self) -> bytes:
|
||||||
|
'''
|
||||||
|
Returns the digest of hashed data.
|
||||||
|
'''
|
0
mocks/trezor/crypto/hashlib/__init__.py
Normal file
0
mocks/trezor/crypto/hashlib/__init__.py
Normal file
0
mocks/trezor/crypto/pbkdf2/.mock-generated
Normal file
0
mocks/trezor/crypto/pbkdf2/.mock-generated
Normal file
8
mocks/trezor/crypto/pbkdf2/Pbkdf2.py
Normal file
8
mocks/trezor/crypto/pbkdf2/Pbkdf2.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||||
|
def update(self, iterations: int) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h
|
||||||
|
def key(self) -> bytes:
|
||||||
|
pass
|
0
mocks/trezor/crypto/pbkdf2/__init__.py
Normal file
0
mocks/trezor/crypto/pbkdf2/__init__.py
Normal file
18
mocks/trezor/crypto/random.py
Normal file
18
mocks/trezor/crypto/random.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
# ../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)
|
||||||
|
'''
|
12
mocks/trezor/crypto/ssss.py
Normal file
12
mocks/trezor/crypto/ssss.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
# ../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
|
||||||
|
def combine(shares: tuple) -> bytes:
|
||||||
|
'''
|
||||||
|
Combine M shares of Shamir's Secret Sharing Scheme into secret
|
||||||
|
'''
|
6
mocks/trezor/debug.py
Normal file
6
mocks/trezor/debug.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezordebug/modtrezordebug.c
|
||||||
|
def memaccess(address: int, length: int) -> bytes:
|
||||||
|
'''
|
||||||
|
Creates a bytes object that can be used to access certain memory location.
|
||||||
|
'''
|
19
mocks/trezor/msg.py
Normal file
19
mocks/trezor/msg.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||||
|
def setup(ifaces: list) -> None:
|
||||||
|
'''
|
||||||
|
Configures USB interfaces with a list of tuples (interface_number, usage_page)
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||||
|
def send(iface: int, message: bytes) -> int:
|
||||||
|
'''
|
||||||
|
Sends message using USB HID (device) or UDP (emulator).
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||||
|
def select(timeout_us: int) -> tuple:
|
||||||
|
'''
|
||||||
|
Polls the event queue and returns the event object.
|
||||||
|
Function returns None if timeout specified in microseconds is reached.
|
||||||
|
'''
|
0
mocks/trezor/ui/.mock-generated
Normal file
0
mocks/trezor/ui/.mock-generated
Normal file
0
mocks/trezor/ui/__init__.py
Normal file
0
mocks/trezor/ui/__init__.py
Normal file
92
mocks/trezor/ui/display.py
Normal file
92
mocks/trezor/ui/display.py
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||||
|
def bar(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None:
|
||||||
|
'''
|
||||||
|
Renders a bar at position (x,y = upper left corner) with width w and height h of color fgcolor.
|
||||||
|
When a bgcolor is set, the bar is drawn with rounded corners and bgcolor is used for background.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||||
|
def blit(x: int, y: int, w: int, h: int, data: bytes) -> None:
|
||||||
|
'''
|
||||||
|
Renders rectangle at position (x,y = upper left corner) with width w and height h with data.
|
||||||
|
The data needs to have the correct format.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../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
|
||||||
|
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:
|
||||||
|
'''
|
||||||
|
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:
|
||||||
|
'''
|
||||||
|
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:
|
||||||
|
'''
|
||||||
|
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:
|
||||||
|
'''
|
||||||
|
Returns a width of text in pixels. Font font is used for rendering.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../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).
|
||||||
|
Scale determines a zoom factor.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||||
|
def loader(progress: 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 exaclty 96x96 pixels size.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||||
|
def orientation(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.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# ../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
|
||||||
|
def raw(reg: int, data: bytes) -> None:
|
||||||
|
'''
|
||||||
|
Performs a raw command on the display. Read the datasheet to learn more.
|
||||||
|
'''
|
Loading…
Reference in New Issue
Block a user