Commit Graph

395 Commits

Author SHA1 Message Date
SomberNight
33d394c9d7 ledger: fix scan_devices for certain devices with multiple interfaces
regression from https://github.com/spesmilo/electrum/pull/8041 (4.3.3)

maybe fixes https://github.com/spesmilo/electrum/issues/8293

-----

Testing with a "Ledger Nano S", btc app version 1.6.3.
btchip-python==0.1.32
ledgercomm==1.1.1
ledger-bitcoin==0.1.1

Trying to scan devices hangs/blocks forever on Linux (ubuntu 22.04).

```patch
diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py
index 17c1caca48..ba5ae2e3ee 100644
--- a/electrum/plugins/ledger/ledger.py
+++ b/electrum/plugins/ledger/ledger.py
@@ -306,17 +306,25 @@ class Ledger_Client(HardwareClientBase, ABC):
     @staticmethod
     def construct_new(*args, device: Device, **kwargs) -> 'Ledger_Client':
         """The 'real' constructor, that automatically decides which subclass to use."""
+        _logger.info(f"xxx construct_new(). cp1. {device.path=}. {device=}")
         if LedgerPlugin.is_hw1(device.product_key):
             return Ledger_Client_Legacy_HW1(*args, **kwargs, device=device)
         # for nano S or newer hw, decide which client impl to use based on software/firmware version:
+        _logger.info(f"xxx construct_new(). cp2.")
         hid_device = HID()
         hid_device.path = device.path
+        _logger.info(f"xxx construct_new(). cp3.")
         hid_device.open()
+        _logger.info(f"xxx construct_new(). cp4.")
         transport = ledger_bitcoin.TransportClient('hid', hid=hid_device)
-        cl = ledger_bitcoin.createClient(transport, chain=get_chain())
+        _logger.info(f"xxx construct_new(). cp5.")
+        cl = ledger_bitcoin.createClient(transport, chain=get_chain(), debug=True)
+        _logger.info(f"xxx construct_new(). cp6.")
         if isinstance(cl, ledger_bitcoin.client.NewClient):
+            _logger.info(f"xxx construct_new(). cp7. trying Ledger_Client_New")
             return Ledger_Client_New(hid_device, *args, **kwargs)
         else:
+            _logger.info(f"xxx construct_new(). cp7. trying Ledger_Client_Legacy")
             return Ledger_Client_Legacy(hid_device, *args, **kwargs)

     def __init__(self, *, plugin: HW_PluginBase):
@@ -1416,7 +1424,7 @@ class LedgerPlugin(HW_PluginBase):
         try:
             return Ledger_Client.construct_new(device=device, product_key=device.product_key, plugin=self)
         except Exception as e:
-            self.logger.info(f"cannot connect at {device.path} {e}")
+            self.logger.info(f"cannot connect at {device.path} {e}")  #
         return None

     def setup_device(self, device_info, wizard, purpose):
```

scanning devices freezes... log:
```
  8.94 | I | plugin.DeviceMgr | scanning devices...
  9.18 | D | util.profiler | DeviceMgr.scan_devices 0.2357 sec
  9.18 | I | plugins.ledger.ledger | xxx construct_new(). cp1. device.path=b'0001:0008:00'. device=Device(path=b'0001:0008:00', interface_number=0, id_="b'0001:0008:00',0001,0,0", product_key=(11415, 4117), usage_page=0, transport_ui_string='hid')
  9.18 | I | plugins.ledger.ledger | xxx construct_new(). cp2.
  9.18 | I | plugins.ledger.ledger | xxx construct_new(). cp3.
heyheyhey. cp1. self.path=b'0001:0008:00'
  9.18 | I | plugins.ledger.ledger | xxx construct_new(). cp4.
  9.18 | I | plugins.ledger.ledger | xxx construct_new(). cp5.
=> b001000000
<= 010c426974636f696e205465737405312e362e3301029000
  9.22 | I | plugins.ledger.ledger | xxx construct_new(). cp6.
  9.22 | I | plugins.ledger.ledger | xxx construct_new(). cp7. trying Ledger_Client_Legacy
  9.29 | I | plugin.DeviceMgr | Registering <electrum.plugins.ledger.ledger.Ledger_Client_Legacy object at 0x7f4369e6e380>
 10.33 | I | plugins.ledger.ledger | xxx construct_new(). cp1. device.path=b'0001:0008:01'. device=Device(path=b'0001:0008:01', interface_number=1, id_="b'0001:0008:01',0001,1,0", product_key=(11415, 4117), usage_page=0, transport_ui_string='hid')
 10.33 | I | plugins.ledger.ledger | xxx construct_new(). cp2.
 10.33 | I | plugins.ledger.ledger | xxx construct_new(). cp3.
heyheyhey. cp1. self.path=b'0001:0008:01'
 10.33 | I | plugins.ledger.ledger | xxx construct_new(). cp4.
 10.33 | I | plugins.ledger.ledger | xxx construct_new(). cp5.
=> b001000000
```

in Qt console (before change):
```
>>> lp = plugins.get_plugin("ledger")
>>> plugins.device_manager.scan_devices()
[Device(path=b'0001:000a:00', interface_number=0, id_="b'0001:000a:00',0001,0,0", product_key=(11415, 4117), usage_page=0, transport_ui_string='hid'), Device(path=b'0001:000a:01', interface_number=1, id_="b'0001:000a:01',0001,1,0", product_key=(11415, 4117), usage_page=0, transport_ui_string='hid')]
```
2023-05-02 17:23:07 +00:00
SomberNight
22b8c4e397 hww: fix digitalbitbox(1) support
regression from cea4238b81

```
975.04 | E | plugin.DeviceMgr | failed to create client for digitalbitbox at <REDACTED>: AttributeError("'NoneType' object has no attribute 'get_passphrase'")
Traceback (most recent call last):
  File "...\electrum\electrum\plugin.py", line 620, in list_pairable_device_infos
    soft_device_id = client.get_soft_device_id()
  File "...\electrum\electrum\plugins\hw_wallet\plugin.py", line 251, in get_soft_device_id
    root_fp = self.request_root_fingerprint_from_device()
  File "...\electrum\electrum\plugin.py", line 362, in wrapper
    return run_in_hwd_thread(partial(func, *args, **kwargs))
  File "...\electrum\electrum\plugin.py", line 352, in run_in_hwd_thread
    return func()
  File "...\electrum\electrum\plugins\hw_wallet\plugin.py", line 264, in request_root_fingerprint_from_device
    child_of_root_xpub = self.get_xpub("m/0'", xtype='standard')
  File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 115, in get_xpub
    reply = self._get_xpub(bip32_path)
  File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 110, in _get_xpub
    if self.check_device_dialog():
  File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 197, in check_device_dialog
    if not self.password_dialog(msg):
  File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 159, in password_dialog
    password = self.handler.get_passphrase(msg, False)
AttributeError: 'NoneType' object has no attribute 'get_passphrase'
```
2023-04-27 17:33:54 +00:00
SomberNight
499f51535f bip32: fix hardened char "h" vs "'" compatibility for some hw wallets
in particular, ledger: fix sign_message for some wallets

```
156.02 | E | plugins.ledger.ledger |
Traceback (most recent call last):
  File "...\electrum\electrum\plugins\ledger\ledger.py", line 1265, in sign_message
    result = base64.b64decode(self.client.sign_message(message, address_path))
  File "...\Python310\site-packages\ledger_bitcoin\client.py", line 230, in sign_message
    sw, response = self._make_request(self.builder.sign_message(message_bytes, bip32_path), client_intepreter)
  File "...\Python310\site-packages\ledger_bitcoin\command_builder.py", line 176, in sign_message
    bip32_path: List[bytes] = bip32_path_from_string(bip32_path)
  File "...\Python310\site-packages\ledger_bitcoin\common.py", line 68, in bip32_path_from_string
    return [int(p).to_bytes(4, byteorder="big") if "'" not in p
  File "...\Python310\site-packages\ledger_bitcoin\common.py", line 68, in <listcomp>
    return [int(p).to_bytes(4, byteorder="big") if "'" not in p
ValueError: invalid literal for int() with base 10: '84h'
```

Regression from df2bd61de6, where the
default hardened char was changed from "'" to "h". Note that there was
no corresponding wallet db upgrade, so some files use one char and
others use the other.
2023-04-27 17:03:16 +00:00
SomberNight
4219022c2e fix flake8-bugbear B023
B023 Function definition does not bind loop variable 'already_selected_buckets_value_sum'

in keepkey/qt.py, looks like this was an actual bug
(fixed in trezor plugin already: 52a4810752 )
2023-04-24 13:00:07 +00:00
SomberNight
e2406f21b4 fix flake8-bugbear B011
B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
2023-04-24 12:58:19 +00:00
SomberNight
312f2641e7 don't use bare except
use "except Exception", or if really needed explicitly "except BaseException"
2023-04-24 12:58:01 +00:00
SomberNight
be159b5b95 bugfix: assert walrus (":=") combo side-eff. breaks w/ asserts disabled
```
$ python3 -O
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> assert (x := 2)
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
```

pity. it looked to be a neat and concise pattern.
2023-04-20 15:17:36 +00:00
Victor Forgeoux
ee61f99c22 Add support for Ledger Stax (#8308)
* Add support for Ledger Stax
2023-04-18 13:11:49 +00:00
ThomasV
2e70776a72 fix missing import 2023-04-12 12:21:08 +02:00
ThomasV
2203bba4ea fix flake8 test 2023-04-12 11:59:52 +02:00
ThomasV
0544c4b651 payserver: fix #8299 2023-04-12 11:28:16 +02:00
3rd Iteration
83ee260ab7 Add Device IDs for DIY Jade on M5StickC-Plus (#8291) 2023-04-04 09:27:38 +02:00
Sander van Grieken
0ce3559d62 qml: trustedcoin icon in 2fas wizard disclaimer 2023-04-03 10:59:50 +02:00
SomberNight
4a626a113d qt receive_tab: fix "show_address_on_hw" functionality
follow-up b07fe970bf

I don't like this being hidden in the toolbar menu.
The other items in the toolbar menu are ~settings or generic actions
independent of the current request. This one is dependent on the
current request, and even the active "tab"... does not make sense
to show this when the lightning tab is active.
It is more difficult to discover it in the first place than previously,
and it being less visible goes against encouraging hw device users of
using it, which is what we should be doing.

Anyway, this commit just makes it functional as-is.
2023-03-31 01:14:08 +00:00
ThomasV
b07fe970bf receive tab: do not use ButtonsTextEdit, add toggle to toolbar. 2023-03-19 10:15:19 +01:00
Sander van Grieken
8528907a5b qml: trsutedcoin layout consistency 2023-03-17 11:51:56 +01:00
Sander van Grieken
0bb41a32c8 qml: fix layout issues in ShowConfirmOTP. fixes #8249 2023-03-17 00:23:50 +01:00
ThomasV
f770905551 follow-up d56162c588 2023-03-14 17:28:33 +01:00
SomberNight
7746cc8e60 bip32: (trivial) rename method strpath_to_intpath, for symmetry
Required a much higher mental load to parse the name "convert_bip32_path_to_list_of_uint32"
than to parse "convert_bip32_strpath_to_intpath".
And we already have the ~inverse: "convert_bip32_intpath_to_strpath".
2023-03-10 14:23:17 +00:00
SomberNight
e457bb50e9 trezor: TrezorPlugin._make_multisig to use MultisigDescriptor
This fixes a regression where the plugin was assuming ordering for
txin.pubkeys (which is now a set).
(previously txin.pubkeys was a list ordered according to the final
sort order of keys inside the bitcoin script)
2023-03-03 16:40:41 +00:00
SomberNight
0647a2cf9f transaction.py: rm PartialTxInput.{num_sig, script_type} 2023-03-03 16:40:12 +00:00
SomberNight
2242a506a9 ledger: fix sign_transaction for Ypub / sh(wsh(multi())) wallets
regression from https://github.com/spesmilo/electrum/pull/8041
2023-02-22 14:02:24 +00:00
ThomasV
4e9ddf6ddd cosignerpool: minor fix, follow-up new GUI flow 2023-02-21 13:15:06 +01:00
SomberNight
373db76ac9 util: kill bh2u
no longer useful, and the name is so confusing...
2023-02-17 11:43:11 +00:00
SomberNight
1ce37c8bb1 transaction: rm hardcoded sighash magic numbers 2023-02-17 11:40:12 +00:00
SomberNight
b20933de6d payserver: better handle running with --offline
```
 19.70 | E | plugin | Plugin error. plugin: payserver, hook: wallet_export_request
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/plugin.py", line 227, in run_hook
    r = f(*args)
  File "/home/user/wspace/electrum/electrum/plugins/payserver/payserver.py", line 69, in wallet_export_request
    d['view_url'] = self.view_url(key)
  File "/home/user/wspace/electrum/electrum/plugins/payserver/payserver.py", line 55, in view_url
    return self.server.base_url + self.server.root + '/pay?id=' + key
AttributeError: 'NoneType' object has no attribute 'base_url'
```
```
 23.22 | E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/plugins/payserver/qt.py", line 48, in settings_dialog
    url = self.server.base_url + self.server.root + '/create_invoice.html'
AttributeError: 'NoneType' object has no attribute 'base_url'
```
2023-02-08 01:51:43 +00:00
ThomasV
dec397af95 update payserver submodule 2023-01-26 15:52:01 +01:00
ThomasV
396fa4a97a payserver: add 'view in payserver' menu item 2023-01-18 11:28:37 +01:00
ThomasV
d13c74eb0d payserver plugin improvements 2023-01-17 12:26:03 +01:00
ThomasV
f680607683 update payserver submodule 2023-01-17 07:35:52 +01:00
ThomasV
9f8b91da50 update payserver submodule 2023-01-16 13:57:08 +01:00
ThomasV
2c0dd0deb0 update payserver www submodule 2023-01-15 10:43:45 +01:00
SomberNight
d5c3c7ca66 payserver: daemon._run should only be called once 2023-01-13 01:02:47 +00:00
SomberNight
9039ec1dc4 payserver: make daemon_wallet_loaded hook reliable
daemon.load_wallet() often early-returns,
e.g. in Qt case, for storage-encrypted wallets.

closes https://github.com/spesmilo/electrum/issues/8118
2023-01-13 00:58:02 +00:00
SomberNight
cea4238b81 hw DeviceMgr: mostly switch away from xpubs for device pairing
- the DeviceMgr no longer uses xpubs to keep track of paired hw devices
- instead, introduce keystore.pairing_code(), based on soft_device_id
- xpubs are now only used in a single place when the actual pairing happens
- motivation is to allow pairing a single device with multiple generic
  output script descriptors, not just a single account-level xpub
- as a side-effect, we now allow pairing a device with multiple open
  windows simultaneously (if keystores have the same root fingerprint
  -- was already the case before if keystores had the same xpub)
2022-12-19 08:19:19 +00:00
SomberNight
8878059b2f hw bitbox02: show error if trying to sign_message on testnet
User was getting confusing traceback.
Original discussion shows the device only supports messages for mainnet.

see https://github.com/spesmilo/electrum/pull/6649#issuecomment-708634831
2022-12-19 07:49:40 +00:00
Sander van Grieken
5246f3d510 qml: refactor is_last checks to mostly lambdas, add multisig flow for 1st cosigner keystore,
add initial flow and view placeholders for additional cosigners.
2022-11-14 12:19:56 +01:00
ghost43
ac239a81b8 Merge pull request #8041 from bigspider/app-bitcoin-new
Modify Ledger plugin to support the new bitcoin app v2.1.0
2022-11-10 14:24:14 +00:00
SomberNight
e75110ec04 hw_wallet: de-dupe "message_dialog" code, make text selectable 2022-11-09 21:10:52 +00:00
SomberNight
9b82eb6d06 ledger: re-add support for HW.1, and add a deprecation warning 2022-11-09 20:42:55 +00:00
SomberNight
3cac7e9a61 ledger: minor clean-up 2022-11-09 20:11:08 +00:00
SomberNight
e4a880e435 trezor: use lower device-enumeration timeout for udp transport
This transport IIUC is only used for the trezor emulator.
The default timeout is 10 seconds. Every time we enumerate hw devices,
we also enumerate trezor devices, including scanning for the udp transport.
For some reason, recently on Windows, sporadically, this scan keeps
hitting the timeout for me. Quite annoying, as I might not even be testing
trezor (and I am certainly not testing using the trezor emulator on Windows...),
but scanning to test other plugins.

Probably overkill to have a 10 sec timeout for contacting localhost anyway.
2022-11-09 17:46:18 +00:00
Salvatore Ingala
e47270daa5 Fix multiple signing 2022-11-09 13:21:14 +01:00
Salvatore Ingala
3c0e3eb7e2 Refactored LedgerPlugin::create_client, and handle errors when creating the client. 2022-11-09 11:34:41 +01:00
Salvatore Ingala
7c80779903 Replace print() with logger 2022-11-09 11:21:21 +01:00
Salvatore Ingala
80e214d465 - Remove code calling hw1-related features, not supported in the version of btchip embedded in ledger_bitcoin
- Fix signature of sign_message in Ledger_Client_Legacy
2022-11-09 10:59:12 +01:00
Salvatore Ingala
f3eb492dca Update Ledger website to ledger.com in error message 2022-11-08 17:44:09 +01:00
Salvatore Ingala
c401f84aa7 Avoid relying on old btchip package; improve missing library error handling 2022-11-08 17:44:06 +01:00
Salvatore Ingala
2d64dc13c9 Modify Ledger plugin to support the new bitcoin app v2.1.0 2022-11-08 17:44:05 +01:00
Pavol Rusnak
b4e5f35e66 trezor: optimize signing speed by not serializing transaction in trezor
Since Electrum is not using TxRequestSerializedType.serialized_tx
we might ask the device not to serialize transactions
by setting SignTx.serialize=False

This flag is only present in trezorlib 0.13.4, so only users on that
version will benefit from the speedup.

However, we decided to keep the minimum required version to 0.13.0,
since the newer version is not strictly required.
2022-11-07 16:48:43 +01:00