Airgapped hardware wallet based on STM32F469-Discovery board using SD card to pass transaction data

Dependencies:   mbed QSPI_DISCO_F469NI BSP_DISCO_F469NI

Revision:
1:b88ef7630eb3
Parent:
0:f43431023689
Child:
2:120e0ca2f3a7
--- a/main.cpp	Sat Jul 20 15:16:38 2019 +0000
+++ b/main.cpp	Sat Jul 20 16:18:54 2019 +0000
@@ -44,6 +44,7 @@
 
 /***************** bitcoin keys ***************/
 
+string mnemonic;
 HDPrivateKey root; // root private key
 HDPrivateKey account; // account master private key
 HDPublicKey xpub; // account master public key
@@ -369,7 +370,54 @@
     return LV_RES_OK;
 }
 
+static const char * keys[] = {"q","w","e","r","t","y","u","i","o","p","\n",
+                              "a","s","d","f","g","h","j","k","l","\n",
+                              " ","z","x","c","v","b","n","m","<",""};
+
+static lv_res_t typeCallback(lv_obj_t * btn, const char * key){
+    if(key[0] == '<'){
+        if(mnemonic.length() > 0){
+            mnemonic = mnemonic.substr(0,mnemonic.length()-1);
+        }
+    }else{
+        mnemonic += key;
+    }
+    dataLbl.text(mnemonic);
+    return LV_RES_OK;
+}
+
+static lv_res_t checkMnemonicCallback(lv_obj_t * btn){
+    if(checkMnemonic(mnemonic.c_str())){
+        saveMnemonic(mnemonic);
+        initKeys(mnemonic);
+        showMessage("Mnemonic is ok", "Recovered sucessfully");
+    }else{
+        mnemonic = "";
+        dataLbl.text(mnemonic);
+    }
+    return LV_RES_OK;
+}
+
 static lv_res_t enterMnemonicCallback(lv_obj_t * btn){
+    gui.clear();
+    mnemonic = "";
+    titleLbl = Label("Enter your mnemonic");
+    titleLbl.size(gui.width(), 20);
+    titleLbl.position(0, 40);
+    titleLbl.alignText(ALIGN_TEXT_CENTER);
+
+    dataLbl = Label(mnemonic);
+    dataLbl.size(gui.width()-100, 50);
+    dataLbl.position(50, 200);
+    dataLbl.alignText(ALIGN_TEXT_CENTER);
+
+    Keyboard kb(typeCallback, keys);
+    kb.size(gui.width(), gui.height()/3);
+    kb.position(0, gui.height()*2/3-150);
+
+    Button btnx(checkMnemonicCallback, "Continue");
+    btnx.size(gui.width()-100, 80);
+    btnx.position(50, gui.height()-100);
     return LV_RES_OK;
 }