Wizard: add seed passphrase to wallet creation

This commit is contained in:
tobtoht 2022-05-25 12:59:28 +02:00
parent 1f90825a5b
commit 13c3e9b8e2
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
12 changed files with 211 additions and 13 deletions

View file

@ -565,6 +565,7 @@ void WindowManager::showWizard(WalletWizard::Page startPage) {
m_wizard = this->createWizard(startPage);
}
m_wizard->resetFields();
m_wizard->setStartId(startPage);
m_wizard->restart();
m_wizard->setEnabled(true);

View file

@ -77,6 +77,8 @@ Seed::Seed(Type type, QStringList mnemonic, NetworkType::Type networkType)
this->time = seed.birthday();
this->setRestoreHeight();
this->encrypted = seed.encrypted();
}
catch (const std::exception &e) {
this->errorString = e.what();

View file

@ -38,6 +38,8 @@ struct Seed {
QString errorString;
bool encrypted = false;
explicit Seed();
explicit Seed(Type type, NetworkType::Type networkType = NetworkType::MAINNET, QString language = "English");
explicit Seed(Type type, QStringList mnemonic, NetworkType::Type networkType = NetworkType::MAINNET);

View file

@ -0,0 +1,29 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#include "PageSetSeedPassphrase.h"
#include "ui_PageSetSeedPassphrase.h"
#include "WalletWizard.h"
PageSetSeedPassphrase::PageSetSeedPassphrase(WizardFields *fields, QWidget *parent)
: QWizardPage(parent)
, ui(new Ui::PageSetSeedPassphrase)
, m_fields(fields)
{
ui->setupUi(this);
this->setTitle("Seed Passphrase");
}
void PageSetSeedPassphrase::initializePage() {
ui->linePassphrase->setText("");
}
bool PageSetSeedPassphrase::validatePage() {
m_fields->seedOffsetPassphrase = ui->linePassphrase->text();
return true;
}
int PageSetSeedPassphrase::nextId() const {
return WalletWizard::Page_WalletFile;
}

View file

@ -0,0 +1,34 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#ifndef FEATHER_PAGESETSEEDPASSPHRASE_H
#define FEATHER_PAGESETSEEDPASSPHRASE_H
#include <QWizardPage>
#include <QWidget>
#include "appcontext.h"
#include "WalletWizard.h"
namespace Ui {
class PageSetSeedPassphrase;
}
class PageSetSeedPassphrase : public QWizardPage
{
Q_OBJECT
public:
explicit PageSetSeedPassphrase(WizardFields *fields, QWidget *parent = nullptr);
void initializePage() override;
bool validatePage() override;
int nextId() const override;
private:
Ui::PageSetSeedPassphrase *ui;
WizardFields *m_fields;
};
#endif //FEATHER_PAGESETSEEDPASSPHRASE_H

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PageSetSeedPassphrase</class>
<widget class="QWizardPage" name="PageSetSeedPassphrase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>710</width>
<height>524</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>You may extend your seed with a passphrase.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>This is referred to as the &quot;seed offset passphrase&quot;, or simply seed passphrase.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Your seed and seed passphrase are both required to restore your wallet.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="linePassphrase"/>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Note that this is NOT your wallet password.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>If you do not know what this is, leave this field empty.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -61,6 +61,7 @@ PageWalletRestoreSeed::PageWalletRestoreSeed(WizardFields *fields, QWidget *pare
this->onSeedTypeToggled();
}
void PageWalletRestoreSeed::onSeedTypeToggled() {
if (ui->radio16->isChecked()) {
m_mode = &m_polyseed;
@ -140,6 +141,11 @@ bool PageWalletRestoreSeed::validatePage() {
Seed _seed = Seed(m_fields->seedType, seedSplit, constants::networkType);
if (_seed.encrypted) {
QMessageBox::warning(this, "Encrypted seed", QString("This seed is encrypted. Encrypted seeds are not supported"));
return false;
}
if (!_seed.errorString.isEmpty()) {
QMessageBox::warning(this, "Invalid seed", QString("Invalid seed:\n\n%1").arg(_seed.errorString));
ui->seedEdit->setStyleSheet(errStyle);

View file

@ -8,6 +8,9 @@
#include "Seed.h"
#include <QMessageBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QDialogButtonBox>
PageWalletSeed::PageWalletSeed(WizardFields *fields, QWidget *parent)
: QWizardPage(parent)
@ -32,6 +35,7 @@ PageWalletSeed::PageWalletSeed(WizardFields *fields, QWidget *parent)
connect(ui->btnCopy, &QPushButton::clicked, [this]{
Utils::copyToClipboard(m_seed.mnemonic.join(" "));
});
connect(ui->btnOptions, &QPushButton::clicked, this, &PageWalletSeed::onOptionsClicked);
}
void PageWalletSeed::initializePage() {
@ -89,7 +93,26 @@ void PageWalletSeed::displaySeed(const QString &seed){
ui->seedWord16->setText(seedSplit[15]);
}
void PageWalletSeed::onOptionsClicked() {
QDialog dialog(this);
QVBoxLayout layout;
QCheckBox checkbox("Extend this seed with a passphrase");
checkbox.setChecked(m_fields->seedOffsetPassphraseEnabled);
layout.addWidget(&checkbox);
QDialogButtonBox buttons(QDialogButtonBox::Ok);
layout.addWidget(&buttons);
dialog.setLayout(&layout);
connect(&buttons, &QDialogButtonBox::accepted, [&dialog]{
dialog.close();
});
dialog.exec();
m_fields->seedOffsetPassphraseEnabled = checkbox.isChecked();
}
int PageWalletSeed::nextId() const {
if (m_fields->seedOffsetPassphraseEnabled) {
return WalletWizard::Page_SetSeedPassphrase;
}
return WalletWizard::Page_WalletFile;
}

View file

@ -31,6 +31,7 @@ public slots:
private:
void seedRoulette(int count);
void generateSeed();
void onOptionsClicked();
signals:
void createWallet();

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>654</width>
<height>594</height>
<width>777</width>
<height>658</height>
</rect>
</property>
<property name="windowTitle">
@ -129,16 +129,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Please take note that mnemonic seeds now consist of 16 words instead of 14.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
@ -891,6 +881,9 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_21"/>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
@ -906,6 +899,13 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="btnOptions">
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View file

@ -13,6 +13,7 @@
#include "PageWalletRestoreKeys.h"
#include "PageSetPassword.h"
#include "PageSetRestoreHeight.h"
#include "PageSetSeedPassphrase.h"
#include "PageHardwareDevice.h"
#include "PageNetworkTor.h"
#include "constants.h"
@ -37,6 +38,7 @@ WalletWizard::WalletWizard(QWidget *parent)
auto createWallet = new PageWalletFile(&m_wizardFields , this);
auto createWalletSeed = new PageWalletSeed(&m_wizardFields, this);
auto walletSetPasswordPage = new PageSetPassword(&m_wizardFields, this);
auto walletSetSeedPassphrasePage = new PageSetSeedPassphrase(&m_wizardFields, this);
setPage(Page_Menu, menuPage);
setPage(Page_WalletFile, createWallet);
setPage(Page_OpenWallet, openWalletPage);
@ -48,6 +50,7 @@ WalletWizard::WalletWizard(QWidget *parent)
setPage(Page_WalletRestoreKeys, new PageWalletRestoreKeys(&m_wizardFields, this));
setPage(Page_SetRestoreHeight, new PageSetRestoreHeight(&m_wizardFields, this));
setPage(Page_HardwareDevice, new PageHardwareDevice(&m_wizardFields, this));
setPage(Page_SetSeedPassphrase, walletSetSeedPassphrasePage);
setStartId(Page_Menu);
@ -79,6 +82,10 @@ WalletWizard::WalletWizard(QWidget *parent)
});
}
void WalletWizard::resetFields() {
m_wizardFields = {};
}
void WalletWizard::onCreateWallet() {
auto walletPath = QString("%1/%2").arg(m_wizardFields.walletDir, m_wizardFields.walletName);
@ -127,4 +134,4 @@ void WalletWizard::onCreateWallet() {
}
emit createWallet(m_wizardFields.seed, walletPath, m_wizardFields.password, m_wizardFields.seedLanguage, m_wizardFields.seedOffsetPassphrase);
}
}

View file

@ -31,6 +31,7 @@ struct WizardFields {
QString walletName;
QString walletDir;
Seed seed;
bool seedOffsetPassphraseEnabled = false;
QString seedOffsetPassphrase;
QString seedLanguage = constants::seedLanguage;
QString password;
@ -42,6 +43,9 @@ struct WizardFields {
int restoreHeight = 0;
Seed::Type seedType;
DeviceType deviceType;
WizardFields(): deviceType(DeviceType::LEDGER), mode(WizardMode::CreateWallet),
seedType(Seed::POLYSEED), seedOffsetPassphraseEnabled(false), restoreHeight(0) {}
};
class WalletWizard : public QWizard
@ -53,6 +57,7 @@ public:
Page_Menu,
Page_WalletFile,
Page_CreateWalletSeed,
Page_SetSeedPassphrase,
Page_SetPasswordPage,
Page_OpenWallet,
Page_Network,
@ -64,6 +69,7 @@ public:
};
explicit WalletWizard(QWidget *parent = nullptr);
void resetFields();
signals:
void initialNetworkConfigured();