forked from ciphrex/mSIGNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeychainbackupwizard.cpp
102 lines (81 loc) · 2.96 KB
/
keychainbackupwizard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
///////////////////////////////////////////////////////////////////////////////
//
// mSIGNA
//
// keychainbackupwizard.cpp
//
// Copyright (c) 2015 Eric Lombrozo
//
// All Rights Reserved.
#include "keychainbackupwizard.h"
#include "wordlistvalidator.h"
#include <CoinCore/bip39.h>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPlainTextEdit>
#include <QLineEdit>
#include <QLabel>
#include <stdexcept>
KeychainBackupWizard::KeychainBackupWizard(const QString& name, const secure_bytes_t& seed, QWidget* parent)
: QWizard(parent)
{
addPage(new WordlistViewPage(name, seed));
addPage(new WordlistVerifyPage(name, seed));
addPage(new WordlistCompletePage(name));
setWindowTitle(tr("Keychain Backup"));
}
WordlistViewPage::WordlistViewPage(const QString& name, const secure_bytes_t& seed, QWidget* parent)
: QWizardPage(parent)
{
setTitle(tr("Step 1: Copy"));
setSubTitle(tr("Keychain: ") + name);
QLabel* promptLabel = new QLabel(tr("IMPORTANT: Please write down the following list of words. In the event you lose your data you can recover your keychain by entering this list."));
promptLabel->setWordWrap(true);
wordlistEdit = new QPlainTextEdit();
wordlistEdit->setReadOnly(true);
wordlistEdit->setPlainText(Coin::BIP39::toWordlist(seed).c_str());
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(promptLabel);
layout->addWidget(wordlistEdit);
setLayout(layout);
}
WordlistVerifyPage::WordlistVerifyPage(const QString& name, const secure_bytes_t& seed, QWidget* parent)
: QWizardPage(parent)
{
using namespace Coin;
setTitle(tr("Step 2: Verify"));
setSubTitle(tr("Keychain: ") + name);
QLabel* promptLabel = new QLabel(tr("Please enter the words in the correct order below:"));
promptLabel->setWordWrap(true);
wordlist = BIP39::toWordlist(seed).c_str();
wordlistEdit = new QLineEdit();
wordlistEdit->setValidator(new WordlistValidator(BIP39::minWordLen(), BIP39::maxWordLen(), this));
QObject::connect(wordlistEdit, &QLineEdit::textChanged, [=]() { emit completeChanged(); });
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(promptLabel);
layout->addWidget(wordlistEdit);
setLayout(layout);
}
/*
void WordlistVerifyPage::keyPressEvent(QKeyEvent* event)
{
QWizardPage::keyPressEvent(event);
}
*/
bool WordlistVerifyPage::isComplete() const
{
// TODO: convert to lowercase and disallow invalid characters and additional whitespace
return (wordlist == wordlistEdit->text());
}
WordlistCompletePage::WordlistCompletePage(const QString& name, QWidget* parent)
: QWizardPage(parent)
{
setTitle(tr("Step 3: Put in safe, secure place"));
setSubTitle(tr("Keychain: ") + name);
QLabel* promptLabel = new QLabel(tr("IMPORTANT: Keep the wordlist in a safe place."));
promptLabel->setWordWrap(true);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(promptLabel);
setLayout(layout);
}