1
0

qml wizard: enforce homogeneous master keys in multisig

- {xpub, Ypub, Zpub} categories cannot be mixed
- old mpk must not be used in multisig
This commit is contained in:
SomberNight
2023-05-11 09:55:19 +00:00
parent f40d603e64
commit d2cf21fc2b
7 changed files with 76 additions and 23 deletions

View File

@@ -33,6 +33,10 @@ Wizard {
walletwizard.path = wiz.path
walletwizard.walletCreated()
}
function onCreateError(error) {
var dialog = app.messageDialog.createObject(app, { text: error })
dialog.open()
}
}
}

View File

@@ -42,10 +42,14 @@ WizardComponent {
if (cosigner) {
applyMasterKey(key)
if (wiz.hasDuplicateKeys(wizard_data)) {
if (wiz.hasDuplicateMasterKeys(wizard_data)) {
validationtext.text = qsTr('Error: duplicate master public key')
return false
}
if (wiz.hasHeterogeneousMasterKeys(wizard_data)) {
validationtext.text = qsTr('Error: master public key types do not match')
return false
}
}
return valid = true

View File

@@ -65,9 +65,12 @@ WizardComponent {
return
} else {
apply()
if (wiz.hasDuplicateKeys(wizard_data)) {
if (wiz.hasDuplicateMasterKeys(wizard_data)) {
validationtext.text = qsTr('Error: duplicate master public key')
return
} else if (wiz.hasHeterogeneousMasterKeys(wizard_data)) {
validationtext.text = qsTr('Error: master public key types do not match')
return
} else {
valid = true
}

View File

@@ -113,22 +113,30 @@ class QEBitcoin(QObject):
return False
k = keystore.from_master_key(key)
if isinstance(k, keystore.Xpub): # has xpub # TODO are these checks useful?
t1 = xpub_type(k.xpub)
if wallet_type == 'standard':
if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']:
if wallet_type == 'standard':
if isinstance(k, keystore.Xpub): # has bip32 xpub
t1 = xpub_type(k.xpub)
if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']: # disallow Ypub/Zpub
self.validationMessage = '%s: %s' % (_('Wrong key type'), t1)
return False
return True
elif wallet_type == 'multisig':
if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']:
self.validationMessage = '%s: %s' % (_('Wrong key type'), t1)
return False
return True
elif isinstance(k, keystore.Old_KeyStore):
pass
else:
self.validationMessage = '%s: %s' % (_('Unsupported wallet type'), wallet_type)
self.logger.error(f'Unsupported wallet type: {wallet_type}')
self._logger.error(f"unexpected keystore type: {type(keystore)}")
return False
elif wallet_type == 'multisig':
if not isinstance(k, keystore.Xpub): # old mpk?
self.validationMessage = '%s: %s' % (_('Wrong key type'), "not bip32")
return False
t1 = xpub_type(k.xpub)
if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']: # disallow ypub/zpub
self.validationMessage = '%s: %s' % (_('Wrong key type'), t1)
return False
else:
self.validationMessage = '%s: %s' % (_('Unsupported wallet type'), wallet_type)
self._logger.error(f'Unsupported wallet type: {wallet_type}')
return False
# looks okay
return True
@pyqtSlot(str, result=bool)

View File

@@ -83,10 +83,16 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
return self._daemon.singlePasswordEnabled
@pyqtSlot('QJSValue', result=bool)
def hasDuplicateKeys(self, js_data):
self._logger.info('Checking for duplicate keys')
def hasDuplicateMasterKeys(self, js_data):
self._logger.info('Checking for duplicate masterkeys')
data = js_data.toVariant()
return self.has_duplicate_keys(data)
return self.has_duplicate_masterkeys(data)
@pyqtSlot('QJSValue', result=bool)
def hasHeterogeneousMasterKeys(self, js_data):
self._logger.info('Checking for heterogeneous masterkeys')
data = js_data.toVariant()
return self.has_heterogeneous_masterkeys(data)
@pyqtSlot('QJSValue', bool, str)
def createStorage(self, js_data, single_password_enabled, single_password):