2016-02-01 10:52:57 +00:00
|
|
|
#TREZOR OS API
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
Auxiliary classes used to tighten the type checking.
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
``` python
|
2016-02-02 17:40:29 +00:00
|
|
|
bytes16 = bytes # bytes variable of exactly 16 bytes
|
|
|
|
bytes20 = bytes # bytes variable of exactly 20 bytes
|
|
|
|
bytes21 = bytes # bytes variable of exactly 21 bytes
|
|
|
|
bytes24 = bytes # bytes variable of exactly 24 bytes
|
|
|
|
bytes32 = bytes # bytes variable of exactly 32 bytes
|
|
|
|
bytes33 = bytes # bytes variable of exactly 33 bytes
|
|
|
|
bytes64 = bytes # bytes variable of exactly 64 bytes
|
|
|
|
bytes65 = bytes # bytes variable of exactly 65 bytes
|
2016-02-01 16:18:04 +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-02-01 10:52:57 +00:00
|
|
|
##trezor.crypto
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
###trezor.crypto.aes
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
``` python
|
2016-02-02 17:40:29 +00:00
|
|
|
AES_CTX = object # AES context
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_encrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_encrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_encrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_decrypt_key128(key: bytes16, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_decrypt_key192(key: bytes24, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_decrypt_key256(key: bytes32, iv: bytes16 = None) -> AES_CTX: # context
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ecb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_cbc_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_cfb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ofb_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ctr_encrypt(ctx: AES_CTX, data: bytes) -> bytes: # encrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ecb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_cbc_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_cfb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ofb_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
|
2016-02-01 16:48:26 +00:00
|
|
|
|
2016-02-02 17:40:29 +00:00
|
|
|
def aes_ctr_decrypt(ctx: AES_CTX, data: bytes) -> bytes: # decrypted
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
###trezor.crypto.base58
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
``` python
|
2016-02-01 16:48:26 +00:00
|
|
|
def encode(data: bytes) -> bytes: # encoded
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
def decode(data: bytes) -> bytes: # decoded
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
def encode_check(data: bytes) -> bytes: # encoded
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
def decode_check(data: bytes) -> bytes: # decoded
|
|
|
|
```
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
###trezor.crypto.ed25519
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
``` python
|
|
|
|
def to_public(secret_key: bytes32) -> bytes32: # public_key
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes32 = None) -> bytes64: # signature
|
|
|
|
|
|
|
|
def verify(message: bytes, public_key: bytes32, signature: bytes64) -> bool: # valid
|
|
|
|
```
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
###trezor.crypto.hash
|
|
|
|
|
|
|
|
``` python
|
2016-02-01 16:18:04 +00:00
|
|
|
def sha256(data: bytes) -> bytes32: # hashed
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def sha512(data: bytes) -> bytes64: # hashed
|
2016-02-01 14:16:33 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def ripemd160(data: bytes) -> bytes20: # hashed
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
###trezor.crypto.hd
|
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
###trezor.crypto.hmac
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def hmac_sha256(key: bytes, message: bytes) -> bytes32: # hmac
|
|
|
|
|
|
|
|
def hmac_sha512(key: bytes, message: bytes) -> bytes64: # hmac
|
|
|
|
```
|
|
|
|
|
|
|
|
###trezor.crypto.kdf
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def pbkdf2_hmac_sha256(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
|
|
|
|
|
|
|
|
def pbkdf2_hmac_sha512(password: bytes, salt: bytes, iterations: int, keylen: int) -> bytes32: # key
|
|
|
|
```
|
|
|
|
|
2016-02-01 10:52:57 +00:00
|
|
|
###trezor.crypto.mnemonic
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
``` python
|
|
|
|
def bip39_generate(strength: int) -> bytes: # sentence
|
|
|
|
|
|
|
|
def bip39_fromdata(data: bytes) -> bytes: # sentence
|
|
|
|
|
|
|
|
def bip39_check(mnemonic: bytes) -> bool: # valid
|
|
|
|
|
|
|
|
def bip39_seed(mnemonic: bytes, passphrase: bytes) -> bytes64: # seed
|
|
|
|
```
|
2016-02-01 16:18:04 +00:00
|
|
|
|
2016-02-01 10:52:57 +00:00
|
|
|
###trezor.crypto.nistp256
|
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
``` python
|
2016-02-01 16:18:04 +00:00
|
|
|
def to_public(secret_key: bytes32) -> bytes33: # public_key
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|
|
|
|
|
2016-02-10 17:01:55 +00:00
|
|
|
###trezor.crypto.reedsolomon
|
|
|
|
|
|
|
|
``` python
|
|
|
|
def encode(data: bytes) -> bytes: # encoded
|
|
|
|
|
|
|
|
def decode(data: bytes) -> bytes: # decoded
|
|
|
|
```
|
|
|
|
|
2016-02-01 10:52:57 +00:00
|
|
|
###trezor.crypto.secp256k1
|
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
``` python
|
2016-02-01 16:18:04 +00:00
|
|
|
def to_public(secret_key: bytes32) -> bytes33: # public_key
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
##trezor.hw
|
|
|
|
|
|
|
|
###trezor.hw.button
|
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 10:52:57 +00:00
|
|
|
###trezor.hw.display
|
|
|
|
|
2016-02-01 16:18:04 +00:00
|
|
|
TODO
|
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
##trezor.utils
|
2016-02-01 10:52:57 +00:00
|
|
|
|
2016-02-01 14:16:33 +00:00
|
|
|
###trezor.utils.qrenc
|
|
|
|
|
|
|
|
``` python
|
2016-02-01 16:18:04 +00:00
|
|
|
class QrLevel(Enum):
|
|
|
|
L = 0
|
|
|
|
M = 1
|
|
|
|
Q = 2
|
|
|
|
H = 3
|
|
|
|
|
2016-02-01 16:48:26 +00:00
|
|
|
def encode(source: bytes, level: QrLevel = QrLevel.H) -> list: # data
|
2016-02-01 10:52:57 +00:00
|
|
|
```
|