2016-05-10 14:19:43 +00:00
|
|
|
#TREZOR Core API
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-02 17:25:27 +00:00
|
|
|
Syntax used below is a valid Python function declaration with type hints defined in [PEP 0484](https://www.python.org/dev/peps/pep-0484/).
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-04-04 18:48:48 +00:00
|
|
|
##trezor.crypto
|
|
|
|
|
|
|
|
###trezor.crypto.base58
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def trezor.crypto.base58.encode(data: bytes) -> str
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-06 14:19:10 +00:00
|
|
|
|
|
|
|
Convert bytes to base58 encoded string.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-04-04 18:48:48 +00:00
|
|
|
def trezor.crypto.base58.decode(string: str) -> bytes
|
|
|
|
```
|
2016-05-06 14:19:10 +00:00
|
|
|
|
|
|
|
Convert base58 encoded string to bytes.
|
|
|
|
|
2016-04-04 14:12:13 +00:00
|
|
|
``` python
|
2016-05-05 19:41:03 +00:00
|
|
|
def trezor.crypto.base58.encode_check(data: bytes) -> str
|
|
|
|
```
|
2016-05-06 14:19:10 +00:00
|
|
|
|
|
|
|
Convert bytes to base58 encoded string, append checksum.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def trezor.crypto.base58.decode_check(string: str) -> bytes
|
2016-04-04 14:12:13 +00:00
|
|
|
```
|
|
|
|
|
2016-05-06 14:19:10 +00:00
|
|
|
Convert base58 encoded string to bytes and verify checksum.
|
|
|
|
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
###trezor.crypto.curve
|
2016-04-04 14:12:13 +00:00
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.curve.ed25519
|
|
|
|
|
2016-04-04 14:12:13 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.ed25519.publickey(secret_key: bytes) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Computes public key from secret key.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.ed25519.sign(secret_key: bytes, message: bytes) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Uses secret key to produce the signature of message.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.ed25519.verify(public_key: bytes, signature: bytes, message: bytes) -> bool
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-04-04 14:12:13 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Uses public key to verify the signature of the message
|
|
|
|
Returns True on success.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.curve.nist256p1
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.nist256p1.publickey(secret_key: bytes, compressed: bool=True) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Computes public key from secret key.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.nist256p1.sign(secret_key: bytes, message: bytes) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Uses secret key to produce the signature of message.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.nist256p1.verify(public_key: bytes, signature: bytes, message: bytes) -> bool
|
2016-04-04 14:12:13 +00:00
|
|
|
```
|
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Uses public key to verify the signature of the message
|
|
|
|
Returns True on success.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.curve.secp256k1
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.secp256k1.publickey(secret_key: bytes, compressed: bool=True) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Computes public key from secret key.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.secp256k1.sign(secret_key: bytes, message: bytes) -> bytes
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Uses secret key to produce the signature of message.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.curve.secp256k1.verify(public_key: bytes, signature: bytes, message: bytes) -> bool
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Uses public key to verify the signature of the message
|
|
|
|
Returns True on success.
|
|
|
|
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
###trezor.crypto.hashlib
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.hashlib.ripemd160
|
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.hashlib.ripemd160(data: bytes=None) -> Ripemd160
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a hash context object.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Ripemd160.update(self, data: bytes) -> None
|
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Update the hash context with hashed data.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Ripemd160.digest(self) -> bytes
|
|
|
|
```
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Returns the digest of hashed data.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.hashlib.sha256
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.hashlib.sha256(data: bytes=None) -> Sha256
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a hash context object.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha256.update(self, data: bytes) -> None
|
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Update the hash context with hashed data.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha256.digest(self) -> bytes
|
|
|
|
```
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Returns the digest of hashed data.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.hashlib.sha512
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.hashlib.sha512(data: bytes=None) -> Sha512
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a hash context object.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha512.hash(self, data: bytes) -> None
|
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Update the hash context with hashed data.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha512.digest(self) -> bytes
|
|
|
|
```
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Returns the digest of hashed data.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.hashlib.sha3_256
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.hashlib.sha3_256(data: bytes=None) -> Sha3_256
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a hash context object.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha3_256.update(self, data: bytes) -> None
|
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Update the hash context with hashed data.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha3_256.digest(self) -> bytes
|
|
|
|
```
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Returns the digest of hashed data.
|
|
|
|
|
|
|
|
|
2016-05-05 20:12:26 +00:00
|
|
|
####trezor.crypto.hashlib.sha3_512
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.crypto.hashlib.sha3_512(data: bytes=None) -> Sha3_512
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a hash context object.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha3_512.update(self, data: bytes) -> None
|
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Update the hash context with hashed data.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def Sha3_512.digest(self) -> bytes
|
|
|
|
```
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Returns the digest of hashed data.
|
|
|
|
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
###trezor.crypto.hmac
|
2016-04-03 23:46:46 +00:00
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
|
|
|
def trezor.crypto.hmac.new(key, msg, digestmod) -> Hmac
|
|
|
|
```
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-06 14:19:10 +00:00
|
|
|
Creates a HMAC context object.
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def Hmac.update(self, msg: bytes) -> None
|
|
|
|
```
|
|
|
|
|
|
|
|
Update the context with data.
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def Hmac.digest(self) -> bytes
|
|
|
|
```
|
|
|
|
|
|
|
|
Returns the digest of processed data.
|
|
|
|
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
##trezor.msg
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.msg.send(message) -> int
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Sends message using USB HID (device) or UDP (emulator).
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.msg.select(timeout_us: int) -> tuple
|
2016-02-01 16:48:26 +00:00
|
|
|
```
|
|
|
|
|
2016-05-05 20:44:47 +00:00
|
|
|
Polls the event queue and returns the event object.
|
|
|
|
Function returns None if timeout specified in microseconds is reached.
|
|
|
|
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
##trezor.ui
|
2016-02-01 16:48:26 +00:00
|
|
|
|
|
|
|
``` python
|
2016-05-05 19:41:03 +00:00
|
|
|
def trezor.ui.rgbcolor(r: int, g: int, b: int) -> int
|
|
|
|
```
|
|
|
|
``` python
|
|
|
|
def trezor.ui.lerpi(a: int, b: int, t: float) -> int
|
|
|
|
```
|
|
|
|
``` python
|
|
|
|
def trezor.ui.blend(ca: int, cb: int, t: float) -> int
|
|
|
|
```
|
|
|
|
``` python
|
|
|
|
def trezor.ui.animate_pulse(func, ca, cb, speed=200000, delay=30000)
|
|
|
|
```
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
###trezor.ui.display
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.bar(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.blit(x: int, y: int, w: int, h: int, data: bytes) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.image(x: int, y: int, image: bytes) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Renders an image at position (x,y).
|
|
|
|
The image needs to be in TREZOR Optimized Image Format (TOIF) - full-color mode.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.icon(x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.text(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.text_center(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.text_right(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.text_width(text: bytes, font: int) -> int
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Returns a width of text in pixels. Font font is used for rendering.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.qrcode(x: int, y: int, data: bytes, scale: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Renders data encoded as a QR code at position (x,y).
|
|
|
|
Scale determines a zoom factor.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.loader(progress: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.orientation(degrees: int) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Sets display orientation to 0, 90, 180 or 270 degrees.
|
|
|
|
Everything needs to be redrawn again when this function is used.
|
|
|
|
|
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.backlight(val: int) -> None
|
2016-05-05 20:44:47 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Sets backlight intensity to the value specified in val.
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.ui.display.raw(reg: int, data: bytes) -> None
|
2016-05-05 19:41:03 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Performs a raw command on the display. Read the datasheet to learn more.
|
|
|
|
|
|
|
|
|
|
|
|
###trezor.utils
|
|
|
|
|
2016-05-05 19:41:03 +00:00
|
|
|
``` python
|
2016-05-06 12:56:58 +00:00
|
|
|
def trezor.utils.memaccess(address: int, length: int) -> bytes
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|
2016-05-05 20:44:47 +00:00
|
|
|
|
|
|
|
Creates a bytes object that can be used to access certain memory location.
|
|
|
|
|