Sign: show signed message key type
This commit is contained in:
3 files changed
+50
-13
No files matched your search
+17
-6
@@ -58,9 +58,20 @@ Rectangle {
|
||||
}
|
||||
|
||||
function displayVerificationResult(result) {
|
||||
if (result) {
|
||||
if (result.valid) {
|
||||
signatureVerificationMessage.title = qsTr("Good signature") + translationManager.emptyString
|
||||
signatureVerificationMessage.text = qsTr("This is a good signature") + translationManager.emptyString
|
||||
if (result.type === "spend") {
|
||||
signatureVerificationMessage.text = qsTr("This is a good signature made with the spend key.") + translationManager.emptyString
|
||||
}
|
||||
else if (result.type === "view") {
|
||||
signatureVerificationMessage.text = qsTr("This is a good signature made with the view key. It does not prove that the signer can spend funds.") + translationManager.emptyString
|
||||
}
|
||||
else {
|
||||
signatureVerificationMessage.text = qsTr("This is a good signature made with an unknown key type.") + translationManager.emptyString
|
||||
}
|
||||
if (result.old) {
|
||||
signatureVerificationMessage.text += "\n\n" + qsTr("This signature uses the old signing algorithm.") + translationManager.emptyString
|
||||
}
|
||||
signatureVerificationMessage.icon = StandardIcon.Information
|
||||
}
|
||||
else {
|
||||
@@ -379,8 +390,8 @@ Rectangle {
|
||||
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)
|
||||
var result = appWindow.currentWallet.verifySignedMessageWithDetails(verifyFileLine.text, verifyAddressLine.text, verifySignatureLine.text, true)
|
||||
displayVerificationResult(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,8 +402,8 @@ Rectangle {
|
||||
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)
|
||||
var result = appWindow.currentWallet.verifySignedMessageWithDetails(verifyMessageLine.text, verifyAddressLine.text, verifySignatureLine.text, false)
|
||||
displayVerificationResult(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,23 @@ namespace {
|
||||
static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5;
|
||||
|
||||
static constexpr char ATTRIBUTE_SUBADDRESS_ACCOUNT[] ="gui.subaddress_account";
|
||||
|
||||
QVariantMap messageSignatureResultToVariantMap(const Monero::Wallet::MessageSignatureResult &result)
|
||||
{
|
||||
QString type = "invalid";
|
||||
switch (result.type) {
|
||||
case Monero::Wallet::MessageSignatureType_Spend: type = "spend"; break;
|
||||
case Monero::Wallet::MessageSignatureType_View: type = "view"; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return {
|
||||
{"valid", result.valid},
|
||||
{"version", result.version},
|
||||
{"old", result.old},
|
||||
{"type", type}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Wallet::Wallet(QObject * parent)
|
||||
@@ -1002,6 +1019,11 @@ QString Wallet::signMessage(const QString &message, bool filename) const
|
||||
}
|
||||
|
||||
bool Wallet::verifySignedMessage(const QString &message, const QString &address, const QString &signature, bool filename) const
|
||||
{
|
||||
return verifySignedMessageWithDetails(message, address, signature, filename).value("valid").toBool();
|
||||
}
|
||||
|
||||
QVariantMap Wallet::verifySignedMessageWithDetails(const QString &message, const QString &address, const QString &signature, bool filename) const
|
||||
{
|
||||
if (filename) {
|
||||
QFile file(message);
|
||||
@@ -1009,31 +1031,31 @@ bool Wallet::verifySignedMessage(const QString &message, const QString &address,
|
||||
|
||||
try {
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
return messageSignatureResultToVariantMap({});
|
||||
quint64 size = file.size();
|
||||
if (size == 0) {
|
||||
file.close();
|
||||
return m_walletImpl->verifySignedMessage(std::string(), address.toStdString(), signature.toStdString());
|
||||
return messageSignatureResultToVariantMap(m_walletImpl->verifySignedMessageWithDetails(std::string(), address.toStdString(), signature.toStdString()));
|
||||
}
|
||||
data = file.map(0, size);
|
||||
if (!data) {
|
||||
file.close();
|
||||
return false;
|
||||
return messageSignatureResultToVariantMap({});
|
||||
}
|
||||
bool ret = m_walletImpl->verifySignedMessage(std::string(reinterpret_cast<const char*>(data), size), address.toStdString(), signature.toStdString());
|
||||
const QVariantMap result = messageSignatureResultToVariantMap(m_walletImpl->verifySignedMessageWithDetails(std::string(reinterpret_cast<const char*>(data), size), address.toStdString(), signature.toStdString()));
|
||||
file.unmap(data);
|
||||
file.close();
|
||||
return ret;
|
||||
return result;
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
if (data)
|
||||
file.unmap(data);
|
||||
file.close();
|
||||
return false;
|
||||
return messageSignatureResultToVariantMap({});
|
||||
}
|
||||
}
|
||||
else {
|
||||
return m_walletImpl->verifySignedMessage(message.toStdString(), address.toStdString(), signature.toStdString());
|
||||
return messageSignatureResultToVariantMap(m_walletImpl->verifySignedMessageWithDetails(message.toStdString(), address.toStdString(), signature.toStdString()));
|
||||
}
|
||||
}
|
||||
bool Wallet::parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QMutex>
|
||||
#include <QList>
|
||||
#include <QJSValue>
|
||||
#include <QVariantMap>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "wallet/api/wallet2_api.h" // we need to have an access to the Monero::Wallet::Status enum here;
|
||||
@@ -320,6 +321,9 @@ public:
|
||||
//! verify a signed message
|
||||
Q_INVOKABLE bool verifySignedMessage(const QString &message, const QString &address, const QString &signature, bool filename = false) const;
|
||||
|
||||
//! verify a signed message and return the signature version and key type
|
||||
Q_INVOKABLE QVariantMap verifySignedMessageWithDetails(const QString &message, const QString &address, const QString &signature, bool filename = false) const;
|
||||
|
||||
//! Parse URI
|
||||
Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error);
|
||||
//! Make URI
|
||||
|
||||
Reference in new issue
Block a user