Browse Source

qml: show private key in address details

master
Sander van Grieken 3 years ago committed by accumulator
parent
commit
016b5eb743
  1. 59
      electrum/gui/qml/components/AddressDetails.qml
  2. 20
      electrum/gui/qml/qeaddressdetails.py

59
electrum/gui/qml/components/AddressDetails.qml

@ -172,13 +172,67 @@ Pane {
}
Label {
Layout.columnSpan: 2
Layout.topMargin: constants.paddingSmall
visible: !Daemon.currentWallet.isWatchOnly
text: qsTr('Private key')
color: Material.accentColor
}
TextHighlightPane {
Layout.columnSpan: 2
Layout.fillWidth: true
visible: !Daemon.currentWallet.isWatchOnly
RowLayout {
width: parent.width
Label {
id: privateKeyText
Layout.fillWidth: true
visible: addressdetails.privkey
text: addressdetails.privkey
wrapMode: Text.Wrap
font.pixelSize: constants.fontSizeLarge
font.family: FixedFont
}
Label {
id: showPrivateKeyText
Layout.fillWidth: true
visible: !addressdetails.privkey
horizontalAlignment: Text.AlignHCenter
text: qsTr('Tap to show private key')
wrapMode: Text.Wrap
font.pixelSize: constants.fontSizeLarge
}
ToolButton {
icon.source: '../../icons/share.png'
visible: addressdetails.privkey
onClicked: {
var dialog = app.genericShareDialog.createObject(root, {
title: qsTr('Private key'),
text: addressdetails.privkey
})
dialog.open()
}
}
MouseArea {
anchors.fill: parent
enabled: !addressdetails.privkey
onClicked: addressdetails.requestShowPrivateKey()
}
}
}
Label {
Layout.topMargin: constants.paddingSmall
text: qsTr('Script type')
color: Material.accentColor
}
Label {
text: addressdetails.scriptType
Layout.topMargin: constants.paddingSmall
Layout.fillWidth: true
text: addressdetails.scriptType
}
Label {
@ -235,5 +289,8 @@ Pane {
address: root.address
onFrozenChanged: addressDetailsChanged()
onLabelChanged: addressDetailsChanged()
onAuthRequired: {
app.handleAuthRequired(addressdetails, method, authMessage)
}
}
}

20
electrum/gui/qml/qeaddressdetails.py

@ -2,12 +2,13 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.logging import get_logger
from .auth import auth_protect, AuthMixin
from .qetransactionlistmodel import QETransactionListModel
from .qetypes import QEAmount
from .qewallet import QEWallet
class QEAddressDetails(QObject):
class QEAddressDetails(AuthMixin, QObject):
_logger = get_logger(__name__)
detailsChanged = pyqtSignal()
@ -66,6 +67,10 @@ class QEAddressDetails(QObject):
def pubkeys(self):
return self._pubkeys
@pyqtProperty(str, notify=detailsChanged)
def privkey(self):
return self._privkey
@pyqtProperty(str, notify=detailsChanged)
def derivationPath(self):
return self._derivationPath
@ -108,6 +113,19 @@ class QEAddressDetails(QObject):
onchain_domain=[self._address], include_lightning=False)
return self._historyModel
@pyqtSlot()
def requestShowPrivateKey(self):
self.retrieve_private_key()
@auth_protect(method='wallet')
def retrieve_private_key(self):
try:
self._privkey = self._wallet.wallet.export_private_key(self._address, self._wallet.password)
except Exception:
self._privkey = ''
self.detailsChanged.emit()
def update(self):
if self._wallet is None:
self._logger.error('wallet undefined')

Loading…
Cancel
Save