mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
add more docu
This commit is contained in:
parent
08009cbeb6
commit
c5b5955539
148
docs/api.md
148
docs/api.md
@ -26,37 +26,67 @@ def trezor.crypto.base58.decode_check(string: str) -> bytes
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.publickey(self, secret_key: bytes) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
```
|
||||
|
||||
Uses public key to verify the signature of the message
|
||||
Returns True on success.
|
||||
|
||||
|
||||
####trezor.crypto.curve.nist256p1
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.nist256p1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.nist256p1.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.nist256p1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
```
|
||||
|
||||
Uses public key to verify the signature of the message
|
||||
Returns True on success.
|
||||
|
||||
|
||||
####trezor.crypto.curve.secp256k1
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.secp256k1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.secp256k1.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.secp256k1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
```
|
||||
|
||||
Uses public key to verify the signature of the message
|
||||
Returns True on success.
|
||||
|
||||
|
||||
###trezor.crypto.hashlib
|
||||
|
||||
####trezor.crypto.hashlib.ripemd160
|
||||
@ -64,61 +94,106 @@ def trezor.crypto.curve.secp256k1.verify(self, public_key: bytes, signature: byt
|
||||
``` python
|
||||
def trezor.crypto.hashlib.ripemd160(self, data: bytes=None) -> Ripemd160
|
||||
```
|
||||
|
||||
Creates a hash context object.
|
||||
|
||||
``` python
|
||||
def Ripemd160.update(self, data: bytes) -> None
|
||||
```
|
||||
|
||||
Update the hash context with hashed data.
|
||||
|
||||
``` python
|
||||
def Ripemd160.digest(self) -> bytes
|
||||
```
|
||||
|
||||
Returns the digest of hashed data.
|
||||
|
||||
|
||||
####trezor.crypto.hashlib.sha256
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hashlib.sha256(self, data: bytes=None) -> Sha256
|
||||
```
|
||||
|
||||
Creates a hash context object.
|
||||
|
||||
``` python
|
||||
def Sha256.update(self, data: bytes) -> None
|
||||
```
|
||||
|
||||
Update the hash context with hashed data.
|
||||
|
||||
``` python
|
||||
def Sha256.digest(self) -> bytes
|
||||
```
|
||||
|
||||
Returns the digest of hashed data.
|
||||
|
||||
|
||||
####trezor.crypto.hashlib.sha512
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hashlib.sha512(self, data: bytes=None) -> Sha512
|
||||
```
|
||||
|
||||
Creates a hash context object.
|
||||
|
||||
``` python
|
||||
def Sha512.hash(self, data: bytes) -> None
|
||||
```
|
||||
|
||||
Update the hash context with hashed data.
|
||||
|
||||
``` python
|
||||
def Sha512.digest(self) -> bytes
|
||||
```
|
||||
|
||||
Returns the digest of hashed data.
|
||||
|
||||
|
||||
####trezor.crypto.hashlib.sha3_256
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hashlib.sha3_256(self, data: bytes=None) -> Sha3_256
|
||||
```
|
||||
|
||||
Creates a hash context object.
|
||||
|
||||
``` python
|
||||
def Sha3_256.update(self, data: bytes) -> None
|
||||
```
|
||||
|
||||
Update the hash context with hashed data.
|
||||
|
||||
``` python
|
||||
def Sha3_256.digest(self) -> bytes
|
||||
```
|
||||
|
||||
Returns the digest of hashed data.
|
||||
|
||||
|
||||
####trezor.crypto.hashlib.sha3_512
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hashlib.sha3_512(self, data: bytes=None) -> Sha3_512
|
||||
```
|
||||
|
||||
Creates a hash context object.
|
||||
|
||||
``` python
|
||||
def Sha3_512.update(self, data: bytes) -> None
|
||||
```
|
||||
|
||||
Update the hash context with hashed data.
|
||||
|
||||
``` python
|
||||
def Sha3_512.digest(self) -> bytes
|
||||
```
|
||||
|
||||
Returns the digest of hashed data.
|
||||
|
||||
|
||||
###trezor.crypto.hmac
|
||||
|
||||
``` python
|
||||
@ -130,10 +205,17 @@ def trezor.crypto.hmac.new(key, msg, digestmod) -> Hmac
|
||||
``` python
|
||||
def trezor.msg.send(self, message) -> int
|
||||
```
|
||||
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
|
||||
``` python
|
||||
def trezor.msg.select(self, timeout_us: int) -> tuple
|
||||
```
|
||||
|
||||
Polls the event queue and returns the event object.
|
||||
Function returns None if timeout specified in microseconds is reached.
|
||||
|
||||
|
||||
##trezor.ui
|
||||
|
||||
``` python
|
||||
@ -154,39 +236,99 @@ def trezor.ui.animate_pulse(func, ca, cb, speed=200000, delay=30000)
|
||||
``` python
|
||||
def trezor.ui.display.bar(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.blit(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None
|
||||
```
|
||||
|
||||
Renders an icon at position (x,y), fgcolor is used as foreground color, bgcolor as background.
|
||||
The image needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.text(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.text_center(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.text_right(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.text_width(self, text: bytes, font: int) -> int
|
||||
```
|
||||
|
||||
Returns a width of text in pixels. Font font is used for rendering.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.qrcode(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.loader(self, 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.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.orientation(self, degrees: int) -> None
|
||||
```
|
||||
``` python
|
||||
def trezor.ui.display.raw(self, reg: int, data: bytes) -> None
|
||||
```
|
||||
|
||||
Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
Everything needs to be redrawn again when this function is used.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.backlight(self, val: int) -> None
|
||||
```
|
||||
|
||||
Sets backlight intensity to the value specified in val.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.raw(self, reg: int, data: bytes) -> None
|
||||
```
|
||||
|
||||
Performs a raw command on the display. Read the datasheet to learn more.
|
||||
|
||||
|
||||
###trezor.utils
|
||||
|
||||
``` python
|
||||
def trezor.utils.memaccess(self, address: int, length: int) -> bytes
|
||||
```
|
||||
|
||||
Creates a bytes object that can be used to access certain memory location.
|
||||
|
||||
|
@ -8,10 +8,14 @@ def process_file(fn):
|
||||
if ext in ['.h', '.c']:
|
||||
for l in src:
|
||||
l = l.rstrip()
|
||||
if l.startswith('/// '):
|
||||
if l.startswith('/// def '):
|
||||
r.append('``` python')
|
||||
r.append(l[4:])
|
||||
r.append('```')
|
||||
elif l.startswith('/// '):
|
||||
r.append(l[4:])
|
||||
elif l == '///':
|
||||
r.append('')
|
||||
elif ext == '.py':
|
||||
mod = mod[4:].replace('/', '.')
|
||||
for l in src:
|
||||
|
@ -59,3 +59,7 @@ Syntax used below is a valid Python function declaration with type hints defined
|
||||
###trezor.ui.display
|
||||
|
||||
@extmod/modtrezorui/modtrezorui-display.h
|
||||
|
||||
###trezor.utils
|
||||
|
||||
@extmod/modtrezorutils/modtrezorutils.c
|
||||
|
@ -21,6 +21,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, siz
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.ed25519.publickey(self, secret_key: bytes) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secret_key) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
@ -35,6 +38,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_publickey(mp_obj_t self, mp_obj_t secre
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ed25519_publickey_obj, mod_TrezorCrypto_Ed25519_publickey);
|
||||
|
||||
/// def trezor.crypto.curve.ed25519.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
|
||||
mp_buffer_info_t sk, msg;
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
@ -52,6 +58,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_sign(mp_obj_t self, mp_obj_t secret_key
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Ed25519_sign_obj, mod_TrezorCrypto_Ed25519_sign);
|
||||
|
||||
/// def trezor.crypto.curve.ed25519.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ed25519_verify(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t pk, sig, msg;
|
||||
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
|
||||
|
@ -22,6 +22,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, s
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.nist256p1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||
@ -42,6 +45,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_publickey(size_t n_args, const mp_obj
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Nist256p1_publickey_obj, 2, 3, mod_TrezorCrypto_Nist256p1_publickey);
|
||||
|
||||
/// def trezor.crypto.curve.nist256p1.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
|
||||
mp_buffer_info_t sk, msg;
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
@ -61,6 +67,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(mp_obj_t self, mp_obj_t secret_k
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Nist256p1_sign_obj, mod_TrezorCrypto_Nist256p1_sign);
|
||||
|
||||
/// def trezor.crypto.curve.nist256p1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_verify(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t pk, sig, msg;
|
||||
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
|
||||
|
@ -20,6 +20,9 @@ typedef struct _mp_obj_Ripemd160_t {
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
|
||||
|
||||
/// def trezor.crypto.hashlib.ripemd160(self, data: bytes=None) -> Ripemd160
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Ripemd160_t *o = m_new_obj(mp_obj_Ripemd160_t);
|
||||
@ -33,6 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, s
|
||||
}
|
||||
|
||||
/// def Ripemd160.update(self, data: bytes) -> None
|
||||
///
|
||||
/// Update the hash context with hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
@ -43,6 +49,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update);
|
||||
|
||||
/// def Ripemd160.digest(self) -> bytes
|
||||
///
|
||||
/// Returns the digest of hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_digest(mp_obj_t self) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
|
@ -22,6 +22,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, s
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.secp256k1.publickey(self, secret_key: bytes, compressed: bool=True) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t sk;
|
||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||
@ -42,6 +45,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_publickey(size_t n_args, const mp_obj
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Secp256k1_publickey_obj, 2, 3, mod_TrezorCrypto_Secp256k1_publickey);
|
||||
|
||||
/// def trezor.crypto.curve.secp256k1.sign(self, secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(mp_obj_t self, mp_obj_t secret_key, mp_obj_t message) {
|
||||
mp_buffer_info_t sk, msg;
|
||||
mp_get_buffer_raise(secret_key, &sk, MP_BUFFER_READ);
|
||||
@ -61,6 +67,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(mp_obj_t self, mp_obj_t secret_k
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorCrypto_Secp256k1_sign_obj, mod_TrezorCrypto_Secp256k1_sign);
|
||||
|
||||
/// def trezor.crypto.curve.secp256k1.verify(self, public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_verify(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t pk, sig, msg;
|
||||
mp_get_buffer_raise(args[1], &pk, MP_BUFFER_READ);
|
||||
|
@ -20,6 +20,9 @@ typedef struct _mp_obj_Sha256_t {
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
|
||||
|
||||
/// def trezor.crypto.hashlib.sha256(self, data: bytes=None) -> Sha256
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha256_t *o = m_new_obj(mp_obj_Sha256_t);
|
||||
@ -33,6 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size
|
||||
}
|
||||
|
||||
/// def Sha256.update(self, data: bytes) -> None
|
||||
///
|
||||
/// Update the hash context with hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
@ -43,6 +49,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update);
|
||||
|
||||
/// def Sha256.digest(self) -> bytes
|
||||
///
|
||||
/// Returns the digest of hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
|
@ -20,6 +20,9 @@ typedef struct _mp_obj_Sha3_256_t {
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
|
||||
|
||||
/// def trezor.crypto.hashlib.sha3_256(self, data: bytes=None) -> Sha3_256
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha3_256_t *o = m_new_obj(mp_obj_Sha3_256_t);
|
||||
@ -33,6 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, si
|
||||
}
|
||||
|
||||
/// def Sha3_256.update(self, data: bytes) -> None
|
||||
///
|
||||
/// Update the hash context with hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
@ -43,6 +49,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update);
|
||||
|
||||
/// def Sha3_256.digest(self) -> bytes
|
||||
///
|
||||
/// Returns the digest of hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
|
@ -20,6 +20,9 @@ typedef struct _mp_obj_Sha3_512_t {
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
|
||||
|
||||
/// def trezor.crypto.hashlib.sha3_512(self, data: bytes=None) -> Sha3_512
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha3_512_t *o = m_new_obj(mp_obj_Sha3_512_t);
|
||||
@ -33,6 +36,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, si
|
||||
}
|
||||
|
||||
/// def Sha3_512.update(self, data: bytes) -> None
|
||||
///
|
||||
/// Update the hash context with hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
@ -43,6 +49,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update);
|
||||
|
||||
/// def Sha3_512.digest(self) -> bytes
|
||||
///
|
||||
/// Returns the digest of hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
|
@ -20,6 +20,9 @@ typedef struct _mp_obj_Sha512_t {
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
|
||||
|
||||
/// def trezor.crypto.hashlib.sha512(self, data: bytes=None) -> Sha512
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha512_t *o = m_new_obj(mp_obj_Sha512_t);
|
||||
@ -32,6 +35,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size
|
||||
}
|
||||
|
||||
/// def Sha512.hash(self, data: bytes) -> None
|
||||
///
|
||||
/// Update the hash context with hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t msg;
|
||||
@ -42,6 +48,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update);
|
||||
|
||||
/// def Sha512.digest(self) -> bytes
|
||||
///
|
||||
/// Returns the digest of hashed data.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
|
@ -37,6 +37,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a
|
||||
}
|
||||
|
||||
/// def trezor.msg.send(self, message) -> int
|
||||
///
|
||||
/// Sends message using USB HID (device) or UDP (emulator).
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t message) {
|
||||
mp_buffer_info_t msg;
|
||||
mp_get_buffer_raise(message, &msg, MP_BUFFER_READ);
|
||||
@ -48,6 +51,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s
|
||||
#define TICK_RESOLUTION 1000
|
||||
|
||||
/// def trezor.msg.select(self, timeout_us: int) -> tuple
|
||||
///
|
||||
/// Polls the event queue and returns the event object.
|
||||
/// Function returns None if timeout specified in microseconds is reached.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
|
||||
int timeout = mp_obj_get_int(timeout_us);
|
||||
if (timeout < 0) {
|
||||
|
@ -292,6 +292,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_make_new(const mp_obj_type_t *type, size_t
|
||||
}
|
||||
|
||||
/// def trezor.ui.display.bar(self, x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -312,6 +316,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_bar_obj, 6, 7, mod_TrezorUi_Display_bar);
|
||||
|
||||
/// def trezor.ui.display.blit(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_blit(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -328,6 +336,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_blit(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6, mod_TrezorUi_Display_blit);
|
||||
|
||||
/// def trezor.ui.display.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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -352,6 +364,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_image_obj, 4, 4, mod_TrezorUi_Display_image);
|
||||
|
||||
/// def trezor.ui.display.icon(self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None
|
||||
///
|
||||
/// Renders an icon at position (x,y), fgcolor is used as foreground color, bgcolor as background.
|
||||
/// The image needs to be in TREZOR Optimized Image Format (TOIF) - gray-scale mode.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -378,6 +394,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon);
|
||||
|
||||
/// def trezor.ui.display.text(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -392,6 +412,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7, mod_TrezorUi_Display_text);
|
||||
|
||||
/// def trezor.ui.display.text_center(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -407,6 +431,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_center_obj, 7, 7, mod_TrezorUi_Display_text_center);
|
||||
|
||||
/// def trezor.ui.display.text_right(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -422,6 +450,9 @@ STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *a
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_right_obj, 7, 7, mod_TrezorUi_Display_text_right);
|
||||
|
||||
/// def trezor.ui.display.text_width(self, text: bytes, font: int) -> int
|
||||
///
|
||||
/// Returns a width of text in pixels. Font font is used for rendering.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_width(mp_obj_t self, mp_obj_t text, mp_obj_t font) {
|
||||
mp_buffer_info_t txt;
|
||||
mp_get_buffer_raise(text, &txt, MP_BUFFER_READ);
|
||||
@ -432,6 +463,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_text_width(mp_obj_t self, mp_obj_t text, mp
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_text_width_obj, mod_TrezorUi_Display_text_width);
|
||||
|
||||
/// def trezor.ui.display.qrcode(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
@ -454,6 +489,12 @@ static void inflate_callback_loader(uint8_t byte, uint32_t pos, void *userdata)
|
||||
}
|
||||
|
||||
/// def trezor.ui.display.loader(self, 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.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t progress = mp_obj_get_int(args[1]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[2]);
|
||||
@ -491,6 +532,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_loader_obj, 4, 6, mod_TrezorUi_Display_loader);
|
||||
|
||||
/// def trezor.ui.display.orientation(self, degrees: int) -> None
|
||||
///
|
||||
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
/// Everything needs to be redrawn again when this function is used.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees) {
|
||||
mp_int_t deg = mp_obj_get_int(degrees);
|
||||
if (deg != 0 && deg != 90 && deg != 180 && deg != 270) {
|
||||
@ -501,7 +546,20 @@ STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_orientation_obj, mod_TrezorUi_Display_orientation);
|
||||
|
||||
/// def trezor.ui.display.backlight(self, val: int) -> None
|
||||
///
|
||||
/// Sets backlight intensity to the value specified in val.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_backlight(mp_obj_t self, mp_obj_t reg) {
|
||||
display_backlight(mp_obj_get_int(reg));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_backlight_obj, mod_TrezorUi_Display_backlight);
|
||||
|
||||
/// def trezor.ui.display.raw(self, reg: int, data: bytes) -> None
|
||||
///
|
||||
/// Performs a raw command on the display. Read the datasheet to learn more.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t data) {
|
||||
mp_int_t r = mp_obj_get_int(reg);
|
||||
mp_buffer_info_t raw;
|
||||
@ -511,13 +569,6 @@ STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t d
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_raw_obj, mod_TrezorUi_Display_raw);
|
||||
|
||||
/// def trezor.ui.display.backlight(self, val: int) -> None
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_backlight(mp_obj_t self, mp_obj_t reg) {
|
||||
display_backlight(mp_obj_get_int(reg));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_backlight_obj, mod_TrezorUi_Display_backlight);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&mod_TrezorUi_Display_bar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_blit), MP_ROM_PTR(&mod_TrezorUi_Display_blit_obj) },
|
||||
@ -530,8 +581,8 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_qrcode), MP_ROM_PTR(&mod_TrezorUi_Display_qrcode_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_TrezorUi_Display_loader_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUi_Display_orientation_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_raw), MP_ROM_PTR(&mod_TrezorUi_Display_raw_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUi_Display_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_raw), MP_ROM_PTR(&mod_TrezorUi_Display_raw_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mod_TrezorUi_Display_locals_dict, mod_TrezorUi_Display_locals_dict_table);
|
||||
|
||||
|
@ -28,6 +28,9 @@ STATIC mp_obj_t mod_TrezorUtils_Utils_make_new(const mp_obj_type_t *type, size_t
|
||||
}
|
||||
|
||||
/// def trezor.utils.memaccess(self, address: int, length: int) -> bytes
|
||||
///
|
||||
/// Creates a bytes object that can be used to access certain memory location.
|
||||
///
|
||||
STATIC mp_obj_t mod_TrezorUtils_Utils_memaccess(mp_obj_t self, mp_obj_t address, mp_obj_t length) {
|
||||
uint32_t addr = mp_obj_get_int(address);
|
||||
uint32_t len = mp_obj_get_int(length);
|
||||
|
Loading…
Reference in New Issue
Block a user