2019-02-11 20:21:24 +01:00
|
|
|
from functools import partial
|
2023-08-23 17:09:19 +02:00
|
|
|
from typing import TYPE_CHECKING
|
2019-02-11 20:21:24 +01:00
|
|
|
|
2024-09-05 16:20:01 +00:00
|
|
|
from PyQt6.QtCore import pyqtSignal
|
|
|
|
|
from PyQt6.QtWidgets import QInputDialog, QLineEdit
|
2019-02-11 20:21:24 +01:00
|
|
|
|
2016-01-11 15:08:12 +09:00
|
|
|
from electrum.i18n import _
|
2018-07-11 17:38:47 +02:00
|
|
|
from electrum.plugin import hook
|
2018-01-11 04:37:41 +11:00
|
|
|
from electrum.wallet import Standard_Wallet
|
2018-03-20 14:15:54 +01:00
|
|
|
|
2020-10-24 23:32:18 +02:00
|
|
|
from .ledger import LedgerPlugin, Ledger_Client
|
2016-08-31 11:50:19 +02:00
|
|
|
from ..hw_wallet.qt import QtHandlerBase, QtPluginBase
|
2018-09-19 20:02:03 +02:00
|
|
|
from ..hw_wallet.plugin import only_hook_if_libraries_available
|
2023-08-23 17:09:19 +02:00
|
|
|
from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUninitialized, WCHWUnlock, WCHWXPub
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from electrum.gui.qt.wizard.wallet import QENewWalletWizard
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2016-12-21 12:52:54 +07:00
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
class Plugin(LedgerPlugin, QtPluginBase):
|
2019-02-01 19:01:21 +01:00
|
|
|
icon_unpaired = "ledger_unpaired.png"
|
|
|
|
|
icon_paired = "ledger.png"
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
def create_handler(self, window):
|
|
|
|
|
return Ledger_Handler(window)
|
|
|
|
|
|
2018-09-19 20:02:03 +02:00
|
|
|
@only_hook_if_libraries_available
|
2018-09-30 00:25:36 +02:00
|
|
|
@hook
|
2018-01-11 04:37:41 +11:00
|
|
|
def receive_menu(self, menu, addrs, wallet):
|
|
|
|
|
if type(wallet) is not Standard_Wallet:
|
|
|
|
|
return
|
|
|
|
|
keystore = wallet.get_keystore()
|
|
|
|
|
if type(keystore) == self.keystore_class and len(addrs) == 1:
|
|
|
|
|
def show_address():
|
2022-10-18 15:29:03 +02:00
|
|
|
keystore.thread.add(partial(self.show_address, wallet, addrs[0], keystore=keystore))
|
2018-01-11 04:37:41 +11:00
|
|
|
menu.addAction(_("Show on Ledger"), show_address)
|
|
|
|
|
|
2023-08-23 17:09:19 +02:00
|
|
|
@hook
|
|
|
|
|
def init_wallet_wizard(self, wizard: 'QENewWalletWizard'):
|
|
|
|
|
self.extend_wizard(wizard)
|
|
|
|
|
|
|
|
|
|
# insert ledger pages in new wallet wizard
|
|
|
|
|
def extend_wizard(self, wizard: 'QENewWalletWizard'):
|
|
|
|
|
super().extend_wizard(wizard)
|
|
|
|
|
views = {
|
|
|
|
|
'ledger_start': {'gui': WCScriptAndDerivation},
|
|
|
|
|
'ledger_xpub': {'gui': WCHWXPub},
|
|
|
|
|
'ledger_not_initialized': {'gui': WCHWUninitialized},
|
|
|
|
|
'ledger_unlock': {'gui': WCHWUnlock}
|
|
|
|
|
}
|
|
|
|
|
wizard.navmap_merge(views)
|
|
|
|
|
|
|
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
class Ledger_Handler(QtHandlerBase):
|
2016-12-21 12:52:54 +07:00
|
|
|
setup_signal = pyqtSignal()
|
2020-10-24 23:32:18 +02:00
|
|
|
auth_signal = pyqtSignal(object, object)
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2022-11-09 21:09:02 +00:00
|
|
|
MESSAGE_DIALOG_TITLE = _("Ledger Status")
|
|
|
|
|
|
2015-11-23 19:38:48 +01:00
|
|
|
def __init__(self, win):
|
2016-08-31 11:50:19 +02:00
|
|
|
super(Ledger_Handler, self).__init__(win, 'Ledger')
|
2016-12-21 12:52:54 +07:00
|
|
|
self.setup_signal.connect(self.setup_dialog)
|
|
|
|
|
self.auth_signal.connect(self.auth_dialog)
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2016-01-30 08:11:41 +01:00
|
|
|
def word_dialog(self, msg):
|
2024-10-10 20:11:24 +00:00
|
|
|
response = QInputDialog.getText(self.top_level_window(), "Ledger Wallet Authentication", msg, QLineEdit.EchoMode.Password)
|
2016-01-30 08:11:41 +01:00
|
|
|
if not response[1]:
|
|
|
|
|
self.word = None
|
|
|
|
|
else:
|
|
|
|
|
self.word = str(response[0])
|
2016-08-18 11:34:37 +02:00
|
|
|
self.done.set()
|
2019-08-12 00:35:23 +02:00
|
|
|
|
2020-10-24 23:32:18 +02:00
|
|
|
def auth_dialog(self, data, client: 'Ledger_Client'):
|
2017-01-09 13:02:48 +01:00
|
|
|
try:
|
|
|
|
|
from .auth2fa import LedgerAuthDialog
|
|
|
|
|
except ImportError as e:
|
2019-07-17 20:12:52 +02:00
|
|
|
self.message_dialog(repr(e))
|
2017-01-09 13:02:48 +01:00
|
|
|
return
|
2020-10-24 23:32:18 +02:00
|
|
|
dialog = LedgerAuthDialog(self, data, client=client)
|
2024-09-05 16:20:01 +00:00
|
|
|
dialog.exec()
|
2016-12-21 12:52:54 +07:00
|
|
|
self.word = dialog.pin
|
|
|
|
|
self.done.set()
|
2019-08-12 00:35:23 +02:00
|
|
|
|
2020-10-24 23:32:18 +02:00
|
|
|
def get_auth(self, data, *, client: 'Ledger_Client'):
|
2016-12-21 12:52:54 +07:00
|
|
|
self.done.clear()
|
2020-10-24 23:32:18 +02:00
|
|
|
self.auth_signal.emit(data, client)
|
2016-12-21 12:52:54 +07:00
|
|
|
self.done.wait()
|
|
|
|
|
return self.word
|
2019-08-12 00:35:23 +02:00
|
|
|
|
2016-12-21 12:52:54 +07:00
|
|
|
def get_setup(self):
|
|
|
|
|
self.done.clear()
|
|
|
|
|
self.setup_signal.emit()
|
|
|
|
|
self.done.wait()
|
2019-08-12 00:35:23 +02:00
|
|
|
return
|
|
|
|
|
|
2016-12-21 12:52:54 +07:00
|
|
|
def setup_dialog(self):
|
2018-03-20 14:15:54 +01:00
|
|
|
self.show_error(_('Initialization of Ledger HW devices is currently disabled.'))
|