X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=gui%2Fqt%2Finstallwizard.py;h=e3799784b7ec521e1ddb029521c24653d1ff0f1f;hb=54973062bd903bda787bb94a66bc4eff7b35b77b;hp=f203b1be83539dd82f3511aafaa3796b3a29b70f;hpb=913ef26dd9bdb6222b791ce46eab3672e9ff78df;p=electrum-nvc.git diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index f203b1b..e379978 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -3,9 +3,10 @@ from PyQt4.QtCore import * import PyQt4.QtCore as QtCore from electrum.i18n import _ -from electrum import Wallet, Wallet_2of3 +from electrum import Wallet, Wallet_2of2, Wallet_2of3 +import electrum.bitcoin as bitcoin -from seed_dialog import SeedDialog +import seed_dialog from network_dialog import NetworkDialog from util import * from amountedit import AmountEdit @@ -14,6 +15,15 @@ import sys import threading from electrum.plugins import run_hook + +MSG_ENTER_ANYTHING = _("Please enter a wallet seed, a master public key, a list of Bitcoin addresses, or a list of private keys") +MSG_SHOW_MPK = _("This is your master public key") +MSG_ENTER_MPK = _("Please enter your master public key") +MSG_ENTER_COLD_MPK = _("Please enter the master public key of your cosigner wallet") +MSG_ENTER_SEED_OR_MPK = _("Please enter a wallet seed, or master public key") +MSG_VERIFY_SEED = _("Your seed is important!") + "\n" + _("To make sure that you have properly saved your seed, please retype it here.") + + class InstallWizard(QDialog): def __init__(self, config, network, storage): @@ -37,56 +47,117 @@ class InstallWizard(QDialog): def restore_or_create(self): + vbox = QVBoxLayout() + + main_label = QLabel(_("Electrum could not find an existing wallet.")) + vbox.addWidget(main_label) + grid = QGridLayout() grid.setSpacing(5) - msg = _("Electrum could not find an existing wallet.") + "\n\n" \ - + _("What do you want to do?") + "\n" - label = QLabel(msg) + label = QLabel(_("What do you want to do?")) label.setWordWrap(True) grid.addWidget(label, 0, 0) - gb = QGroupBox() + gb1 = QGroupBox() + grid.addWidget(gb1, 0, 0) - b1 = QRadioButton(gb) + group1 = QButtonGroup() + + b1 = QRadioButton(gb1) b1.setText(_("Create new wallet")) b1.setChecked(True) - b2 = QRadioButton(gb) - b2.setText(_("Restore an existing wallet from its seed")) + b2 = QRadioButton(gb1) + b2.setText(_("Restore an existing wallet")) - b3 = QRadioButton(gb) - b3.setText(_("Create a watching-only version of an existing wallet")) + group1.addButton(b1) + group1.addButton(b2) - grid.addWidget(b1,1,0) - grid.addWidget(b2,2,0) - grid.addWidget(b3,3,0) + grid.addWidget(b1, 1, 0) + grid.addWidget(b2, 2, 0) + vbox.addLayout(grid) - vbox = QVBoxLayout() - self.set_layout(vbox) + grid2 = QGridLayout() + grid2.setSpacing(5) - vbox.addLayout(grid) + class ClickableLabel(QLabel): + def mouseReleaseEvent(self, ev): + self.emit(SIGNAL('clicked()')) + + label2 = ClickableLabel(_("Wallet type:") + " [+]") + hbox = QHBoxLayout() + hbox.addWidget(label2) + grid2.addLayout(hbox, 3, 0) + + gb2 = QGroupBox() + grid.addWidget(gb2, 3, 0) + + group2 = QButtonGroup() + + bb1 = QRadioButton(gb2) + bb1.setText(_("Standard wallet")) + bb1.setChecked(True) + + bb2 = QRadioButton(gb2) + bb2.setText(_("Wallet with two-factor authentication (plugin)")) + + bb3 = QRadioButton(gb2) + bb3.setText(_("Multisig wallet (2 of 2)")) + bb3.setHidden(True) + + bb4 = QRadioButton(gb2) + bb4.setText(_("Multisig wallet (2 of 3)")) + bb4.setHidden(True) + + grid2.addWidget(bb1, 4, 0) + grid2.addWidget(bb2, 5, 0) + grid2.addWidget(bb3, 6, 0) + grid2.addWidget(bb4, 7, 0) + + def toggle(): + x = not bb3.isHidden() + label2.setText(_("Wallet type:") + (' [+]' if x else ' [-]')) + bb3.setHidden(x) + bb4.setHidden(x) + + self.connect(label2, SIGNAL('clicked()'), toggle) + + grid2.addWidget(label2) + + group2.addButton(bb1) + group2.addButton(bb2) + group2.addButton(bb3) + group2.addButton(bb4) + + vbox.addLayout(grid2) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + hbox, button = ok_cancel_buttons2(self, _('Next')) + vbox.addLayout(hbox) + self.set_layout(vbox) + self.show() + self.raise_() + button.setDefault(True) if not self.exec_(): - return + return None, None - if b1.isChecked(): - answer = 'create' - elif b2.isChecked(): - answer = 'restore' - else: - answer = 'watching' - - return answer + action = 'create' if b1.isChecked() else 'restore' + if bb1.isChecked(): + t = 'standard' + elif bb2.isChecked(): + t = '2fa' + elif bb3.isChecked(): + t = '2of2' + elif bb4.isChecked(): + t = '2of3' + return action, t - - def verify_seed(self, seed): - r = self.seed_dialog(False) + def verify_seed(self, seed, sid): + r = self.enter_seed_dialog(MSG_VERIFY_SEED, sid) if not r: return @@ -97,52 +168,82 @@ class InstallWizard(QDialog): return True - def seed_dialog(self, is_restore=True): + def get_seed_text(self, seed_e): + text = unicode(seed_e.toPlainText()).strip() + text = ' '.join(text.split()) + return text - vbox = QVBoxLayout() - if is_restore: - msg = _("Please enter your wallet seed.") + "\n" - else: - msg = _("Your seed is important!") \ - + "\n" + _("To make sure that you have properly saved your seed, please retype it here.") - - logo = QLabel() - logo.setPixmap(QPixmap(":icons/seed.png").scaledToWidth(56)) - logo.setMaximumWidth(60) - label = QLabel(msg) - label.setWordWrap(True) + def is_any(self, seed_e): + text = self.get_seed_text(seed_e) + return Wallet.is_seed(text) or Wallet.is_old_mpk(text) or Wallet.is_xpub(text) or Wallet.is_xprv(text) or Wallet.is_address(text) or Wallet.is_private_key(text) - seed_e = QTextEdit() - seed_e.setMaximumHeight(100) + def is_mpk(self, seed_e): + text = self.get_seed_text(seed_e) + return Wallet.is_xpub(text) or Wallet.is_old_mpk(text) - vbox.addWidget(label) - grid = QGridLayout() - grid.addWidget(logo, 0, 0) - grid.addWidget(seed_e, 0, 1) + def enter_seed_dialog(self, msg, sid): + vbox, seed_e = seed_dialog.enter_seed_box(msg, sid) + vbox.addStretch(1) + hbox, button = ok_cancel_buttons2(self, _('Next')) + vbox.addLayout(hbox) + button.setEnabled(False) + seed_e.textChanged.connect(lambda: button.setEnabled(self.is_any(seed_e))) + self.set_layout(vbox) + if not self.exec_(): + return + return self.get_seed_text(seed_e) - vbox.addLayout(grid) + def multi_mpk_dialog(self, xpub_hot, n): + vbox = QVBoxLayout() + vbox0, seed_e0 = seed_dialog.enter_seed_box(MSG_SHOW_MPK, 'hot') + vbox.addLayout(vbox0) + seed_e0.setText(xpub_hot) + seed_e0.setReadOnly(True) + entries = [] + for i in range(n): + vbox2, seed_e2 = seed_dialog.enter_seed_box(MSG_ENTER_COLD_MPK, 'cold') + vbox.addLayout(vbox2) + entries.append(seed_e2) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _('Next'))) - + hbox, button = ok_cancel_buttons2(self, _('Next')) + vbox.addLayout(hbox) + button.setEnabled(False) + f = lambda: button.setEnabled( map(lambda e: self.is_xpub(e), entries) == [True]*len(entries)) + for e in entries: + e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return + return map(lambda e: self.get_seed_text(e), entries) - seed = seed_e.toPlainText() - seed = unicode(seed.toLower()) - if not seed: - QMessageBox.warning(None, _('Error'), _('No seed'), _('OK')) - return + def multi_seed_dialog(self, n): + vbox = QVBoxLayout() + vbox1, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, 'hot') + vbox.addLayout(vbox1) + entries = [seed_e1] + for i in range(n): + vbox2, seed_e2 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, 'cold') + vbox.addLayout(vbox2) + entries.append(seed_e2) + vbox.addStretch(1) + hbox, button = ok_cancel_buttons2(self, _('Next')) + vbox.addLayout(hbox) + button.setEnabled(False) + + f = lambda: button.setEnabled( map(lambda e: self.is_any(e), entries) == [True]*len(entries)) + for e in entries: + e.textChanged.connect(f) + + self.set_layout(vbox) + if not self.exec_(): + return + return map(lambda e: self.get_seed_text(e), entries) - if not Wallet.is_seed(seed): - QMessageBox.warning(None, _('Error'), _('Invalid seed'), _('OK')) - return - return seed @@ -161,32 +262,6 @@ class InstallWizard(QDialog): - def mpk_dialog(self): - - vbox = QVBoxLayout() - vbox.addWidget(QLabel(_("Please enter your master public key."))) - - grid = QGridLayout() - grid.setSpacing(8) - - label = QLabel(_("Key")) - grid.addWidget(label, 0, 0) - mpk_e = QTextEdit() - mpk_e.setMaximumHeight(100) - grid.addWidget(mpk_e, 0, 1) - - vbox.addLayout(grid) - - vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _('Next'))) - - self.set_layout(vbox) - if not self.exec_(): - return None - - mpk = str(mpk_e.toPlainText()).strip() - return mpk - def network_dialog(self): @@ -237,131 +312,246 @@ class InstallWizard(QDialog): return - def show_message(self, msg): + def show_message(self, msg, icon=None): vbox = QVBoxLayout() + self.set_layout(vbox) + if icon: + logo = QLabel() + logo.setPixmap(icon) + vbox.addWidget(logo) vbox.addWidget(QLabel(msg)) vbox.addStretch(1) vbox.addLayout(close_button(self, _('Next'))) - self.set_layout(vbox) if not self.exec_(): return None - def question(self, msg): + + def question(self, msg, icon=None): vbox = QVBoxLayout() + self.set_layout(vbox) + if icon: + logo = QLabel() + logo.setPixmap(icon) + vbox.addWidget(logo) vbox.addWidget(QLabel(msg)) vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self, _('OK'))) - self.set_layout(vbox) if not self.exec_(): return None return True def show_seed(self, seed, sid): - from seed_dialog import make_seed_dialog - vbox = make_seed_dialog(seed, sid) + vbox = seed_dialog.show_seed_box(seed, sid) vbox.addLayout(ok_cancel_buttons(self, _("Next"))) self.set_layout(vbox) return self.exec_() - def password_dialog(self, wallet): + def password_dialog(self): msg = _("Please choose a password to encrypt your wallet keys.")+'\n'\ +_("Leave these fields empty if you want to disable encryption.") from password_dialog import make_password_dialog, run_password_dialog - self.set_layout( make_password_dialog(self, wallet, msg) ) - return run_password_dialog(self, wallet, self) + self.set_layout( make_password_dialog(self, None, msg) ) + return run_password_dialog(self, None, self)[2] - def choose_wallet_type(self): - grid = QGridLayout() - grid.setSpacing(5) + def create_cold_seed(self, wallet): + from electrum.bitcoin import mnemonic_to_seed, bip32_root + msg = _('You are about to generate the cold storage seed of your wallet.') + '\n' \ + + _('For safety, you should do this on an offline computer.') + icon = QPixmap( ':icons/cold_seed.png').scaledToWidth(56) + if not self.question(msg, icon): + return - msg = _("Choose your wallet.") - label = QLabel(msg) - label.setWordWrap(True) - grid.addWidget(label, 0, 0) + cold_seed = wallet.make_seed() + if not self.show_seed(cold_seed, 'cold'): + return + if not self.verify_seed(cold_seed, 'cold'): + return - gb = QGroupBox() + hex_seed = mnemonic_to_seed(cold_seed,'').encode('hex') + xpriv, xpub = bip32_root(hex_seed) + wallet.add_master_public_key('cold/', xpub) - b1 = QRadioButton(gb) - b1.setText(_("Standard wallet (protected by password)")) - b1.setChecked(True) + msg = _('Your master public key was saved in your wallet file.') + '\n'\ + + _('Your cold seed must be stored on paper; it is not in the wallet file.')+ '\n\n' \ + + _('This program is about to close itself.') + '\n'\ + + _('You will need to reopen your wallet on an online computer, in order to complete the creation of your wallet') + self.show_message(msg) - b2 = QRadioButton(gb) - b2.setText(_("Multi-signature wallet (two-factor authentication)")) - grid.addWidget(b1,1,0) - grid.addWidget(b2,2,0) - vbox = QVBoxLayout() + def run(self, action): - vbox.addLayout(grid) - vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + if action == 'new': + action, t = self.restore_or_create() - self.set_layout(vbox) - if not self.exec_(): + if action is None: return - - if b1.isChecked(): - return 'standard' - elif b2.isChecked(): - return '2of3' + + if action == 'create': + if t == 'standard': + wallet = Wallet(self.storage) + + elif t == '2fa': + wallet = Wallet_2of3(self.storage) + run_hook('create_cold_seed', wallet, self) + self.create_cold_seed(wallet) + return + elif t == '2of2': + wallet = Wallet_2of2(self.storage) + action = 'create_2of2_1' - def run(self, action = None): + elif t == '2of3': + wallet = Wallet_2of3(self.storage) + action = 'create_2of3_1' - if action is None: - action = self.restore_or_create() - if action is None: - return + if action in ['create_2fa_2', 'create_2of3_2']: + wallet = Wallet_2of3(self.storage) - if action == 'create': - t = self.choose_wallet_type() - if t == '2of3': - run_hook('create_cold_seed', self.storage, self) + if action in ['create_2of2_2']: + wallet = Wallet_2of2(self.storage) + + if action in ['create', 'create_2of2_1', 'create_2fa_2', 'create_2of3_1']: + seed = wallet.make_seed() + sid = None if action == 'create' else 'hot' + if not self.show_seed(seed, sid): + return + if not self.verify_seed(seed, sid): + return + password = self.password_dialog() + wallet.add_seed(seed, password) + if action == 'create': + wallet.create_accounts(password) + self.waiting_dialog(wallet.synchronize) + elif action == 'create_2of2_1': + action = 'create_2of2_2' + elif action == 'create_2of3_1': + action = 'create_2of3_2' + elif action == 'create_2fa_2': + action = 'create_2fa_3' + + if action == 'create_2of2_2': + xpub_hot = wallet.master_public_keys.get("m/") + r = self.multi_mpk_dialog(xpub_hot, 1) + if not r: return + xpub_cold = r[0] + wallet.add_master_public_key("cold/", xpub_cold) + wallet.create_account() + self.waiting_dialog(wallet.synchronize) - if action in ['create', 'create2of3']: + if action == 'create_2of3_2': + xpub_hot = wallet.master_public_keys.get("m/") + r = self.multi_mpk_dialog(xpub_hot, 2) + if not r: + return + xpub1, xpub2 = r + wallet.add_master_public_key("cold/", xpub1) + wallet.add_master_public_key("remote/", xpub2) + wallet.create_account() + self.waiting_dialog(wallet.synchronize) - wallet = Wallet(self.storage) - wallet.init_seed(None) - seed = wallet.get_mnemonic(None) - if not self.show_seed(seed, 'hot' if action == 'create2of3' else None): - return - if not self.verify_seed(seed): + if action == 'create_2fa_3': + run_hook('create_remote_key', wallet, self) + if not wallet.master_public_keys.get("remote/"): return - ok, old_password, password = self.password_dialog(wallet) - wallet.save_seed(password) + wallet.create_account() + self.waiting_dialog(wallet.synchronize) + - if action == 'create2of3': - run_hook('create_hot_seed', wallet, self) + if action == 'restore': - wallet.create_accounts(password) - def create(): - wallet.synchronize() # generate first addresses offline - self.waiting_dialog(create) + if t == 'standard': + text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None) + if not text: + return + if Wallet.is_seed(text): + password = self.password_dialog() + wallet = Wallet.from_seed(text, self.storage) + wallet.add_seed(text, password) + wallet.create_accounts(password) + elif Wallet.is_xprv(text): + password = self.password_dialog() + wallet = Wallet.from_xprv(text, password, self.storage) + elif Wallet.is_old_mpk(text): + wallet = Wallet.from_old_mpk(text, self.storage) + elif Wallet.is_xpub(text): + wallet = Wallet.from_xpub(text, self.storage) + elif Wallet.is_address(text): + wallet = Wallet.from_address(text, self.storage) + elif Wallet.is_private_key(text): + wallet = Wallet.from_private_key(text, self.storage) + else: + raise + + elif t in ['2fa', '2of2']: + r = self.multi_seed_dialog(1) + if not r: + return + text1, text2 = r + password = self.password_dialog() + if t == '2of2': + wallet = Wallet_2of2(self.storage) + elif t == '2of3': + wallet = Wallet_2of3(self.storage) + elif t == '2fa': + wallet = Wallet_2of3(self.storage) + + if Wallet.is_seed(text1): + wallet.add_seed(text1, password) + if Wallet.is_seed(text2): + wallet.add_cold_seed(text2, password) + else: + wallet.add_master_public_key("cold/", text2) + + elif Wallet.is_mpk(text1): + if Wallet.is_seed(text2): + wallet.add_seed(text2, password) + wallet.add_master_public_key("cold/", text1) + else: + wallet.add_master_public_key("m/", text1) + wallet.add_master_public_key("cold/", text2) + + if t == '2fa': + run_hook('restore_third_key', wallet, self) + + wallet.create_account() + + elif t in ['2of3']: + r = self.multi_seed_dialog(2) + if not r: + return + text1, text2, text3 = r + password = self.password_dialog() + wallet = Wallet_2of3(self.storage) + + if Wallet.is_seed(text1): + wallet.add_seed(text1, password) + if Wallet.is_seed(text2): + wallet.add_cold_seed(text2, password) + else: + wallet.add_master_public_key("cold/", text2) + + elif Wallet.is_mpk(text1): + if Wallet.is_seed(text2): + wallet.add_seed(text2, password) + wallet.add_master_public_key("cold/", text1) + else: + wallet.add_master_public_key("m/", text1) + wallet.add_master_public_key("cold/", text2) + + wallet.create_account() + + else: + raise - elif action == 'restore': - seed = self.seed_dialog() - if not Wallet.is_seed(seed): - return - wallet = Wallet.from_seed(seed, self.storage) - ok, old_password, password = self.password_dialog(wallet) - wallet.save_seed(password) - wallet.create_accounts(password) - - elif action == 'watching': - mpk = self.mpk_dialog() - if not mpk: - return - wallet = Wallet.from_mpk(mpk, self.storage) - else: raise #if not self.config.get('server'): if self.network: