Browse Source

ask users to enter their seed on create

283
thomasv 12 years ago
parent
commit
98f7d36313
  1. 21
      electrum
  2. 3
      gui/gui_android.py
  3. 127
      gui/gui_classic.py
  4. 4
      gui/gui_gtk.py
  5. 2
      gui/gui_text.py
  6. 2
      lib/interface.py
  7. 2
      lib/wallet.py

21
electrum

@ -126,8 +126,6 @@ if __name__ == '__main__':
interface = Interface(config, True) interface = Interface(config, True)
wallet.interface = interface wallet.interface = interface
interface.start(wait = False)
interface.send([('server.peers.subscribe',[])])
gui = gui.ElectrumGui(wallet, config) gui = gui.ElectrumGui(wallet, config)
@ -135,11 +133,16 @@ if __name__ == '__main__':
if not found: if not found:
a = gui.restore_or_create() a = gui.restore_or_create()
if not a: exit() if not a: exit()
# select a server.
s = gui.network_dialog()
if a =='create': if a =='create':
wallet.init_seed(None) wallet.init_seed(None)
# display seed
gui.show_seed()
# retype seed
if not gui.verify_seed():
exit()
else: else:
# ask for seed and gap. # ask for seed and gap.
sg = gui.seed_dialog() sg = gui.seed_dialog()
@ -153,13 +156,15 @@ if __name__ == '__main__':
else: else:
wallet.init_seed(str(seed)) wallet.init_seed(str(seed))
# select a server.
s = gui.network_dialog()
interface.start(wait = False)
interface.send([('server.peers.subscribe',[])])
# generate the first addresses, in case we are offline # generate the first addresses, in case we are offline
if s is None or a == 'create': if not found and ( s is None or a == 'create'):
wallet.synchronize() wallet.synchronize()
if a == 'create':
# display seed
gui.show_seed()
verifier = WalletVerifier(interface, config) verifier = WalletVerifier(interface, config)
verifier.start() verifier.start()

3
gui/gui_android.py

@ -969,6 +969,9 @@ class ElectrumGui:
def network_dialog(self): def network_dialog(self):
return True return True
def verify_seed(self):
self.wallet.save_seed()
return True
def show_seed(self): def show_seed(self):
modal_dialog('Your seed is:', wallet.seed) modal_dialog('Your seed is:', wallet.seed)

127
gui/gui_classic.py

@ -1604,57 +1604,6 @@ class ElectrumWindow(QMainWindow):
parent.password_button.setIcon( icon ) parent.password_button.setIcon( icon )
@staticmethod
def seed_dialog(wallet, parent=None):
d = QDialog(parent)
d.setModal(1)
vbox = QVBoxLayout()
msg = _("Please enter your wallet seed (or your master public key if you want to create a watching-only wallet)." + '\n')
vbox.addWidget(QLabel(msg))
grid = QGridLayout()
grid.setSpacing(8)
seed_e = QLineEdit()
grid.addWidget(QLabel(_('Seed or master public key')), 1, 0)
grid.addWidget(seed_e, 1, 1)
grid.addWidget(HelpButton(_("Your seed can be entered as a mnemonic (sequence of words), or as a hexadecimal string.")), 1, 3)
gap_e = AmountEdit(None, True)
gap_e.setText("5")
grid.addWidget(QLabel(_('Gap limit')), 2, 0)
grid.addWidget(gap_e, 2, 1)
grid.addWidget(HelpButton(_('Keep the default value unless you modified this parameter in your wallet.')), 2, 3)
vbox.addLayout(grid)
vbox.addLayout(ok_cancel_buttons(d))
d.setLayout(vbox)
if not d.exec_(): return
try:
gap = int(unicode(gap_e.text()))
except:
QMessageBox.warning(None, _('Error'), 'error', 'OK')
return
try:
seed = str(seed_e.text())
seed.decode('hex')
except:
print_error("Warning: Not hex, trying decode")
try:
seed = mnemonic.mn_decode( seed.split(' ') )
except:
QMessageBox.warning(None, _('Error'), _('I cannot decode this'), _('OK'))
return
if not seed:
QMessageBox.warning(None, _('Error'), _('No seed'), _('OK'))
return
return seed, gap
def generate_transaction_information_widget(self, tx): def generate_transaction_information_widget(self, tx):
tabs = QTabWidget(self) tabs = QTabWidget(self)
@ -2352,8 +2301,79 @@ class ElectrumGui:
if r==2: return None if r==2: return None
return 'restore' if r==1 else 'create' return 'restore' if r==1 else 'create'
def seed_dialog(self):
return ElectrumWindow.seed_dialog( self.wallet ) def verify_seed(self):
r = self.seed_dialog(False)
if not r: return False
if r[0] != self.wallet.seed:
QMessageBox.warning(None, _('Error'), 'incorrect seed', 'OK')
return False
else:
self.wallet.save_seed()
return True
def seed_dialog(self, is_restore=True):
d = QDialog()
d.setModal(1)
vbox = QVBoxLayout()
if is_restore:
msg = _("Please enter your wallet seed (or your master public key if you want to create a watching-only wallet)." + '\n')
else:
msg = _("Please type your seed." + '\n')
vbox.addWidget(QLabel(msg))
grid = QGridLayout()
grid.setSpacing(8)
seed_e = QLineEdit()
seed_e.setMinimumWidth(400)
grid.addWidget(QLabel(_('Seed or master public key') if is_restore else _('Seed')), 1, 0)
grid.addWidget(seed_e, 1, 1)
grid.addWidget(HelpButton(_("Your seed can be entered as a mnemonic (sequence of words), or as a hexadecimal string.")), 1, 3)
if is_restore:
gap_e = AmountEdit(None, True)
gap_e.setText("5")
grid.addWidget(QLabel(_('Gap limit')), 2, 0)
grid.addWidget(gap_e, 2, 1)
grid.addWidget(HelpButton(_('Keep the default value unless you modified this parameter in your wallet.')), 2, 3)
vbox.addLayout(grid)
vbox.addLayout(ok_cancel_buttons(d))
d.setLayout(vbox)
if not d.exec_(): return
if is_restore:
try:
gap = int(unicode(gap_e.text()))
except:
QMessageBox.warning(None, _('Error'), 'error', 'OK')
return
else:
gap = None
try:
seed = str(seed_e.text())
seed.decode('hex')
except:
print_error("Warning: Not hex, trying decode")
try:
seed = mnemonic.mn_decode( seed.split(' ') )
except:
QMessageBox.warning(None, _('Error'), _('I cannot decode this'), _('OK'))
return
if not seed:
QMessageBox.warning(None, _('Error'), _('No seed'), _('OK'))
return
return seed, gap
def network_dialog(self): def network_dialog(self):
return ElectrumWindow.network_dialog( self.wallet, parent=None ) return ElectrumWindow.network_dialog( self.wallet, parent=None )
@ -2362,7 +2382,6 @@ class ElectrumGui:
def show_seed(self): def show_seed(self):
ElectrumWindow.show_seed(self.wallet.seed, self.wallet.imported_keys) ElectrumWindow.show_seed(self.wallet.seed, self.wallet.imported_keys)
def password_dialog(self): def password_dialog(self):
if self.wallet.seed: if self.wallet.seed:
ElectrumWindow.change_password_dialog(self.wallet) ElectrumWindow.change_password_dialog(self.wallet)

4
gui/gui_gtk.py

@ -1292,6 +1292,10 @@ class ElectrumGui():
def seed_dialog(self): def seed_dialog(self):
return run_recovery_dialog( self.wallet ) return run_recovery_dialog( self.wallet )
def verify_seed(self):
self.wallet.save_seed()
return True
def network_dialog(self): def network_dialog(self):
return run_network_dialog( self.wallet, parent=None ) return run_network_dialog( self.wallet, parent=None )

2
gui/gui_text.py

@ -47,6 +47,8 @@ class ElectrumGui:
def restore_or_create(self): def restore_or_create(self):
pass pass
def verify_seed(self):
pass
def get_string(self, y, x): def get_string(self, y, x):
curses.curs_set(1) curses.curs_set(1)

2
lib/interface.py

@ -382,7 +382,7 @@ class Interface(threading.Thread):
def __init__(self, config=None, loop=False): def __init__(self, config=None, loop=False):
self.server = None self.server = random.choice(DEFAULT_SERVERS[:])
self.proxy = None self.proxy = None
if config is None: if config is None:

2
lib/wallet.py

@ -152,6 +152,8 @@ class Wallet:
if not seed: if not seed:
seed = random_seed(128) seed = random_seed(128)
self.seed = seed self.seed = seed
def save_seed(self):
self.config.set_key('seed', self.seed, True) self.config.set_key('seed', self.seed, True)
self.config.set_key('seed_version', self.seed_version, True) self.config.set_key('seed_version', self.seed_version, True)
mpk = self.SequenceClass.mpk_from_seed(self.seed) mpk = self.SequenceClass.mpk_from_seed(self.seed)

Loading…
Cancel
Save