1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00

update tools to use the new transport API

also drop some python2 compatibility things
This commit is contained in:
matejcik 2018-03-05 17:30:44 +01:00
parent ff80ca1b82
commit 967d479a19
9 changed files with 32 additions and 79 deletions

View File

@ -16,21 +16,15 @@ import hashlib
import binascii
from trezorlib.client import TrezorClient
from trezorlib.device import TrezorDevice
# Python2 vs Python3
try:
input = raw_input
except NameError:
pass
from trezorlib.transport import enumerate_devices
def wait_for_devices():
devices = TrezorDevice.enumerate()
devices = enumerate_devices()
while not len(devices):
sys.stderr.write("Please connect TREZOR to computer and press Enter...")
input()
devices = TrezorDevice.enumerate()
devices = enumerate_devices()
return devices

View File

@ -1,21 +1,11 @@
#!/usr/bin/env python3
from __future__ import print_function
from trezorlib.client import TrezorClient
from trezorlib.device import TrezorDevice
from trezorlib.transport import get_transport
def main():
# List all connected TREZORs on USB/UDP
devices = TrezorDevice.enumerate()
# Check whether we found any
if len(devices) == 0:
print('No TREZOR found')
return
# Use first connected device
transport = devices[0]
transport = get_transport()
# Creates object for manipulating TREZOR
client = TrezorClient(transport)

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python3
from __future__ import print_function
from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.transport import enumerate_devices
import binascii
import sys
@ -16,8 +14,8 @@ sectorlens = [0x4000, 0x4000, 0x4000, 0x4000,
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# List all debuggable TREZORs
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')]
# Check whether we found any
if len(devices) == 0:

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python3
from __future__ import print_function
from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.transport import enumerate_devices
import sys
# usage examples
@ -16,8 +14,8 @@ import sys
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# List all debuggable TREZORs
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')]
# Check whether we found any
if len(devices) == 0:

View File

@ -1,16 +1,14 @@
#!/usr/bin/env python3
from __future__ import print_function
from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.transport import enumerate_devices
import binascii
import sys
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# List all debuggable TREZORs
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')]
# Check whether we found any
if len(devices) == 0:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function
import binascii
import hashlib
import mnemonic
@ -16,12 +15,6 @@ __doc__ = '''
without an internet connection).
'''
# Python2 vs Python3
try:
input = raw_input
except NameError:
pass
def generate_entropy(strength, internal_entropy, external_entropy):
'''

View File

@ -1,7 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function
from binascii import hexlify, unhexlify
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
@ -9,14 +6,10 @@ import hmac
import hashlib
import json
import os
try:
from urllib.parse import urlparse
except:
from urlparse import urlparse
input = raw_input
from urllib.parse import urlparse
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.transport import get_transport
# Return path by BIP-32
def getPath(client):
@ -124,12 +117,13 @@ def printEntries(entries):
def main():
devices = HidTransport.enumerate()
if not devices:
print('TREZOR is not plugged in. Please, connect TREZOR and retry.')
try:
transport = get_transport()
except Exception as e:
print(e)
return
client = TrezorClient(devices[0])
client = TrezorClient(transport)
print()
print('Confirm operation on TREZOR')

View File

@ -8,21 +8,14 @@ from __future__ import print_function
import io
import sys
from trezorlib.client import TrezorClient
from trezorlib.device import TrezorDevice
def get_client():
devices = TrezorDevice.enumerate() # list all connected TREZORs on USB
if len(devices) == 0: # check whether we found any
return None
transport = devices[0] # use first connected device
return TrezorClient(transport) # creates object for communicating with TREZOR
from trezorlib.transport import get_transport
def main():
client = get_client()
if not client:
print('No TREZOR connected')
try:
client = TrezorClient(get_transport())
except Exception as e:
print(e)
return
arg1 = sys.argv[1] # output file

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import binascii
import os
import random
@ -12,8 +11,7 @@ import hashlib
from trezorlib.client import TrezorClient
from trezorlib.tx_api import TxApiTestnet
from trezorlib.tx_api import TxApiBitcoin
from trezorlib.transport_hid import HidTransport
from trezorlib.transport_bridge import BridgeTransport
from trezorlib.transport import get_transport
def hash160(x):
@ -152,16 +150,13 @@ def main():
numinputs = 100
sizeinputtx = 10
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# Check whether we found any
if len(devices) == 0:
print('No TREZOR found')
# Use first connected device
try:
transport = get_transport()
except Exception as e:
print(e)
return
# Use first connected device
transport = devices[0]
print(transport)
txstore = MyTxApiBitcoin()