示例#1
0
def get_device_list(
        allow_bootloader_mode: bool = False) -> List[hw_common.HWDevice]:
    from ledgerwallet.client import LedgerClient
    from ledgerwallet.transport.hid import HidDevice

    ret_list = []
    exception: Optional[Exception] = None

    try:
        dongles = get_dongles()
        if dongles:
            for d in dongles:
                model_symbol = d.device.get_manufacturer_string(
                ) + ' ' + d.device.get_product_string()
                d.close()
                in_bootloader_mode = False
                initialized = True
                version = None
                dev = None
                try:
                    dev = HidDevice(
                        bytes(d.__getattribute__('hidDevicePath'), 'ascii'))
                    client = LedgerClient(device=dev)
                    version_info = client.get_version_info()
                    in_bootloader_mode = version_info.flags.recovery_mode is True
                    initialized = version_info.flags.is_onboarded is True
                    version = version_info.se_version
                except Exception as e:
                    logging.exception(str(e))
                finally:
                    if dev:
                        dev.close()
                        del client

                # device_transport_id = hashlib.sha256(str(d.hidDevicePath).encode('ascii')).hexdigest()

                if allow_bootloader_mode or in_bootloader_mode is False:
                    ret_list.append(
                        hw_common.HWDevice(
                            hw_type=HWType.ledger_nano,
                            device_id=d.__getattribute__('hidDevicePath'),
                            model_symbol=model_symbol,
                            device_label=None,
                            firmware_version=version,
                            hw_client=None,
                            bootloader_mode=in_bootloader_mode,
                            transport_id=d,
                            initialized=initialized))

    except BTChipException as e:
        if e.message != 'No dongle found':
            logging.exception(str(e))
            exception = e

    if not ret_list and exception:
        raise exception
    ret_list = sorted(ret_list, key=lambda x: x.get_description())
    return ret_list
示例#2
0
def client():
    devices = enumerate_devices()
    if len(devices) == 0:
        print("No Ledger device has been found.")
        sys.exit(0)

    return LedgerClient(devices[0], cla=CLA)
示例#3
0
 def get_client():
     devices = enumerate_devices()
     if len(devices) == 0:
         click.echo("No Ledger device has been found.")
         sys.exit(0)
     return LedgerClient(devices[0], private_key=get_private_key())
示例#4
0
 def get_client():
     try:
         return LedgerClient(private_key=get_private_key())
     except NoLedgerDeviceException as exception:
         click.echo(exception)
         sys.exit(0)