You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/docs/api.md

165 lines
4.2 KiB

9 years ago
#TREZOR OS API
9 years ago
Auxiliary classes used to tighten the type checking.
9 years ago
``` python
9 years ago
class bytes16(bytes): pass # bytes variable of exactly 16 bytes
class bytes20(bytes): pass # bytes variable of exactly 20 bytes
class bytes21(bytes): pass # bytes variable of exactly 21 bytes
9 years ago
class bytes24(bytes): pass # bytes variable of exactly 24 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
```
9 years ago
Syntax used below is a valid Python function declaration with anotations defined in [PEP 3107](https://www.python.org/dev/peps/pep-3107/).
9 years ago
##trezor.crypto
9 years ago
###trezor.crypto.aes
9 years ago
9 years ago
``` python
9 years ago
class aes_ctx(object): pass # AES context
9 years ago
9 years ago
def aes_encrypt_key128(key: bytes16, iv: bytes16 = None) -> aes_ctx: # context
9 years ago
9 years ago
def aes_encrypt_key192(key: bytes24, iv: bytes16 = None) -> aes_ctx: # context
def aes_encrypt_key256(key: bytes32, iv: bytes16 = None) -> aes_ctx: # context
def aes_decrypt_key128(key: bytes16, iv: bytes16 = None) -> aes_ctx: # context
def aes_decrypt_key192(key: bytes24, iv: bytes16 = None) -> aes_ctx: # context
def aes_decrypt_key256(key: bytes32, iv: bytes16 = None) -> aes_ctx: # context
def aes_ecb_encrypt(ctx: aes_ctx, data: bytes) -> bytes: # encrypted
def aes_cbc_encrypt(ctx: aes_ctx, data: bytes) -> bytes: # encrypted
def aes_cfb_encrypt(ctx: aes_ctx, data: bytes) -> bytes: # encrypted
def aes_ofb_encrypt(ctx: aes_ctx, data: bytes) -> bytes: # encrypted
def aes_ctr_encrypt(ctx: aes_ctx, data: bytes) -> bytes: # encrypted
def aes_ecb_decrypt(ctx: aes_ctx, data: bytes) -> bytes: # decrypted
def aes_cbc_decrypt(ctx: aes_ctx, data: bytes) -> bytes: # decrypted
def aes_cfb_decrypt(ctx: aes_ctx, data: bytes) -> bytes: # decrypted
def aes_ofb_decrypt(ctx: aes_ctx, data: bytes) -> bytes: # decrypted
def aes_ctr_decrypt(ctx: aes_ctx, data: bytes) -> bytes: # decrypted
9 years ago
```
9 years ago
###trezor.crypto.base58
9 years ago
9 years ago
``` python
9 years ago
def encode(data: bytes) -> bytes: # encoded
9 years ago
9 years ago
def decode(data: bytes) -> bytes: # decoded
9 years ago
def encode_check(data: bytes) -> bytes: # encoded
9 years ago
def decode_check(data: bytes) -> bytes: # decoded
```
9 years ago
###trezor.crypto.ed25519
9 years ago
``` python
def to_public(secret_key: bytes32) -> bytes32: # public_key
9 years ago
9 years ago
def sign(message: bytes, secret_key: bytes32, public_key: bytes32 = None) -> bytes64: # signature
def verify(message: bytes, public_key: bytes32, signature: bytes64) -> bool: # valid
```
9 years ago
9 years ago
###trezor.crypto.hash
``` python
def sha256(data: bytes) -> bytes32: # hashed
9 years ago
def sha512(data: bytes) -> bytes64: # hashed
9 years ago
def ripemd160(data: bytes) -> bytes20: # hashed
9 years ago
```
###trezor.crypto.hd
TODO
9 years ago
###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
```
9 years ago
###trezor.crypto.mnemonic
9 years ago
``` 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
```
9 years ago
###trezor.crypto.nistp256
9 years ago
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
9 years ago
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
9 years ago
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
9 years ago
```
###trezor.crypto.secp256k1
9 years ago
``` python
def to_public(secret_key: bytes32) -> bytes33: # public_key
9 years ago
def sign(message: bytes, secret_key: bytes32, public_key: bytes33 = None) -> bytes65: # signature
9 years ago
def verify(message: bytes, public_key: bytes33, signature: bytes65) -> bool: # valid
9 years ago
```
##trezor.hw
###trezor.hw.button
TODO
9 years ago
###trezor.hw.display
TODO
9 years ago
##trezor.utils
9 years ago
9 years ago
###trezor.utils.qrenc
``` python
class QrLevel(Enum):
L = 0
M = 1
Q = 2
H = 3
9 years ago
def encode(source: bytes, level: QrLevel = QrLevel.H) -> list: # data
9 years ago
```