|
|
|
@ -21,17 +21,16 @@
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import binascii
|
|
|
|
|
import argparse
|
|
|
|
|
import json
|
|
|
|
|
import base64
|
|
|
|
|
import tempfile
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
from trezorlib.client import TrezorClient, TrezorClientDebug, CallException
|
|
|
|
|
from trezorlib.client import TrezorClient, TrezorClientVerbose, CallException
|
|
|
|
|
import trezorlib.types_pb2 as types
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ether_units = {
|
|
|
|
|
"wei": 1,
|
|
|
|
|
"kwei": 1000,
|
|
|
|
@ -54,6 +53,7 @@ ether_units = {
|
|
|
|
|
"eth": 1000000000000000000,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_parser(commands):
|
|
|
|
|
parser = argparse.ArgumentParser(description='Commandline tool for TREZOR devices.')
|
|
|
|
|
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Prints communication to device')
|
|
|
|
@ -80,38 +80,33 @@ def init_parser(commands):
|
|
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
def get_transport(transport_string, path, **kwargs):
|
|
|
|
|
if transport_string == 'usb':
|
|
|
|
|
from trezorlib.transport_hid import HidTransport
|
|
|
|
|
|
|
|
|
|
for d in HidTransport.enumerate():
|
|
|
|
|
# Two-tuple of (normal_interface, debug_interface)
|
|
|
|
|
if path == '' or path in d:
|
|
|
|
|
return HidTransport(d, **kwargs)
|
|
|
|
|
def get_transport_class_by_name(name):
|
|
|
|
|
|
|
|
|
|
raise CallException(types.Failure_NotInitialized, "Device not found")
|
|
|
|
|
if name == 'usb':
|
|
|
|
|
from trezorlib.transport_hid import HidTransport
|
|
|
|
|
return HidTransport
|
|
|
|
|
|
|
|
|
|
if transport_string == 'udp':
|
|
|
|
|
if name == 'udp':
|
|
|
|
|
from trezorlib.transport_udp import UdpTransport
|
|
|
|
|
return UdpTransport(path, **kwargs)
|
|
|
|
|
return UdpTransport
|
|
|
|
|
|
|
|
|
|
if transport_string == 'pipe':
|
|
|
|
|
if name == 'pipe':
|
|
|
|
|
from trezorlib.transport_pipe import PipeTransport
|
|
|
|
|
if path == '':
|
|
|
|
|
path = '/tmp/pipe.trezor'
|
|
|
|
|
return PipeTransport(path, is_device=False, **kwargs)
|
|
|
|
|
return PipeTransport
|
|
|
|
|
|
|
|
|
|
if transport_string == 'bridge':
|
|
|
|
|
if name == 'bridge':
|
|
|
|
|
from trezorlib.transport_bridge import BridgeTransport
|
|
|
|
|
return BridgeTransport
|
|
|
|
|
|
|
|
|
|
raise NotImplementedError('Unknown transport: "%s"' % name)
|
|
|
|
|
|
|
|
|
|
devices = BridgeTransport.enumerate()
|
|
|
|
|
for d in devices:
|
|
|
|
|
if path == '' or d['path'] == binascii.hexlify(path):
|
|
|
|
|
return BridgeTransport(d, **kwargs)
|
|
|
|
|
|
|
|
|
|
raise CallException(types.Failure_NotInitialized, "Device not found")
|
|
|
|
|
def get_transport(transport_name, path):
|
|
|
|
|
transport = get_transport_class_by_name(transport_name)
|
|
|
|
|
dev = transport.find_by_path(path)
|
|
|
|
|
return dev
|
|
|
|
|
|
|
|
|
|
raise NotImplementedError("Unknown transport")
|
|
|
|
|
|
|
|
|
|
class Commands(object):
|
|
|
|
|
def __init__(self, client):
|
|
|
|
@ -594,7 +589,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
transport = get_transport(args.transport, args.path)
|
|
|
|
|
if args.verbose:
|
|
|
|
|
client = TrezorClientDebug(transport)
|
|
|
|
|
client = TrezorClientVerbose(transport)
|
|
|
|
|
else:
|
|
|
|
|
client = TrezorClient(transport)
|
|
|
|
|
|
|
|
|
@ -616,3 +611,4 @@ def main():
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|
|
|
|
|
|