From a81148fb528f43e4779f7f974c480c40536e7f03 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 24 Jan 2023 18:29:59 +0100 Subject: [PATCH] VerifyProofDialog: add verify Tx Secret Key --- src/dialog/TxConfAdvDialog.cpp | 5 +++ src/dialog/TxInfoDialog.cpp | 5 +++ src/dialog/VerifyProofDialog.cpp | 26 +++++++++++++ src/dialog/VerifyProofDialog.h | 1 + src/dialog/VerifyProofDialog.ui | 64 ++++++++++++++++++++++++++++++++ src/libwalletqt/Wallet.cpp | 7 ++-- src/libwalletqt/Wallet.h | 11 +++++- 7 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/dialog/TxConfAdvDialog.cpp b/src/dialog/TxConfAdvDialog.cpp index c021d0d..9ab1d69 100644 --- a/src/dialog/TxConfAdvDialog.cpp +++ b/src/dialog/TxConfAdvDialog.cpp @@ -205,6 +205,11 @@ void TxConfAdvDialog::signedCopy() { } void TxConfAdvDialog::txKeyCopy() { + if (m_ctx->wallet->isHwBacked()) { + QMessageBox::warning(this, "Unable to get tx private key", "Unable to get tx secret key: wallet is backed by hardware device"); + return; + } + Utils::copyToClipboard(m_tx->transaction(0)->txKey()); } diff --git a/src/dialog/TxInfoDialog.cpp b/src/dialog/TxInfoDialog.cpp index 8c8b5ab..5a80ffd 100644 --- a/src/dialog/TxInfoDialog.cpp +++ b/src/dialog/TxInfoDialog.cpp @@ -161,6 +161,11 @@ void TxInfoDialog::copyTxID() { } void TxInfoDialog::copyTxKey() { + if (m_ctx->wallet->isHwBacked()) { + QMessageBox::warning(this, "Unable to get tx private key", "Unable to get tx secret key: wallet is backed by hardware device"); + return; + } + m_ctx->wallet->getTxKeyAsync(m_txid, [this](QVariantMap map){ QString txKey = map.value("tx_key").toString(); if (txKey.isEmpty()) { diff --git a/src/dialog/VerifyProofDialog.cpp b/src/dialog/VerifyProofDialog.cpp index f28f86b..e7df7fe 100644 --- a/src/dialog/VerifyProofDialog.cpp +++ b/src/dialog/VerifyProofDialog.cpp @@ -47,6 +47,11 @@ VerifyProofDialog::VerifyProofDialog(Wallet *wallet, QWidget *parent) ui->input_inMessage->clear(); ui->input_InProof->clear(); break; + case 3: + ui->line_keyTxID->clear(); + ui->line_keyTxKey->clear(); + ui->line_keyAddress->clear(); + break; } }); @@ -67,6 +72,9 @@ void VerifyProofDialog::checkProof() { case 2: this->checkInProof(); break; + case 3: + this->checkTxKey(); + break; } } @@ -91,6 +99,24 @@ void VerifyProofDialog::checkInProof() { this->checkTxProof(ui->lineEdit_inTxID->text(), ui->lineEdit_inAddress->text(), ui->input_inMessage->toPlainText(), ui->input_InProof->toPlainText()); } +void VerifyProofDialog::checkTxKey() { + ui->btn_verifyFormattedProof->setEnabled(false); + ui->btn_verify->setEnabled(false); + TxKeyResult res = m_wallet->checkTxKey(ui->line_keyTxID->text(), ui->line_keyTxKey->text(), ui->line_keyAddress->text()); + + if (!res.succes) { + this->proofStatus(false, QString("Error: %1").arg(res.errorString)); + return; + } + + if (!res.good) { + this->proofStatus(false, QString("Tx secret key does not decode any outputs for this transaction.")); + return; + } + + this->proofStatus(true, QString("Proof is valid.\n\nThis address received %1 XMR, with %2 confirmations").arg(res.amount, QString::number(res.confirmations))); +} + void VerifyProofDialog::checkFormattedProof() { QRegularExpression proof("-----BEGIN (?\\w+)-----\\n" "Network: (?\\w+) (?\\w+)\\n" diff --git a/src/dialog/VerifyProofDialog.h b/src/dialog/VerifyProofDialog.h index 3703bda..472650a 100644 --- a/src/dialog/VerifyProofDialog.h +++ b/src/dialog/VerifyProofDialog.h @@ -30,6 +30,7 @@ private: void checkSpendProof(const QString &txId, const QString &message, const QString &signature); void checkOutProof(); void checkInProof(); + void checkTxKey(); void checkFormattedProof(); void proofStatus(bool success, const QString &message); void onTxProofVerified(TxProofResult result); diff --git a/src/dialog/VerifyProofDialog.ui b/src/dialog/VerifyProofDialog.ui index 76bac4f..9f49e36 100644 --- a/src/dialog/VerifyProofDialog.ui +++ b/src/dialog/VerifyProofDialog.ui @@ -380,6 +380,70 @@ + + + TxKey + + + + + + Similar to an OutProof, the Transaction Secret Key can be used to prove the sum of outputs sent to an address in a transaction. + + + true + + + + + + + + + Transaction ID: + + + + + + + Transaction Secret Key: + + + + + + + Address: + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 8e6ec86..935d045 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -995,14 +995,15 @@ void Wallet::getTxKeyAsync(const QString &txid, const std::functioncheckTxKey(txid.toStdString(), tx_key.toStdString(), address.toStdString(), received, in_pool, confirmations); - std::string result = std::string(success ? "true" : "false") + "|" + QString::number(received).toStdString() + "|" + std::string(in_pool ? "true" : "false") + "|" + QString::number(confirmations).toStdString(); - return QString::fromStdString(result); + QString errorString = success ? "" : this->errorString(); + bool good = received > 0; + return {success, good, QString::fromStdString(Monero::Wallet::displayAmount(received)), in_pool, confirmations, errorString}; } TxProof Wallet::getTxProof(const QString &txid, const QString &address, const QString &message) const diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 231af94..d4c94c7 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -30,6 +30,15 @@ struct TxProof { QString error; }; +struct TxKeyResult { + bool succes = false; + bool good = false; + QString amount; + bool inPool; + uint64_t confirmations; + QString errorString; +}; + struct SubaddressIndex { SubaddressIndex(int major, int minor) { this->major = major; @@ -410,7 +419,7 @@ public: QString getTxKey(const QString &txid) const; void getTxKeyAsync(const QString &txid, const std::function &callback); - QString checkTxKey(const QString &txid, const QString &tx_key, const QString &address); + TxKeyResult checkTxKey(const QString &txid, const QString &tx_key, const QString &address); TxProof getTxProof(const QString &txid, const QString &address, const QString &message) const; // void getTxProofAsync(const QString &txid, const QString &address, const QString &message, const QJSValue &callback); //QString checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature);