2016-02-01 02:52:57 -08:00
|
|
|
#TREZOR OS API
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
Syntax used below are valid Python function declarations with anotations defined in [PEP 3107](https://www.python.org/dev/peps/pep-3107/).
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
``` python
|
|
|
|
class bytes20(bytes): pass # bytes variable of exactly 20 bytes
|
|
|
|
class bytes21(bytes): pass # bytes variable of exactly 21 bytes
|
|
|
|
class bytes32(bytes): pass # bytes variable of exactly 32 bytes
|
|
|
|
class bytes33(bytes): pass # bytes variable of exactly 33 bytes
|
|
|
|
class bytes64(bytes): pass # bytes variable of exactly 64 bytes
|
|
|
|
class bytes65(bytes): pass # bytes variable of exactly 65 bytes
|
|
|
|
|
|
|
|
class uint32(int): pass # 32-bit unsigned int
|
|
|
|
```
|
|
|
|
|
2016-02-01 02:52:57 -08:00
|
|
|
##trezor.crypto
|
|
|
|
|
|
|
|
###trezor.crypto.ed25519
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
``` python
|
2016-02-01 08:18:04 -08:00
|
|
|
def to_public(secret_key: bytes32) -> bytes32: # public_key
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes32 = None) -> bytes64: # signature
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def verify(message: bytes, public_key: bytes32, signature: bytes64) -> bool: # valid
|
2016-02-01 02:52:57 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
###trezor.crypto.func
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
``` python
|
|
|
|
def aes():
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def base58_encode(data: bytes) -> bytes: # encoded
|
|
|
|
|
|
|
|
def base58_decode(data: bytes) -> bytes: # decoded
|
|
|
|
|
|
|
|
def base58_encode_check(data: bytes) -> bytes: # encoded
|
|
|
|
|
|
|
|
def base58_decode_check(data: bytes) -> bytes: # decoded
|
|
|
|
|
|
|
|
def hmac_sha256(key: bytes, message: bytes) -> bytes32: # hmac
|
2016-02-01 06:16:33 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def hmac_sha512(key: bytes, message: bytes) -> bytes64: # hmac
|
2016-02-01 06:16:33 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def sha256(data: bytes) -> bytes32: # hashed
|
2016-02-01 06:16:33 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def sha512(data: bytes) -> bytes64: # hashed
|
2016-02-01 06:16:33 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def ripemd160(data: bytes) -> bytes20: # hashed
|
|
|
|
|
|
|
|
def pbkdf2_hmac_sha256(password: bytes, salt: bytes, iterations: uint32, keylen: uint32) -> bytes32: # key
|
|
|
|
|
|
|
|
def pbkdf2_hmac_sha512(password: bytes, salt: bytes, iterations: uint32, keylen: uint32) -> bytes32: # key
|
2016-02-01 02:52:57 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
###trezor.crypto.hd
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 02:52:57 -08:00
|
|
|
###trezor.crypto.mnemonic
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 02:52:57 -08:00
|
|
|
###trezor.crypto.nistp256
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
``` python
|
2016-02-01 08:18:04 -08:00
|
|
|
def to_public(secret_key: bytes32) -> bytes33: # public_key
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
|
2016-02-01 02:52:57 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
###trezor.crypto.secp256k1
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
``` python
|
2016-02-01 08:18:04 -08:00
|
|
|
def to_public(secret_key: bytes32) -> bytes33: # public_key
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
|
2016-02-01 02:52:57 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
##trezor.hw
|
|
|
|
|
|
|
|
###trezor.hw.button
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 02:52:57 -08:00
|
|
|
###trezor.hw.display
|
|
|
|
|
2016-02-01 08:18:04 -08:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
##trezor.utils
|
2016-02-01 02:52:57 -08:00
|
|
|
|
2016-02-01 06:16:33 -08:00
|
|
|
###trezor.utils.qrenc
|
|
|
|
|
|
|
|
``` python
|
2016-02-01 08:18:04 -08:00
|
|
|
class QrLevel(Enum):
|
|
|
|
L = 0
|
|
|
|
M = 1
|
|
|
|
Q = 2
|
|
|
|
H = 3
|
|
|
|
|
|
|
|
def encode(source: bytes, level: QrLevel = QrLevel.H) -> (int, list): # size, data
|
2016-02-01 02:52:57 -08:00
|
|
|
```
|