Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion electrum/gui/qt/wizard/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def is_seed(self, x):
# really only used for electrum seeds. bip39 and slip39 are validated in SeedWidget
t = mnemonic.calc_seed_type(x)
if self.wizard_data['wallet_type'] == 'standard':
return mnemonic.is_seed(x) and not mnemonic.is_any_2fa_seed_type(t)
return mnemonic.is_seed(x) and (self.wizard.supports_2fa() or not mnemonic.is_any_2fa_seed_type(t))
elif self.wizard_data['wallet_type'] == '2fa':
return mnemonic.is_any_2fa_seed_type(t)
else:
Expand Down
36 changes: 33 additions & 3 deletions electrum/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ def is_multisig(self, wizard_data: dict) -> bool:
def is_hardware(self, wizard_data: dict) -> bool:
return wizard_data['keystore_type'] == 'hardware'

def supports_2fa(self) -> bool:
return False

def wallet_password_view(self, wizard_data: dict) -> str:
if self.is_hardware(wizard_data) and wizard_data['wallet_type'] == 'standard':
return 'wallet_password_hardware'
Expand Down Expand Up @@ -345,6 +348,9 @@ def validate_seed(self, seed: str, seed_variant: str, wallet_type: str) -> Tuple
# check if seed matches wallet type
if wallet_type == '2fa' and not is_any_2fa_seed_type(seed_type):
seed_valid = False
elif wallet_type == 'standard' and is_any_2fa_seed_type(seed_type):
# wizard will redirect
seed_valid = self.supports_2fa()
elif wallet_type == 'standard' and seed_type not in ['old', 'standard', 'segwit', 'bip39', 'slip39']:
seed_valid = False
elif wallet_type == 'multisig' and seed_type not in ['standard', 'segwit', 'bip39', 'slip39']:
Expand Down Expand Up @@ -433,10 +439,10 @@ def __init__(self, daemon: 'Daemon', plugins: 'Plugins'):
'last': lambda d: self.is_single_password() and not self.is_multisig(d)
},
'have_seed': {
'next': lambda d: 'have_ext' if self.wants_ext(d) else self.on_have_or_confirm_seed(d),
'accept': lambda d: None if self.wants_ext(d) else self.maybe_master_pubkey(d),
'next': self.on_have_seed,
'accept': self.on_accept_have_seed,
'last': lambda d: self.is_single_password() and not
(self.needs_derivation_path(d) or self.is_multisig(d) or self.wants_ext(d)),
(self.needs_derivation_path(d) or self.is_multisig(d) or self.wants_ext(d) or self.wants_2fa(d)),
},
'have_ext': {
'next': self.on_have_or_confirm_seed,
Expand Down Expand Up @@ -530,6 +536,30 @@ def on_keystore_type(self, wizard_data: dict) -> str:
'hardware': 'choose_hardware_device'
}.get(t)

def supports_2fa(self) -> bool:
return True

def wants_2fa(self, wizard_data: dict) -> bool:
# True if the user entered a 2fa seed while restoring a wallet of type 'standard'
return (wizard_data['wallet_type'] == 'standard'
and is_any_2fa_seed_type(wizard_data.get('seed_type', ''))
and self.supports_2fa())

def on_have_seed(self, wizard_data: dict) -> str:
if wizard_data['wallet_type'] == '2fa': # redirected by on_accept_have_seed
return 'trustedcoin_have_ext' if self.wants_ext(wizard_data) else 'trustedcoin_keep_disable'
elif self.wants_ext(wizard_data):
return 'have_ext'
else:
return self.on_have_or_confirm_seed(wizard_data)

def on_accept_have_seed(self, wizard_data: dict) -> None:
if self.wants_2fa(wizard_data):
wizard_data['wallet_type'] = '2fa'
return
if not self.wants_ext(wizard_data):
self.maybe_master_pubkey(wizard_data)

def on_have_or_confirm_seed(self, wizard_data: dict) -> str:
if self.needs_derivation_path(wizard_data):
return 'script_and_derivation'
Expand Down