VerifyProofDialog: add verify Tx Secret Key

This commit is contained in:
tobtoht 2023-01-24 18:29:59 +01:00
parent 80a8c82bd2
commit a81148fb52
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
7 changed files with 115 additions and 4 deletions

View file

@ -205,6 +205,11 @@ void TxConfAdvDialog::signedCopy() {
} }
void TxConfAdvDialog::txKeyCopy() { 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()); Utils::copyToClipboard(m_tx->transaction(0)->txKey());
} }

View file

@ -161,6 +161,11 @@ void TxInfoDialog::copyTxID() {
} }
void TxInfoDialog::copyTxKey() { 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){ m_ctx->wallet->getTxKeyAsync(m_txid, [this](QVariantMap map){
QString txKey = map.value("tx_key").toString(); QString txKey = map.value("tx_key").toString();
if (txKey.isEmpty()) { if (txKey.isEmpty()) {

View file

@ -47,6 +47,11 @@ VerifyProofDialog::VerifyProofDialog(Wallet *wallet, QWidget *parent)
ui->input_inMessage->clear(); ui->input_inMessage->clear();
ui->input_InProof->clear(); ui->input_InProof->clear();
break; 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: case 2:
this->checkInProof(); this->checkInProof();
break; 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()); 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() { void VerifyProofDialog::checkFormattedProof() {
QRegularExpression proof("-----BEGIN (?<type>\\w+)-----\\n" QRegularExpression proof("-----BEGIN (?<type>\\w+)-----\\n"
"Network: (?<coin>\\w+) (?<network>\\w+)\\n" "Network: (?<coin>\\w+) (?<network>\\w+)\\n"

View file

@ -30,6 +30,7 @@ private:
void checkSpendProof(const QString &txId, const QString &message, const QString &signature); void checkSpendProof(const QString &txId, const QString &message, const QString &signature);
void checkOutProof(); void checkOutProof();
void checkInProof(); void checkInProof();
void checkTxKey();
void checkFormattedProof(); void checkFormattedProof();
void proofStatus(bool success, const QString &message); void proofStatus(bool success, const QString &message);
void onTxProofVerified(TxProofResult result); void onTxProofVerified(TxProofResult result);

View file

@ -380,6 +380,70 @@
</item> </item>
</layout> </layout>
</widget> </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> </widget>
</item> </item>
<item> <item>

View file

@ -995,14 +995,15 @@ void Wallet::getTxKeyAsync(const QString &txid, const std::function<void (QVaria
}, callback); }, 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; uint64_t received;
bool in_pool; bool in_pool;
uint64_t confirmations; uint64_t confirmations;
bool success = m_walletImpl->checkTxKey(txid.toStdString(), tx_key.toStdString(), address.toStdString(), received, in_pool, 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(); QString errorString = success ? "" : this->errorString();
return QString::fromStdString(result); 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 TxProof Wallet::getTxProof(const QString &txid, const QString &address, const QString &message) const

View file

@ -30,6 +30,15 @@ struct TxProof {
QString error; QString error;
}; };
struct TxKeyResult {
bool succes = false;
bool good = false;
QString amount;
bool inPool;
uint64_t confirmations;
QString errorString;
};
struct SubaddressIndex { struct SubaddressIndex {
SubaddressIndex(int major, int minor) { SubaddressIndex(int major, int minor) {
this->major = major; this->major = major;
@ -410,7 +419,7 @@ public:
QString getTxKey(const QString &txid) const; QString getTxKey(const QString &txid) const;
void getTxKeyAsync(const QString &txid, const std::function<void (QVariantMap)> &callback); 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; 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); // 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); //QString checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature);