Browse Source

hardware wallets: smarter pairing during sign_transaction

Scenario:
- 2of2 multisig wallet with device1 and device2
- disconnect all devices
- open wallet file
- fail all pairings at wallet-open
- connect device2
- try to sign a tx
At this point Electrum will try to find the device for keystore1 first, and there is only a single unpaired device: device2.
Automatic pairing of keystore1 and device2 will fail, due to device id mismatching compared to what is persisted on disk for keystore1, so the user is prompted for manual selection. The selection dialog is somewhat confusing as it is not clear that the app is asking to select a device for keystore1. Pairing would fail, so the user is expected to cancel the dialog. If they cancel, keystore1 is skipped, and we try to pair for keystore2 now, and device2 will pair with it automatically.

fixes https://github.com/spesmilo/electrum/issues/4199#issuecomment-1112552416
patch-4
SomberNight 3 years ago
parent
commit
238619f1ed
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/keystore.py
  2. 3
      electrum/wallet.py

8
electrum/keystore.py

@ -847,7 +847,13 @@ class Hardware_KeyStore(Xpub, KeyStore):
def has_usable_connection_with_device(self) -> bool:
if not hasattr(self, 'plugin'):
return False
client = self.plugin.get_client(self, force_pair=False)
# we try to create a client even if there isn't one already,
# but do not prompt the user if auto-select fails:
client = self.plugin.get_client(
self,
force_pair=True,
allow_user_interaction=False,
)
if client is None:
return False
return client.has_usable_connection_with_device()

3
electrum/wallet.py

@ -2100,6 +2100,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
tmp_tx = copy.deepcopy(tx)
tmp_tx.add_info_from_wallet(self, include_xpubs=True)
# sign. start with ready keystores.
# note: ks.ready_to_sign() side-effect: we trigger pairings with potential hw devices.
# We only do this once, before the loop, however we could rescan after each iteration,
# to see if the user connected/disconnected devices in the meantime.
for k in sorted(self.get_keystores(), key=lambda ks: ks.ready_to_sign(), reverse=True):
try:
if k.can_sign(tmp_tx):

Loading…
Cancel
Save