trezor: split trezorlib-specific code

This commit is contained in:
Roman Zeyde 2015-08-17 10:08:06 +03:00
parent 91d0905364
commit 241b342f43
2 changed files with 20 additions and 21 deletions

View File

@ -7,36 +7,17 @@ import os
from . import util from . import util
from . import formats from . import formats
from . import trezor_library
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class TrezorLibrary(object):
@staticmethod
def client():
# pylint: disable=import-error
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
devices = HidTransport.enumerate()
if len(devices) != 1:
msg = '{:d} Trezor devices found'.format(len(devices))
raise IOError(msg)
return TrezorClient(HidTransport(devices[0]))
@staticmethod
def identity_type(**kwargs):
# pylint: disable=import-error
from trezorlib.types_pb2 import IdentityType
return IdentityType(**kwargs)
class Client(object): class Client(object):
curve_name = 'nist256p1' curve_name = 'nist256p1'
def __init__(self, factory=TrezorLibrary): def __init__(self, factory=trezor_library):
self.factory = factory self.factory = factory
self.client = self.factory.client() self.client = self.factory.client()
f = self.client.features f = self.client.features

View File

@ -0,0 +1,18 @@
''' Thin wrapper around trezorlib. '''
def client():
# pylint: disable=import-error
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
devices = HidTransport.enumerate()
if len(devices) != 1:
msg = '{:d} Trezor devices found'.format(len(devices))
raise IOError(msg)
return TrezorClient(HidTransport(devices[0]))
def identity_type(**kwargs):
# pylint: disable=import-error
from trezorlib.types_pb2 import IdentityType
return IdentityType(**kwargs)