diff options
| author | Wladimir J. van der Laan <[email protected]> | 2012-05-14 11:11:16 -0700 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2012-05-14 11:11:16 -0700 |
| commit | bb361cc644eb56689b1b0be5da9078d32640bd96 (patch) | |
| tree | 44d3a54d53494ae4c2e9d0825024c6d46669e1e9 /src/qt/verifymessagedialog.cpp | |
| parent | Merge pull request #1301 from laanwj/2012_05_rpcscrolltoend (diff) | |
| parent | Add a menu option to verify a signed message (diff) | |
| download | discoin-bb361cc644eb56689b1b0be5da9078d32640bd96.tar.xz discoin-bb361cc644eb56689b1b0be5da9078d32640bd96.zip | |
Merge pull request #906 from sje397/ValidateMessage
Add a menu option and dialog to verify a signed message
Diffstat (limited to 'src/qt/verifymessagedialog.cpp')
| -rw-r--r-- | src/qt/verifymessagedialog.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/qt/verifymessagedialog.cpp b/src/qt/verifymessagedialog.cpp new file mode 100644 index 000000000..884290871 --- /dev/null +++ b/src/qt/verifymessagedialog.cpp @@ -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()); +} |