18
18
#include "../crypto/curves.h"
19
19
#include "../crypto/memzero.h"
20
20
21
+ #define DERIV_PURPOSE 44
22
+ #define DERIV_ACCOUNT 0
23
+ #define DERIV_CHANGE 0
24
+
25
+ #define VERSION_PRIVATE 0x0488ade4
26
+ #define VERSION_PUBLIC 0x0488b21e
27
+ #define ADDR_VERSION 0x00
28
+ #define WIF_VERSION 0x80
29
+
30
+ #define DOGE_VERSION_PRIVATE 0x02fac398
31
+ #define DOGE_VERSION_PUBLIC 0x02facafd
32
+ #define DOGE_ADDR_VERSION 0x1e
33
+ #define DOGE_WIF_VERSION 0x9e
34
+
21
35
struct FlipBipScene1 {
22
36
View * view ;
23
37
FlipBipScene1Callback callback ;
@@ -46,6 +60,7 @@ static CONFIDENTIAL char s_disp_text3[30 + 1];
46
60
static CONFIDENTIAL char s_disp_text4 [30 + 1 ];
47
61
static CONFIDENTIAL char s_disp_text5 [30 + 1 ];
48
62
static CONFIDENTIAL char s_disp_text6 [30 + 1 ];
63
+ static char * s_derivation_text = "m/44'/x'/0'/0" ;
49
64
static bool s_busy = false;
50
65
51
66
void flipbip_scene_1_set_callback (
@@ -137,9 +152,7 @@ static void flipbip_scene_1_draw_mnemonic(const char* mnemonic) {
137
152
static void flipbip_scene_1_draw_seed (FlipBipScene1Model * const model ) {
138
153
char * seed_working = malloc (64 * 2 + 1 );
139
154
// Convert the seed to a hex string
140
- for (size_t i = 0 ; i < 64 ; i ++ ) {
141
- flipbip_btox (model -> seed [i ], seed_working + (i * 2 ));
142
- }
155
+ flipbip_btox (model -> seed , 64 , seed_working );
143
156
144
157
flipbip_scene_1_draw_generic (seed_working , 22 );
145
158
@@ -162,31 +175,33 @@ static void
162
175
hdnode_private_ckd (addr_node , addr_index );
163
176
hdnode_fill_public_key (addr_node );
164
177
165
- if (addr_type == 0 ) { // BTC
166
- // BTC style address
167
- const char addr_version = 0x00 ;
168
- //const char wif_version = 0x80;
169
- ecdsa_get_address (
170
- addr_node -> public_key , addr_version , HASHER_SHA2_RIPEMD , HASHER_SHA2D , buf , buflen );
178
+ if (addr_type == COIN_BTC || addr_type == COIN_DOGE ) { // BTC / DOGE
179
+ if (addr_type == COIN_BTC ) {
180
+ // BTC style address
181
+ ecdsa_get_address (
182
+ addr_node -> public_key , ADDR_VERSION , HASHER_SHA2_RIPEMD , HASHER_SHA2D , buf , buflen );
183
+ } else if (addr_type == COIN_DOGE ) {
184
+ // DOGE style address
185
+ ecdsa_get_address (
186
+ addr_node -> public_key , DOGE_ADDR_VERSION , HASHER_SHA2_RIPEMD , HASHER_SHA2D , buf , buflen );
187
+ }
171
188
172
189
char * address = malloc (buflen + 1 );
173
190
strncpy (address , buf , buflen );
174
191
flipbip_scene_1_draw_generic (address , 12 );
175
192
memzero (address , buflen + 1 );
176
193
free (address );
177
194
178
- //ecdsa_get_wif(addr_node->private_key, wif_version , HASHER_SHA2D, buf, buflen);
195
+ //ecdsa_get_wif(addr_node->private_key, WIF_VERSION , HASHER_SHA2D, buf, buflen);
179
196
//char *wif = malloc(buflen + 1);
180
197
//strncpy(wif, buf, buflen);
181
- } else if (addr_type == 60 ) { // ETH
198
+ } else if (addr_type == COIN_ETH ) { // ETH
182
199
// ETH style address
183
200
hdnode_get_ethereum_pubkeyhash (addr_node , (uint8_t * )buf );
184
201
char * address = malloc (42 + 1 );
185
202
memcpy (address , "0x" , 2 );
186
203
// Convert the hash to a hex string
187
- for (size_t i = 0 ; i < 20 ; i ++ ) {
188
- flipbip_btox (buf [i ], address + 2 + (i * 2 ));
189
- }
204
+ flipbip_btox ((uint8_t * )buf , 20 , address + 2 );
190
205
flipbip_scene_1_draw_generic (address , 12 );
191
206
memzero (address , 42 + 1 );
192
207
free (address );
@@ -242,14 +257,16 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
242
257
if (model -> page == 0 ) {
243
258
canvas_set_font (canvas , FontPrimary );
244
259
canvas_draw_str (canvas , 1 , 10 , "Loading..." );
245
- canvas_draw_str (canvas , 6 , 30 , "m/44'/x'/0'/0" );
260
+ canvas_draw_str (canvas , 6 , 30 , s_derivation_text );
246
261
canvas_draw_icon (canvas , 86 , 25 , & I_Keychain_39x36 );
247
262
} else if (model -> page >= 9 && model -> page <= 13 ) {
248
263
canvas_set_font (canvas , FontSecondary );
249
264
const char * receive_text ;
250
- if (model -> coin == 0 ) { // BTC
265
+ if (model -> coin == COIN_BTC ) { // BTC
251
266
receive_text = "BTC receive address:" ;
252
- } else if (model -> coin == 60 ) { // ETH
267
+ } else if (model -> coin == COIN_DOGE ) { // DOGE
268
+ receive_text = "DOGE receive address:" ;
269
+ } else if (model -> coin == COIN_ETH ) { // ETH
253
270
receive_text = "ETH receive address:" ;
254
271
} else {
255
272
receive_text = "Receive address:" ;
@@ -318,30 +335,17 @@ static int flipbip_scene_1_model_init(
318
335
HDNode * root = malloc (sizeof (HDNode ));
319
336
hdnode_from_seed (model -> seed , 64 , SECP256K1_NAME , root );
320
337
321
- // m/44'/0'/0'/0 or m/44'/60'/0'/0
322
- const uint32_t purpose = 44 ;
323
- //const uint32_t coin = 0; // BTC
324
- //const uint32_t coin = 60; // ETH
325
- const uint32_t account = 0 ;
326
- const uint32_t change = 0 ;
327
-
328
- // constants for BTC / ETH
329
- const uint32_t version_public = 0x0488b21e ;
330
- const uint32_t version_private = 0x0488ade4 ;
331
- // "xprv_magic": 76066276,
332
- // "xpub_magic": 76067358,
333
- // "xpub_magic_segwit_p2sh": 77429938,
334
- // "xpub_magic_segwit_native": 78792518,
335
- // "xpub_magic_multisig_segwit_p2sh": 43365439,
336
- // "xpub_magic_multisig_segwit_native": 44728019,
337
-
338
338
// buffer for key serialization
339
339
const size_t buflen = 128 ;
340
340
char buf [128 + 1 ];
341
341
342
342
// root
343
343
uint32_t fingerprint = 0 ;
344
- hdnode_serialize_private (root , fingerprint , version_private , buf , buflen );
344
+ if (model -> coin == COIN_DOGE ) {
345
+ hdnode_serialize_private (root , fingerprint , DOGE_VERSION_PRIVATE , buf , buflen );
346
+ } else {
347
+ hdnode_serialize_private (root , fingerprint , VERSION_PRIVATE , buf , buflen );
348
+ }
345
349
char * xprv_root = malloc (buflen + 1 );
346
350
strncpy (xprv_root , buf , buflen );
347
351
model -> xprv_root = xprv_root ;
@@ -350,36 +354,52 @@ static int flipbip_scene_1_model_init(
350
354
351
355
// purpose m/44'
352
356
fingerprint = hdnode_fingerprint (node );
353
- hdnode_private_ckd_prime (node , purpose ); // purpose
357
+ hdnode_private_ckd_prime (node , DERIV_PURPOSE ); // purpose
354
358
355
359
// coin m/44'/0' or m/44'/60'
356
360
fingerprint = hdnode_fingerprint (node );
357
361
hdnode_private_ckd_prime (node , model -> coin ); // coin
358
362
359
363
// account m/44'/0'/0' or m/44'/60'/0'
360
364
fingerprint = hdnode_fingerprint (node );
361
- hdnode_private_ckd_prime (node , account ); // account
365
+ hdnode_private_ckd_prime (node , DERIV_ACCOUNT ); // account
362
366
363
- hdnode_serialize_private (node , fingerprint , version_private , buf , buflen );
367
+ if (model -> coin == COIN_DOGE ) {
368
+ hdnode_serialize_private (node , fingerprint , DOGE_VERSION_PRIVATE , buf , buflen );
369
+ } else {
370
+ hdnode_serialize_private (node , fingerprint , VERSION_PRIVATE , buf , buflen );
371
+ }
364
372
char * xprv_acc = malloc (buflen + 1 );
365
373
strncpy (xprv_acc , buf , buflen );
366
374
model -> xprv_account = xprv_acc ;
367
375
368
- hdnode_serialize_public (node , fingerprint , version_public , buf , buflen );
376
+ if (model -> coin == COIN_DOGE ) {
377
+ hdnode_serialize_public (node , fingerprint , DOGE_VERSION_PUBLIC , buf , buflen );
378
+ } else {
379
+ hdnode_serialize_public (node , fingerprint , VERSION_PUBLIC , buf , buflen );
380
+ }
369
381
char * xpub_acc = malloc (buflen + 1 );
370
382
strncpy (xpub_acc , buf , buflen );
371
383
model -> xpub_account = xpub_acc ;
372
384
373
385
// external/internal (change) m/44'/0'/0'/0 or m/44'/60'/0'/0
374
386
fingerprint = hdnode_fingerprint (node );
375
- hdnode_private_ckd (node , change ); // external/internal (change)
387
+ hdnode_private_ckd (node , DERIV_CHANGE ); // external/internal (change)
376
388
377
- hdnode_serialize_private (node , fingerprint , version_private , buf , buflen );
389
+ if (model -> coin == COIN_DOGE ) {
390
+ hdnode_serialize_private (node , fingerprint , DOGE_VERSION_PRIVATE , buf , buflen );
391
+ } else {
392
+ hdnode_serialize_private (node , fingerprint , VERSION_PRIVATE , buf , buflen );
393
+ }
378
394
char * xprv_ext = malloc (buflen + 1 );
379
395
strncpy (xprv_ext , buf , buflen );
380
396
model -> xprv_extended = xprv_ext ;
381
397
382
- hdnode_serialize_public (node , fingerprint , version_public , buf , buflen );
398
+ if (model -> coin == COIN_DOGE ) {
399
+ hdnode_serialize_public (node , fingerprint , DOGE_VERSION_PUBLIC , buf , buflen );
400
+ } else {
401
+ hdnode_serialize_public (node , fingerprint , VERSION_PUBLIC , buf , buflen );
402
+ }
383
403
char * xpub_ext = malloc (buflen + 1 );
384
404
strncpy (xpub_ext , buf , buflen );
385
405
model -> xpub_extended = xpub_ext ;
@@ -504,9 +524,14 @@ void flipbip_scene_1_enter(void* context) {
504
524
strength = 192 ; // 18 words (192 bit)
505
525
506
526
// BIP44 Coin setting
507
- int coin_setting = app -> bip44_coin ;
508
- uint32_t coin = 0 ; //FlipBipCoinBTC0 // BTC (0)
509
- if (coin_setting == FlipBipCoinETH60 ) coin = 60 ; // ETH (60)
527
+ uint32_t coin = app -> bip44_coin ;
528
+ if (coin == COIN_BTC ) {
529
+ s_derivation_text = "m/44'/0'/0'/0" ;
530
+ } else if (coin == COIN_DOGE ) {
531
+ s_derivation_text = "m/44'/3'/0'/0" ;
532
+ } else if (coin == COIN_ETH ) {
533
+ s_derivation_text = "m/44'/60'/0'/0" ;
534
+ }
510
535
511
536
// Overwrite the saved seed with a new one setting
512
537
bool overwrite = app -> overwrite_saved_seed != 0 ;
0 commit comments