feat: FlipBIP v1.13

This commit is contained in:
Struan Clark
2023-08-11 23:51:28 -06:00
parent 5e710916d6
commit 92a481e770
26 changed files with 127 additions and 456 deletions

View File

@@ -5,10 +5,7 @@
#include <gui/elements.h>
#include <storage/storage.h>
#include <string.h>
#include "flipbip_icons.h"
#include <assets_icons.h>
#include "../helpers/flipbip_haptic.h"
#include "../helpers/flipbip_led.h"
//#include "flipbip_icons.h"
#include "../helpers/flipbip_string.h"
#include "../helpers/flipbip_file.h"
// From: /lib/crypto
@@ -43,7 +40,7 @@
#define TEXT_NEW_WALLET "New wallet"
#define TEXT_DEFAULT_COIN "Coin"
#define TEXT_RECEIVE_ADDRESS "receive address:"
#define TEXT_DEFAULT_DERIV "m/44'/X'/0'/0"
// #define TEXT_DEFAULT_DERIV "m/44'/X'/0'/0"
const char* TEXT_INFO = "-Scroll pages with up/down-"
"p1,2) BIP39 Mnemonic/Seed"
"p3) BIP32 Root Key "
@@ -55,16 +52,19 @@ const char* TEXT_INFO = "-Scroll pages with up/down-"
#define TEXT_QRFILE_EXT ".qrcode" // 7 chars + 1 null
// bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
const uint32_t COIN_INFO_ARRAY[3][6] = {
const uint32_t COIN_INFO_ARRAY[4][6] = {
{COIN_BTC, 0x0488ade4, 0x0488b21e, 0x00, 0x80, FlipBipCoinBTC0},
{COIN_ETH, 0x0488ade4, 0x0488b21e, 0x00, 0x80, FlipBipCoinETH60},
{COIN_DOGE, 0x02fac398, 0x02facafd, 0x1e, 0x9e, FlipBipCoinBTC0}};
{COIN_DOGE, 0x02fac398, 0x02facafd, 0x1e, 0x9e, FlipBipCoinBTC0},
{COIN_ZEC, 0x0488ade4, 0x0488b21e, 0x1cb8, 0x80, FlipBipCoinZEC133},
};
// coin_name, derivation_path
const char* COIN_TEXT_ARRAY[3][3] = {
const char* COIN_TEXT_ARRAY[4][3] = {
{"BTC", "m/44'/0'/0'/0", "bitcoin:"},
{"ETH", "m/44'/60'/0'/0", "ethereum:"},
{"DOGE", "m/44'/3'/0'/0", "dogecoin:"}};
{"DOGE", "m/44'/3'/0'/0", "dogecoin:"},
{"ZEC", "m/44'/133'/0'/0", "zcash:"}};
struct FlipBipScene1 {
View* view;
@@ -98,7 +98,7 @@ static CONFIDENTIAL char* s_disp_text4 = NULL;
static CONFIDENTIAL char* s_disp_text5 = NULL;
static CONFIDENTIAL char* s_disp_text6 = NULL;
// Derivation path text
static const char* s_derivation_text = TEXT_DEFAULT_DERIV;
static const char* s_derivation_text = TEXT_DEFAULT_COIN; // TEXT_DEFAULT_DERIV;
// Warning text
static bool s_warn_insecure = false;
#define WARN_INSECURE_TEXT_1 "Recommendation:"
@@ -147,7 +147,6 @@ static void flipbip_scene_1_init_address(
ecdsa_get_address(
s_addr_node->public_key, coin_info[3], HASHER_SHA2_RIPEMD, HASHER_SHA2D, buf, buflen);
strcpy(addr_text, buf);
//ecdsa_get_wif(addr_node->private_key, WIF_VERSION, HASHER_SHA2D, buf, buflen);
} else if(coin_info[5] == FlipBipCoinETH60) { // ETH
@@ -157,6 +156,12 @@ static void flipbip_scene_1_init_address(
addr_text[1] = 'x';
// Convert the hash to a hex string
flipbip_btox((uint8_t*)buf, 20, addr_text + 2);
} else if(coin_info[5] == FlipBipCoinZEC133) { // ZEC
ecdsa_get_address(
s_addr_node->public_key, coin_info[3], HASHER_SHA2_RIPEMD, HASHER_SHA2D, buf, buflen);
addr_text[0] = 't';
strcpy(addr_text, buf);
}
// Clear the address node
@@ -311,7 +316,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 10, TEXT_LOADING);
canvas_draw_str(canvas, 7, 30, s_derivation_text);
canvas_draw_icon(canvas, 86, 22, &I_Keychain_39x36);
// canvas_draw_icon(canvas, 86, 22, &I_Keychain_39x36);
if(s_warn_insecure) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 50, WARN_INSECURE_TEXT_1);
@@ -654,9 +659,12 @@ void flipbip_scene_1_enter(void* context) {
s_derivation_text = TEXT_NEW_WALLET;
}
flipbip_play_happy_bump(app);
// Wait a beat to allow the display time to update to the loading screen
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
//flipbip_play_happy_bump(app);
//notification_message(app->notification, &sequence_blink_cyan_100);
flipbip_led_set_rgb(app, 255, 0, 0);
//flipbip_led_set_rgb(app, 255, 0, 0);
with_view_model(
instance->view,
@@ -669,7 +677,8 @@ void flipbip_scene_1_enter(void* context) {
// nonzero status, free the mnemonic
if(status != FlipBipStatusSuccess) {
memzero((void*)model->mnemonic, strlen(model->mnemonic));
// calling strlen on mnemonic here can cause a crash, don't.
// it wasn't loaded properly anyways, no need to zero the memory
free((void*)model->mnemonic);
}
@@ -677,15 +686,15 @@ void flipbip_scene_1_enter(void* context) {
if(status == FlipBipStatusSaveError) {
model->mnemonic = "ERROR:,Save error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
} else if(status == FlipBipStatusLoadError) {
model->mnemonic = "ERROR:,Load error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
} else if(status == FlipBipStatusMnemonicCheckError) {
model->mnemonic = "ERROR:,Mnemonic check error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
}
// s_busy = false;

View File

@@ -1,131 +0,0 @@
#include "../flipbip.h"
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include "flipbip_icons.h"
#include <assets_icons.h>
struct FlipBipStartscreen {
View* view;
FlipBipStartscreenCallback callback;
void* context;
};
typedef struct {
int some_value;
} FlipBipStartscreenModel;
void flipbip_startscreen_set_callback(
FlipBipStartscreen* instance,
FlipBipStartscreenCallback callback,
void* context) {
furi_assert(instance);
furi_assert(callback);
instance->callback = callback;
instance->context = context;
}
void flipbip_startscreen_draw(Canvas* canvas, FlipBipStartscreenModel* model) {
UNUSED(model);
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_icon(canvas, 1, 33, &I_Auth_62x31);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 18, 11, "FlipBIP - BIP32/39/44");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 23, 22, "Crypto toolkit for Flipper");
canvas_draw_str(canvas, 99, 34, FLIPBIP_VERSION);
elements_button_right(canvas, "Start");
}
static void flipbip_startscreen_model_init(FlipBipStartscreenModel* const model) {
model->some_value = 1;
}
bool flipbip_startscreen_input(InputEvent* event, void* context) {
furi_assert(context);
FlipBipStartscreen* instance = context;
if(event->type == InputTypeRelease) {
switch(event->key) {
case InputKeyBack:
with_view_model(
instance->view,
FlipBipStartscreenModel * model,
{
UNUSED(model);
instance->callback(FlipBipCustomEventStartscreenBack, instance->context);
},
true);
break;
case InputKeyLeft:
case InputKeyRight:
case InputKeyUp:
case InputKeyDown:
case InputKeyOk:
with_view_model(
instance->view,
FlipBipStartscreenModel * model,
{
UNUSED(model);
instance->callback(FlipBipCustomEventStartscreenOk, instance->context);
},
true);
break;
case InputKeyMAX:
break;
}
}
return true;
}
void flipbip_startscreen_exit(void* context) {
furi_assert(context);
}
void flipbip_startscreen_enter(void* context) {
furi_assert(context);
FlipBipStartscreen* instance = (FlipBipStartscreen*)context;
with_view_model(
instance->view,
FlipBipStartscreenModel * model,
{ flipbip_startscreen_model_init(model); },
true);
}
FlipBipStartscreen* flipbip_startscreen_alloc() {
FlipBipStartscreen* instance = malloc(sizeof(FlipBipStartscreen));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipStartscreenModel));
view_set_context(instance->view, instance); // furi_assert crashes in events without this
view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_startscreen_draw);
view_set_input_callback(instance->view, flipbip_startscreen_input);
//view_set_enter_callback(instance->view, flipbip_startscreen_enter);
//view_set_exit_callback(instance->view, flipbip_startscreen_exit);
with_view_model(
instance->view,
FlipBipStartscreenModel * model,
{ flipbip_startscreen_model_init(model); },
true);
return instance;
}
void flipbip_startscreen_free(FlipBipStartscreen* instance) {
furi_assert(instance);
with_view_model(
instance->view, FlipBipStartscreenModel * model, { UNUSED(model); }, true);
view_free(instance->view);
free(instance);
}
View* flipbip_startscreen_get_view(FlipBipStartscreen* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -1,19 +0,0 @@
#pragma once
#include <gui/view.h>
#include "../helpers/flipbip_custom_event.h"
typedef struct FlipBipStartscreen FlipBipStartscreen;
typedef void (*FlipBipStartscreenCallback)(FlipBipCustomEvent event, void* context);
void flipbip_startscreen_set_callback(
FlipBipStartscreen* flipbip_startscreen,
FlipBipStartscreenCallback callback,
void* context);
View* flipbip_startscreen_get_view(FlipBipStartscreen* flipbip_static);
FlipBipStartscreen* flipbip_startscreen_alloc();
void flipbip_startscreen_free(FlipBipStartscreen* flipbip_static);