question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ledger: Handle automatic lock better

See original GitHub issue

When a Ledger Nano S was unlocked and then went into the auto lock, EC does not react to it well. Starting a new EC instance with a Ledger in this state connected results in the following:

Traceback (most recent call last):
  File "/home/user/src/electrum/gui/qt/util.py", line 691, in run
    result = task.task()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 549, in get_client
    client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
  File "/home/user/src/electrum/lib/plugins.py", line 718, in client_for_keystore
    client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
  File "/home/user/src/electrum/lib/plugins.py", line 748, in force_pair_xpub
    client_xpub = client.get_xpub(derivation, xtype)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 78, in catch_exception
    return func(self, *args, **kwargs)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 88, in get_xpub
    self.checkDevice()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 208, in checkDevice
    raise e
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 204, in checkDevice
    self.perform_hw1_preflight()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 199, in perform_hw1_preflight
    raise e
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 185, in perform_hw1_preflight
    raise e
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 181, in perform_hw1_preflight
    self.dongleObject.getWalletPublicKey("44'/145'/0'/0/0", showOnScreen=False, cashAddr=True)
  File "/home/user/.local/lib/python3.5/site-packages/btchip/btchip.py", line 124, in getWalletPublicKey
    response = self.dongle.exchange(bytearray(apdu))
  File "/home/user/.local/lib/python3.5/site-packages/btchip/btchipComm.py", line 127, in exchange
    raise BTChipException("Invalid status %04x" % sw, sw)
btchip.btchipException.BTChipException: Exception : Invalid status 6f04

After this, when I click the Ledger icon to retry the connection I get this:

Traceback (most recent call last):
  File "/home/user/src/electrum/gui/qt/main_window.py", line 82, in onPress
    self.func()
  File "/home/user/src/electrum/plugins/hw_wallet/qt.py", line 230, in show_settings_dialog
    device_id = self.choose_device(window, keystore)
  File "/home/user/src/electrum/plugins/hw_wallet/qt.py", line 223, in choose_device
    info = self.device_manager().select_device(self, keystore.handler, keystore)
  File "/home/user/src/electrum/lib/plugins.py", line 786, in select_device
    infos = self.unpaired_device_infos(handler, plugin, devices)
  File "/home/user/src/electrum/lib/plugins.py", line 775, in unpaired_device_infos
    client = self.create_client(device, handler, plugin)
  File "/home/user/src/electrum/lib/plugins.py", line 651, in create_client
    client = plugin.create_client(device, handler)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 522, in create_client
    client = self.get_btchip_device(device)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 515, in get_btchip_device
    dev.open_path(device.path)
  File "hid.pyx", line 72, in hid.device.open_path
OSError: open failed

Seems that the device was not properly released and can’t be reopened. After restarting EC I then get the following:

Traceback (most recent call last):
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 149, in perform_hw1_preflight
    firmwareInfo = self.dongleObject.getFirmwareVersion()
  File "/home/user/.local/lib/python3.5/site-packages/btchip/btchip.py", line 561, in getFirmwareVersion
    response = self.dongle.exchange(bytearray(apdu))
  File "/home/user/.local/lib/python3.5/site-packages/btchip/btchipComm.py", line 127, in exchange
    raise BTChipException("Invalid status %04x" % sw, sw)
btchip.btchipException.BTChipException: Exception : Invalid status 6faa

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/src/electrum/gui/qt/util.py", line 691, in run
    result = task.task()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 549, in get_client
    client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
  File "/home/user/src/electrum/lib/plugins.py", line 718, in client_for_keystore
    client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
  File "/home/user/src/electrum/lib/plugins.py", line 748, in force_pair_xpub
    client_xpub = client.get_xpub(derivation, xtype)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 78, in catch_exception
    return func(self, *args, **kwargs)
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 88, in get_xpub
    self.checkDevice()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 204, in checkDevice
    self.perform_hw1_preflight()
  File "/home/user/src/electrum/plugins/ledger/ledger.py", line 192, in perform_hw1_preflight
    raise Exception("Dongle is temporarily locked - please unplug it and replug it again")
Exception: Dongle is temporarily locked - please unplug it and replug it again

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
EchterAgocommented, Apr 3, 2019

No worries, I will try to fix these. I am opening these to remind me.

1reaction
EchterAgocommented, Apr 3, 2019

So, first I’m going to use inspection to determine whether btchip-python supports CashAddr like this:

gwpkArgSpecs = inspect.getfullargspec(self.dongleObject.getWalletPublicKey)
self.cashaddrSWSupported = 'cashAddr' in gwpkArgSpecs.args

This way we do not have to actually call getWalletPublicKey in perform_hw1_preflight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set PIN lock and power off - Ledger Support
Set PIN lock or auto-power off to automatically lock or shutdown your Ledger Nano X device after a period of inactivity.
Read more >
Ledger locks during transaction creation due to screensaver #79
The screensaver should not lock during transaction creation, this is not something that the user should have to manually increase. This was ...
Read more >
The Advantages of Pushbutton Locks - Locksmith Ledger
With the more sophisticated systems, homeowners can get notifications ... Lever handle on both inside and outside; Auto-locking with Passage ...
Read more >
Ledger Nano X Hardware Wallet Setup Guide (Latest Version ...
00:00 Intro 00:43 Unboxing01:12 Download Ledger Live App02:38 Launch ... Set Password/ Auto Lock for Ledger Live 20:24 Buy Bitcoin, Ethereum, ...
Read more >
User Manual Ledger Nano X Certification - FCC Report
to manage the battery and Bluetooth, and to access device settings. ... If you've enabled auto-lock your device will show bouncing Ledger logos...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found