#!/usr/bin/env python3 import binascii import click import pyblake2 import struct from trezorlib import ed25519raw, ed25519cosi indexmap = { 'bootloader': 0, 'vendorheader': 1, 'firmware': 2, } def get_trezor(): from trezorlib.client import TrezorClient from trezorlib.transport_hid import HidTransport devices = HidTransport.enumerate() if len(devices) > 0: return TrezorClient(devices[0]) else: raise Exception('No TREZOR found') def header_to_sign(index, data): z = bytes(65 * [0x00]) if index == 0: # bootloader return data[:0x03BF] + z elif index == 1: # vendorheader return data[:-65] + z elif index == 2: # firmware vhdrlen = struct.unpack('