Browse Source

Merge pull request #1469 from Diapolo/signverifymessagedialog

GUI: merge sign/verify message into a single window with tabbed UI
miguelfreitas
Wladimir J. van der Laan 13 years ago
parent
commit
249856d557
  1. 11
      bitcoin-qt.pro
  2. 29
      src/qt/addressbookpage.cpp
  3. 1
      src/qt/addressbookpage.h
  4. 86
      src/qt/bitcoingui.cpp
  5. 12
      src/qt/bitcoingui.h
  6. 22
      src/qt/forms/addressbookpage.ui
  7. 181
      src/qt/forms/messagepage.ui
  8. 386
      src/qt/forms/signverifymessagedialog.ui
  9. 140
      src/qt/forms/verifymessagedialog.ui
  10. 143
      src/qt/messagepage.cpp
  11. 42
      src/qt/messagepage.h
  12. 274
      src/qt/signverifymessagedialog.cpp
  13. 49
      src/qt/signverifymessagedialog.h
  14. 119
      src/qt/verifymessagedialog.cpp
  15. 33
      src/qt/verifymessagedialog.h

11
bitcoin-qt.pro

@ -100,7 +100,7 @@ HEADERS += src/qt/bitcoingui.h \ @@ -100,7 +100,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/optionsdialog.h \
src/qt/sendcoinsdialog.h \
src/qt/addressbookpage.h \
src/qt/messagepage.h \
src/qt/signverifymessagedialog.h \
src/qt/aboutdialog.h \
src/qt/editaddressdialog.h \
src/qt/bitcoinaddressvalidator.h \
@ -160,8 +160,7 @@ HEADERS += src/qt/bitcoingui.h \ @@ -160,8 +160,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/qtipcserver.h \
src/allocators.h \
src/ui_interface.h \
src/qt/rpcconsole.h \
src/qt/verifymessagedialog.h
src/qt/rpcconsole.h
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/transactiontablemodel.cpp \
@ -169,7 +168,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ @@ -169,7 +168,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/optionsdialog.cpp \
src/qt/sendcoinsdialog.cpp \
src/qt/addressbookpage.cpp \
src/qt/messagepage.cpp \
src/qt/signverifymessagedialog.cpp \
src/qt/aboutdialog.cpp \
src/qt/editaddressdialog.cpp \
src/qt/bitcoinaddressvalidator.cpp \
@ -220,7 +219,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ @@ -220,7 +219,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/notificator.cpp \
src/qt/qtipcserver.cpp \
src/qt/rpcconsole.cpp \
src/qt/verifymessagedialog.cpp \
src/noui.cpp
RESOURCES += \
@ -229,7 +227,7 @@ RESOURCES += \ @@ -229,7 +227,7 @@ RESOURCES += \
FORMS += \
src/qt/forms/sendcoinsdialog.ui \
src/qt/forms/addressbookpage.ui \
src/qt/forms/messagepage.ui \
src/qt/forms/signverifymessagedialog.ui \
src/qt/forms/aboutdialog.ui \
src/qt/forms/editaddressdialog.ui \
src/qt/forms/transactiondescdialog.ui \
@ -237,7 +235,6 @@ FORMS += \ @@ -237,7 +235,6 @@ FORMS += \
src/qt/forms/sendcoinsentry.ui \
src/qt/forms/askpassphrasedialog.ui \
src/qt/forms/rpcconsole.ui \
src/qt/forms/verifymessagedialog.ui \
src/qt/forms/optionsdialog.ui
contains(USE_QRCODE, 1) {

29
src/qt/addressbookpage.cpp

@ -67,6 +67,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -67,6 +67,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
QAction *editAction = new QAction(tr("&Edit"), this);
QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this);
QAction *signMessageAction = new QAction(ui->signMessage->text(), this);
QAction *verifyMessageAction = new QAction(ui->verifyMessage->text(), this);
deleteAction = new QAction(ui->deleteButton->text(), this);
// Build context menu
@ -80,6 +81,8 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -80,6 +81,8 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
contextMenu->addAction(showQRCodeAction);
if(tab == ReceivingTab)
contextMenu->addAction(signMessageAction);
else if(tab == SendingTab)
contextMenu->addAction(verifyMessageAction);
// Connect signals for context menu actions
connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked()));
@ -88,6 +91,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -88,6 +91,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked()));
connect(showQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showQRCode_clicked()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(on_signMessage_clicked()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(on_verifyMessage_clicked()));
connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
@ -189,7 +193,25 @@ void AddressBookPage::on_signMessage_clicked() @@ -189,7 +193,25 @@ void AddressBookPage::on_signMessage_clicked()
QObject *qoGUI = parent()->parent();
BitcoinGUI *gui = qobject_cast<BitcoinGUI *>(qoGUI);
if (gui)
gui->gotoMessagePage(addr);
gui->gotoSignMessageTab(addr);
}
void AddressBookPage::on_verifyMessage_clicked()
{
QTableView *table = ui->tableView;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
QString addr;
foreach (QModelIndex index, indexes)
{
QVariant address = index.data();
addr = address.toString();
}
QObject *qoGUI = parent()->parent();
BitcoinGUI *gui = qobject_cast<BitcoinGUI *>(qoGUI);
if (gui)
gui->gotoVerifyMessageTab(addr);
}
void AddressBookPage::on_newAddressButton_clicked()
@ -237,6 +259,8 @@ void AddressBookPage::selectionChanged() @@ -237,6 +259,8 @@ void AddressBookPage::selectionChanged()
deleteAction->setEnabled(true);
ui->signMessage->setEnabled(false);
ui->signMessage->setVisible(false);
ui->verifyMessage->setEnabled(true);
ui->verifyMessage->setVisible(true);
break;
case ReceivingTab:
// Deleting receiving addresses, however, is not allowed
@ -245,6 +269,8 @@ void AddressBookPage::selectionChanged() @@ -245,6 +269,8 @@ void AddressBookPage::selectionChanged()
deleteAction->setEnabled(false);
ui->signMessage->setEnabled(true);
ui->signMessage->setVisible(true);
ui->verifyMessage->setEnabled(false);
ui->verifyMessage->setVisible(false);
break;
}
ui->copyToClipboard->setEnabled(true);
@ -256,6 +282,7 @@ void AddressBookPage::selectionChanged() @@ -256,6 +282,7 @@ void AddressBookPage::selectionChanged()
ui->showQRCode->setEnabled(false);
ui->copyToClipboard->setEnabled(false);
ui->signMessage->setEnabled(false);
ui->verifyMessage->setEnabled(false);
}
}

1
src/qt/addressbookpage.h

@ -63,6 +63,7 @@ private slots: @@ -63,6 +63,7 @@ private slots:
/** Copy address of currently selected address entry to clipboard */
void on_copyToClipboard_clicked();
void on_signMessage_clicked();
void on_verifyMessage_clicked();
void selectionChanged();
void on_showQRCode_clicked();
/** Spawn contextual menu (right mouse menu) for address book entry */

86
src/qt/bitcoingui.cpp

@ -8,8 +8,7 @@ @@ -8,8 +8,7 @@
#include "transactiontablemodel.h"
#include "addressbookpage.h"
#include "sendcoinsdialog.h"
#include "messagepage.h"
#include "verifymessagedialog.h"
#include "signverifymessagedialog.h"
#include "optionsdialog.h"
#include "aboutdialog.h"
#include "clientmodel.h"
@ -108,7 +107,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -108,7 +107,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
sendCoinsPage = new SendCoinsDialog(this);
messagePage = new MessagePage(this);
signVerifyMessageDialog = new SignVerifyMessageDialog(this);
centralWidget = new QStackedWidget(this);
centralWidget->addWidget(overviewPage);
@ -117,7 +116,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -117,7 +116,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
centralWidget->addWidget(receiveCoinsPage);
centralWidget->addWidget(sendCoinsPage);
#ifdef FIRST_CLASS_MESSAGING
centralWidget->addWidget(messagePage);
centralWidget->addWidget(signVerifyMessageDialog);
#endif
setCentralWidget(centralWidget);
@ -212,12 +211,20 @@ void BitcoinGUI::createActions() @@ -212,12 +211,20 @@ void BitcoinGUI::createActions()
sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
tabGroup->addAction(sendCoinsAction);
messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
messageAction->setToolTip(tr("Prove you control an address"));
signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
signMessageAction->setToolTip(tr("Sign a message to prove you own a Bitcoin address"));
tabGroup->addAction(signMessageAction);
verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
verifyMessageAction->setToolTip(tr("Verify a message to ensure it was signed with a specified Bitcoin address"));
tabGroup->addAction(verifyMessageAction);
#ifdef FIRST_CLASS_MESSAGING
messageAction->setCheckable(true);
firstClassMessagingAction = new QAction(QIcon(":/icons/edit"), tr("S&ignatures"), this);
firstClassMessagingAction->setToolTip(signMessageAction->toolTip() + QString(". / ") + verifyMessageAction->toolTip() + QString("."));
firstClassMessagingAction->setCheckable(true);
tabGroup->addAction(firstClassMessagingAction);
#endif
tabGroup->addAction(messageAction);
connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
@ -229,8 +236,15 @@ void BitcoinGUI::createActions() @@ -229,8 +236,15 @@ void BitcoinGUI::createActions()
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
#ifdef FIRST_CLASS_MESSAGING
connect(firstClassMessagingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
// Always start with the sign message tab for FIRST_CLASS_MESSAGING
connect(firstClassMessagingAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
#endif
quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
quitAction->setToolTip(tr("Quit application"));
@ -258,8 +272,6 @@ void BitcoinGUI::createActions() @@ -258,8 +272,6 @@ void BitcoinGUI::createActions()
changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
verifyMessageAction->setToolTip(tr("Verify a message signature"));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
@ -269,7 +281,6 @@ void BitcoinGUI::createActions() @@ -269,7 +281,6 @@ void BitcoinGUI::createActions()
connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(verifyMessage()));
}
void BitcoinGUI::createMenuBar()
@ -287,9 +298,9 @@ void BitcoinGUI::createMenuBar() @@ -287,9 +298,9 @@ void BitcoinGUI::createMenuBar()
file->addAction(backupWalletAction);
file->addAction(exportAction);
#ifndef FIRST_CLASS_MESSAGING
file->addAction(messageAction);
#endif
file->addAction(signMessageAction);
file->addAction(verifyMessageAction);
#endif
file->addSeparator();
file->addAction(quitAction);
@ -316,7 +327,7 @@ void BitcoinGUI::createToolBars() @@ -316,7 +327,7 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(historyAction);
toolbar->addAction(addressBookAction);
#ifdef FIRST_CLASS_MESSAGING
toolbar->addAction(messageAction);
toolbar->addAction(firstClassMessagingAction);
#endif
QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
@ -377,7 +388,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel) @@ -377,7 +388,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);
messagePage->setModel(walletModel);
signVerifyMessageDialog->setModel(walletModel);
setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
@ -417,7 +428,7 @@ void BitcoinGUI::createTrayIcon() @@ -417,7 +428,7 @@ void BitcoinGUI::createTrayIcon()
#ifndef FIRST_CLASS_MESSAGING
trayIconMenu->addSeparator();
#endif
trayIconMenu->addAction(messageAction);
trayIconMenu->addAction(signMessageAction);
trayIconMenu->addAction(verifyMessageAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(optionsAction);
@ -719,20 +730,42 @@ void BitcoinGUI::gotoSendCoinsPage() @@ -719,20 +730,42 @@ void BitcoinGUI::gotoSendCoinsPage()
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
}
void BitcoinGUI::gotoMessagePage(QString addr)
void BitcoinGUI::gotoSignMessageTab(QString addr)
{
#ifdef FIRST_CLASS_MESSAGING
firstClassMessagingAction->setChecked(true);
centralWidget->setCurrentWidget(signVerifyMessageDialog);
exportAction->setEnabled(false);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
signVerifyMessageDialog->showTab_SM(false);
#else
// call show() in showTab_SM()
signVerifyMessageDialog->showTab_SM(true);
#endif
if(!addr.isEmpty())
messagePage->setAddress(addr);
signVerifyMessageDialog->setAddress_SM(addr);
}
void BitcoinGUI::gotoVerifyMessageTab(QString addr)
{
#ifdef FIRST_CLASS_MESSAGING
messageAction->setChecked(true);
centralWidget->setCurrentWidget(messagePage);
firstClassMessagingAction->setChecked(true);
centralWidget->setCurrentWidget(signVerifyMessageDialog);
exportAction->setEnabled(false);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
signVerifyMessageDialog->showTab_VM(false);
#else
messagePage->show();
// call show() in showTab_VM()
signVerifyMessageDialog->showTab_VM(true);
#endif
if(!addr.isEmpty())
signVerifyMessageDialog->setAddress_VM(addr);
}
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
@ -835,13 +868,6 @@ void BitcoinGUI::changePassphrase() @@ -835,13 +868,6 @@ void BitcoinGUI::changePassphrase()
dlg.exec();
}
void BitcoinGUI::verifyMessage()
{
VerifyMessageDialog *dlg = new VerifyMessageDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
}
void BitcoinGUI::unlockWallet()
{
if(!walletModel)

12
src/qt/bitcoingui.h

@ -11,7 +11,7 @@ class TransactionView; @@ -11,7 +11,7 @@ class TransactionView;
class OverviewPage;
class AddressBookPage;
class SendCoinsDialog;
class MessagePage;
class SignVerifyMessageDialog;
class Notificator;
class RPCConsole;
@ -64,7 +64,7 @@ private: @@ -64,7 +64,7 @@ private:
AddressBookPage *addressBookPage;
AddressBookPage *receiveCoinsPage;
SendCoinsDialog *sendCoinsPage;
MessagePage *messagePage;
SignVerifyMessageDialog *signVerifyMessageDialog;
QLabel *labelEncryptionIcon;
QLabel *labelConnectionsIcon;
@ -78,8 +78,9 @@ private: @@ -78,8 +78,9 @@ private:
QAction *quitAction;
QAction *sendCoinsAction;
QAction *addressBookAction;
QAction *messageAction;
QAction *signMessageAction;
QAction *verifyMessageAction;
QAction *firstClassMessagingAction;
QAction *aboutAction;
QAction *receiveCoinsAction;
QAction *optionsAction;
@ -131,7 +132,8 @@ public slots: @@ -131,7 +132,8 @@ public slots:
void askFee(qint64 nFeeRequired, bool *payFee);
void handleURI(QString strURI);
void gotoMessagePage(QString addr = "");
void gotoSignMessageTab(QString addr = "");
void gotoVerifyMessageTab(QString addr = "");
private slots:
/** Switch to overview (home) page */
@ -164,8 +166,6 @@ private slots: @@ -164,8 +166,6 @@ private slots:
void backupWallet();
/** Change encrypted wallet passphrase */
void changePassphrase();
/** Verify a message signature */
void verifyMessage();
/** Ask for pass phrase to unlock wallet temporarily */
void unlockWallet();

22
src/qt/forms/addressbookpage.ui

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<width>691</width>
<height>347</height>
</rect>
</property>
@ -17,10 +17,10 @@ @@ -17,10 +17,10 @@
<item>
<widget class="QLabel" name="labelExplanation">
<property name="text">
<string>These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you.</string>
<string>These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you.</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
<enum>Qt::PlainText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -99,7 +99,7 @@ @@ -99,7 +99,7 @@
<item>
<widget class="QPushButton" name="signMessage">
<property name="toolTip">
<string>Sign a message to prove you own this address</string>
<string>Sign a message to prove you own a Bitcoin address</string>
</property>
<property name="text">
<string>&amp;Sign Message</string>
@ -110,6 +110,20 @@ @@ -110,6 +110,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="verifyMessage">
<property name="toolTip">
<string>Verify a message to ensure it was signed with a specified Bitcoin address</string>
</property>
<property name="text">
<string>&amp;Verify Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/transaction_0</normaloff>:/icons/transaction_0</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="toolTip">

181
src/qt/forms/messagepage.ui

@ -1,181 +0,0 @@ @@ -1,181 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MessagePage</class>
<widget class="QWidget" name="MessagePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<height>380</height>
</rect>
</property>
<property name="windowTitle">
<string>Sign Message</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="labelExplanation">
<property name="text">
<string>You can sign messages with your addresses to prove you own them. Be careful not to sign anything vague, as phishing attacks may try to trick you into signing your identity over to them. Only sign fully-detailed statements you agree to.</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QValidatedLineEdit" name="signFrom">
<property name="toolTip">
<string>The address to sign the message with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
<property name="maxLength">
<number>34</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addressBookButton">
<property name="toolTip">
<string>Choose adress from address book</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pasteButton">
<property name="toolTip">
<string>Paste address from clipboard</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editpaste</normaloff>:/icons/editpaste</iconset>
</property>
<property name="shortcut">
<string>Alt+P</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="message">
<property name="toolTip">
<string>Enter the message you want to sign here</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="signature">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="signMessage">
<property name="toolTip">
<string>Sign a message to prove you own this address</string>
</property>
<property name="text">
<string>&amp;Sign Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/edit</normaloff>:/icons/edit</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyToClipboard">
<property name="toolTip">
<string>Copy the current signature to the system clipboard</string>
</property>
<property name="text">
<string>&amp;Copy Signature</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editcopy</normaloff>:/icons/editcopy</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="toolTip">
<string>Reset all sign message fields</string>
</property>
<property name="text">
<string>Clear &amp;All</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QValidatedLineEdit</class>
<extends>QLineEdit</extends>
<header>qvalidatedlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections/>
</ui>

386
src/qt/forms/signverifymessagedialog.ui

@ -0,0 +1,386 @@ @@ -0,0 +1,386 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SignVerifyMessageDialog</class>
<widget class="QDialog" name="SignVerifyMessageDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>700</width>
<height>380</height>
</rect>
</property>
<property name="windowTitle">
<string>Messaging - Sign / Verify a Message</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabSignMessage">
<attribute name="title">
<string>&amp;Sign Message</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_SM">
<item>
<widget class="QLabel" name="infoLabel_SM">
<property name="text">
<string>You can sign messages with your addresses to prove you own them. Be careful not to sign anything vague, as phishing attacks may try to trick you into signing your identity over to them. Only sign fully-detailed statements you agree to.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1_SM">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QValidatedLineEdit" name="addressIn_SM">
<property name="toolTip">
<string>The address to sign the message with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
<property name="maxLength">
<number>34</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addressBookButton_SM">
<property name="toolTip">
<string>Choose an address from the address book</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pasteButton_SM">
<property name="toolTip">
<string>Paste address from clipboard</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editpaste</normaloff>:/icons/editpaste</iconset>
</property>
<property name="shortcut">
<string>Alt+P</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="messageIn_SM">
<property name="toolTip">
<string>Enter the message you want to sign here</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2_SM">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="signatureOut_SM">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copySignatureButton_SM">
<property name="toolTip">
<string>Copy the current signature to the system clipboard</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editcopy</normaloff>:/icons/editcopy</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3_SM">
<item>
<widget class="QPushButton" name="signMessageButton_SM">
<property name="toolTip">
<string>Sign the message to prove you own this Bitcoin address</string>
</property>
<property name="text">
<string>&amp;Sign Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/edit</normaloff>:/icons/edit</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton_SM">
<property name="toolTip">
<string>Reset all sign message fields</string>
</property>
<property name="text">
<string>Clear &amp;All</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_1_SM">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statusLabel_SM">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2_SM">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabVerifyMessage">
<attribute name="title">
<string>&amp;Verify Message</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_VM">
<item>
<widget class="QLabel" name="infoLabel_VM">
<property name="text">
<string>Enter the signing address, message (ensure you copy line breaks, spaces, tabs, etc. exactly) and signature below to verify the message. Be careful not to read more into the signature than what is in the signed message itself, to avoid being tricked by a man-in-the-middle attack.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1_VM">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QValidatedLineEdit" name="addressIn_VM">
<property name="toolTip">
<string>The address the message was signed with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
<property name="maxLength">
<number>34</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addressBookButton_VM">
<property name="toolTip">
<string>Choose an address from the address book</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="messageIn_VM"/>
</item>
<item>
<widget class="QValidatedLineEdit" name="signatureIn_VM"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2_VM">
<item>
<widget class="QPushButton" name="verifyMessageButton_VM">
<property name="toolTip">
<string>Verify the message to ensure it was signed with the specified Bitcoin address</string>
</property>
<property name="text">
<string>&amp;Verify Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/transaction_0</normaloff>:/icons/transaction_0</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton_VM">
<property name="toolTip">
<string>Reset all verify message fields</string>
</property>
<property name="text">
<string>Clear &amp;All</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_1_VM">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statusLabel_VM">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2_VM">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QValidatedLineEdit</class>
<extends>QLineEdit</extends>
<header>qvalidatedlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections/>
</ui>

140
src/qt/forms/verifymessagedialog.ui

@ -1,140 +0,0 @@ @@ -1,140 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VerifyMessageDialog</class>
<widget class="QDialog" name="VerifyMessageDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>380</height>
</rect>
</property>
<property name="windowTitle">
<string>Verify Signed Message</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enter the signing address, signature and message below (be careful to correctly copy newlines, spaces, tabs and other invisible characters) to verify the message.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="lnAddress">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="lnSig">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="edMessage"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="verifyMessage">
<property name="toolTip">
<string>Verify a message to ensure it was signed with the specified Bitcoin address</string>
</property>
<property name="text">
<string>&amp;Verify Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/transaction_0</normaloff>:/icons/transaction_0</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="toolTip">
<string>Reset all verify message fields</string>
</property>
<property name="text">
<string>Clear &amp;All</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblStatus">
<property name="minimumSize">
<size>
<width>0</width>
<height>48</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QValidatedLineEdit</class>
<extends>QLineEdit</extends>
<header>qvalidatedlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections/>
</ui>

143
src/qt/messagepage.cpp

@ -1,143 +0,0 @@ @@ -1,143 +0,0 @@
#include <string>
#include <vector>
#include <QClipboard>
#include <QInputDialog>
#include <QList>
#include <QListWidgetItem>
#include <QMessageBox>
#include "main.h"
#include "wallet.h"
#include "init.h"
#include "base58.h"
#include "messagepage.h"
#include "ui_messagepage.h"
#include "addressbookpage.h"
#include "guiutil.h"
#include "walletmodel.h"
MessagePage::MessagePage(QWidget *parent) :
QDialog(parent),
ui(new Ui::MessagePage)
{
ui->setupUi(this);
#if (QT_VERSION >= 0x040700)
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
ui->signFrom->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->signature->setPlaceholderText(tr("Click \"Sign Message\" to get signature"));
#endif
GUIUtil::setupAddressWidget(ui->signFrom, this);
ui->signature->installEventFilter(this);
ui->signFrom->setFocus();
}
MessagePage::~MessagePage()
{
delete ui;
}
void MessagePage::setModel(WalletModel *model)
{
this->model = model;
}
void MessagePage::setAddress(QString addr)
{
ui->signFrom->setText(addr);
ui->message->setFocus();
}
void MessagePage::on_pasteButton_clicked()
{
setAddress(QApplication::clipboard()->text());
}
void MessagePage::on_addressBookButton_clicked()
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{
setAddress(dlg.getReturnValue());
}
}
void MessagePage::on_copyToClipboard_clicked()
{
QApplication::clipboard()->setText(ui->signature->text());
}
void MessagePage::on_signMessage_clicked()
{
QString address = ui->signFrom->text();
CBitcoinAddress addr(address.toStdString());
if (!addr.IsValid())
{
QMessageBox::critical(this, tr("Error signing"), tr("%1 is not a valid address.").arg(address),
QMessageBox::Abort, QMessageBox::Abort);
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
QMessageBox::critical(this, tr("Error signing"), tr("%1 does not refer to a key.").arg(address),
QMessageBox::Abort, QMessageBox::Abort);
return;
}
WalletModel::UnlockContext ctx(model->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet was cancelled
return;
}
CKey key;
if (!pwalletMain->GetKey(keyID, key))
{
QMessageBox::critical(this, tr("Error signing"), tr("Private key for %1 is not available.").arg(address),
QMessageBox::Abort, QMessageBox::Abort);
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->message->document()->toPlainText().toStdString();
std::vector<unsigned char> vchSig;
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
{
QMessageBox::critical(this, tr("Error signing"), tr("Sign failed"),
QMessageBox::Abort, QMessageBox::Abort);
}
ui->signature->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
ui->signature->setFont(GUIUtil::bitcoinAddressFont());
}
void MessagePage::on_clearButton_clicked()
{
ui->signFrom->clear();
ui->message->clear();
ui->signature->clear();
ui->signFrom->setFocus();
}
bool MessagePage::eventFilter(QObject *object, QEvent *event)
{
if(object == ui->signature && (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::FocusIn))
{
ui->signature->selectAll();
return true;
}
return QDialog::eventFilter(object, event);
}

42
src/qt/messagepage.h

@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
#ifndef MESSAGEPAGE_H
#define MESSAGEPAGE_H
#include <QDialog>
namespace Ui {
class MessagePage;
}
class WalletModel;
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
class MessagePage : public QDialog
{
Q_OBJECT
public:
explicit MessagePage(QWidget *parent = 0);
~MessagePage();
void setModel(WalletModel *model);
void setAddress(QString);
protected:
bool eventFilter(QObject *object, QEvent *event);
private:
Ui::MessagePage *ui;
WalletModel *model;
private slots:
void on_pasteButton_clicked();
void on_addressBookButton_clicked();
void on_signMessage_clicked();
void on_copyToClipboard_clicked();
void on_clearButton_clicked();
};
#endif // MESSAGEPAGE_H

274
src/qt/signverifymessagedialog.cpp

@ -0,0 +1,274 @@ @@ -0,0 +1,274 @@
#include "signverifymessagedialog.h"
#include "ui_signverifymessagedialog.h"
#include "addressbookpage.h"
#include "base58.h"
#include "guiutil.h"
#include "init.h"
#include "main.h"
#include "optionsmodel.h"
#include "walletmodel.h"
#include "wallet.h"
#include <string>
#include <vector>
#include <QClipboard>
SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SignVerifyMessageDialog),
model(0)
{
ui->setupUi(this);
#if (QT_VERSION >= 0x040700)
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
ui->addressIn_SM->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->signatureOut_SM->setPlaceholderText(tr("Click \"Sign Message\" to generate signature"));
ui->addressIn_VM->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->signatureIn_VM->setPlaceholderText(tr("Enter Bitcoin signature"));
#endif
GUIUtil::setupAddressWidget(ui->addressIn_SM, this);
GUIUtil::setupAddressWidget(ui->addressIn_VM, this);
ui->addressIn_SM->installEventFilter(this);
ui->messageIn_SM->installEventFilter(this);
ui->signatureOut_SM->installEventFilter(this);
ui->addressIn_VM->installEventFilter(this);
ui->messageIn_VM->installEventFilter(this);
ui->signatureIn_VM->installEventFilter(this);
ui->signatureOut_SM->setFont(GUIUtil::bitcoinAddressFont());
ui->signatureIn_VM->setFont(GUIUtil::bitcoinAddressFont());
}
SignVerifyMessageDialog::~SignVerifyMessageDialog()
{
delete ui;
}
void SignVerifyMessageDialog::setModel(WalletModel *model)
{
this->model = model;
}
void SignVerifyMessageDialog::setAddress_SM(QString address)
{
ui->addressIn_SM->setText(address);
ui->messageIn_SM->setFocus();
}
void SignVerifyMessageDialog::setAddress_VM(QString address)
{
ui->addressIn_VM->setText(address);
ui->messageIn_VM->setFocus();
}
void SignVerifyMessageDialog::showTab_SM(bool fShow)
{
ui->tabWidget->setCurrentIndex(0);
if (fShow)
this->show();
}
void SignVerifyMessageDialog::showTab_VM(bool fShow)
{
ui->tabWidget->setCurrentIndex(1);
if (fShow)
this->show();
}
void SignVerifyMessageDialog::on_addressBookButton_SM_clicked()
{
if (model && model->getAddressTableModel())
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
{
setAddress_SM(dlg.getReturnValue());
}
}
}
void SignVerifyMessageDialog::on_pasteButton_SM_clicked()
{
setAddress_SM(QApplication::clipboard()->text());
}
void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
{
/* Clear old signature to ensure users don't get confused on error with an old signature displayed */
ui->signatureOut_SM->clear();
CBitcoinAddress addr(ui->addressIn_SM->text().toStdString());
if (!addr.IsValid())
{
ui->addressIn_SM->setValid(false);
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
ui->addressIn_SM->setValid(false);
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
return;
}
WalletModel::UnlockContext ctx(model->requestUnlock());
if (!ctx.isValid())
{
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(tr("Wallet unlock was canceled."));
return;
}
CKey key;
if (!pwalletMain->GetKey(keyID, key))
{
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(tr("Private key for the entered address is not available."));
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->messageIn_SM->document()->toPlainText().toStdString();
std::vector<unsigned char> vchSig;
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
{
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>"));
return;
}
ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }");
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>"));
ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
}
void SignVerifyMessageDialog::on_copySignatureButton_SM_clicked()
{
QApplication::clipboard()->setText(ui->signatureOut_SM->text());
}
void SignVerifyMessageDialog::on_clearButton_SM_clicked()
{
ui->addressIn_SM->clear();
ui->messageIn_SM->clear();
ui->signatureOut_SM->clear();
ui->statusLabel_SM->clear();
ui->addressIn_SM->setFocus();
}
void SignVerifyMessageDialog::on_addressBookButton_VM_clicked()
{
if (model && model->getAddressTableModel())
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
{
setAddress_VM(dlg.getReturnValue());
}
}
}
void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()
{
CBitcoinAddress addr(ui->addressIn_VM->text().toStdString());
if (!addr.IsValid())
{
ui->addressIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
ui->addressIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
return;
}
bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid);
if (fInvalid)
{
ui->signatureIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again."));
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->messageIn_VM->document()->toPlainText().toStdString();
CKey key;
if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
{
ui->signatureIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again."));
return;
}
if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
{
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
return;
}
ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }");
ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
}
void SignVerifyMessageDialog::on_clearButton_VM_clicked()
{
ui->addressIn_VM->clear();
ui->signatureIn_VM->clear();
ui->messageIn_VM->clear();
ui->statusLabel_VM->clear();
ui->addressIn_VM->setFocus();
}
bool SignVerifyMessageDialog::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn)
{
if (ui->tabWidget->currentIndex() == 0)
{
/* Clear status message on focus change */
ui->statusLabel_SM->clear();
/* Select generated signature */
if (object == ui->signatureOut_SM)
{
ui->signatureOut_SM->selectAll();
return true;
}
}
else if (ui->tabWidget->currentIndex() == 1)
{
/* Clear status message on focus change */
ui->statusLabel_VM->clear();
}
}
return QDialog::eventFilter(object, event);
}

49
src/qt/signverifymessagedialog.h

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
#ifndef SIGNVERIFYMESSAGEDIALOG_H
#define SIGNVERIFYMESSAGEDIALOG_H
#include <QDialog>
namespace Ui {
class SignVerifyMessageDialog;
}
class WalletModel;
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
class SignVerifyMessageDialog : public QDialog
{
Q_OBJECT
public:
explicit SignVerifyMessageDialog(QWidget *parent = 0);
~SignVerifyMessageDialog();
void setModel(WalletModel *model);
void setAddress_SM(QString address);
void setAddress_VM(QString address);
void showTab_SM(bool fShow);
void showTab_VM(bool fShow);
protected:
bool eventFilter(QObject *object, QEvent *event);
private:
Ui::SignVerifyMessageDialog *ui;
WalletModel *model;
private slots:
/* sign message */
void on_addressBookButton_SM_clicked();
void on_pasteButton_SM_clicked();
void on_signMessageButton_SM_clicked();
void on_copySignatureButton_SM_clicked();
void on_clearButton_SM_clicked();
/* verify message */
void on_addressBookButton_VM_clicked();
void on_verifyMessageButton_VM_clicked();
void on_clearButton_VM_clicked();
};
#endif // SIGNVERIFYMESSAGEDIALOG_H

119
src/qt/verifymessagedialog.cpp

@ -1,119 +0,0 @@ @@ -1,119 +0,0 @@
#include "verifymessagedialog.h"
#include "ui_verifymessagedialog.h"
#include <string>
#include <vector>
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QPushButton>
#include "main.h"
#include "wallet.h"
#include "walletmodel.h"
#include "guiutil.h"
#include "base58.h"
VerifyMessageDialog::VerifyMessageDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::VerifyMessageDialog)
{
ui->setupUi(this);
#if (QT_VERSION >= 0x040700)
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
ui->lnAddress->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->lnSig->setPlaceholderText(tr("Enter Bitcoin signature"));
#endif
GUIUtil::setupAddressWidget(ui->lnAddress, this);
ui->lnAddress->installEventFilter(this);
ui->lnSig->setFont(GUIUtil::bitcoinAddressFont());
ui->lnAddress->setFocus();
}
VerifyMessageDialog::~VerifyMessageDialog()
{
delete ui;
}
void VerifyMessageDialog::on_verifyMessage_clicked()
{
CBitcoinAddress addr(ui->lnAddress->text().toStdString());
if (!addr.IsValid())
{
ui->lnAddress->setValid(false);
ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->lblStatus->setText(tr("\"%1\" is not a valid address.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again."));
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
ui->lnAddress->setValid(false);
ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->lblStatus->setText(tr("\"%1\" does not refer to a key.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again."));
return;
}
bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &fInvalid);
if (fInvalid)
{
ui->lnSig->setValid(false);
ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->lblStatus->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again."));
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->edMessage->document()->toPlainText().toStdString();
CKey key;
if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
{
ui->lnSig->setValid(false);
ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->lblStatus->setText(tr("The signature did not match the message digest.")+ QString(" ") + tr("Please check the signature and try again."));
return;
}
if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
{
ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->lblStatus->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
return;
}
ui->lblStatus->setStyleSheet("QLabel { color: green; }");
ui->lblStatus->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
}
void VerifyMessageDialog::on_clearButton_clicked()
{
ui->lnAddress->clear();
ui->lnSig->clear();
ui->edMessage->clear();
ui->lblStatus->clear();
ui->edMessage->setFocus();
}
bool VerifyMessageDialog::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->lnAddress && (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::FocusIn))
{
// set lnAddress to valid, as QEvent::FocusIn would not reach QValidatedLineEdit::focusInEvent
ui->lnAddress->setValid(true);
ui->lnAddress->selectAll();
return true;
}
return QDialog::eventFilter(object, event);
}

33
src/qt/verifymessagedialog.h

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
#ifndef VERIFYMESSAGEDIALOG_H
#define VERIFYMESSAGEDIALOG_H
#include <QDialog>
namespace Ui {
class VerifyMessageDialog;
}
class AddressTableModel;
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
class VerifyMessageDialog : public QDialog
{
Q_OBJECT
public:
explicit VerifyMessageDialog(QWidget *parent);
~VerifyMessageDialog();
protected:
bool eventFilter(QObject *object, QEvent *event);
private:
Ui::VerifyMessageDialog *ui;
private slots:
void on_verifyMessage_clicked();
void on_clearButton_clicked();
};
#endif // VERIFYMESSAGEDIALOG_H
Loading…
Cancel
Save