fix spelling of TREZOR

This commit is contained in:
Pavol Rusnak 2016-02-10 16:46:58 +01:00
parent c665350a35
commit f3449fcbd7
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
13 changed files with 79 additions and 76 deletions

View File

@ -4,7 +4,7 @@ python-trezor
.. image:: https://travis-ci.org/trezor/python-trezor.svg?branch=master
:target: https://travis-ci.org/trezor/python-trezor
Client side implementation for Trezor-compatible Bitcoin hardware wallets.
Client side implementation for TREZOR-compatible Bitcoin hardware wallets.
See http://bitcointrezor.com for more information.

View File

@ -58,7 +58,7 @@ class TestZeroSig(common.TrezorTest):
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = ord(serialized_tx[44])
# Trezor must strip leading zero from signature
# TREZOR must strip leading zero from signature
self.assertEqual(siglen, 67)
def test_two_zero_signature(self):
@ -79,7 +79,7 @@ class TestZeroSig(common.TrezorTest):
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = ord(serialized_tx[44])
# Trezor must strip leading zero from signature
# TREZOR must strip leading zero from signature
self.assertEqual(siglen, 66)
if __name__ == '__main__':

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
'''
Use Trezor as a hardware key for opening EncFS filesystem!
Use TREZOR as a hardware key for opening EncFS filesystem!
Demo usage:
@ -20,7 +20,7 @@ from trezorlib.transport_hid import HidTransport
def wait_for_devices():
devices = HidTransport.enumerate()
while not len(devices):
sys.stderr.write("Please connect Trezor to computer and press Enter...")
sys.stderr.write("Please connect TREZOR to computer and press Enter...")
raw_input()
devices = HidTransport.enumerate()
@ -28,7 +28,7 @@ def wait_for_devices():
def choose_device(devices):
if not len(devices):
raise Exception("No Trezor connected!")
raise Exception("No TREZOR connected!")
if len(devices) == 1:
try:
@ -78,7 +78,7 @@ def main():
sys.stderr.write('Please provide label for new drive: ')
label = raw_input()
sys.stderr.write('Computer asked Trezor for new strong password.\n')
sys.stderr.write('Computer asked TREZOR for new strong password.\n')
sys.stderr.write('Please confirm action on your device.\n')
# 32 bytes, good for AES

View File

@ -10,7 +10,7 @@ import tempfile
from trezorlib.client import TrezorClient, TrezorClientDebug
def parse_args(commands):
parser = argparse.ArgumentParser(description='Commandline tool for Trezor devices.')
parser = argparse.ArgumentParser(description='Commandline tool for TREZOR devices.')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Prints communication to device')
parser.add_argument('-t', '--transport', dest='transport', choices=['usb', 'serial', 'pipe', 'socket', 'bridge'], default='usb', help="Transport used for talking with the device")
parser.add_argument('-p', '--path', dest='path', default='', help="Path used by the transport (usually serial port)")
@ -46,7 +46,7 @@ def get_transport(transport_string, path, **kwargs):
try:
path = list_usb()[0][0]
except IndexError:
raise Exception("No Trezor found on USB")
raise Exception("No TREZOR found on USB")
for d in HidTransport.enumerate():
# Two-tuple of (normal_interface, debug_interface)
@ -237,14 +237,14 @@ class Commands(object):
fp.seek(0)
if fp.read(4) != 'TRZR':
raise Exception("Trezor firmware header expected")
raise Exception("TREZOR firmware header expected")
print "Please confirm action on device..."
fp.seek(0)
return self.client.firmware_update(fp=fp)
list.help = 'List connected Trezor USB devices'
list.help = 'List connected TREZOR USB devices'
ping.help = 'Send ping message'
get_address.help = 'Get bitcoin address in base58 encoding'
get_entropy.help = 'Get example entropy'

View File

@ -105,6 +105,9 @@ class BaseClient(object):
self.transport = transport
super(BaseClient, self).__init__() # *args, **kwargs)
def cancel(self):
self.transport.write(proto.Cancel())
def call_raw(self, msg):
try:
self.transport.session_begin()

View File

@ -21,7 +21,7 @@ class PinMatrixWidget(QWidget):
'''
Displays widget with nine blank buttons and password box.
Encodes button clicks into sequence of numbers for passing
into PinAck messages of Trezor.
into PinAck messages of TREZOR.
show_strength=True may be useful for entering new PIN
'''

View File

@ -12,31 +12,31 @@ class Transport(object):
self.device = device
self.session_depth = 0
self._open()
def _open(self):
raise NotImplementedException("Not implemented")
def _close(self):
raise NotImplementedException("Not implemented")
def _write(self, msg, protobuf_msg):
raise NotImplementedException("Not implemented")
def _read(self):
raise NotImplementedException("Not implemented")
def _session_begin(self):
pass
def _session_end(self):
pass
def ready_to_read(self):
"""
Returns True if there is data to be read from the transport. Otherwise, False.
"""
raise NotImplementedException("Not implemented")
def session_begin(self):
"""
Apply a lock to the device in order to preform synchronous multistep "conversations" with the device. For example, before entering the transaction signing workflow, one begins a session. After the transaction is complete, the session may be ended.
@ -44,7 +44,7 @@ class Transport(object):
if self.session_depth == 0:
self._session_begin()
self.session_depth += 1
def session_end(self):
"""
End a session. Se session_begin for an in depth description of TREZOR sessions.
@ -53,13 +53,13 @@ class Transport(object):
self.session_depth = max(0, self.session_depth)
if self.session_depth == 0:
self._session_end()
def close(self):
"""
Close the connection to the physical device or file descriptor represented by the Transport.
"""
self._close()
def write(self, msg):
"""
Write mesage to tansport. msg should be a member of a valid `protobuf class <https://developers.google.com/protocol-buffers/docs/pythontutorial>`_ with a SerializeToString() method.
@ -79,9 +79,9 @@ class Transport(object):
data = self._read()
if data == None:
return None
return self._parse_message(data)
def read_blocking(self):
"""
Same as read, except blocks untill data is available to be read.
@ -90,7 +90,7 @@ class Transport(object):
data = self._read()
if data != None:
break
return self._parse_message(data)
def _parse_message(self, data):
@ -101,7 +101,7 @@ class Transport(object):
inst = mapping.get_class(msg_type)()
inst.ParseFromString(data)
return inst
def _read_headers(self, read_f):
# Try to read headers until some sane value are detected
is_ok = False
@ -129,5 +129,5 @@ class Transport(object):
break
except:
raise Exception("Cannot parse header length")
return (msg_type, datalen)

View File

@ -50,7 +50,7 @@ class BridgeTransport(Transport):
enum = r.json()
return enum;
return enum
def _open(self):

View File

@ -7,18 +7,18 @@ from transport import Transport, NotImplementedException
class FakeTransport(Transport):
def __init__(self, device, *args, **kwargs):
super(FakeTransport, self).__init__(device, *args, **kwargs)
def _open(self):
pass
def _close(self):
pass
def ready_to_read(self):
return False
def _write(self, msg, protobuf_msg):
pass
def _read(self):
raise NotImplementedException("Not implemented")

View File

@ -6,8 +6,8 @@ import platform
from transport import Transport, ConnectionError, NotImplementedException
DEVICE_IDS = [
# (0x10c4, 0xea80), # Shield
(0x534c, 0x0001), # Trezor
# (0x10c4, 0xea80), # TREZOR Shield
(0x534c, 0x0001), # TREZOR
(0x2b24, 0x0001), # KeepKey
]
@ -15,7 +15,7 @@ class FakeRead(object):
# Let's pretend we have a file-like interface
def __init__(self, func):
self.func = func
def read(self, size):
return self.func(size)
@ -65,35 +65,35 @@ class HidTransport(Transport):
if d['path'] == self.device:
return True
return False
def _open(self):
self.buffer = ''
self.hid = hid.device()
self.hid.open_path(self.device)
self.hid.set_nonblocking(True)
# the following was needed just for Trezor Shield
# the following was needed just for TREZOR Shield
# self.hid.send_feature_report([0x41, 0x01]) # enable UART
# self.hid.send_feature_report([0x43, 0x03]) # purge TX/RX FIFOs
def _close(self):
self.hid.close()
self.buffer = ''
self.hid = None
def ready_to_read(self):
return False
def _write(self, msg, protobuf_msg):
msg = bytearray(msg)
while len(msg):
while len(msg):
# Report ID, data padded to 63 bytes
self.hid.write([63, ] + list(msg[:63]) + [0] * (63 - len(msg[:63])))
msg = msg[63:]
def _read(self):
(msg_type, datalen) = self._read_headers(FakeRead(self._raw_read))
return (msg_type, self._raw_read(datalen))
def _raw_read(self, length):
start = time.time()
while len(self.buffer) < length:
@ -112,11 +112,11 @@ class HidTransport(Transport):
continue
report_id = data[0]
if report_id > 63:
# Command report
raise Exception("Not implemented")
# Payload received, skip the report ID
self.buffer += str(bytearray(data[1:]))

View File

@ -8,14 +8,14 @@ from transport import Transport
class PipeTransport(Transport):
def __init__(self, device, is_device, *args, **kwargs):
self.is_device = is_device # Set True if act as device
super(PipeTransport, self).__init__(device, *args, **kwargs)
super(PipeTransport, self).__init__(device, *args, **kwargs)
def _open(self):
if self.is_device:
self.filename_read = self.device+'.to'
self.filename_write = self.device+'.from'
os.mkfifo(self.filename_read, 0600)
os.mkfifo(self.filename_write, 0600)
else:
@ -24,13 +24,13 @@ class PipeTransport(Transport):
if not os.path.exists(self.filename_write):
raise Exception("Not connected")
self.write_fd = os.open(self.filename_write, os.O_RDWR)#|os.O_NONBLOCK)
self.write_f = os.fdopen(self.write_fd, 'w+')
self.read_fd = os.open(self.filename_read, os.O_RDWR)#|os.O_NONBLOCK)
self.read_f = os.fdopen(self.read_fd, 'rb')
def _close(self):
self.read_f.close()
self.write_f.close()
@ -41,7 +41,7 @@ class PipeTransport(Transport):
def ready_to_read(self):
rlist, _, _ = select([self.read_f], [], [], 0)
return len(rlist) > 0
def _write(self, msg, protobuf_msg):
try:
self.write_f.write(msg)
@ -49,7 +49,7 @@ class PipeTransport(Transport):
except OSError:
print "Error while writing to socket"
raise
def _read(self):
try:
(msg_type, datalen) = self._read_headers(self.read_f)

View File

@ -10,18 +10,18 @@ class SerialTransport(Transport):
def __init__(self, device, *args, **kwargs):
self.serial = None
super(SerialTransport, self).__init__(device, *args, **kwargs)
def _open(self):
self.serial = serial.Serial(self.device, 115200, timeout=10, writeTimeout=10)
def _close(self):
self.serial.close()
self.serial = None
def ready_to_read(self):
rlist, _, _ = select([self.serial], [], [], 0)
return len(rlist) > 0
def _write(self, msg, protobuf_msg):
try:
self.serial.write(msg)
@ -29,7 +29,7 @@ class SerialTransport(Transport):
except serial.SerialException:
print "Error while writing to socket"
raise
def _read(self):
try:
(msg_type, datalen) = self._read_headers(self.serial)

View File

@ -12,26 +12,26 @@ class SocketTransportClient(Transport):
else:
device = (device[0], int(device[1]))
self.socket = None
self.socket = None
super(SocketTransportClient, self).__init__(device, *args, **kwargs)
def _open(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(self.device)
self.filelike = self.socket.makefile()
def _close(self):
self.socket.close()
self.socket = None
self.filelike = None
def ready_to_read(self):
rlist, _, _ = select([self.socket], [], [], 0)
return len(rlist) > 0
return len(rlist) > 0
def _write(self, msg, protobuf_msg):
self.socket.sendall(msg)
def _read(self):
try:
(msg_type, datalen) = self._read_headers(self.filelike)
@ -53,27 +53,27 @@ class SocketTransport(Transport):
self.filelike = None
super(SocketTransport, self).__init__(device, *args, **kwargs)
def _open(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#self.socket.setblocking(0)
self.socket.bind(self.device)
self.socket.listen(5)
def _disconnect_client(self):
print "Disconnecting client"
if self.client != None:
self.client.close()
self.client = None
self.filelike = None
def _close(self):
self._disconnect_client()
self.socket.close()
self.socket = None
def ready_to_read(self):
if self.filelike:
# Connected
@ -88,18 +88,18 @@ class SocketTransport(Transport):
self.filelike = self.client.makefile()
return self.ready_to_read()
return False
def _write(self, msg, protobuf_msg):
if self.filelike:
# None on disconnected client
try:
self.filelike.write(msg)
self.filelike.flush()
except socket.error:
print "Socket error"
self._disconnect_client()
def _read(self):
try:
(msg_type, datalen) = self._read_headers(self.filelike)