1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-05 23:10:12 +00:00
trezor-firmware/common/protob/check.py

38 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import re
import sys
from glob import glob
error = False
MYDIR = os.path.dirname(__file__)
feat(core/ethereum): EIP-712 Based on original contribution by Max Kupriianov <xlab@hey.com> Implemented EIP-712 typed data signatures in Ethereum app. Add eth_abi into pyproject deps device test for EIP 712 fixed hex decoding for address fixup! fixed hex decoding for address code quality, more pythonic code, removing unused imports running black and isort on changed files trezorctl file input for EIP 712 data signing fixup! code quality, more pythonic code, removing unused imports fixup! fixup! code quality, more pythonic code, removing unused imports necessary changes after rebase to master unit tests for sign_typed_data.py new protobuf messages, working for nonarray types simplified and verified solution for our simple data support for simple arrays, without their confirmation reverting protobuf value messages to bytes, appropriate changes showing arrays in Trezor, code quality improvements data validation on Trezor, minor improvements using custom types for storing type data instead of dicts, addressing feedback from review moving helper functions to its own file, tests for decode_data additional overall tests support for arrays of structs adding support for metamask_v4_compat variable using HashWriter object to collect the final hash continously minor improvements in code quality validate_field_type function streaming values from client without saving them, missing UI prototype of streamed UI using confirm_properties accounting for bytes in data, more data types in integration tests rebase on master, using f-strings minor fixes and improvements from code review StructHasher class for the whole hashing process mypy and style changes asking users whether to show structs and arrays protobuf descriptions to fix make defs_check unifying comments, mypy fix unit tests for StructHasher class UI fixtures, skipping device tests for T1 addressing majority of code review comments about code quality and structure changing file structure - layouts, helpers, sign_typed_data decode_data renaming and docstring, renaming unit test file using tuples instead of lists in elifs layout improvements excluding core/src/apps/common/confirm.py file from the PR True/False returning layout with Show more button code review layout improvements forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
EXPECTED_PREFIX_RE = re.compile(r"messages-(\w+)(?:-.*)?\.proto")
# Checking all protobuf files for their `enum` and `message` declarations
# and making sure their names start with expected prefix
for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))):
with open(fn, "rt") as f:
prefix = EXPECTED_PREFIX_RE.search(fn).group(1).capitalize()
if prefix in ("Bitcoin", "Bootloader", "Common", "Crypto", "Management"):
continue
if prefix == "Nem":
prefix = "NEM"
elif prefix == "Webauthn":
prefix = "WebAuthn"
for line in f:
line = line.strip().split(" ")
if line[0] not in ("enum", "message"):
continue
expected_prefixes = (prefix, f"Debug{prefix}")
if not line[1].startswith(expected_prefixes):
print("ERROR: protobuf message does not start with expected prefix")
print(f" file: {fn}")
print(f" message: {line[1]}")
print(f" expected prefixes: {expected_prefixes}")
error = True
if error:
sys.exit(1)