|
24 | 24 | # SOFTWARE. |
25 | 25 |
|
26 | 26 | import os |
| 27 | +import bitcoin |
27 | 28 | import keystore |
28 | 29 | from wallet import Wallet, Imported_Wallet, Standard_Wallet, Multisig_Wallet, WalletStorage, wallet_types |
29 | 30 | from i18n import _ |
@@ -85,16 +86,19 @@ def new(self): |
85 | 86 | choices = [pair for pair in wallet_kinds if pair[0] in wallet_types] |
86 | 87 | self.choice_dialog(title=title, message=message, choices=choices, run_next=self.on_wallet_type) |
87 | 88 |
|
| 89 | + def load_2fa(self): |
| 90 | + self.storage.put('wallet_type', '2fa') |
| 91 | + self.storage.put('use_trustedcoin', True) |
| 92 | + self.plugin = self.plugins.load_plugin('trustedcoin') |
| 93 | + |
88 | 94 | def on_wallet_type(self, choice): |
89 | 95 | self.wallet_type = choice |
90 | 96 | if choice == 'standard': |
91 | 97 | action = 'choose_keystore' |
92 | 98 | elif choice == 'multisig': |
93 | 99 | action = 'choose_multisig' |
94 | 100 | elif choice == '2fa': |
95 | | - self.storage.put('wallet_type', '2fa') |
96 | | - self.storage.put('use_trustedcoin', True) |
97 | | - self.plugin = self.plugins.load_plugin('trustedcoin') |
| 101 | + self.load_2fa() |
98 | 102 | action = self.storage.get_action() |
99 | 103 | elif choice == 'imported': |
100 | 104 | action = 'import_addresses' |
@@ -243,31 +247,46 @@ def on_hw_derivation(self, name, device_info, derivation): |
243 | 247 | k = hardware_keystore(d) |
244 | 248 | self.on_keystore(k) |
245 | 249 |
|
246 | | - def restore_from_seed(self): |
247 | | - self.opt_bip39 = True |
248 | | - self.restore_seed_dialog(run_next=self.on_restore_seed, test=keystore.is_seed) |
| 250 | + def passphrase_dialog(self, run_next): |
| 251 | + message = '\n'.join([ |
| 252 | + _('Your seed may be extended with a passphrase.'), |
| 253 | + _('If that is the case, enter it here.'), |
| 254 | + ]) |
| 255 | + warning = '\n'.join([ |
| 256 | + _('Note that this is NOT your encryption password.'), |
| 257 | + _('If you do not know what this is, leave this field empty.'), |
| 258 | + ]) |
| 259 | + self.line_dialog(title=_('Passphrase'), message=message, warning=warning, default='', test=lambda x:True, run_next=run_next) |
249 | 260 |
|
250 | | - def on_restore_seed(self, seed, is_bip39): |
251 | | - if keystore.is_new_seed(seed) or is_bip39: |
252 | | - message = '\n'.join([ |
253 | | - _('Your seed may be extended with a passphrase.'), |
254 | | - _('If that is the case, enter it here.'), |
255 | | - ]) |
256 | | - warning = '\n'.join([ |
257 | | - _('Note that this is NOT your encryption password.'), |
258 | | - _('If you do not know what this is, leave this field empty.'), |
259 | | - ]) |
260 | | - f = lambda x: self.on_restore_passphrase(seed, x, is_bip39) |
261 | | - self.line_dialog(title=_('Passphrase'), message=message, warning=warning, default='', test=lambda x:True, run_next=f) |
| 261 | + def restore_from_seed(self): |
| 262 | + if self.wallet_type == 'standard': |
| 263 | + self.opt_bip39 = True |
| 264 | + test = bitcoin.is_seed |
262 | 265 | else: |
263 | | - self.on_restore_passphrase(seed, '', False) |
| 266 | + self.opt_bip39 = False |
| 267 | + test = bitcoin.is_new_seed |
| 268 | + self.restore_seed_dialog(run_next=self.on_restore_seed, test=test) |
264 | 269 |
|
265 | | - def on_restore_passphrase(self, seed, passphrase, is_bip39): |
| 270 | + def on_restore_seed(self, seed, is_bip39): |
266 | 271 | if is_bip39: |
267 | | - f = lambda x: self.run('on_bip44', seed, passphrase, int(x)) |
268 | | - self.account_id_dialog(f) |
| 272 | + f = lambda x: self.on_restore_bip39(seed, x) |
| 273 | + self.passphrase_dialog(run_next=f) |
269 | 274 | else: |
270 | | - self.run('create_keystore', seed, passphrase) |
| 275 | + seed_type = bitcoin.seed_type(seed) |
| 276 | + if seed_type == 'standard': |
| 277 | + f = lambda x: self.run('create_keystore', seed, x) |
| 278 | + self.passphrase_dialog(run_next=f) |
| 279 | + elif seed_type == 'old': |
| 280 | + self.run('create_keystore', seed, passphrase) |
| 281 | + elif seed_type == '2fa': |
| 282 | + self.load_2fa() |
| 283 | + self.run('on_restore_seed', seed) |
| 284 | + else: |
| 285 | + raise |
| 286 | + |
| 287 | + def on_restore_bip39(self, seed, passphrase): |
| 288 | + f = lambda x: self.run('on_bip44', seed, passphrase, int(x)) |
| 289 | + self.account_id_dialog(f) |
271 | 290 |
|
272 | 291 | def create_keystore(self, seed, passphrase): |
273 | 292 | k = keystore.from_seed(seed, passphrase) |
|
0 commit comments