Browse Source

qml: fix wizard_data not available to 'last' check on have seed wizard page

also refactor seed verification, split off seed_variant from seed_type (partial disambiguation),
fix bip39 wallet creation
patch-4
Sander van Grieken 2 years ago
parent
commit
fac4003354
  1. 4
      electrum/gui/qml/components/wizard/WCBIP39Refine.qml
  2. 29
      electrum/gui/qml/components/wizard/WCHaveSeed.qml
  3. 22
      electrum/gui/qml/qebitcoin.py
  4. 2
      electrum/wizard.py

4
electrum/gui/qml/components/wizard/WCBIP39Refine.qml

@ -51,10 +51,9 @@ WizardComponent {
clip:true clip:true
interactive: height < contentHeight interactive: height < contentHeight
GridLayout { ColumnLayout {
id: mainLayout id: mainLayout
width: parent.width width: parent.width
columns: 1
Label { text: qsTr('Script type and Derivation path') } Label { text: qsTr('Script type and Derivation path') }
Button { Button {
@ -79,6 +78,7 @@ WizardComponent {
text: qsTr('native segwit (p2wpkh)') text: qsTr('native segwit (p2wpkh)')
} }
InfoTextArea { InfoTextArea {
Layout.preferredWidth: parent.width
text: qsTr('You can override the suggested derivation path.') + ' ' + text: qsTr('You can override the suggested derivation path.') + ' ' +
qsTr('If you are not sure what this is, leave this field unchanged.') qsTr('If you are not sure what this is, leave this field unchanged.')
} }

29
electrum/gui/qml/components/wizard/WCHaveSeed.qml

@ -14,38 +14,37 @@ WizardComponent {
property bool is2fa: false property bool is2fa: false
onAccept: { function apply() {
wizard_data['seed'] = seedtext.text wizard_data['seed'] = seedtext.text
wizard_data['seed_variant'] = seed_variant.currentValue
wizard_data['seed_type'] = bitcoin.seed_type wizard_data['seed_type'] = bitcoin.seed_type
wizard_data['seed_extend'] = extendcb.checked wizard_data['seed_extend'] = extendcb.checked
wizard_data['seed_extra_words'] = extendcb.checked ? customwordstext.text : '' wizard_data['seed_extra_words'] = extendcb.checked ? customwordstext.text : ''
wizard_data['seed_bip39'] = seed_type.getTypeCode() == 'BIP39'
wizard_data['seed_slip39'] = seed_type.getTypeCode() == 'SLIP39'
} }
function setSeedTypeHelpText() { function setSeedTypeHelpText() {
var t = { var t = {
'Electrum': [ 'electrum': [
qsTr('Electrum seeds are the default seed type.'), qsTr('Electrum seeds are the default seed type.'),
qsTr('If you are restoring from a seed previously created by Electrum, choose this option') qsTr('If you are restoring from a seed previously created by Electrum, choose this option')
].join(' '), ].join(' '),
'BIP39': [ 'bip39': [
qsTr('BIP39 seeds can be imported in Electrum, so that users can access funds locked in other wallets.'), qsTr('BIP39 seeds can be imported in Electrum, so that users can access funds locked in other wallets.'),
'<br/><br/>', '<br/><br/>',
qsTr('However, we do not generate BIP39 seeds, because they do not meet our safety standard.'), qsTr('However, we do not generate BIP39 seeds, because they do not meet our safety standard.'),
qsTr('BIP39 seeds do not include a version number, which compromises compatibility with future software.') qsTr('BIP39 seeds do not include a version number, which compromises compatibility with future software.')
].join(' '), ].join(' '),
'SLIP39': [ 'slip39': [
qsTr('SLIP39 seeds can be imported in Electrum, so that users can access funds locked in other wallets.'), qsTr('SLIP39 seeds can be imported in Electrum, so that users can access funds locked in other wallets.'),
'<br/><br/>', '<br/><br/>',
qsTr('However, we do not generate SLIP39 seeds.') qsTr('However, we do not generate SLIP39 seeds.')
].join(' ') ].join(' ')
} }
infotext.text = t[seed_type.currentText] infotext.text = t[seed_variant.currentValue]
} }
function checkValid() { function checkValid() {
bitcoin.verify_seed(seedtext.text, seed_type.getTypeCode() == 'BIP39', seed_type.getTypeCode() == 'SLIP39', wizard_data['wallet_type']) bitcoin.verify_seed(seedtext.text, seed_variant.currentValue, wizard_data['wallet_type'])
} }
Flickable { Flickable {
@ -65,16 +64,20 @@ WizardComponent {
Layout.fillWidth: true Layout.fillWidth: true
} }
ComboBox { ComboBox {
id: seed_type id: seed_variant
visible: !is2fa visible: !is2fa
model: ['Electrum', 'BIP39'/*, 'SLIP39'*/]
textRole: 'text'
valueRole: 'value'
model: [
{ text: qsTr('Electrum'), value: 'electrum' },
{ text: qsTr('BIP39'), value: 'bip39' }
]
onActivated: { onActivated: {
setSeedTypeHelpText() setSeedTypeHelpText()
checkIsLast()
checkValid() checkValid()
} }
function getTypeCode() {
return currentText
}
} }
InfoTextArea { InfoTextArea {
id: infotext id: infotext

22
electrum/gui/qml/qebitcoin.py

@ -68,23 +68,18 @@ class QEBitcoin(QObject):
asyncio.run_coroutine_threadsafe(co_gen_seed(seed_type, language), get_asyncio_loop()) asyncio.run_coroutine_threadsafe(co_gen_seed(seed_type, language), get_asyncio_loop())
@pyqtSlot(str) @pyqtSlot(str,str)
@pyqtSlot(str,bool,bool) @pyqtSlot(str,str,str)
@pyqtSlot(str,bool,bool,str) def verify_seed(self, seed, seed_variant, wallet_type='standard'):
@pyqtSlot(str,bool,bool,str,str)
def verify_seed(self, seed, bip39=False, slip39=False, wallet_type='standard', language='en'):
self._logger.debug('bip39 ' + str(bip39))
self._logger.debug('slip39 ' + str(slip39))
seed_type = '' seed_type = ''
seed_valid = False seed_valid = False
self.validationMessage = '' self.validationMessage = ''
if not (bip39 or slip39): if seed_variant == 'electrum':
seed_type = mnemonic.seed_type(seed) seed_type = mnemonic.seed_type(seed)
if seed_type != '': if seed_type != '':
seed_valid = True seed_valid = True
elif bip39: elif seed_variant == 'bip39':
is_checksum, is_wordlist = keystore.bip39_is_checksum_valid(seed) is_checksum, is_wordlist = keystore.bip39_is_checksum_valid(seed)
status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist' status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
self.validationMessage = 'BIP39 (%s)' % status self.validationMessage = 'BIP39 (%s)' % status
@ -92,8 +87,7 @@ class QEBitcoin(QObject):
if is_checksum: if is_checksum:
seed_type = 'bip39' seed_type = 'bip39'
seed_valid = True seed_valid = True
elif seed_variant == 'slip39': # TODO: incomplete impl, this code only validates a single share.
elif slip39: # TODO: incomplete impl, this code only validates a single share.
try: try:
share = decode_mnemonic(seed) share = decode_mnemonic(seed)
seed_type = 'slip39' seed_type = 'slip39'
@ -101,11 +95,13 @@ class QEBitcoin(QObject):
except Slip39Error as e: except Slip39Error as e:
self.validationMessage = 'SLIP39: %s' % str(e) self.validationMessage = 'SLIP39: %s' % str(e)
seed_valid = False # for now seed_valid = False # for now
else:
raise Exception(f'unknown seed variant {seed_variant}')
# check if seed matches wallet type # check if seed matches wallet type
if wallet_type == '2fa' and not is_any_2fa_seed_type(seed_type): if wallet_type == '2fa' and not is_any_2fa_seed_type(seed_type):
seed_valid = False seed_valid = False
elif wallet_type == 'standard' and seed_type not in ['old', 'standard', 'segwit']: elif wallet_type == 'standard' and seed_type not in ['old', 'standard', 'segwit', 'bip39']:
seed_valid = False seed_valid = False
self.seedType = seed_type self.seedType = seed_type

2
electrum/wizard.py

@ -182,7 +182,7 @@ class NewWalletWizard(AbstractWizard):
raise NotImplementedError() raise NotImplementedError()
def last_if_single_password_and_not_bip39(self, view, wizard_data): def last_if_single_password_and_not_bip39(self, view, wizard_data):
return self.last_if_single_password(view, wizard_data) and not wizard_data['seed_type'] == 'bip39' return self.last_if_single_password(view, wizard_data) and not wizard_data['seed_variant'] == 'bip39'
def on_wallet_type(self, wizard_data): def on_wallet_type(self, wizard_data):
t = wizard_data['wallet_type'] t = wizard_data['wallet_type']

Loading…
Cancel
Save