Skip to content

Commit

Permalink
Merge pull request #1 from xtruan/develop
Browse files Browse the repository at this point in the history
ETH wallet and address generation
  • Loading branch information
xtruan authored Mar 4, 2023
2 parents 820aaa5 + 4ea47f6 commit 3925557
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 96 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ The application will be compiled and copied onto your device
- BIP39 mnemonic to BIP39 seed generation
- Hierarchical Deterministic (HD) wallet generation from seed
- Generation of offline `m/44'/0'/0'/0` BTC wallet
- Generation of offline `m/44'/60'/0'/0` ETH wallet (coded from the $SPORK Castle of ETHDenver 2023!)
- Similar features to: https://iancoleman.io/bip39/

### Work in Progress

- Support for BIP39 passphrase
- Currently blank
- Support for custom BIP32 wallet paths
- Support for more custom BIP32 wallet paths
- Currently hardcoded to `m/44'/0'/0'/0`

### (FAR) Future
Expand Down
13 changes: 9 additions & 4 deletions crypto/bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ int hdnode_fill_public_key(HDNode *node) {
#if USE_ETHEREUM
int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash) {
uint8_t buf[65] = {0};
SHA3_CTX ctx = {0};
//SHA3_CTX ctx = {0};
SHA3_CTX *ctx = malloc(sizeof(SHA3_CTX));
memzero(ctx, sizeof(SHA3_CTX));

/* get uncompressed public key */
if (ecdsa_get_public_key65(node->curve->params, node->private_key, buf) !=
Expand All @@ -516,9 +518,12 @@ int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash) {
}

/* compute sha3 of x and y coordinate without 04 prefix */
sha3_256_Init(&ctx);
sha3_Update(&ctx, buf + 1, 64);
keccak_Final(&ctx, buf);
sha3_256_Init(ctx);
sha3_Update(ctx, buf + 1, 64);
keccak_Final(ctx, buf);

memzero(ctx, sizeof(SHA3_CTX));
free(ctx);

/* result are the least significant 160 bits */
memcpy(pubkeyhash, buf + 12, 20);
Expand Down
4 changes: 2 additions & 2 deletions crypto/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

// support Ethereum operations
#ifndef USE_ETHEREUM
#define USE_ETHEREUM 0
#define USE_ETHEREUM 1
#endif

// support NEM operations
Expand All @@ -83,7 +83,7 @@

// support Keccak hashing
#ifndef USE_KECCAK
#define USE_KECCAK 0
#define USE_KECCAK 1
#endif

// add way how to mark confidential data
Expand Down
3 changes: 2 additions & 1 deletion flipbip.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ FlipBip* flipbip_app_alloc() {
view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipbip_custom_event_callback);
app->submenu = submenu_alloc();

// Settings
app->haptic = 1;
//app->speaker = 1;
app->led = 1;
app->bip39_strength = 2; // 256 bits (24 words)
app->bip44_coin = 0; // 0 (BTC)

view_dispatcher_add_view(app->view_dispatcher, FlipBipViewIdMenu, submenu_get_view(app->submenu));
app->flipbip_startscreen = flipbip_startscreen_alloc();
Expand Down
12 changes: 6 additions & 6 deletions flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ typedef struct {
FlipBipScene1* flipbip_scene_1;
// FlipBipScene2* flipbip_scene_2;
int haptic;
// int speaker;
int led;
int bip39_strength;
int bip44_coin;
} FlipBip;

typedef enum {
Expand All @@ -44,11 +44,6 @@ typedef enum {
FlipBipHapticOn,
} FlipBipHapticState;

// typedef enum {
// FlipBipSpeakerOff,
// FlipBipSpeakerOn,
// } FlipBipSpeakerState;

typedef enum {
FlipBipLedOff,
FlipBipLedOn,
Expand All @@ -59,3 +54,8 @@ typedef enum {
FlipBipStrength192,
FlipBipStrength256,
} FlipBipStrengthState;

typedef enum {
FlipBipCoinBTC0,
FlipBipCoinETH60,
} FlipBipCoinState;
7 changes: 6 additions & 1 deletion scenes/flipbip_scene_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ void flipbip_scene_menu_submenu_callback(void* context, uint32_t index) {
void flipbip_scene_menu_on_enter(void* context) {
FlipBip* app = context;

submenu_add_item(app->submenu, "Generate wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
if (app->bip44_coin == FlipBipCoinBTC0) { // BTC
submenu_add_item(app->submenu, "Generate BTC wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
}
if (app->bip44_coin == FlipBipCoinETH60) { // ETH
submenu_add_item(app->submenu, "Generate ETH wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
}
//submenu_add_item(app->submenu, "Scene 2", SubmenuIndexScene2, flipbip_scene_menu_submenu_callback, app);
submenu_add_item(app->submenu, "Settings", SubmenuIndexSettings, flipbip_scene_menu_submenu_callback, app);

Expand Down
56 changes: 28 additions & 28 deletions scenes/flipbip_scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// enum SettingsIndex {
// SettingsIndexBip39Strength = 10,
// SettingsIndexBip44Coin,
// SettingsIndexHaptic,
// SettingsIndexValue1,
// SettingsIndexValue2,
// };

const char* const haptic_text[2] = {
Expand All @@ -17,15 +17,6 @@ const uint32_t haptic_value[2] = {
FlipBipHapticOn,
};

// const char* const speaker_text[2] = {
// "OFF",
// "ON",
// };
// const uint32_t speaker_value[2] = {
// FlipBipSpeakerOff,
// FlipBipSpeakerOn,
// };

const char* const led_text[2] = {
"OFF",
"ON",
Expand All @@ -46,20 +37,22 @@ const uint32_t bip39_strength_value[3] = {
FlipBipStrength256,
};

const char* const bip44_coin_text[2] = {
"BTC",
"ETH",
};
const uint32_t bip44_coin_value[2] = {
FlipBipCoinBTC0,
FlipBipCoinETH60,
};

static void flipbip_scene_settings_set_haptic(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, haptic_text[index]);
app->haptic = haptic_value[index];
}

// static void flipbip_scene_settings_set_speaker(VariableItem* item) {
// FlipBip* app = variable_item_get_context(item);
// uint8_t index = variable_item_get_current_value_index(item);
// variable_item_set_current_value_text(item, speaker_text[index]);
// app->speaker = speaker_value[index];
// }

static void flipbip_scene_settings_set_led(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand All @@ -74,6 +67,13 @@ static void flipbip_scene_settings_set_bip39_strength(VariableItem* item) {
app->bip39_strength = bip39_strength_value[index];
}

static void flipbip_scene_settings_set_bip44_coin(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, bip44_coin_text[index]);
app->bip44_coin = bip44_coin_value[index];
}

void flipbip_scene_settings_submenu_callback(void* context, uint32_t index) {
FlipBip* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
Expand All @@ -95,6 +95,17 @@ void flipbip_scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bip39_strength_text[value_index]);

// BIP44 Coin
item = variable_item_list_add(
app->variable_item_list,
"BIP44 Coin:",
2,
flipbip_scene_settings_set_bip44_coin,
app);
value_index = value_index_uint32(app->bip44_coin, bip44_coin_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bip44_coin_text[value_index]);

// Vibro on/off
item = variable_item_list_add(
app->variable_item_list,
Expand All @@ -106,17 +117,6 @@ void flipbip_scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, haptic_text[value_index]);

// // Sound on/off
// item = variable_item_list_add(
// app->variable_item_list,
// "Sound:",
// 2,
// flipbip_scene_settings_set_speaker,
// app);
// value_index = value_index_uint32(app->speaker, speaker_value, 2);
// variable_item_set_current_value_index(item, value_index);
// variable_item_set_current_value_text(item, speaker_text[value_index]);

// LED Effects on/off
item = variable_item_list_add(
app->variable_item_list,
Expand Down
Loading

0 comments on commit 3925557

Please sign in to comment.