From 14568118429d086b91084921d4e7065d0bc7c845 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Wed, 31 Jul 2019 14:31:10 -0700 Subject: [PATCH] Handle case where private keys are multiline --- src/mainwindow.cpp | 12 +++++++++++- src/settings.cpp | 10 ++++++++++ src/settings.h | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ea7f52a..25b9d30 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -830,7 +830,7 @@ void MainWindow::doImport(QList* keys) { keys->pop_front(); bool rescan = keys->isEmpty(); - if (key.startsWith("S") || + if (key.startsWith("SK") || key.startsWith("secret")) { // Z key rpc->importZPrivKey(key, rescan, [=] (auto) { this->doImport(keys); }); } else { @@ -954,6 +954,16 @@ void MainWindow::importPrivKey() { return key.trimmed().split(" ")[0]; }); + // Special case. + // Sometimes, when importing from a paperwallet or such, the key is split by newlines, and might have + // been pasted like that. So check to see if the whole thing is one big private key + if (Settings::getInstance()->isValidSaplingPrivateKey(keys->join(""))) { + auto multiline = keys; + keys = new QList(); + keys->append(multiline->join("")); + delete multiline; + } + // Start the import. The function takes ownership of keys QTimer::singleShot(1, [=]() {doImport(keys);}); diff --git a/src/settings.cpp b/src/settings.cpp index fec889f..72e2b1b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -328,6 +328,16 @@ QString Settings::getZboardAddr() { } } +bool Settings::isValidSaplingPrivateKey(QString pk) { + if (isTestnet()) { + QRegExp zspkey("^secret-extended-key-test[0-9a-z]{278}$", Qt::CaseInsensitive); + return zspkey.exactMatch(pk); + } else { + QRegExp zspkey("^secret-extended-key-main[0-9a-z]{278}$", Qt::CaseInsensitive); + return zspkey.exactMatch(pk); + } +} + bool Settings::isValidAddress(QString addr) { QRegExp zcexp("^z[a-z0-9]{94}$", Qt::CaseInsensitive); QRegExp zsexp("^z[a-z0-9]{77}$", Qt::CaseInsensitive); diff --git a/src/settings.h b/src/settings.h index 612fe4b..4250644 100644 --- a/src/settings.h +++ b/src/settings.h @@ -37,6 +37,8 @@ public: bool isSaplingAddress(QString addr); bool isSproutAddress(QString addr); + bool isValidSaplingPrivateKey(QString pk); + bool isSyncing(); void setSyncing(bool syncing);