]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
VerifyProofDialog: add verify Tx Secret Key
authortobtoht <tob@featherwallet.org>
Tue, 24 Jan 2023 17:29:59 +0000 (18:29 +0100)
committertobtoht <tob@featherwallet.org>
Tue, 24 Jan 2023 17:49:30 +0000 (18:49 +0100)
src/dialog/TxConfAdvDialog.cpp
src/dialog/TxInfoDialog.cpp
src/dialog/VerifyProofDialog.cpp
src/dialog/VerifyProofDialog.h
src/dialog/VerifyProofDialog.ui
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h

index c021d0d33006ea27be62891aeece88f3702ecd60..9ab1d696886945124b67c86289bead10b0085419 100644 (file)
@@ -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());
 }
 
index 8c8b5ab777fa745f43f68d13e5d10ac15ec3732c..5a80ffda7c9def6c55a8f5e95d49bba077e44d3e 100644 (file)
@@ -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()) {
index f28f86b62d4ad6f107a95205b937684523e5fa20..e7df7fe391945c6080b82061ffec2d7e85a7657d 100644 (file)
@@ -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 (?<type>\\w+)-----\\n"
                              "Network: (?<coin>\\w+) (?<network>\\w+)\\n"
index 3703bdaa255a39d8c4af83c4870861fa0dcb8a94..472650a548d8e4644ed85b002395892d84ed63da 100644 (file)
@@ -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);
index 76bac4f4dd600b027d9f9ebf33771a99653dfce3..9f49e3616f8cd463ee6a8a43e823c8a94dc71978 100644 (file)
            </item>
           </layout>
          </widget>
+         <widget class="QWidget" name="TxKey">
+          <attribute name="title">
+           <string>TxKey</string>
+          </attribute>
+          <layout class="QVBoxLayout" name="verticalLayout_7">
+           <item>
+            <widget class="QLabel" name="label_20">
+             <property name="text">
+              <string>Similar to an OutProof, the Transaction Secret Key can be used to prove the sum of outputs sent to an address in a transaction.</string>
+             </property>
+             <property name="wordWrap">
+              <bool>true</bool>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <layout class="QFormLayout" name="formLayout">
+             <item row="0" column="0">
+              <widget class="QLabel" name="label_17">
+               <property name="text">
+                <string>Transaction ID:</string>
+               </property>
+              </widget>
+             </item>
+             <item row="1" column="0">
+              <widget class="QLabel" name="label_18">
+               <property name="text">
+                <string>Transaction Secret Key:</string>
+               </property>
+              </widget>
+             </item>
+             <item row="2" column="0">
+              <widget class="QLabel" name="label_19">
+               <property name="text">
+                <string>Address:</string>
+               </property>
+              </widget>
+             </item>
+             <item row="0" column="1">
+              <widget class="QLineEdit" name="line_keyTxID"/>
+             </item>
+             <item row="1" column="1">
+              <widget class="QLineEdit" name="line_keyTxKey"/>
+             </item>
+             <item row="2" column="1">
+              <widget class="QLineEdit" name="line_keyAddress"/>
+             </item>
+            </layout>
+           </item>
+           <item>
+            <spacer name="verticalSpacer_4">
+             <property name="orientation">
+              <enum>Qt::Vertical</enum>
+             </property>
+             <property name="sizeHint" stdset="0">
+              <size>
+               <width>20</width>
+               <height>40</height>
+              </size>
+             </property>
+            </spacer>
+           </item>
+          </layout>
+         </widget>
         </widget>
        </item>
        <item>
index 8e6ec862da9f96b82bc01e2b8bbe0dc029ada1a6..935d0451de35c7225b9b78da45640d160e86a69e 100644 (file)
@@ -995,14 +995,15 @@ void Wallet::getTxKeyAsync(const QString &txid, const std::function<void (QVaria
     }, callback);
 }
 
-QString Wallet::checkTxKey(const QString &txid, const QString &tx_key, const QString &address)
+TxKeyResult Wallet::checkTxKey(const QString &txid, const QString &tx_key, const QString &address)
 {
     uint64_t received;
     bool in_pool;
     uint64_t confirmations;
     bool success = m_walletImpl->checkTxKey(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
index 231af9404f91d2ef192b1d40ce0e161e5f1d99c3..d4c94c7de11a260cf85912a0b09ff0331760a46c 100644 (file)
@@ -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<void (QVariantMap)> &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);