|
|
@@ -11,10 +11,10 @@
|
|
|
|
|
|
#include <string.h>
|
|
|
#include "../helpers/printf.h"
|
|
|
-// #include "../crypto/bip32.h"
|
|
|
+#include "../crypto/bip32.h"
|
|
|
#include "../crypto/bip39.h"
|
|
|
// #include "../crypto/ecdsa.h"
|
|
|
-// #include "../crypto/curves.h"
|
|
|
+#include "../crypto/curves.h"
|
|
|
#include "../crypto/memzero.h"
|
|
|
|
|
|
struct FlipBip39Scene1 {
|
|
|
@@ -90,7 +90,7 @@ static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, cons
|
|
|
|
|
|
// Generate a random mnemonic using trezor-crypto
|
|
|
model->strength = strength;
|
|
|
- const char* mnemonic = mnemonic_generate(model->strength);
|
|
|
+ const char *mnemonic = mnemonic_generate(model->strength);
|
|
|
|
|
|
// Delineate sections of the mnemonic every 4 words
|
|
|
char *mnemo = malloc(strlen(mnemonic) + 1);
|
|
|
@@ -150,45 +150,57 @@ static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, cons
|
|
|
// WIP / TODO: Generate a BIP32 root key from the mnemonic
|
|
|
|
|
|
// //bool root_set = false;
|
|
|
- // HDNode root;
|
|
|
- // hdnode_from_seed(seed, 64, SECP256K1_NAME, &root);
|
|
|
+ HDNode *root = malloc(sizeof(HDNode));
|
|
|
+ hdnode_from_seed(seedbytes, 64, SECP256K1_NAME, root);
|
|
|
// //root_set = true;
|
|
|
|
|
|
- // int arg1 = 1;
|
|
|
- // // constants for Bitcoin
|
|
|
- // const uint32_t version_public = 0x0488b21e;
|
|
|
- // const uint32_t version_private = 0x0488ade4;
|
|
|
- // const char addr_version = 0x00, wif_version = 0x80;
|
|
|
- // const size_t buflen = 128;
|
|
|
- // char buf[buflen + 1];
|
|
|
- // HDNode node;
|
|
|
- // uint32_t fingerprint;
|
|
|
- // // 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, 0 | 0x80000000); // bitcoin
|
|
|
- // hdnode_private_ckd(&node, (arg1 - 1) | 0x80000000);
|
|
|
- // fingerprint = hdnode_fingerprint(&node);
|
|
|
- // 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);
|
|
|
- // hdnode_private_ckd(&node, chain); // external / internal
|
|
|
- // for (int i = 0; i < 10; i++) {
|
|
|
- // HDNode node2 = node;
|
|
|
- // hdnode_private_ckd(&node2, i);
|
|
|
- // hdnode_fill_public_key(&node2);
|
|
|
- // ecdsa_get_address(node2.public_key, addr_version, HASHER_SHA2_RIPEMD, HASHER_SHA2D, buf, buflen);
|
|
|
- // //QString address = QString(buf);
|
|
|
- // ecdsa_get_wif(node2.private_key, wif_version, HASHER_SHA2D, buf, buflen);
|
|
|
- // //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"));
|
|
|
- // }
|
|
|
- // }
|
|
|
+ int arg1 = 1;
|
|
|
+ // constants for Bitcoin
|
|
|
+ const uint32_t version_public = 0x0488b21e;
|
|
|
+ const uint32_t version_private = 0x0488ade4;
|
|
|
+ //const char addr_version = 0x00, wif_version = 0x80;
|
|
|
+ const size_t buflen = 128;
|
|
|
+ char buf[buflen + 1];
|
|
|
+ //HDNode node;
|
|
|
+ uint32_t fingerprint;
|
|
|
+ // external chain
|
|
|
+ for (int chain = 0; chain < 2; chain++) {
|
|
|
+ //QTableWidget *list = chain == 0 ? ui->listAddress : ui->listChange;
|
|
|
+ HDNode *node = root;
|
|
|
+ hdnode_private_ckd(node, 44 | 0x80000000);
|
|
|
+ hdnode_private_ckd(node, 0 | 0x80000000); // bitcoin
|
|
|
+ hdnode_private_ckd(node, (arg1 - 1) | 0x80000000);
|
|
|
+ fingerprint = hdnode_fingerprint(node);
|
|
|
+ hdnode_serialize_private(node, fingerprint, version_private, buf, buflen);
|
|
|
+ char *xprv = malloc(22 + 1);
|
|
|
+ strncpy(xprv, buf, 22);
|
|
|
+ if (chain == 0) model->seed3 = xprv;
|
|
|
+ if (chain == 1) model->seed4 = xprv;
|
|
|
+ //QString xprv = QString(buf); ui->lineXprv->setText(xprv);
|
|
|
+ hdnode_serialize_public(node, fingerprint, version_public, buf, buflen);
|
|
|
+ char *xpub = malloc(22 + 1);
|
|
|
+ strncpy(xpub, buf, 22);
|
|
|
+ if (chain == 0) model->seed5 = xpub;
|
|
|
+ if (chain == 1) model->seed6 = xpub;
|
|
|
+ //QString xpub = QString(buf); ui->lineXpub->setText(xpub);
|
|
|
+ // hdnode_private_ckd(&node, chain); // external / internal
|
|
|
+ // for (int i = 0; i < 10; i++) {
|
|
|
+ // HDNode node2 = node;
|
|
|
+ // hdnode_private_ckd(&node2, i);
|
|
|
+ // hdnode_fill_public_key(&node2);
|
|
|
+ // ecdsa_get_address(node2.public_key, addr_version, HASHER_SHA2_RIPEMD, HASHER_SHA2D, buf, buflen);
|
|
|
+ // //QString address = QString(buf);
|
|
|
+ // ecdsa_get_wif(node2.private_key, wif_version, HASHER_SHA2D, buf, buflen);
|
|
|
+ // //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"));
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear the root node
|
|
|
+ memzero(root, sizeof(HDNode));
|
|
|
+ free(root);
|
|
|
|
|
|
// Clear the mnemonic
|
|
|
mnemonic_clear();
|