Skip to content

Commit

Permalink
Improve wallet import dialogues
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed May 11, 2024
1 parent 60720a6 commit 6ac2d60
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 196 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ if (WIN32)
add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600 /DSTATICLIB)

add_subdirectory(cryptonote/external/zstd EXCLUDE_FROM_ALL)
add_subdirectory(cryptonote/external/snappy EXCLUDE_FROM_ALL)
add_subdirectory(cryptonote/external/rocksdb EXCLUDE_FROM_ALL)
add_subdirectory(cryptonote/external/leveldb EXCLUDE_FROM_ALL)
add_subdirectory(cryptonote/external/snappy EXCLUDE_FROM_ALL)
set_property(TARGET rocksdb leveldb snappy zstd PROPERTY FOLDER "external")

include_directories(cryptonote/src/platform/msc)
Expand Down
44 changes: 43 additions & 1 deletion src/gui/ImportKeyDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2018 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>

#include "Common/Base58.h"
#include "Common/StringTools.h"
#include "CryptoNoteCore/CryptoNoteTools.h"
#include "CurrencyAdapter.h"

#include "ImportKeyDialog.h"

#include "ui_importkeydialog.h"
Expand All @@ -16,6 +22,7 @@ namespace WalletGui {

ImportKeyDialog::ImportKeyDialog(QWidget* _parent) : QDialog(_parent), m_ui(new Ui::ImportKeyDialog) {
m_ui->setupUi(this);
m_ui->m_okButton->setEnabled(false);
}

ImportKeyDialog::~ImportKeyDialog() {
Expand All @@ -33,6 +40,10 @@ quint32 ImportKeyDialog::getSyncHeight() const {
return m_ui->m_syncHeight->value();
}

CryptoNote::AccountKeys ImportKeyDialog::getAccountKeys() const {
return m_keys;
}

void ImportKeyDialog::selectPathClicked() {
QString filePath = QFileDialog::getSaveFileName(this, tr("Wallet file"),
#ifdef Q_OS_WIN
Expand All @@ -51,4 +62,35 @@ void ImportKeyDialog::selectPathClicked() {
m_ui->m_pathEdit->setText(filePath);
}

void ImportKeyDialog::onTextChanged() {
if (getKeyString().isEmpty() || getKeyString().size() != 183) {
m_ui->m_okButton->setEnabled(false);
} else {
m_ui->m_okButton->setEnabled(true);
}
}

void ImportKeyDialog::onAccept() {
uint64_t addressPrefix;
std::string data;
QString keyString = getKeyString().trimmed();
if (!keyString.isEmpty() && Tools::Base58::decode_addr(keyString.toStdString(), addressPrefix, data) && addressPrefix == CurrencyAdapter::instance().getAddressPrefix() && data.size() == sizeof(m_keys)) {
if (!CryptoNote::fromBinaryArray(m_keys, Common::asBinaryArray(data))) {
QMessageBox::warning(nullptr, tr("Wallet keys are not valid"), tr("Failed to parse account keys"), QMessageBox::Ok);
return;
}
} else {
QMessageBox::warning(nullptr, tr("Wallet keys are not valid"), tr("The private keys you entered are not valid."), QMessageBox::Ok);
return;
}

QString filePath = getFilePath();
if (filePath.isEmpty()) {
QMessageBox::critical(nullptr, tr("File path is empty"), tr("Please enter the path where to save the wallet file and its name."), QMessageBox::Ok);
return;
}

accept();
}

}
8 changes: 7 additions & 1 deletion src/gui/ImportKeyDialog.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2017 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <QDialog>
#include <CryptoNote.h>

namespace Ui {
class ImportKeyDialog;
Expand All @@ -24,11 +25,16 @@ class ImportKeyDialog : public QDialog {
QString getKeyString() const;
QString getFilePath() const;
quint32 getSyncHeight() const;
CryptoNote::AccountKeys getAccountKeys() const;

private:
QScopedPointer<Ui::ImportKeyDialog> m_ui;

CryptoNote::AccountKeys m_keys;

Q_SLOT void selectPathClicked();
Q_SLOT void onTextChanged();
Q_SLOT void onAccept();
};

}
62 changes: 61 additions & 1 deletion src/gui/ImportKeysDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2019 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>

#include "Common/StringTools.h"
#include "CryptoNoteCore/CryptoNoteTools.h"
#include "CurrencyAdapter.h"

#include "ImportKeysDialog.h"

#include "ui_importkeysdialog.h"
Expand All @@ -16,6 +21,7 @@ namespace WalletGui {

ImportKeysDialog::ImportKeysDialog(QWidget* _parent) : QDialog(_parent), m_ui(new Ui::ImportKeysDialog) {
m_ui->setupUi(this);
m_ui->m_okButton->setEnabled(false);
}

ImportKeysDialog::~ImportKeysDialog() {
Expand All @@ -37,6 +43,10 @@ quint32 ImportKeysDialog::getSyncHeight() const {
return m_ui->m_syncHeight->value();
}

CryptoNote::AccountKeys ImportKeysDialog::getAccountKeys() const {
return m_keys;
}

void ImportKeysDialog::selectPathClicked() {
QString filePath = QFileDialog::getSaveFileName(this, tr("Wallet file"),
#ifdef Q_OS_WIN
Expand All @@ -55,4 +65,54 @@ void ImportKeysDialog::selectPathClicked() {
m_ui->m_pathEdit->setText(filePath);
}

void ImportKeysDialog::onTextChanged(QString _text) {
Q_UNUSED(_text);
if (getViewKeyString().isEmpty() || getSpendKeyString().isEmpty() || getViewKeyString().size() != 64 || getSpendKeyString().size() != 64) {
m_ui->m_okButton->setEnabled(false);
} else {
m_ui->m_okButton->setEnabled(true);
}
}

void ImportKeysDialog::onAccept() {
QString viewKeyString = getViewKeyString().trimmed();
QString spendKeyString = getSpendKeyString().trimmed();

if (viewKeyString.isEmpty() || spendKeyString.isEmpty()) {
return; // no error message, it's obvious
}

uint64_t addressPrefix;
std::string data;

std::string private_spend_key_string = spendKeyString.toStdString();
std::string private_view_key_string = viewKeyString.toStdString();

Crypto::Hash private_spend_key_hash;
Crypto::Hash private_view_key_hash;

size_t size;
if (!Common::fromHex(private_spend_key_string, &private_spend_key_hash, sizeof(private_spend_key_hash), size) || size != sizeof(private_spend_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The private spend key you entered is not valid."), QMessageBox::Ok);
return;
}
if (!Common::fromHex(private_view_key_string, &private_view_key_hash, sizeof(private_view_key_hash), size) || size != sizeof(private_view_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The private view key you entered is not valid."), QMessageBox::Ok);
return;
}

m_keys.spendSecretKey = *(struct Crypto::SecretKey *) &private_spend_key_hash;
m_keys.viewSecretKey = *(struct Crypto::SecretKey *) &private_view_key_hash;

Crypto::secret_key_to_public_key(m_keys.spendSecretKey, m_keys.address.spendPublicKey);
Crypto::secret_key_to_public_key(m_keys.viewSecretKey, m_keys.address.viewPublicKey);

if (getFilePath().isEmpty()) {
QMessageBox::critical(nullptr, tr("File path is empty"), tr("Please enter the path where to save the wallet file and its name."), QMessageBox::Ok);
return;
}

accept();
}

}
8 changes: 7 additions & 1 deletion src/gui/ImportKeysDialog.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2019 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <QDialog>
#include <CryptoNote.h>

namespace Ui {
class ImportKeysDialog;
Expand All @@ -25,11 +26,16 @@ class ImportKeysDialog : public QDialog {
QString getSpendKeyString() const;
QString getFilePath() const;
quint32 getSyncHeight() const;
CryptoNote::AccountKeys getAccountKeys() const;

private:
QScopedPointer<Ui::ImportKeysDialog> m_ui;

CryptoNote::AccountKeys m_keys;

Q_SLOT void selectPathClicked();
Q_SLOT void onTextChanged(QString _text);
Q_SLOT void onAccept();
};

}
82 changes: 81 additions & 1 deletion src/gui/ImportTrackingKeyDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2018 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>

#include "Common/StringTools.h"
#include "CryptoNoteCore/CryptoNoteTools.h"
#include "CurrencyAdapter.h"

#include "ImportTrackingKeyDialog.h"

#include "ui_importtrackingkeydialog.h"
Expand All @@ -16,6 +21,7 @@ namespace WalletGui {

ImportTrackingKeyDialog::ImportTrackingKeyDialog(QWidget* _parent) : QDialog(_parent), m_ui(new Ui::ImportTrackingKeyDialog) {
m_ui->setupUi(this);
m_ui->m_okButton->setEnabled(false);
}

ImportTrackingKeyDialog::~ImportTrackingKeyDialog() {
Expand All @@ -33,6 +39,10 @@ quint32 ImportTrackingKeyDialog::getSyncHeight() const {
return m_ui->m_syncHeight->value();
}

CryptoNote::AccountKeys ImportTrackingKeyDialog::getAccountKeys() const {
return m_keys;
}

void ImportTrackingKeyDialog::selectPathClicked() {
QString filePath = QFileDialog::getSaveFileName(this, tr("Tracking wallet file"),
#ifdef Q_OS_WIN
Expand All @@ -51,4 +61,74 @@ void ImportTrackingKeyDialog::selectPathClicked() {
m_ui->m_pathEdit->setText(filePath);
}

void ImportTrackingKeyDialog::onTextChanged() {
if (getKeyString().isEmpty() || getKeyString().size() != 256) {
m_ui->m_okButton->setEnabled(false);
} else {
m_ui->m_okButton->setEnabled(true);
}
}

void ImportTrackingKeyDialog::onAccept() {
QString keyString = getKeyString().trimmed();
if (keyString.isEmpty() || keyString.size() != 256) {
QMessageBox::warning(this, tr("Tracking key is not valid"), tr("The tracking key you entered is not valid."), QMessageBox::Ok);
return;
}

// XDN style tracking key import
// uint64_t addressPrefix;
// std::string data;

// if (Tools::Base58::decode_addr(keyString.toStdString(), addressPrefix, data) && addressPrefix == CurrencyAdapter::instance().getAddressPrefix() &&
// data.size() == sizeof(keys)) {
// std::memcpy(&keys, data.data(), sizeof(keys));

// To prevent confusing with import of private key / paperwallet lets use Bytecoin style tracking keys, they look different
std::string public_spend_key_string = keyString.mid(0,64).toStdString();
std::string public_view_key_string = keyString.mid(64,64).toStdString();
std::string private_spend_key_string = keyString.mid(128,64).toStdString();
std::string private_view_key_string = keyString.mid(192,64).toStdString();

Crypto::Hash public_spend_key_hash;
Crypto::Hash public_view_key_hash;
Crypto::Hash private_spend_key_hash;
Crypto::Hash private_view_key_hash;

size_t size;
if (!Common::fromHex(public_spend_key_string, &public_spend_key_hash, sizeof(public_spend_key_hash), size) || size != sizeof(public_spend_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The public spend key you entered is not valid."), QMessageBox::Ok);
return;
}
if (!Common::fromHex(public_view_key_string, &public_view_key_hash, sizeof(public_view_key_hash), size) || size != sizeof(public_view_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The public view key you entered is not valid."), QMessageBox::Ok);
return;
}
if (!Common::fromHex(private_spend_key_string, &private_spend_key_hash, sizeof(private_spend_key_hash), size) || size != sizeof(private_spend_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The private spend key you entered is not valid."), QMessageBox::Ok);
return;
}
if (!Common::fromHex(private_view_key_string, &private_view_key_hash, sizeof(private_view_key_hash), size) || size != sizeof(private_view_key_hash)) {
QMessageBox::warning(this, tr("Key is not valid"), tr("The private view key you entered is not valid."), QMessageBox::Ok);
return;
}

Crypto::PublicKey public_spend_key = *(struct Crypto::PublicKey *) &public_spend_key_hash;
Crypto::PublicKey public_view_key = *(struct Crypto::PublicKey *) &public_view_key_hash;
Crypto::SecretKey private_spend_key = *(struct Crypto::SecretKey *) &private_spend_key_hash;
Crypto::SecretKey private_view_key = *(struct Crypto::SecretKey *) &private_view_key_hash;

m_keys.address.spendPublicKey = public_spend_key;
m_keys.address.viewPublicKey = public_view_key;
m_keys.spendSecretKey = private_spend_key;
m_keys.viewSecretKey = private_view_key;

if (getFilePath().isEmpty()) {
QMessageBox::critical(nullptr, tr("File path is empty"), tr("Please enter the path where to save the wallet file and its name."), QMessageBox::Ok);
return;
}

accept();
}

}
8 changes: 7 additions & 1 deletion src/gui/ImportTrackingKeyDialog.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2017 The Karbowanec developers
// Copyright (c) 2016-2022 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <QDialog>
#include <CryptoNote.h>

namespace Ui {
class ImportTrackingKeyDialog;
Expand All @@ -24,11 +25,16 @@ class ImportTrackingKeyDialog : public QDialog {
QString getKeyString() const;
QString getFilePath() const;
quint32 getSyncHeight() const;
CryptoNote::AccountKeys getAccountKeys() const;

private:
QScopedPointer<Ui::ImportTrackingKeyDialog> m_ui;

CryptoNote::AccountKeys m_keys;

Q_SLOT void selectPathClicked();
Q_SLOT void onTextChanged();
Q_SLOT void onAccept();
};

}
Loading

0 comments on commit 6ac2d60

Please sign in to comment.