mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
add simple gui qt utility
This commit is contained in:
parent
5e9cd15527
commit
322c06bf7b
1
gui/.gitignore
vendored
Normal file
1
gui/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
gui.pro.user
|
11
gui/gui.pro
Normal file
11
gui/gui.pro
Normal file
@ -0,0 +1,11 @@
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = gui
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += ../bip32.c ../bip39.c ../sha2.c ../pbkdf2.c ../hmac.c ../rand.c ../bignum.c ../ecdsa.c ../ripemd160.c ../base58.c ../secp256k1.c mainwindow.cpp main.cpp
|
||||
|
||||
HEADERS += mainwindow.h ../bip32.h ../bip39.h
|
||||
|
||||
FORMS += mainwindow.ui
|
10
gui/main.cpp
Normal file
10
gui/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
66
gui/mainwindow.cpp
Normal file
66
gui/mainwindow.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <QMessageBox>
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
extern "C" {
|
||||
#include "../bip32.h"
|
||||
#include "../bip39.h"
|
||||
#include "../ecdsa.h"
|
||||
}
|
||||
|
||||
HDNode root;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ui->listAddress->insertRow(i);
|
||||
ui->listChange->insertRow(i);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
||||
|
||||
void MainWindow::on_buttonLoad_clicked()
|
||||
{
|
||||
ui->listAccount->clear();
|
||||
if (!mnemonic_check(ui->editMnemonic->text().toLocal8Bit().data())) {
|
||||
QMessageBox::critical(this, "Error", "Text is not a valid BIP39 mnemonic.", QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
uint8_t seed[64];
|
||||
mnemonic_to_seed(ui->editMnemonic->text().toLocal8Bit().data(), ui->editPassphrase->text().toLocal8Bit().data(), seed, 0);
|
||||
hdnode_from_seed(seed, 64, &root);
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
ui->listAccount->addItem(QString("Account #") + QString::number(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_listAccount_clicked(const QModelIndex &index)
|
||||
{
|
||||
const char addr_version = 0x00, wif_version = 0x80;
|
||||
char buf[64];
|
||||
HDNode node;
|
||||
// external chain
|
||||
for (int chain = 0; chain < 2; chain++) {
|
||||
QTableWidget *list = chain == 0 ? ui->listAddress : ui->listChange;
|
||||
node = root;
|
||||
hdnode_private_ckd(&node, 44 | 0x80000000);
|
||||
hdnode_private_ckd(&node, index.row() | 0x80000000);
|
||||
hdnode_private_ckd(&node, chain); // external / internal
|
||||
for (int i = 0; i < 100; i++) {
|
||||
HDNode node2 = node;
|
||||
hdnode_private_ckd(&node2, i);
|
||||
ecdsa_get_address(node2.public_key, addr_version, buf); QString address = QString(buf);
|
||||
ecdsa_get_wif(node2.private_key, wif_version, buf); QString wif = QString(buf);
|
||||
list->setItem(i, 0, new QTableWidgetItem(address));
|
||||
list->setItem(i, 1, new QTableWidgetItem(wif));
|
||||
list->setItem(i, 2, new QTableWidgetItem("0.0"));
|
||||
}
|
||||
}
|
||||
}
|
27
gui/mainwindow.h
Normal file
27
gui/mainwindow.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QModelIndex>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void on_buttonLoad_clicked();
|
||||
void on_listAccount_clicked(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
121
gui/mainwindow.ui
Normal file
121
gui/mainwindow.ui
Normal file
@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>DejaVu Sans Mono</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>TREZOR</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLineEdit" name="editMnemonic"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="editPassphrase">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="buttonLoad">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="2">
|
||||
<widget class="QListWidget" name="listAccount">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<widget class="QTableWidget" name="listAddress">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>address</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>private key</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>balance</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QTableWidget" name="listChange">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>address</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>private key</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>balance</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
<tabstop>editMnemonic</tabstop>
|
||||
<tabstop>buttonLoad</tabstop>
|
||||
<tabstop>listAccount</tabstop>
|
||||
<tabstop>listAddress</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user