mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
remove homebrew docu generator, use docstring syntax
This commit is contained in:
parent
c0dfe2d702
commit
9f40362482
435
docs/api.md
435
docs/api.md
@ -1,438 +1,3 @@
|
||||
#TREZOR Core API
|
||||
|
||||
Syntax used below is a valid Python function declaration with type hints defined in [PEP 0484](https://www.python.org/dev/peps/pep-0484/).
|
||||
|
||||
##trezor.crypto
|
||||
|
||||
###trezor.crypto.base58
|
||||
|
||||
``` python
|
||||
def trezor.crypto.base58.encode(data: bytes) -> str
|
||||
```
|
||||
|
||||
Convert bytes to base58 encoded string.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.base58.decode(string: str) -> bytes
|
||||
```
|
||||
|
||||
Convert base58 encoded string to bytes.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.base58.encode_check(data: bytes) -> str
|
||||
```
|
||||
|
||||
Convert bytes to base58 encoded string, append checksum.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.base58.decode_check(string: str) -> bytes
|
||||
```
|
||||
|
||||
Convert base58 encoded string to bytes and verify checksum.
|
||||
|
||||
|
||||
###trezor.crypto.bip39
|
||||
|
||||
``` python
|
||||
def trezor.crypto.bip39.generate(strength: int) -> str
|
||||
```
|
||||
|
||||
Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits)
|
||||
|
||||
``` python
|
||||
def trezor.crypto.bip39.from_data(data: bytes) -> str
|
||||
```
|
||||
|
||||
Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes)
|
||||
|
||||
``` python
|
||||
def trezor.crypto.bip39.check(mnemonic: str) -> bool
|
||||
```
|
||||
|
||||
Check whether given mnemonic is valid
|
||||
|
||||
``` python
|
||||
def trezor.crypto.bip39.seed(mnemonic: str, passphrase: str) -> bytes
|
||||
```
|
||||
|
||||
Generate seed from mnemonic and passphrase
|
||||
|
||||
|
||||
###trezor.crypto.curve
|
||||
|
||||
####trezor.crypto.curve.ed25519
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.publickey(secret_key: bytes) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.sign(secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.ed25519.verify(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(secret_key: bytes, compressed: bool=True) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.nist256p1.sign(secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.nist256p1.verify(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(secret_key: bytes, compressed: bool=True) -> bytes
|
||||
```
|
||||
|
||||
Computes public key from secret key.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.secp256k1.sign(secret_key: bytes, message: bytes) -> bytes
|
||||
```
|
||||
|
||||
Uses secret key to produce the signature of message.
|
||||
|
||||
``` python
|
||||
def trezor.crypto.curve.secp256k1.verify(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
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hashlib.ripemd160(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(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(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(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(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.random
|
||||
|
||||
``` python
|
||||
def trezor.crypto.random.uniform(n: int) -> int
|
||||
```
|
||||
|
||||
Compute uniform random number from interval 0 ... n - 1
|
||||
|
||||
``` python
|
||||
def trezor.crypto.random.bytes(len: int) -> bytes
|
||||
```
|
||||
|
||||
Generate random bytes sequence of length len
|
||||
|
||||
``` python
|
||||
def trezor.crypto.random.shuffle(data: list) -> None
|
||||
```
|
||||
|
||||
Shuffles items of given list (in-place)
|
||||
|
||||
|
||||
####trezor.crypto.ssss
|
||||
|
||||
``` python
|
||||
def trezor.crypto.ssss.split(m: int, n: int, secret: bytes) -> tuple
|
||||
```
|
||||
|
||||
Split secret to (M of N) shares using Shamir's Secret Sharing Scheme
|
||||
|
||||
``` python
|
||||
def trezor.crypto.ssss.combine(shares: tuple) -> bytes
|
||||
```
|
||||
|
||||
Combine M shares of Shamir's Secret Sharing Scheme into secret
|
||||
|
||||
|
||||
###trezor.crypto.hmac
|
||||
|
||||
``` python
|
||||
def trezor.crypto.hmac.new(key, msg, digestmod) -> Hmac
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
|
||||
##trezor.msg
|
||||
|
||||
``` python
|
||||
def trezor.msg.setup(ifaces: list) -> None
|
||||
```
|
||||
|
||||
Configures USB interfaces with a list of tuples (interface_number, usage_page)
|
||||
|
||||
``` python
|
||||
def trezor.msg.send(iface: int, message: bytes) -> int
|
||||
```
|
||||
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
|
||||
``` python
|
||||
def trezor.msg.select(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
|
||||
def trezor.ui.rgbcolor(r: int, g: int, b: int) -> int
|
||||
```
|
||||
``` python
|
||||
def trezor.ui.in_area(pos: tuple, area: tuple) -> bool
|
||||
```
|
||||
``` 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)
|
||||
```
|
||||
``` python
|
||||
def trezor.ui.rotate_coords(pos: tuple) -> tuple
|
||||
```
|
||||
|
||||
###trezor.ui.display
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.bar(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(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(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(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(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(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(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(text: bytes, font: int) -> int
|
||||
```
|
||||
|
||||
Returns a width of text in pixels. Font font is used for rendering.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.qrcode(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(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(degrees: int=None) -> int
|
||||
```
|
||||
|
||||
Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
Everything needs to be redrawn again when this function is used.
|
||||
Call without the degrees parameter to just perform the read of the value.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.backlight(val: int=None) -> int
|
||||
```
|
||||
|
||||
Sets backlight intensity to the value specified in val.
|
||||
Call without the val parameter to just perform the read of the value.
|
||||
|
||||
``` python
|
||||
def trezor.ui.display.raw(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(address: int, length: int) -> bytes
|
||||
```
|
||||
|
||||
Creates a bytes object that can be used to access certain memory location.
|
||||
|
||||
|
59
docs/api.py
59
docs/api.py
@ -1,59 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import re
|
||||
|
||||
def process_file(fn):
|
||||
mod, ext = os.path.splitext(fn)
|
||||
src = open('../%s' % (fn)).readlines()
|
||||
r = []
|
||||
cls = ''
|
||||
if ext in ['.h', '.c']:
|
||||
for l in src:
|
||||
l = l.rstrip()
|
||||
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('/', '.')
|
||||
if mod.endswith('.__init__'):
|
||||
mod = mod[:-9]
|
||||
for l in src:
|
||||
l = l.rstrip()
|
||||
if l.startswith('def '):
|
||||
r.append('``` python')
|
||||
r.append('def %s.' % mod + l[4:-1])
|
||||
r.append('```')
|
||||
elif l.startswith('### '):
|
||||
r.append(l[4:])
|
||||
elif l.startswith('###'):
|
||||
r.append('')
|
||||
elif l.startswith('class '):
|
||||
cls = re.match('class ([A-Za-z0-9_]*)', l).group(1)
|
||||
elif l.startswith(' def ') and not l.startswith(' def __init__'):
|
||||
r.append('``` python')
|
||||
r.append('def %s.' % cls + l[8:-1])
|
||||
r.append('```')
|
||||
elif l.startswith(' ### '):
|
||||
r.append(l[8:])
|
||||
elif l.startswith(' ###'):
|
||||
r.append('')
|
||||
return r
|
||||
|
||||
def main():
|
||||
tpl = open('api.template.md', 'rt').readlines()
|
||||
f = open('api.md', 'wt')
|
||||
for line in tpl:
|
||||
if line.startswith('@'):
|
||||
for l in process_file(line[1:].strip()):
|
||||
f.write(l + '\n')
|
||||
else:
|
||||
f.write(line)
|
||||
f.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,77 +0,0 @@
|
||||
#TREZOR Core API
|
||||
|
||||
Syntax used below is a valid Python function declaration with type hints defined in [PEP 0484](https://www.python.org/dev/peps/pep-0484/).
|
||||
|
||||
##trezor.crypto
|
||||
|
||||
###trezor.crypto.base58
|
||||
|
||||
@src/trezor/crypto/base58.py
|
||||
|
||||
###trezor.crypto.bip39
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-bip39.h
|
||||
|
||||
###trezor.crypto.curve
|
||||
|
||||
####trezor.crypto.curve.ed25519
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-ed25519.h
|
||||
|
||||
####trezor.crypto.curve.nist256p1
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
||||
|
||||
####trezor.crypto.curve.secp256k1
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h
|
||||
|
||||
###trezor.crypto.hashlib
|
||||
|
||||
####trezor.crypto.hashlib.ripemd160
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h
|
||||
|
||||
####trezor.crypto.hashlib.sha256
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-sha256.h
|
||||
|
||||
####trezor.crypto.hashlib.sha512
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-sha512.h
|
||||
|
||||
####trezor.crypto.hashlib.sha3_256
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h
|
||||
|
||||
####trezor.crypto.hashlib.sha3_512
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h
|
||||
|
||||
####trezor.crypto.random
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-random.h
|
||||
|
||||
####trezor.crypto.ssss
|
||||
|
||||
@extmod/modtrezorcrypto/modtrezorcrypto-ssss.h
|
||||
|
||||
###trezor.crypto.hmac
|
||||
|
||||
@src/trezor/crypto/hmac.py
|
||||
|
||||
##trezor.msg
|
||||
|
||||
@extmod/modtrezormsg/modtrezormsg.c
|
||||
|
||||
##trezor.ui
|
||||
|
||||
@src/trezor/ui/__init__.py
|
||||
|
||||
###trezor.ui.display
|
||||
|
||||
@extmod/modtrezorui/modtrezorui-display.h
|
||||
|
||||
###trezor.utils
|
||||
|
||||
@extmod/modtrezorutils/modtrezorutils.c
|
@ -27,11 +27,20 @@ STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
/// def trezor.config.get(app: int, key: int) -> bytes
|
||||
/// '''
|
||||
/// Gets a value of given key for given app (or None if not set).
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_t key) {
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorConfig_Config_get_obj, mod_TrezorConfig_Config_get);
|
||||
|
||||
/// def trezor.config.set(app: int, key: int) -> bool
|
||||
/// '''
|
||||
/// Sets a value of given key for given app.
|
||||
/// Returns True on success.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_make_new(const mp_obj_type_t *type, size_
|
||||
}
|
||||
|
||||
/// def trezor.crypto.bip39.generate(strength: int) -> str
|
||||
///
|
||||
/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits)
|
||||
///
|
||||
/// '''
|
||||
/// Generate a mnemonic of given strength (128, 160, 192, 224 and 256 bits)
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength) {
|
||||
int bits = mp_obj_get_int(strength);
|
||||
if (bits % 32 || bits < 128 || bits > 256) {
|
||||
@ -38,9 +38,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_generate(mp_obj_t self, mp_obj_t strength
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_generate_obj, mod_TrezorCrypto_Bip39_generate);
|
||||
|
||||
/// def trezor.crypto.bip39.from_data(data: bytes) -> str
|
||||
///
|
||||
/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes)
|
||||
///
|
||||
/// '''
|
||||
/// Generate a mnemonic from given data (of 16, 20, 24, 28 and 32 bytes)
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) {
|
||||
mp_buffer_info_t bin;
|
||||
mp_get_buffer_raise(data, &bin, MP_BUFFER_READ);
|
||||
@ -56,9 +56,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_from_data(mp_obj_t self, mp_obj_t data) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_from_data_obj, mod_TrezorCrypto_Bip39_from_data);
|
||||
|
||||
/// def trezor.crypto.bip39.check(mnemonic: str) -> bool
|
||||
///
|
||||
/// Check whether given mnemonic is valid
|
||||
///
|
||||
/// '''
|
||||
/// Check whether given mnemonic is valid
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) {
|
||||
mp_buffer_info_t text;
|
||||
mp_get_buffer_raise(mnemonic, &text, MP_BUFFER_READ);
|
||||
@ -67,9 +67,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip39_check(mp_obj_t self, mp_obj_t mnemonic) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip39_check_obj, mod_TrezorCrypto_Bip39_check);
|
||||
|
||||
/// def trezor.crypto.bip39.seed(mnemonic: str, passphrase: str) -> bytes
|
||||
///
|
||||
/// Generate seed from mnemonic and passphrase
|
||||
///
|
||||
/// '''
|
||||
/// Generate seed from mnemonic and passphrase
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Bip39_seed(mp_obj_t self, mp_obj_t mnemonic, mp_obj_t passphrase) {
|
||||
mp_buffer_info_t mnemo;
|
||||
mp_buffer_info_t phrase;
|
||||
|
@ -21,9 +21,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Ed25519_make_new(const mp_obj_type_t *type, siz
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.ed25519.publickey(secret_key: bytes) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -38,9 +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(secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -58,10 +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(public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +22,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_make_new(const mp_obj_type_t *type, s
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.nist256p1.publickey(secret_key: bytes, compressed: bool=True) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -45,9 +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(secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -67,10 +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(public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
|
@ -21,9 +21,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_make_new(const mp_obj_type_t *type, size
|
||||
}
|
||||
|
||||
/// def trezor.crypto.random.uniform(n: int) -> int
|
||||
///
|
||||
/// Compute uniform random number from interval 0 ... n - 1
|
||||
///
|
||||
/// '''
|
||||
/// Compute uniform random number from interval 0 ... n - 1
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Random_uniform(mp_obj_t self, mp_obj_t n) {
|
||||
uint32_t nn = mp_obj_get_int(n);
|
||||
if (nn == 0) {
|
||||
@ -34,9 +34,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_uniform(mp_obj_t self, mp_obj_t n) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_uniform_obj, mod_TrezorCrypto_Random_uniform);
|
||||
|
||||
/// def trezor.crypto.random.bytes(len: int) -> bytes
|
||||
///
|
||||
/// Generate random bytes sequence of length len
|
||||
///
|
||||
/// '''
|
||||
/// Generate random bytes sequence of length len
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Random_bytes(mp_obj_t self, mp_obj_t len) {
|
||||
uint32_t l = mp_obj_get_int(len);
|
||||
vstr_t vstr;
|
||||
@ -47,9 +47,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Random_bytes(mp_obj_t self, mp_obj_t len) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Random_bytes_obj, mod_TrezorCrypto_Random_bytes);
|
||||
|
||||
/// def trezor.crypto.random.shuffle(data: list) -> None
|
||||
///
|
||||
/// Shuffles items of given list (in-place)
|
||||
///
|
||||
/// '''
|
||||
/// Shuffles items of given list (in-place)
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Random_shuffle(mp_obj_t self, mp_obj_t data) {
|
||||
mp_uint_t item_cnt;
|
||||
mp_obj_t *items;
|
||||
|
@ -20,9 +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(data: bytes=None) -> Ripemd160
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -36,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
@ -49,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +22,9 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_make_new(const mp_obj_type_t *type, s
|
||||
}
|
||||
|
||||
/// def trezor.crypto.curve.secp256k1.publickey(secret_key: bytes, compressed: bool=True) -> bytes
|
||||
///
|
||||
/// Computes public key from secret key.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -45,9 +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(secret_key: bytes, message: bytes) -> bytes
|
||||
///
|
||||
/// Uses secret key to produce the signature of message.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -67,10 +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(public_key: bytes, signature: bytes, message: bytes) -> bool
|
||||
///
|
||||
/// Uses public key to verify the signature of the message
|
||||
/// Returns True on success.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +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(data: bytes=None) -> Sha256
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -36,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
@ -49,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +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(data: bytes=None) -> Sha3_256
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -36,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
@ -49,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +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(data: bytes=None) -> Sha3_512
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -36,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
@ -49,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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,9 +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(data: bytes=None) -> Sha512
|
||||
///
|
||||
/// Creates a hash context object.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -35,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
@ -48,9 +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.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
|
@ -22,9 +22,9 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_make_new(const mp_obj_type_t *type, size_t
|
||||
}
|
||||
|
||||
/// def trezor.crypto.ssss.split(m: int, n: int, secret: bytes) -> tuple
|
||||
///
|
||||
/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme
|
||||
///
|
||||
/// '''
|
||||
/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t m = mp_obj_get_int(args[1]);
|
||||
mp_int_t n = mp_obj_get_int(args[2]);
|
||||
@ -54,9 +54,9 @@ STATIC mp_obj_t mod_TrezorCrypto_SSSS_split(size_t n_args, const mp_obj_t *args)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_SSSS_split_obj, 4, 4, mod_TrezorCrypto_SSSS_split);
|
||||
|
||||
/// def trezor.crypto.ssss.combine(shares: tuple) -> bytes
|
||||
///
|
||||
/// Combine M shares of Shamir's Secret Sharing Scheme into secret
|
||||
///
|
||||
/// '''
|
||||
/// Combine M shares of Shamir's Secret Sharing Scheme into secret
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorCrypto_SSSS_combine(mp_obj_t self, mp_obj_t shares) {
|
||||
mp_uint_t n;
|
||||
mp_obj_t *share;
|
||||
|
@ -37,9 +37,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a
|
||||
}
|
||||
|
||||
/// def trezor.msg.setup(ifaces: list) -> None
|
||||
///
|
||||
/// Configures USB interfaces with a list of tuples (interface_number, usage_page)
|
||||
///
|
||||
/// '''
|
||||
/// Configures USB interfaces with a list of tuples (interface_number, usage_page)
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_setup(mp_obj_t self, mp_obj_t ifaces) {
|
||||
mp_uint_t iface_cnt;
|
||||
mp_obj_t *iface;
|
||||
@ -68,9 +68,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_setup(mp_obj_t self, mp_obj_t ifaces) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_setup_obj, mod_TrezorMsg_Msg_setup);
|
||||
|
||||
/// def trezor.msg.send(iface: int, message: bytes) -> int
|
||||
///
|
||||
/// Sends message using USB HID (device) or UDP (emulator).
|
||||
///
|
||||
/// '''
|
||||
/// Sends message using USB HID (device) or UDP (emulator).
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t iface, mp_obj_t message) {
|
||||
uint8_t iface_num = mp_obj_get_int(iface);
|
||||
mp_buffer_info_t msg;
|
||||
@ -84,10 +84,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s
|
||||
#define TOUCH_IFACE 256
|
||||
|
||||
/// def trezor.msg.select(timeout_us: int) -> tuple
|
||||
///
|
||||
/// Polls the event queue and returns the event object.
|
||||
/// Function returns None if timeout specified in microseconds is reached.
|
||||
///
|
||||
/// '''
|
||||
/// 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) {
|
||||
|
@ -22,10 +22,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_make_new(const mp_obj_type_t *type, size_t
|
||||
}
|
||||
|
||||
/// def trezor.ui.display.bar(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -46,10 +46,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -66,10 +66,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -94,10 +94,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -124,10 +124,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -142,10 +142,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -161,10 +161,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -180,9 +180,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(text: bytes, font: int) -> int
|
||||
///
|
||||
/// Returns a width of text in pixels. Font font is used for rendering.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
@ -193,10 +193,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(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -212,12 +212,12 @@ STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args)
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5, mod_TrezorUi_Display_qrcode);
|
||||
|
||||
/// def trezor.ui.display.loader(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.
|
||||
///
|
||||
/// '''
|
||||
/// 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]);
|
||||
@ -253,11 +253,11 @@ 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(degrees: int=None) -> int
|
||||
///
|
||||
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
/// Everything needs to be redrawn again when this function is used.
|
||||
/// Call without the degrees parameter to just perform the read of the value.
|
||||
///
|
||||
/// '''
|
||||
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
/// Everything needs to be redrawn again when this function is used.
|
||||
/// Call without the degrees parameter to just perform the read of the value.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_orientation(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t deg;
|
||||
if (n_args > 1) {
|
||||
@ -274,10 +274,10 @@ STATIC mp_obj_t mod_TrezorUi_Display_orientation(size_t n_args, const mp_obj_t *
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_orientation_obj, 1, 2, mod_TrezorUi_Display_orientation);
|
||||
|
||||
/// def trezor.ui.display.backlight(val: int=None) -> int
|
||||
///
|
||||
/// Sets backlight intensity to the value specified in val.
|
||||
/// Call without the val parameter to just perform the read of the value.
|
||||
///
|
||||
/// '''
|
||||
/// Sets backlight intensity to the value specified in val.
|
||||
/// Call without the val parameter to just perform the read of the value.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_backlight(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t val;
|
||||
if (n_args > 1) {
|
||||
@ -294,9 +294,9 @@ STATIC mp_obj_t mod_TrezorUi_Display_backlight(size_t n_args, const mp_obj_t *ar
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_backlight_obj, 1, 2, mod_TrezorUi_Display_backlight);
|
||||
|
||||
/// def trezor.ui.display.raw(reg: int, data: bytes) -> None
|
||||
///
|
||||
/// Performs a raw command on the display. Read the datasheet to learn more.
|
||||
///
|
||||
/// '''
|
||||
/// 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;
|
||||
|
@ -28,9 +28,9 @@ STATIC mp_obj_t mod_TrezorUtils_Utils_make_new(const mp_obj_type_t *type, size_t
|
||||
}
|
||||
|
||||
/// def trezor.utils.memaccess(address: int, length: int) -> bytes
|
||||
///
|
||||
/// Creates a bytes object that can be used to access certain memory location.
|
||||
///
|
||||
/// '''
|
||||
/// 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);
|
||||
|
@ -19,9 +19,9 @@ from .hashlib import sha256
|
||||
_alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
|
||||
def encode(data: bytes) -> str:
|
||||
###
|
||||
### Convert bytes to base58 encoded string.
|
||||
###
|
||||
'''
|
||||
Convert bytes to base58 encoded string.
|
||||
'''
|
||||
origlen = len(data)
|
||||
data = data.lstrip(b'\0')
|
||||
newlen = len(data)
|
||||
@ -40,9 +40,9 @@ def encode(data: bytes) -> str:
|
||||
|
||||
|
||||
def decode(string: str) -> bytes:
|
||||
###
|
||||
### Convert base58 encoded string to bytes.
|
||||
###
|
||||
'''
|
||||
Convert base58 encoded string to bytes.
|
||||
'''
|
||||
origlen = len(string)
|
||||
string = string.lstrip(_alphabet[0])
|
||||
newlen = len(string)
|
||||
@ -61,21 +61,21 @@ def decode(string: str) -> bytes:
|
||||
|
||||
|
||||
def encode_check(data: bytes) -> str:
|
||||
###
|
||||
### Convert bytes to base58 encoded string, append checksum.
|
||||
###
|
||||
'''
|
||||
Convert bytes to base58 encoded string, append checksum.
|
||||
'''
|
||||
digest = sha256(sha256(data).digest()).digest()
|
||||
return encode(data + digest[:4])
|
||||
|
||||
def decode_check(string: str) -> bytes:
|
||||
###
|
||||
### Convert base58 encoded string to bytes and verify checksum.
|
||||
###
|
||||
'''
|
||||
Convert base58 encoded string to bytes and verify checksum.
|
||||
'''
|
||||
result = decode(string)
|
||||
result, check = result[:-4], result[-4:]
|
||||
digest = sha256(sha256(result).digest()).digest()
|
||||
|
||||
if check != digest[:4]:
|
||||
raise ValueError("Invalid checksum")
|
||||
raise ValueError('Invalid checksum')
|
||||
|
||||
return result
|
||||
|
@ -1,7 +1,7 @@
|
||||
def new(key, msg, digestmod) -> Hmac:
|
||||
###
|
||||
### Creates a HMAC context object.
|
||||
###
|
||||
'''
|
||||
Creates a HMAC context object.
|
||||
'''
|
||||
return Hmac(key, msg, digestmod)
|
||||
|
||||
class Hmac:
|
||||
@ -18,15 +18,15 @@ class Hmac:
|
||||
self.update(msg)
|
||||
|
||||
def update(self, msg: bytes) -> None:
|
||||
###
|
||||
### Update the context with data.
|
||||
###
|
||||
'''
|
||||
Update the context with data.
|
||||
'''
|
||||
self.__inner.update(msg)
|
||||
|
||||
def digest(self) -> bytes:
|
||||
###
|
||||
### Returns the digest of processed data.
|
||||
###
|
||||
'''
|
||||
Returns the digest of processed data.
|
||||
'''
|
||||
outer = self.__digestmod()
|
||||
outer.update(bytes((x ^ 0x5C) for x in self.__key))
|
||||
outer.update(self.__inner.digest())
|
||||
|
@ -4,12 +4,18 @@ except ImportError:
|
||||
resdata = None
|
||||
|
||||
def load(name):
|
||||
'''
|
||||
Loads resource of a given name as bytes.
|
||||
'''
|
||||
if resdata and name in resdata:
|
||||
return resdata[name]
|
||||
with open(name, 'rb') as f:
|
||||
return f.read()
|
||||
|
||||
def gettext(message):
|
||||
'''
|
||||
Returns localized string. This function is aliased to _.
|
||||
'''
|
||||
return message
|
||||
|
||||
_ = gettext
|
||||
|
Loading…
Reference in New Issue
Block a user