travis: add make style (using flake8)

pull/25/head
Pavol Rusnak 7 years ago
parent 2c3221810e
commit 73b2ea6c85
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -38,6 +38,7 @@ script:
- test "$GOAL" != "unix" || make build_unix TREZOR_NOUI=1
- test "$GOAL" != "unix" || make test
- test "$GOAL" != "unix" || make testpy
- test "$GOAL" != "unix" || make style
notifications:
webhooks:

@ -50,6 +50,9 @@ testpy: ## run selected unit tests from python-trezor
pylint: ## run pylint on application sources
pylint --rcfile=pylint.rc -E $(shell find src -name *.py)
style: ## run code style check on application sources
flake8 --ignore=E221,E241,E402,E501,F401 $(shell find src -name *.py)
## build commands:
build: build_boardloader build_bootloader build_firmware build_unix build_cross ## build all

@ -26,6 +26,7 @@ def strip(address_type, raw_address):
l = length(address_type)
return raw_address[l:]
def split(coin, raw_address):
l = None
for f in ['', '_p2sh', '_p2wpkh', '_p2wsh']:

@ -2,6 +2,7 @@ from trezor.crypto.hashlib import sha256
from apps.wallet.sign_tx.signing import HashWriter, write_varint
def message_digest(coin, message):
h = HashWriter(sha256)

@ -9,5 +9,6 @@ def dispatch_EthereumGetAddress(*args, **kwargs):
from .ethereum_get_address import layout_ethereum_get_address
return layout_ethereum_get_address(*args, **kwargs)
def boot():
register(EthereumGetAddress, protobuf_workflow, dispatch_EthereumGetAddress)

@ -13,8 +13,8 @@ async def layout_ethereum_get_address(session_id, msg):
node.derive_path(msg.address_n or ())
seckey = node.private_key()
public_key = secp256k1.publickey(seckey, False) # uncompressed
address = sha3_256(public_key[1:]).digest(True)[12:] # Keccak
public_key = secp256k1.publickey(seckey, False) # uncompressed
address = sha3_256(public_key[1:]).digest(True)[12:] # Keccak
if msg.show_display:
await _show_address(session_id, address)

@ -86,8 +86,8 @@ _APDU_DATA = const(7) # uint8_t data[1]; // Data field
def frame_init() -> dict:
# uint32_t cid; // Channel identifier
# uint8_t cmd; // Command - b7 set
# uint32_t cid; // Channel identifier
# uint8_t cmd; // Command - b7 set
# uint8_t bcnth; // Message byte count - high part
# uint8_t bcntl; // Message byte count - low part
# uint8_t data[HID_RPT_SIZE - 7]; // Data payload
@ -100,8 +100,8 @@ def frame_init() -> dict:
def frame_cont() -> dict:
# uint32_t cid; // Channel identifier
# uint8_t seq; // Sequence number - b7 cleared
# uint32_t cid; // Channel identifier
# uint8_t seq; // Sequence number - b7 cleared
# uint8_t data[HID_RPT_SIZE - 5]; // Data payload
return {
'cid': 0 | uctypes.UINT32,
@ -114,7 +114,7 @@ def resp_cmd_init() -> dict:
# uint8_t nonce[8]; // Client application nonce
# uint32_t cid; // Channel identifier
# uint8_t versionInterface; // Interface version
# uint8_t versionMajor; // Major version number
# uint8_t versionMajor; // Major version number
# uint8_t versionMinor; // Minor version number
# uint8_t versionBuild; // Build version number
# uint8_t capFlags; // Capabilities flags
@ -415,8 +415,7 @@ class ConfirmContent(ui.Widget):
name = knownapps.knownapps[app_id]
icon = res.load('apps/fido_u2f/res/u2f_%s.toif' % name.lower().replace(' ', '_'))
else:
name = ubinascii.hexlify(app_id[:4]) + '...' + \
ubinascii.hexlify(app_id[-4:])
name = '%s...%s' % (ubinascii.hexlify(app_id[:4]), ubinascii.hexlify(app_id[-4:]))
icon = res.load('apps/fido_u2f/res/u2f_unknown.toif')
self.app_name = name
self.app_icon = icon

@ -1,12 +1,12 @@
from trezor.crypto import hashlib
knownapps = {
hashlib.sha256(b'https://bitbucket.org').digest() : 'Bitbucket',
hashlib.sha256(b'https://www.dropbox.com/u2f-app-id.json').digest() : 'Dropbox',
hashlib.sha256(b'https://www.fastmail.com').digest() : 'FastMail',
hashlib.sha256(b'https://github.com/u2f/trusted_facets').digest() : 'GitHub',
hashlib.sha256(b'https://gitlab.com').digest() : 'GitLab',
hashlib.sha256(b'https://www.gstatic.com/securitykey/origins.json').digest() : 'Google',
hashlib.sha256(b'https://slushpool.com/static/security/u2f.json').digest() : 'Slush Pool',
hashlib.sha256(b'https://demo.yubico.com').digest() : 'Yubico U2F Demo',
hashlib.sha256(b'https://bitbucket.org').digest(): 'Bitbucket',
hashlib.sha256(b'https://www.dropbox.com/u2f-app-id.json').digest(): 'Dropbox',
hashlib.sha256(b'https://www.fastmail.com').digest(): 'FastMail',
hashlib.sha256(b'https://github.com/u2f/trusted_facets').digest(): 'GitHub',
hashlib.sha256(b'https://gitlab.com').digest(): 'GitLab',
hashlib.sha256(b'https://www.gstatic.com/securitykey/origins.json').digest(): 'Google',
hashlib.sha256(b'https://slushpool.com/static/security/u2f.json').digest(): 'Slush Pool',
hashlib.sha256(b'https://demo.yubico.com').digest(): 'Yubico U2F Demo',
}

@ -7,7 +7,6 @@ async def layout_get_entropy(session_id, msg):
from trezor.messages.Entropy import Entropy
from trezor.crypto import random
l = min(msg.size, 1024)
await _show_entropy(session_id)

@ -53,7 +53,6 @@ def sign_challenge(seckey: bytes,
from trezor.crypto.curve import ed25519
from ..common.signverify import message_digest
if sigtype == 'gpg':
data = challenge_hidden
elif sigtype == 'ssh':
@ -63,8 +62,7 @@ def sign_challenge(seckey: bytes,
data = challenge_hidden
else:
# sigtype is coin
challenge = sha256(challenge_hidden).digest() + \
sha256(challenge_visual).digest()
challenge = sha256(challenge_hidden).digest() + sha256(challenge_visual).digest()
data = message_digest(sigtype, challenge)
if curve == 'secp256k1':

@ -162,7 +162,7 @@ class MessageType(Type):
@classmethod
async def load(cls, source=None, target=None):
if target is None:
target = build_protobuf_message(cls)
target = build_message(cls)
if source is None:
source = StreamReader()
try:

@ -48,6 +48,7 @@ class __dummy:
def __getitem__(self, *args):
return object
__t = __dummy()
for __n in __names_get:
@ -64,4 +65,5 @@ def TypeVar(*args):
def NewType(*args):
return lambda x: x
TYPE_CHECKING = False

@ -59,25 +59,23 @@ def decode(string: str) -> bytes:
return bytes((b for b in reversed(result + [0] * (origlen - newlen))))
def encode_check(data: bytes, digestfunc=None) -> str:
def _dsha256_32(data: bytes) -> bytes:
from .hashlib import sha256
return sha256(sha256(data).digest()).digest()[:4]
def encode_check(data: bytes, digestfunc=_dsha256_32) -> str:
'''
Convert bytes to base58 encoded string, append checksum.
'''
if digestfunc is None:
from .hashlib import sha256
digestfunc = lambda x: sha256(sha256(x).digest()).digest()[:4]
return encode(data + digestfunc(data))
def decode_check(string: str, digestfunc=None) -> bytes:
def decode_check(string: str, digestfunc=_dsha256_32) -> bytes:
'''
Convert base58 encoded string to bytes and verify checksum.
'''
result = decode(string)
if digestfunc is None:
from .hashlib import sha256
digestfunc = lambda x: sha256(sha256(x).digest()).digest()[:4]
digestlen = len(digestfunc(b''))
result, check = result[:-digestlen], result[-digestlen:]

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Address(p.MessageType):
FIELDS = {
1: ('address', p.UnicodeType, 0), # required
1: ('address', p.UnicodeType, 0), # required
}
MESSAGE_WIRE_TYPE = 30

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ApplySettings(p.MessageType):
FIELDS = {
1: ('language', p.UnicodeType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ButtonAck(p.MessageType):
MESSAGE_WIRE_TYPE = 27

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ButtonRequest(p.MessageType):
FIELDS = {
1: ('code', p.UVarintType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Cancel(p.MessageType):
MESSAGE_WIRE_TYPE = 20

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ChangePin(p.MessageType):
FIELDS = {
1: ('remove', p.BoolType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class CipherKeyValue(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class CipheredKeyValue(p.MessageType):
FIELDS = {
1: ('value', p.BytesType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ClearSession(p.MessageType):
MESSAGE_WIRE_TYPE = 24

@ -1,17 +1,16 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class CoinType(p.MessageType):
FIELDS = {
1: ('coin_name', p.UnicodeType, 0),
2: ('coin_shortcut', p.UnicodeType, 0),
3: ('address_type', p.UVarintType, 0), # default=0
3: ('address_type', p.UVarintType, 0), # default=0
4: ('maxfee_kb', p.UVarintType, 0),
5: ('address_type_p2sh', p.UVarintType, 0), # default=5
5: ('address_type_p2sh', p.UVarintType, 0), # default=5
8: ('signed_message_header', p.UnicodeType, 0),
9: ('xpub_magic', p.UVarintType, 0), # default=76067358
10: ('xprv_magic', p.UVarintType, 0), # default=76066276
9: ('xpub_magic', p.UVarintType, 0), # default=76067358
10: ('xprv_magic', p.UVarintType, 0), # default=76066276
11: ('segwit', p.BoolType, 0),
}

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkDecision(p.MessageType):
FIELDS = {
1: ('yes_no', p.BoolType, 0), # required
1: ('yes_no', p.BoolType, 0), # required
}
MESSAGE_WIRE_TYPE = 100

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkFlashErase(p.MessageType):
FIELDS = {
1: ('sector', p.UVarintType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkGetState(p.MessageType):
MESSAGE_WIRE_TYPE = 101

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkLog(p.MessageType):
FIELDS = {
1: ('level', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkMemory(p.MessageType):
FIELDS = {
1: ('memory', p.BytesType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkMemoryRead(p.MessageType):
FIELDS = {
1: ('address', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkMemoryWrite(p.MessageType):
FIELDS = {
1: ('address', p.UVarintType, 0),

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodeType import HDNodeType
class DebugLinkState(p.MessageType):
FIELDS = {
1: ('layout', p.BytesType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DebugLinkStop(p.MessageType):
MESSAGE_WIRE_TYPE = 103

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DecryptMessage(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class DecryptedMessage(p.MessageType):
FIELDS = {
1: ('message', p.BytesType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ECDHSessionKey(p.MessageType):
FIELDS = {
1: ('session_key', p.BytesType, 0),

@ -1,14 +1,13 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EncryptMessage(p.MessageType):
FIELDS = {
1: ('pubkey', p.BytesType, 0),
2: ('message', p.BytesType, 0),
3: ('display_only', p.BoolType, 0),
4: ('address_n', p.UVarintType, p.FLAG_REPEATED),
5: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
5: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
}
MESSAGE_WIRE_TYPE = 49

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EncryptedMessage(p.MessageType):
FIELDS = {
1: ('nonce', p.BytesType, 0),

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Entropy(p.MessageType):
FIELDS = {
1: ('entropy', p.BytesType, 0), # required
1: ('entropy', p.BytesType, 0), # required
}
MESSAGE_WIRE_TYPE = 10

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EntropyAck(p.MessageType):
FIELDS = {
1: ('entropy', p.BytesType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EntropyRequest(p.MessageType):
MESSAGE_WIRE_TYPE = 35

@ -1,12 +1,11 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EstimateTxSize(p.MessageType):
FIELDS = {
1: ('outputs_count', p.UVarintType, 0), # required
2: ('inputs_count', p.UVarintType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
1: ('outputs_count', p.UVarintType, 0), # required
2: ('inputs_count', p.UVarintType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
}
MESSAGE_WIRE_TYPE = 43

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EthereumAddress(p.MessageType):
FIELDS = {
1: ('address', p.BytesType, 0), # required
1: ('address', p.BytesType, 0), # required
}
MESSAGE_WIRE_TYPE = 57

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EthereumGetAddress(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EthereumSignTx(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EthereumTxAck(p.MessageType):
FIELDS = {
1: ('data_chunk', p.BytesType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class EthereumTxRequest(p.MessageType):
FIELDS = {
1: ('data_length', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Failure(p.MessageType):
FIELDS = {
1: ('code', p.UVarintType, 0),

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .CoinType import CoinType
class Features(p.MessageType):
FIELDS = {
1: ('vendor', p.UnicodeType, 0),

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class FirmwareErase(p.MessageType):
MESSAGE_WIRE_TYPE = 6

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class FirmwareRequest(p.MessageType):
FIELDS = {
1: ('offset', p.UVarintType, 0),

@ -1,11 +1,10 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class FirmwareUpload(p.MessageType):
FIELDS = {
1: ('payload', p.BytesType, 0), # required
1: ('payload', p.BytesType, 0), # required
2: ('hash', p.BytesType, 0),
}
MESSAGE_WIRE_TYPE = 7

@ -1,15 +1,14 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType
class GetAddress(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
2: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
3: ('show_display', p.BoolType, 0),
4: ('multisig', MultisigRedeemScriptType, 0),
5: ('script_type', p.UVarintType, 0), # default=0
5: ('script_type', p.UVarintType, 0), # default=0
}
MESSAGE_WIRE_TYPE = 29

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .IdentityType import IdentityType
class GetECDHSessionKey(p.MessageType):
FIELDS = {
1: ('identity', IdentityType, 0),

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class GetEntropy(p.MessageType):
FIELDS = {
1: ('size', p.UVarintType, 0), # required
1: ('size', p.UVarintType, 0), # required
}
MESSAGE_WIRE_TYPE = 9

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class GetFeatures(p.MessageType):
MESSAGE_WIRE_TYPE = 55

@ -1,13 +1,12 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class GetPublicKey(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('ecdsa_curve_name', p.UnicodeType, 0),
3: ('show_display', p.BoolType, 0),
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
}
MESSAGE_WIRE_TYPE = 11

@ -1,11 +1,10 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodeType import HDNodeType
class HDNodePathType(p.MessageType):
FIELDS = {
1: ('node', HDNodeType, 0), # required
1: ('node', HDNodeType, 0), # required
2: ('address_n', p.UVarintType, p.FLAG_REPEATED),
}

@ -1,14 +1,13 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class HDNodeType(p.MessageType):
FIELDS = {
1: ('depth', p.UVarintType, 0), # required
2: ('fingerprint', p.UVarintType, 0), # required
3: ('child_num', p.UVarintType, 0), # required
4: ('chain_code', p.BytesType, 0), # required
1: ('depth', p.UVarintType, 0), # required
2: ('fingerprint', p.UVarintType, 0), # required
3: ('child_num', p.UVarintType, 0), # required
4: ('chain_code', p.BytesType, 0), # required
5: ('private_key', p.BytesType, 0),
6: ('public_key', p.BytesType, 0),
}

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class IdentityType(p.MessageType):
FIELDS = {
1: ('proto', p.UnicodeType, 0),
@ -10,5 +9,5 @@ class IdentityType(p.MessageType):
3: ('host', p.UnicodeType, 0),
4: ('port', p.UnicodeType, 0),
5: ('path', p.UnicodeType, 0),
6: ('index', p.UVarintType, 0), # default=0
6: ('index', p.UVarintType, 0), # default=0
}

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Initialize(p.MessageType):
MESSAGE_WIRE_TYPE = 0

@ -1,16 +1,15 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodeType import HDNodeType
class LoadDevice(p.MessageType):
FIELDS = {
1: ('mnemonic', p.UnicodeType, 0),
2: ('node', HDNodeType, 0),
3: ('pin', p.UnicodeType, 0),
4: ('passphrase_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=u'english'
5: ('language', p.UnicodeType, 0), # default=u'english'
6: ('label', p.UnicodeType, 0),
7: ('skip_checksum', p.BoolType, 0),
8: ('u2f_counter', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class MessageSignature(p.MessageType):
FIELDS = {
1: ('address', p.UnicodeType, 0),

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodePathType import HDNodePathType
class MultisigRedeemScriptType(p.MessageType):
FIELDS = {
1: ('pubkeys', HDNodePathType, p.FLAG_REPEATED),

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class PassphraseAck(p.MessageType):
FIELDS = {
1: ('passphrase', p.UnicodeType, 0), # required
1: ('passphrase', p.UnicodeType, 0), # required
}
MESSAGE_WIRE_TYPE = 42

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class PassphraseRequest(p.MessageType):
MESSAGE_WIRE_TYPE = 41

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class PinMatrixAck(p.MessageType):
FIELDS = {
1: ('pin', p.UnicodeType, 0), # required
1: ('pin', p.UnicodeType, 0), # required
}
MESSAGE_WIRE_TYPE = 19

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class PinMatrixRequest(p.MessageType):
FIELDS = {
1: ('type', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Ping(p.MessageType):
FIELDS = {
1: ('message', p.UnicodeType, 0),

@ -1,12 +1,11 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodeType import HDNodeType
class PublicKey(p.MessageType):
FIELDS = {
1: ('node', HDNodeType, 0), # required
1: ('node', HDNodeType, 0), # required
2: ('xpub', p.UnicodeType, 0),
}
MESSAGE_WIRE_TYPE = 12

@ -1,14 +1,13 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class RecoveryDevice(p.MessageType):
FIELDS = {
1: ('word_count', p.UVarintType, 0),
2: ('passphrase_protection', p.BoolType, 0),
3: ('pin_protection', p.BoolType, 0),
4: ('language', p.UnicodeType, 0), # default=u'english'
4: ('language', p.UnicodeType, 0), # default=u'english'
5: ('label', p.UnicodeType, 0),
6: ('enforce_wordlist', p.BoolType, 0),
8: ('type', p.UVarintType, 0),

@ -1,15 +1,14 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class ResetDevice(p.MessageType):
FIELDS = {
1: ('display_random', p.BoolType, 0),
2: ('strength', p.UVarintType, 0), # default=256
2: ('strength', p.UVarintType, 0), # default=256
3: ('passphrase_protection', p.BoolType, 0),
4: ('pin_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=u'english'
5: ('language', p.UnicodeType, 0), # default=u'english'
6: ('label', p.UnicodeType, 0),
7: ('u2f_counter', p.UVarintType, 0),
}

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class SetU2FCounter(p.MessageType):
FIELDS = {
1: ('u2f_counter', p.UVarintType, 0),

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .IdentityType import IdentityType
class SignIdentity(p.MessageType):
FIELDS = {
1: ('identity', IdentityType, 0),

@ -1,12 +1,11 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class SignMessage(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('message', p.BytesType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
2: ('message', p.BytesType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
}
MESSAGE_WIRE_TYPE = 38

@ -1,14 +1,13 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class SignTx(p.MessageType):
FIELDS = {
1: ('outputs_count', p.UVarintType, 0), # required
2: ('inputs_count', p.UVarintType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
4: ('version', p.UVarintType, 0), # default=1
5: ('lock_time', p.UVarintType, 0), # default=0
1: ('outputs_count', p.UVarintType, 0), # required
2: ('inputs_count', p.UVarintType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
4: ('version', p.UVarintType, 0), # default=1
5: ('lock_time', p.UVarintType, 0), # default=0
}
MESSAGE_WIRE_TYPE = 15

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class SignedIdentity(p.MessageType):
FIELDS = {
1: ('address', p.UnicodeType, 0),

@ -1,18 +1,17 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .TxInputType import TxInputType
from .TxOutputType import TxOutputType
from .TransactionType import TransactionType
class SimpleSignTx(p.MessageType):
FIELDS = {
1: ('inputs', TxInputType, p.FLAG_REPEATED),
2: ('outputs', TxOutputType, p.FLAG_REPEATED),
3: ('transactions', TransactionType, p.FLAG_REPEATED),
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
5: ('version', p.UVarintType, 0), # default=1
6: ('lock_time', p.UVarintType, 0), # default=0
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
5: ('version', p.UVarintType, 0), # default=1
6: ('lock_time', p.UVarintType, 0), # default=0
}
MESSAGE_WIRE_TYPE = 16

@ -1,12 +1,11 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .HDNodeType import HDNodeType
class Storage(p.MessageType):
FIELDS = {
1: ('version', p.UVarintType, 0), # required
1: ('version', p.UVarintType, 0), # required
2: ('node', HDNodeType, 0),
3: ('mnemonic', p.UnicodeType, 0),
4: ('passphrase_protection', p.BoolType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class Success(p.MessageType):
FIELDS = {
1: ('message', p.UnicodeType, 0),

@ -1,11 +1,10 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .TxInputType import TxInputType
from .TxOutputBinType import TxOutputBinType
from .TxOutputType import TxOutputType
class TransactionType(p.MessageType):
FIELDS = {
1: ('version', p.UVarintType, 0),

@ -1,9 +1,8 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .TransactionType import TransactionType
class TxAck(p.MessageType):
FIELDS = {
1: ('tx', TransactionType, 0),

@ -1,17 +1,16 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType
class TxInputType(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('prev_hash', p.BytesType, 0), # required
3: ('prev_index', p.UVarintType, 0), # required
2: ('prev_hash', p.BytesType, 0), # required
3: ('prev_index', p.UVarintType, 0), # required
4: ('script_sig', p.BytesType, 0),
5: ('sequence', p.UVarintType, 0), # default=4294967295
6: ('script_type', p.UVarintType, 0), # default=0
5: ('sequence', p.UVarintType, 0), # default=4294967295
6: ('script_type', p.UVarintType, 0), # default=0
7: ('multisig', MultisigRedeemScriptType, 0),
8: ('amount', p.UVarintType, 0),
}

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class TxOutputBinType(p.MessageType):
FIELDS = {
1: ('amount', p.UVarintType, 0), # required
2: ('script_pubkey', p.BytesType, 0), # required
1: ('amount', p.UVarintType, 0), # required
2: ('script_pubkey', p.BytesType, 0), # required
}

@ -1,15 +1,14 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType
class TxOutputType(p.MessageType):
FIELDS = {
1: ('address', p.UnicodeType, 0),
2: ('address_n', p.UVarintType, p.FLAG_REPEATED),
3: ('amount', p.UVarintType, 0), # required
4: ('script_type', p.UVarintType, 0), # required
3: ('amount', p.UVarintType, 0), # required
4: ('script_type', p.UVarintType, 0), # required
5: ('multisig', MultisigRedeemScriptType, 0),
6: ('op_return_data', p.BytesType, 0),
}

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
from .TxRequestDetailsType import TxRequestDetailsType
from .TxRequestSerializedType import TxRequestSerializedType
class TxRequest(p.MessageType):
FIELDS = {
1: ('request_type', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class TxRequestDetailsType(p.MessageType):
FIELDS = {
1: ('request_index', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class TxRequestSerializedType(p.MessageType):
FIELDS = {
1: ('signature_index', p.UVarintType, 0),

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class TxSize(p.MessageType):
FIELDS = {
1: ('tx_size', p.UVarintType, 0),

@ -1,13 +1,12 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class VerifyMessage(p.MessageType):
FIELDS = {
1: ('address', p.UnicodeType, 0),
2: ('signature', p.BytesType, 0),
3: ('message', p.BytesType, 0),
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
4: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
}
MESSAGE_WIRE_TYPE = 39

@ -1,7 +1,6 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class WipeDevice(p.MessageType):
MESSAGE_WIRE_TYPE = 5

@ -1,10 +1,9 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class WordAck(p.MessageType):
FIELDS = {
1: ('word', p.UnicodeType, 0), # required
1: ('word', p.UnicodeType, 0), # required
}
MESSAGE_WIRE_TYPE = 47

@ -1,8 +1,7 @@
# Automatically generated by pb2py
from micropython import const
import protobuf as p
class WordRequest(p.MessageType):
FIELDS = {
1: ('type', p.UVarintType, 0),

@ -9,5 +9,5 @@ def get_protobuf_type_name(wire_type):
def get_protobuf_type(wire_type):
name = get_protobuf_type_name(wire_type)
module = __import__('trezor.messages.%s' % name, None, None, (name,) , 0)
module = __import__('trezor.messages.%s' % name, None, None, (name, ), 0)
return getattr(module, name)

@ -20,4 +20,5 @@ def gettext(message):
'''
return message
_ = gettext

@ -18,9 +18,9 @@ def rgbcolor(r: int, g: int, b: int) -> int:
LIGHT_RED = rgbcolor(0xFF, 0x00, 0x00)
#RED E4572E
# RED E4572E
RED = rgbcolor(0xE4, 0x57, 0x2E)
#ACTIVE DARK RED A64022
# ACTIVE DARK RED A64022
ACTIVE_RED = rgbcolor(0xA6, 0x40, 0x22)
PINK = rgbcolor(0xE9, 0x1E, 0x63)
PURPLE = rgbcolor(0x9C, 0x27, 0xB0)
@ -31,9 +31,9 @@ LIGHT_BLUE = rgbcolor(0x03, 0xA9, 0xF4)
CYAN = rgbcolor(0x00, 0xBC, 0xD4)
TEAL = rgbcolor(0x00, 0x96, 0x88)
#GREEN 4CC148
# GREEN 4CC148
GREEN = rgbcolor(0x4C, 0xC1, 0x48)
#ACTIVE DARK GREEN 1A8C14
# ACTIVE DARK GREEN 1A8C14
ACTIVE_GREEN = rgbcolor(0x1A, 0x8C, 0x14)
LIGHT_GREEN = rgbcolor(0x87, 0xCE, 0x26)

@ -42,9 +42,9 @@ class Swipe(ui.Widget):
# check if its vertical scroll up
velya = abs(pdy / td) if td > 0 else 1
ratio = int(pdxa / pdya * 100) if pdya > 0 else 100
if (velya >= _SWIPE_VELOCITY_THRESHOLD
and pdya >= _SWIPE_DISTANCE_THRESHOLD
and ratio <= _SWIPE_RATIO_THRESHOLD):
if (velya >= _SWIPE_VELOCITY_THRESHOLD and
pdya >= _SWIPE_DISTANCE_THRESHOLD and
ratio <= _SWIPE_RATIO_THRESHOLD):
light = ui.display.backlight()
if light > self.light_target:
light -= 5
@ -68,17 +68,17 @@ class Swipe(ui.Widget):
# Horizontal direction
velxa = abs(pdx / td)
ratio = int(pdya / pdxa * 100) if pdxa > 0 else 100
if (velxa >= _SWIPE_VELOCITY_THRESHOLD
and pdxa >= _SWIPE_DISTANCE_THRESHOLD
and ratio <= _SWIPE_RATIO_THRESHOLD):
if (velxa >= _SWIPE_VELOCITY_THRESHOLD and
pdxa >= _SWIPE_DISTANCE_THRESHOLD and
ratio <= _SWIPE_RATIO_THRESHOLD):
return SWIPE_RIGHT if pdx > 0 else SWIPE_LEFT
else:
# Vertical direction
velya = abs(pdy / td)
ratio = int(pdxa / pdya * 100) if pdya > 0 else 100
if (velya >= _SWIPE_VELOCITY_THRESHOLD
and pdya >= _SWIPE_DISTANCE_THRESHOLD
and ratio <= _SWIPE_RATIO_THRESHOLD):
if (velya >= _SWIPE_VELOCITY_THRESHOLD and
pdya >= _SWIPE_DISTANCE_THRESHOLD and
ratio <= _SWIPE_RATIO_THRESHOLD):
if pdy < 0:
ui.display.backlight(self.light_origin)
return SWIPE_DOWN if pdy > 0 else SWIPE_UP

@ -3,6 +3,8 @@ CURDIR=$(pwd)
mkdir -p $CURDIR/pb2/
echo > $CURDIR/pb2/__init__.py
mkdir -p ../src/trezor/messages
INDEX=../src/trezor/messages/wire_types.py
rm -f $INDEX
echo '# Automatically generated by pb2py' >> $INDEX
@ -18,7 +20,7 @@ done
for i in types messages storage ; do
# Convert google protobuf library to trezor's internal format
cd $CURDIR
../../trezor-common/tools/pb2py -m -p $CURDIR -i $INDEX $i ../src/trezor/messages/
./pb2py -m -p $CURDIR -i $INDEX $i ../src/trezor/messages/
done
rm -rf $CURDIR/pb2/

@ -0,0 +1,189 @@
#!/usr/bin/env python
# Converts Google's protobuf python definitions of TREZOR wire messages
# to plain-python objects as used in TREZOR Core and python-trezor
import sys
import os
import argparse
from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper
def process_type(t, cls, msg_id, indexfile, is_upy):
print(" * type %s" % t)
imports = ['import protobuf as p']
out = ["", "", "class %s(p.MessageType):" % t, ]
if cls.DESCRIPTOR.fields_by_name:
out.append(" FIELDS = {")
elif msg_id is None:
out.append(" pass")
for v in sorted(cls.DESCRIPTOR.fields_by_name.values(), key=lambda x: x.number):
number = v.number
fieldname = v.name
type = None
repeated = v.label == 3
required = v.label == 2
# print v.has_default_value, v.default_value
if v.type in (4, 13, 14):
# TYPE_UINT64 = 4
# TYPE_UINT32 = 13
# TYPE_ENUM = 14
type = 'p.UVarintType'
elif v.type == 9:
# TYPE_STRING = 9
type = 'p.UnicodeType'
elif v.type == 8:
# TYPE_BOOL = 8
type = 'p.BoolType'
elif v.type == 12:
# TYPE_BYTES = 12
type = 'p.BytesType'
elif v.type == 11:
# TYPE_MESSAGE = 1
type = v.message_type.name
imports.append("from .%s import %s" %
(v.message_type.name, v.message_type.name))
else:
raise Exception("Unknown field type %s for field %s" %
(v.type, fieldname))
if required:
comment = ' # required'
elif v.has_default_value:
comment = ' # default=%s' % repr(v.default_value)
else:
comment = ''
if repeated:
flags = 'p.FLAG_REPEATED'
else:
flags = '0'
out.append(" %d: ('%s', %s, %s),%s" %
(number, fieldname, type, flags, comment))
# print fieldname, number, type, repeated, comment
# print v.__dict__
# print v.CPPTYPE_STRING
# print v.LABEL_REPEATED
# print v.enum_type
# v.has_default_value, v.default_value
# v.label == 3 # repeated
# print v.number
if cls.DESCRIPTOR.fields_by_name:
out.append(" }")
if msg_id is not None:
out.append(" MESSAGE_WIRE_TYPE = %d" % msg_id)
if indexfile is not None:
if is_upy:
indexfile.write("%s = const(%d)\n" % (t, msg_id))
else:
indexfile.write("%s = %d\n" % (t, msg_id))
return imports + out
def process_enum(t, cls, is_upy):
out = []
if is_upy:
out += ("from micropython import const", "")
print(" * enum %s" % t)
for k, v in cls.items():
# Remove type name from the beginning of the constant
# For example "PinMatrixRequestType_Current" -> "Current"
if k.startswith("%s_" % t):
k = k.replace("%s_" % t, '')
# If type ends with *Type, but constant use type name without *Type, remove it too :)
# For example "ButtonRequestType & ButtonRequest_Other" => "Other"
if t.endswith("Type") and k.startswith("%s_" % t.replace("Type", '')):
k = k.replace("%s_" % t.replace("Type", ''), '')
if is_upy:
out.append("%s = const(%s)" % (k, v))
else:
out.append("%s = %s" % (k, v))
return out
def find_msg_type(msg_types, t):
for k, v in msg_types:
msg_name = k.replace('MessageType_', '')
if msg_name == t:
return v
def process_module(mod, genpath, indexfile, is_upy):
print("Processing module %s" % mod.__name__)
types = dict([(name, cls)
for name, cls in mod.__dict__.items() if isinstance(cls, type)])
msg_types = __import__('pb2', globals(), locals(), [
'messages_pb2', ]).messages_pb2.MessageType.items()
for t, cls in types.items():
# Find message type for given class
msg_id = find_msg_type(msg_types, t)
out = process_type(t, cls, msg_id, indexfile, is_upy)
write_to_file(genpath, t, out)
enums = dict([(name, cls) for name, cls in mod.__dict__.items()
if isinstance(cls, EnumTypeWrapper)])
for t, cls in enums.items():
out = process_enum(t, cls, is_upy)
write_to_file(genpath, t, out)
def write_to_file(genpath, t, out):
# Write generated sourcecode to given file
f = open(os.path.join(genpath, "%s.py" % t), 'w')
out = ["# Automatically generated by pb2py"] + out
data = "\n".join(out) + "\n"
f.write(data)
f.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('modulename', type=str, help="Name of module to generate")
parser.add_argument('genpath', type=str, help="Directory for generated source code")
parser.add_argument('-i', '--indexfile', type=str, help="[optional] Generate index file of wire types")
parser.add_argument('-p', '--protopath', type=str, help="[optional] Path to search for pregenerated Google's python sources")
parser.add_argument('-m', '--micropython', action='store_true', help="Use micropython-favoured source code")
args = parser.parse_args()
if args.indexfile:
indexfile = open(args.indexfile, 'a')
else:
indexfile = None
if args.protopath:
sys.path.append(args.protopath)
# Dynamically load module from argv[1]
tmp = __import__('pb2', globals(), locals(), ['%s_pb2' % args.modulename])
mod = getattr(tmp, "%s_pb2" % args.modulename)
process_module(mod, args.genpath, indexfile, args.micropython)
Loading…
Cancel
Save