From ba2905105d072f8c84ce606df40d12d0475a6924 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 14 Nov 2022 12:19:13 +0100 Subject: [PATCH] qml: multisig wizard check duplicate keys --- .../gui/qml/components/wizard/WCHaveSeed.qml | 5 ++-- electrum/wizard.py | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qml/components/wizard/WCHaveSeed.qml b/electrum/gui/qml/components/wizard/WCHaveSeed.qml index 8f27dcb25..753dada8e 100644 --- a/electrum/gui/qml/components/wizard/WCHaveSeed.qml +++ b/electrum/gui/qml/components/wizard/WCHaveSeed.qml @@ -158,6 +158,7 @@ WizardComponent { id: extendcb Layout.columnSpan: 2 text: qsTr('Extend seed with custom words') + onCheckedChanged: validationTimer.restart() } TextField { id: customwordstext @@ -165,9 +166,7 @@ WizardComponent { Layout.fillWidth: true Layout.columnSpan: 2 placeholderText: qsTr('Enter your custom word(s)') - onTextChanged: { - validationTimer.restart() - } + onTextChanged: validationTimer.restart() } } } diff --git a/electrum/wizard.py b/electrum/wizard.py index cfb0743b7..46f11d553 100644 --- a/electrum/wizard.py +++ b/electrum/wizard.py @@ -262,9 +262,36 @@ class NewWalletWizard(AbstractWizard): return True def has_duplicate_keys(self, wizard_data): - # TODO + xpubs = [] + xpubs.append(self.xpub_from_data(wizard_data)) + for cosigner in wizard_data['multisig_cosigner_data']: + xpubs.append(self.xpub_from_data(wizard_data['multisig_cosigner_data'][cosigner])) + + while len(xpubs): + xpub = xpubs.pop() + if xpub in xpubs: + return True + return False + def xpub_from_data(self, data): + if 'seed' in data: + if data['seed_variant'] == 'electrum': + k = keystore.from_seed(data['seed'], data['seed_extra_words'], True) + elif data['seed_variant'] == 'bip39': + root_seed = keystore.bip39_to_seed(data['seed'], data['seed_extra_words']) + derivation = normalize_bip32_derivation(data['derivation_path']) + k = keystore.from_bip43_rootseed(root_seed, derivation, xtype='p2wsh') + else: + raise Exception('Unsupported seed variant %s' % data['seed_variant']) + + return k.get_master_public_key() + elif 'master_key' in data: + k = keystore.from_master_key(data['master_key']) + return k.get_master_public_key() + else: + raise Exception('no seed or master_key in data') + def finished(self, wizard_data): self._logger.debug('finished') # override