コード例 #1
0
def wait_for_devices():
    devices = TrezorDevice.enumerate()
    while not len(devices):
        sys.stderr.write(
            "Please connect TREZOR to computer and press Enter...")
        input()
        devices = TrezorDevice.enumerate()

    return devices
コード例 #2
0
    def create_client(self, device, handler):
        from trezorlib.device import TrezorDevice
        try:
            self.print_error("connecting to device at", device.path)
            transport = TrezorDevice.find_by_path(device.path)
        except BaseException as e:
            self.print_error("cannot connect at", device.path, str(e))
            return None

        if not transport:
            self.print_error("cannot connect at", device.path)
            return

        self.print_error("connected to device at", device.path)
        client = self.client_class(transport, handler, self)

        # Try a ping for device sanity
        try:
            client.ping('t')
        except BaseException as e:
            self.print_error("ping failed", str(e))
            return None

        if not client.atleast_version(*self.minimum_firmware):
            msg = (_('Outdated {} firmware for device labelled {}. Please '
                     'download the updated firmware from {}').format(
                         self.device, client.label(), self.firmware_URL))
            self.print_error(msg)
            handler.show_error(msg)
            return None

        return client
コード例 #3
0
ファイル: trezor.py プロジェクト: romanz/electrum
    def create_client(self, device, handler):
        from trezorlib.device import TrezorDevice
        try:
            self.print_error("connecting to device at", device.path)
            transport = TrezorDevice.find_by_path(device.path)
        except BaseException as e:
            self.print_error("cannot connect at", device.path, str(e))
            return None

        if not transport:
            self.print_error("cannot connect at", device.path)
            return

        self.print_error("connected to device at", device.path)
        client = self.client_class(transport, handler, self)

        # Try a ping for device sanity
        try:
            client.ping('t')
        except BaseException as e:
            self.print_error("ping failed", str(e))
            return None

        if not client.atleast_version(*self.minimum_firmware):
            msg = (_('Outdated {} firmware for device labelled {}. Please '
                     'download the updated firmware from {}')
                   .format(self.device, client.label(), self.firmware_URL))
            self.print_error(msg)
            handler.show_error(msg)
            return None

        return client
コード例 #4
0
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]

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)

    # Print out TREZOR's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    # (should be the same address as shown in wallet.trezor.io)
    bip32_path = client.expand_path("44'/0'/0'/0/0")
    address = client.get_address('Bitcoin', bip32_path)
    print('Bitcoin address:', address)

    client.close()
コード例 #5
0
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
コード例 #6
0
    def find_trezor(self):
        u"""Selects a trezor device and initialize the client."""

        devices = TrezorDevice.enumerate()
        if len(devices) == 0:
            raise NoTrezorFoundError('No Trezor device was found. Make sure it'
                                     ' is plugged.')

        transport = devices[0]
        trezor = TrezorClient(transport, ui=ui.ClickUI())
        return trezor
コード例 #7
0
 def enumerate(self):
     from trezorlib.device import TrezorDevice
     return [
         Device(d.get_path(), -1, d.get_path(), 'TREZOR', 0)
         for d in TrezorDevice.enumerate()
     ]
コード例 #8
0
def enumerate_transports():
    """Returns all available transports."""
    return TrezorDevice.enumerate()
コード例 #9
0
#!/usr/bin/env python3
import code
import readline
import rlcompleter
import struct
import sys

from trezorlib.device import TrezorDevice

import trezorlib.messages as proto

try:
    transport, = (device.find_debug() for device in TrezorDevice.enumerate())
except ValueError:
    sys.exit("Exactly one TREZOR must be connected, with debug link enabled.")

transport.session_begin()


class HexInteger(int):
    def __repr__(self):
        return hex(self)


class MemoryMappedInteger(object):
    def __init__(self, fmt, address):
        self.struct = struct.Struct("<" + fmt)
        self.address = address

    def read(self):
        transport.write(
コード例 #10
0
ファイル: trezor.py プロジェクト: romanz/electrum
 def enumerate(self):
     from trezorlib.device import TrezorDevice
     return [Device(d.get_path(), -1, d.get_path(), 'TREZOR', 0) for d in TrezorDevice.enumerate()]