Wladimir J. van der Laan
13 years ago
8 changed files with 283 additions and 4 deletions
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
<?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>494</width> |
||||
<height>342</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 message and signature below (be careful to correctly copy newlines, spaces, tabs, and other invisible characters), and press apply to obtain the bitcoin address used to sign 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="QPlainTextEdit" name="edMessage"/> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="lnSig"> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="placeholderText"> |
||||
<string>Signature</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="lnAddress"> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="readOnly"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="placeholderText"> |
||||
<string>Address</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="lblStatus"> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QPushButton" name="copyToClipboard"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Copy the currently selected address to the system clipboard</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>&Copy Address</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../bitcoin.qrc"> |
||||
<normaloff>:/icons/editcopy</normaloff>:/icons/editcopy</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> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set> |
||||
</property> |
||||
<property name="centerButtons"> |
||||
<bool>false</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources> |
||||
<include location="../bitcoin.qrc"/> |
||||
</resources> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>VerifyMessageDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>VerifyMessageDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
#include "verifymessagedialog.h" |
||||
#include "ui_verifymessagedialog.h" |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include <QDialogButtonBox> |
||||
#include <QAbstractButton> |
||||
#include <QClipboard> |
||||
#include <QMessageBox> |
||||
|
||||
#include "main.h" |
||||
#include "wallet.h" |
||||
#include "walletmodel.h" |
||||
#include "addresstablemodel.h" |
||||
#include "guiutil.h" |
||||
|
||||
VerifyMessageDialog::VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::VerifyMessageDialog), |
||||
model(addressModel) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
GUIUtil::setupAddressWidget(ui->lnAddress, this); |
||||
} |
||||
|
||||
VerifyMessageDialog::~VerifyMessageDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
bool VerifyMessageDialog::checkAddress() |
||||
{ |
||||
CDataStream ss(SER_GETHASH, 0); |
||||
ss << strMessageMagic; |
||||
ss << ui->edMessage->document()->toPlainText().toStdString(); |
||||
uint256 hash = Hash(ss.begin(), ss.end()); |
||||
|
||||
bool invalid = true; |
||||
std::vector<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &invalid); |
||||
|
||||
if(invalid) |
||||
{ |
||||
QMessageBox::warning(this, tr("Invalid Signature"), tr("The signature could not be decoded. Please check the signature and try again.")); |
||||
return false; |
||||
} |
||||
|
||||
CKey key; |
||||
if(!key.SetCompactSignature(hash, vchSig)) |
||||
{ |
||||
QMessageBox::warning(this, tr("Invalid Signature"), tr("The signature did not match the message digest. Please check the signature and try again.")); |
||||
return false; |
||||
} |
||||
|
||||
CBitcoinAddress address(key.GetPubKey()); |
||||
QString qStringAddress = QString::fromStdString(address.ToString()); |
||||
ui->lnAddress->setText(qStringAddress); |
||||
ui->copyToClipboard->setEnabled(true); |
||||
|
||||
QString label = model->labelForAddress(qStringAddress); |
||||
ui->lblStatus->setText(label.isEmpty() ? tr("Address not found in address book.") : tr("Address found in address book: %1").arg(label)); |
||||
return true; |
||||
} |
||||
|
||||
void VerifyMessageDialog::on_buttonBox_clicked(QAbstractButton *button) |
||||
{ |
||||
if(ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) |
||||
checkAddress(); |
||||
} |
||||
|
||||
void VerifyMessageDialog::on_copyToClipboard_clicked() |
||||
{ |
||||
QApplication::clipboard()->setText(ui->lnAddress->text()); |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#ifndef VERIFYMESSAGEDIALOG_H |
||||
#define VERIFYMESSAGEDIALOG_H |
||||
|
||||
#include <QDialog> |
||||
|
||||
class AddressTableModel; |
||||
|
||||
QT_BEGIN_NAMESPACE |
||||
class QAbstractButton; |
||||
QT_END_NAMESPACE |
||||
|
||||
namespace Ui { |
||||
class VerifyMessageDialog; |
||||
} |
||||
|
||||
class VerifyMessageDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent = 0); |
||||
~VerifyMessageDialog(); |
||||
|
||||
private slots: |
||||
void on_buttonBox_clicked(QAbstractButton *button); |
||||
|
||||
void on_copyToClipboard_clicked(); |
||||
|
||||
private: |
||||
bool checkAddress(); |
||||
|
||||
Ui::VerifyMessageDialog *ui; |
||||
AddressTableModel *model; |
||||
}; |
||||
|
||||
#endif // VERIFYMESSAGEDIALOG_H
|
Loading…
Reference in new issue