monero-gui/pages/Sign.qml

438 lines
17 KiB
QML
Raw Normal View History

2019-04-28 04:28:52 +00:00
// Copyright (c) 2014-2019, The Monero Project
2016-11-08 10:06:34 +00:00
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2019-04-11 01:17:29 +00:00
import QtQuick 2.9
2016-11-08 10:06:34 +00:00
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import moneroComponents.Clipboard 1.0
import moneroComponents.WalletManager 1.0
import "../components" as MoneroComponents
2016-11-08 10:06:34 +00:00
Rectangle {
2019-05-07 05:19:40 +00:00
property alias signHeight: mainLayout.height
property bool messageMode: true
property bool fileMode: false
2016-11-08 10:06:34 +00:00
2018-03-19 22:30:34 +00:00
color: "transparent"
2016-11-08 10:06:34 +00:00
Clipboard { id: clipboard }
MessageDialog {
// dynamically change onclose handler
property var onCloseCallback
id: signatureVerificationMessage
standardButtons: StandardButton.Ok
onAccepted: {
if (onCloseCallback) {
onCloseCallback()
}
}
}
function displayVerificationResult(result) {
if (result) {
signatureVerificationMessage.title = qsTr("Good signature") + translationManager.emptyString
signatureVerificationMessage.text = qsTr("This is a good signature") + translationManager.emptyString
signatureVerificationMessage.icon = StandardIcon.Information
}
else {
signatureVerificationMessage.title = qsTr("Bad signature") + translationManager.emptyString
signatureVerificationMessage.text = qsTr("This signature did not verify") + translationManager.emptyString
signatureVerificationMessage.icon = StandardIcon.Critical
}
signatureVerificationMessage.open()
}
// ================
// Sign a message
// message: [ ] [SIGN]
// [SELECT] file: [ ] [SIGN]
// signature: [ ]
// ================
// verify a message
// address: [ ]
// message: [ ] [VERIFY]
// [SELECT] file: [ ] [VERIFY]
// signature: [ ]
// ================
// sign / verify
ColumnLayout {
2019-02-01 21:20:38 +00:00
id: mainLayout
Layout.fillWidth: true
2019-09-05 22:11:12 +00:00
anchors.margins: 20
anchors.topMargin: 0
2018-12-08 15:55:29 +00:00
anchors.left: parent.left
2019-02-01 21:20:38 +00:00
anchors.top: parent.top
2016-11-08 10:06:34 +00:00
anchors.right: parent.right
2019-04-25 19:09:23 +00:00
spacing: 20
2016-11-08 10:06:34 +00:00
2019-02-01 21:20:38 +00:00
MoneroComponents.Label {
2019-04-25 19:09:23 +00:00
fontSize: 24
2019-02-01 21:20:38 +00:00
text: qsTr("Sign/verify") + translationManager.emptyString
}
2019-04-11 01:17:29 +00:00
MoneroComponents.TextPlain {
2019-02-01 21:20:38 +00:00
text: qsTr("This page lets you sign/verify a message (or file contents) with your address.") + translationManager.emptyString
wrapMode: Text.Wrap
Layout.fillWidth: true
font.family: MoneroComponents.Style.fontRegular.name
2019-04-25 19:09:23 +00:00
font.pixelSize: 14
2019-02-01 21:20:38 +00:00
color: MoneroComponents.Style.defaultFontColor
}
ColumnLayout {
id: modeRow
Layout.fillWidth: true
2016-11-08 10:06:34 +00:00
2019-04-11 01:17:29 +00:00
MoneroComponents.TextPlain {
id: modeText
2018-03-21 22:56:53 +00:00
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
Layout.topMargin: 12
text: qsTr("Mode") + translationManager.emptyString
wrapMode: Text.Wrap
2018-12-28 04:50:19 +00:00
font.family: MoneroComponents.Style.fontRegular.name
2019-04-25 19:09:23 +00:00
font.pixelSize: 20
textFormat: Text.RichText
color: MoneroComponents.Style.defaultFontColor
2016-11-08 10:06:34 +00:00
}
2019-04-28 04:28:52 +00:00
ColumnLayout {
id: modeButtonsColumn
2019-04-25 19:09:23 +00:00
Layout.topMargin: 10
2019-04-28 04:28:52 +00:00
MoneroComponents.RadioButton {
id: handleMessageButton
text: qsTr("Message") + translationManager.emptyString
2019-04-28 04:28:52 +00:00
fontSize: 16
checked: true
onClicked: {
2019-04-28 04:28:52 +00:00
checked = true;
handleFileButton.checked = false;
messageMode = true;
fileMode = false;
2016-11-08 10:06:34 +00:00
}
}
2019-04-28 04:28:52 +00:00
MoneroComponents.RadioButton {
id: handleFileButton
text: qsTr("File") + translationManager.emptyString
2019-04-28 04:28:52 +00:00
fontSize: 16
checked: false
onClicked: {
2019-04-28 04:28:52 +00:00
checked = true;
handleMessageButton.checked = false;
fileMode = true;
messageMode = false;
2016-11-08 10:06:34 +00:00
}
}
}
}
2016-11-08 10:06:34 +00:00
ColumnLayout {
id: signSection
2019-04-25 19:09:23 +00:00
spacing: 10
2019-02-01 21:20:38 +00:00
MoneroComponents.LabelSubheader {
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
Layout.topMargin: 12
Layout.bottomMargin: 24
2019-02-01 21:20:38 +00:00
textFormat: Text.RichText
text: fileMode ? qsTr("Sign file") + translationManager.emptyString : qsTr("Sign message") + translationManager.emptyString
}
ColumnLayout{
id: signMessageRow
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
spacing: 10
visible: messageMode
MoneroComponents.LineEditMulti{
id: signMessageLine
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
labelFontSize: 14
labelText: qsTr("Message") + translationManager.emptyString;
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2019-02-01 21:20:38 +00:00
placeholderText: qsTr("Enter a message to sign") + translationManager.emptyString;
readOnly: false
onTextChanged: signSignatureLine.text = ''
wrapMode: Text.WrapAnywhere
2016-11-08 10:06:34 +00:00
}
}
2016-11-08 10:06:34 +00:00
RowLayout {
id: signFileRow
Layout.fillWidth: true
visible: fileMode
MoneroComponents.LineEditMulti {
id: signFileLine
2019-04-25 19:09:23 +00:00
labelFontSize: 14
labelText: qsTr("File") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
placeholderText: qsTr("Enter path to file") + translationManager.emptyString;
readOnly: false
2016-11-08 10:06:34 +00:00
Layout.fillWidth: true
onTextChanged: signSignatureLine.text = ""
wrapMode: Text.WrapAnywhere
text: ''
}
2016-11-08 10:06:34 +00:00
MoneroComponents.StandardButton {
id: loadFileToSignButton
Layout.alignment: Qt.AlignBottom
small: false
text: qsTr("Browse") + translationManager.emptyString
enabled: true
onClicked: {
signFileDialog.open();
2016-11-08 10:06:34 +00:00
}
}
2018-03-21 22:56:53 +00:00
}
2016-11-08 10:06:34 +00:00
2018-03-21 22:56:53 +00:00
ColumnLayout {
id: signSignatureRow
2016-11-08 10:06:34 +00:00
MoneroComponents.LineEditMulti {
id: signSignatureLine
2019-04-25 19:09:23 +00:00
labelFontSize: 14
2019-02-01 21:20:38 +00:00
labelText: qsTr("Signature") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
placeholderText: messageMode ? qsTr("Click [Sign Message] to generate signature") + translationManager.emptyString : qsTr("Click [Sign File] to generate signature") + translationManager.emptyString;
readOnly: true
Layout.fillWidth: true
copyButton: true
wrapMode: Text.WrapAnywhere
2016-11-08 10:06:34 +00:00
}
}
RowLayout{
Layout.fillWidth: true
Layout.alignment: Qt.AlignRight
MoneroComponents.StandardButton {
id: clearSignButton
text: qsTr("Clear") + translationManager.emptyString
enabled: signMessageLine.text !== '' || signFileLine.text !== ''
small: true
onClicked: {
signMessageLine.text = '';
signSignatureLine.text = '';
signFileLine.text = '';
2018-03-21 22:56:53 +00:00
}
}
2016-11-08 10:06:34 +00:00
MoneroComponents.StandardButton {
id: signMessageButton
visible: messageMode
text: qsTr("Sign Message") + translationManager.emptyString
enabled: signMessageLine.text !== ''
small: true
onClicked: {
var signature = appWindow.currentWallet.signMessage(signMessageLine.text, false)
signSignatureLine.text = signature
2016-11-08 10:06:34 +00:00
}
}
MoneroComponents.StandardButton {
id: signFileButton
visible: fileMode
small: true
Layout.alignment: Qt.AlignBottom
text: qsTr("Sign File") + translationManager.emptyString
enabled: signFileLine.text !== ''
onClicked: {
var signature = appWindow.currentWallet.signMessage(signFileLine.text, true);
signSignatureLine.text = signature;
2016-11-08 10:06:34 +00:00
}
}
}
}
ColumnLayout {
id: verifySection
2019-04-25 19:09:23 +00:00
spacing: 16
2019-02-01 21:20:38 +00:00
MoneroComponents.LabelSubheader {
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
Layout.bottomMargin: 24
2019-02-01 21:20:38 +00:00
textFormat: Text.RichText
text: fileMode ? qsTr("Verify file") + translationManager.emptyString : qsTr("Verify message") + translationManager.emptyString
}
MoneroComponents.LineEditMulti {
id: verifyMessageLine
visible: messageMode
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
labelFontSize: 14
2019-02-01 21:20:38 +00:00
labelText: qsTr("Message") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2019-02-01 21:20:38 +00:00
placeholderText: qsTr("Enter the message to verify") + translationManager.emptyString
readOnly: false
wrapMode: Text.WrapAnywhere
text: ''
}
2016-11-08 10:06:34 +00:00
RowLayout {
id: verifyFileRow
Layout.fillWidth: true
visible: fileMode
MoneroComponents.LineEditMulti {
id: verifyFileLine
2019-04-25 19:09:23 +00:00
labelFontSize: 14
2019-02-01 21:20:38 +00:00
labelText: qsTr("File") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2019-02-01 21:20:38 +00:00
placeholderText: qsTr("Enter path to file") + translationManager.emptyString
readOnly: false
2016-11-08 10:06:34 +00:00
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
text: ''
}
2016-11-08 10:06:34 +00:00
MoneroComponents.StandardButton {
id: loadFileToVerifyButton
Layout.alignment: Qt.AlignBottom
small: false
text: qsTr("Browse") + translationManager.emptyString;
enabled: true
onClicked: {
verifyFileDialog.open()
2016-11-08 10:06:34 +00:00
}
}
}
MoneroComponents.LineEditMulti {
id: verifyAddressLine
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
labelFontSize: 14
2019-02-01 21:20:38 +00:00
labelText: qsTr("Address") + translationManager.emptyString
addressValidation: true
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2019-02-01 21:20:38 +00:00
placeholderText: qsTr("Enter the Monero Address (example: 44AFFq5kSiGBoZ...)") + translationManager.emptyString
wrapMode: Text.WrapAnywhere
text: ''
}
MoneroComponents.LineEditMulti {
id: verifySignatureLine
2019-04-25 19:09:23 +00:00
labelFontSize: 14
2019-02-01 21:20:38 +00:00
labelText: qsTr("Signature") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2019-02-01 21:20:38 +00:00
placeholderText: qsTr("Enter the signature to verify") + translationManager.emptyString
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
text: ''
}
RowLayout{
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
Layout.topMargin: 12
Layout.alignment: Qt.AlignRight
MoneroComponents.StandardButton {
id: clearVerifyButton
text: qsTr("Clear") + translationManager.emptyString
enabled: verifyMessageLine.text !== '' || verifyFileLine.text !== '' || verifyAddressLine.text !== '' || verifySignatureLine.text !== ''
small: true
onClicked: {
verifyMessageLine.text = '';
verifySignatureLine.text = '';
verifyAddressLine.text = '';
verifyFileLine.text = '';
2018-03-21 22:56:53 +00:00
}
}
2016-11-08 10:06:34 +00:00
MoneroComponents.StandardButton {
id: verifyFileButton
visible: fileMode
small: true
text: qsTr("Verify File") + translationManager.emptyString
enabled: verifyFileLine.text !== '' && verifyAddressLine.text !== '' && verifySignatureLine.text !== ''
onClicked: {
var verified = appWindow.currentWallet.verifySignedMessage(verifyFileLine.text, verifyAddressLine.text, verifySignatureLine.text, true)
displayVerificationResult(verified)
}
}
2016-11-08 10:06:34 +00:00
MoneroComponents.StandardButton {
id: verifyMessageButton
visible: messageMode
small: true
text: qsTr("Verify Message") + translationManager.emptyString
enabled: verifyMessageLine.text !== '' && verifyAddressLine.text !== '' && verifySignatureLine.text !== ''
onClicked: {
var verified = appWindow.currentWallet.verifySignedMessage(verifyMessageLine.text, verifyAddressLine.text, verifySignatureLine.text, false)
displayVerificationResult(verified)
}
2016-11-08 10:06:34 +00:00
}
}
}
2018-03-21 22:56:53 +00:00
FileDialog {
id: signFileDialog
title: qsTr("Please choose a file to sign") + translationManager.emptyString;
folder: "file://"
nameFilters: [ "*"]
onAccepted: {
signFileLine.text = walletManager.urlToLocalPath(signFileDialog.fileUrl)
}
}
FileDialog {
id: verifyFileDialog
title: qsTr("Please choose a file to verify") + translationManager.emptyString;
folder: "file://"
nameFilters: [ "*"]
onAccepted: {
verifyFileLine.text = walletManager.urlToLocalPath(verifyFileDialog.fileUrl)
}
}
2016-11-08 10:06:34 +00:00
}
function clearFields() {
verifyMessageLine.text = ""
signMessageLine.text = ""
signSignatureLine.text = ""
verifyAddressLine.text = ""
verifySignatureLine.text = ""
signFileLine.text = ""
verifyFileLine.text = ""
}
2016-11-08 10:06:34 +00:00
function onPageCompleted() {
console.log("Sign/verify page loaded");
}
}