You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.7 KiB
79 lines
2.7 KiB
![]()
10 years ago
|
#include <QMessageBox>
|
||
|
#include "mainwindow.h"
|
||
|
#include "ui_mainwindow.h"
|
||
|
extern "C" {
|
||
|
#include "../bip32.h"
|
||
|
#include "../bip39.h"
|
||
|
#include "../ecdsa.h"
|
||
![]()
9 years ago
|
#include "../curves.h"
|
||
![]()
10 years ago
|
}
|
||
|
|
||
![]()
10 years ago
|
bool root_set = false;
|
||
![]()
10 years ago
|
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()
|
||
|
{
|
||
|
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);
|
||
![]()
9 years ago
|
hdnode_from_seed(seed, 64, SECP256K1_NAME, &root);
|
||
![]()
10 years ago
|
root_set = true;
|
||
|
ui->spinAccount->setValue(1);
|
||
|
on_spinAccount_valueChanged(1);
|
||
![]()
10 years ago
|
}
|
||
|
|
||
![]()
10 years ago
|
void MainWindow::on_spinAccount_valueChanged(int arg1)
|
||
![]()
10 years ago
|
{
|
||
![]()
10 years ago
|
if (!root_set) return;
|
||
![]()
8 years ago
|
// constants for Bitcoin
|
||
|
const uint32_t version_public = 0x0488b21e;
|
||
|
const uint32_t version_private = 0x0488ade4;
|
||
![]()
10 years ago
|
const char addr_version = 0x00, wif_version = 0x80;
|
||
![]()
9 years ago
|
const size_t buflen = 128;
|
||
|
char buf[buflen + 1];
|
||
![]()
10 years ago
|
HDNode node;
|
||
![]()
8 years ago
|
uint32_t fingerprint;
|
||
![]()
10 years ago
|
// 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);
|
||
![]()
10 years ago
|
hdnode_private_ckd(&node, 0 | 0x80000000); // bitcoin
|
||
|
hdnode_private_ckd(&node, (arg1 - 1) | 0x80000000);
|
||
![]()
8 years ago
|
fingerprint = hdnode_fingerprint(&node);
|
||
![]()
8 years ago
|
hdnode_serialize_private(&node, fingerprint, version_private, buf, buflen); QString xprv = QString(buf); ui->lineXprv->setText(xprv);
|
||
|
hdnode_serialize_public(&node, fingerprint, version_public, buf, buflen); QString xpub = QString(buf); ui->lineXpub->setText(xpub);
|
||
![]()
10 years ago
|
hdnode_private_ckd(&node, chain); // external / internal
|
||
|
for (int i = 0; i < 100; i++) {
|
||
|
HDNode node2 = node;
|
||
|
hdnode_private_ckd(&node2, i);
|
||
![]()
8 years ago
|
hdnode_fill_public_key(&node2);
|
||
![]()
9 years ago
|
ecdsa_get_address(node2.public_key, addr_version, buf, buflen); QString address = QString(buf);
|
||
|
ecdsa_get_wif(node2.private_key, wif_version, buf, buflen); QString wif = QString(buf);
|
||
![]()
10 years ago
|
list->setItem(i, 0, new QTableWidgetItem(address));
|
||
|
list->setItem(i, 1, new QTableWidgetItem(wif));
|
||
|
list->setItem(i, 2, new QTableWidgetItem("0.0"));
|
||
|
}
|
||
|
}
|
||
|
}
|