22
22
#define DERIV_ACCOUNT 0
23
23
#define DERIV_CHANGE 0
24
24
25
+ #define MAX_ADDR_LEN 42 + 1 // 42 = max length of address + null terminator
26
+ #define NUM_ADDRS 6
27
+
25
28
#define PAGE_LOADING 0
26
29
#define PAGE_INFO 1
27
30
#define PAGE_MNEMONIC 2
32
35
#define PAGE_XPRV_EXTD 7
33
36
#define PAGE_XPUB_EXTD 8
34
37
#define PAGE_ADDR_BEGIN 9
35
- #define PAGE_ADDR_END 14 //18
36
-
37
- #define MAX_ADDR_LEN 42 + 1 // 42 = max length of address + null terminator
38
+ #define PAGE_ADDR_END (PAGE_ADDR_BEGIN + NUM_ADDRS - 1)
38
39
39
40
#define TEXT_LOADING "Loading..."
40
41
#define TEXT_NEW_WALLET "New wallet"
@@ -85,11 +86,11 @@ typedef struct {
85
86
CONFIDENTIAL const char * xpub_account ;
86
87
CONFIDENTIAL const char * xprv_extended ;
87
88
CONFIDENTIAL const char * xpub_extended ;
89
+ char * recv_addresses [NUM_ADDRS ];
88
90
} FlipBipScene1Model ;
89
91
90
92
// Node for the receive address
91
93
static CONFIDENTIAL HDNode * s_addr_node = NULL ;
92
- static char * s_addr_text = NULL ;
93
94
// Generic display text
94
95
static CONFIDENTIAL char * s_disp_text1 = NULL ;
95
96
static CONFIDENTIAL char * s_disp_text2 = NULL ;
@@ -111,6 +112,54 @@ void flipbip_scene_1_set_callback(
111
112
instance -> context = context ;
112
113
}
113
114
115
+ static void flipbip_scene_1_init_address (
116
+ char * addr_text ,
117
+ const HDNode * node ,
118
+ uint32_t coin_type ,
119
+ uint32_t addr_index ) {
120
+ //s_busy = true;
121
+
122
+ // Buffer for address serialization
123
+ const size_t buflen = 40 ;
124
+ char buf [40 + 1 ] = {0 };
125
+
126
+ // Use static node for address generation
127
+ memcpy (s_addr_node , node , sizeof (HDNode ));
128
+ memzero (addr_text , MAX_ADDR_LEN );
129
+
130
+ hdnode_private_ckd (s_addr_node , addr_index );
131
+ hdnode_fill_public_key (s_addr_node );
132
+
133
+ // coin info
134
+ // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
135
+ uint32_t coin_info [6 ] = {0 };
136
+ for (size_t i = 0 ; i < 6 ; i ++ ) {
137
+ coin_info [i ] = COIN_INFO_ARRAY [coin_type ][i ];
138
+ }
139
+
140
+ if (coin_info [5 ] == FlipBipCoinBTC0 ) { // BTC / DOGE style address
141
+ // BTC / DOGE style address
142
+ ecdsa_get_address (
143
+ s_addr_node -> public_key , coin_info [3 ], HASHER_SHA2_RIPEMD , HASHER_SHA2D , buf , buflen );
144
+ strcpy (addr_text , buf );
145
+
146
+ //ecdsa_get_wif(addr_node->private_key, WIF_VERSION, HASHER_SHA2D, buf, buflen);
147
+
148
+ } else if (coin_info [5 ] == FlipBipCoinETH60 ) { // ETH
149
+ // ETH style address
150
+ hdnode_get_ethereum_pubkeyhash (s_addr_node , (uint8_t * )buf );
151
+ addr_text [0 ] = '0' ;
152
+ addr_text [1 ] = 'x' ;
153
+ // Convert the hash to a hex string
154
+ flipbip_btox ((uint8_t * )buf , 20 , addr_text + 2 );
155
+ }
156
+
157
+ // Clear the address node
158
+ memzero (s_addr_node , sizeof (HDNode ));
159
+
160
+ //s_busy = false;
161
+ }
162
+
114
163
static void flipbip_scene_1_draw_generic (const char * text , size_t line_len ) {
115
164
// Split the text into parts
116
165
for (size_t si = 1 ; si <= 6 ; si ++ ) {
@@ -201,55 +250,6 @@ static void flipbip_scene_1_draw_seed(FlipBipScene1Model* const model) {
201
250
free (seed_working );
202
251
}
203
252
204
- static void
205
- flipbip_scene_1_draw_address (const HDNode * node , uint32_t addr_type , uint32_t addr_index ) {
206
- //s_busy = true;
207
-
208
- // Buffer for address serialization
209
- const size_t buflen = 40 ;
210
- char buf [40 + 1 ] = {0 };
211
-
212
- // Use static node for address generation
213
- memcpy (s_addr_node , node , sizeof (HDNode ));
214
- memzero (s_addr_text , MAX_ADDR_LEN );
215
-
216
- hdnode_private_ckd (s_addr_node , addr_index );
217
- hdnode_fill_public_key (s_addr_node );
218
-
219
- // coin info
220
- // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
221
- uint32_t coin_info [6 ] = {0 };
222
- for (size_t i = 0 ; i < 6 ; i ++ ) {
223
- coin_info [i ] = COIN_INFO_ARRAY [addr_type ][i ];
224
- }
225
-
226
- if (coin_info [5 ] == FlipBipCoinBTC0 ) { // BTC / DOGE style address
227
- // BTC / DOGE style address
228
- ecdsa_get_address (
229
- s_addr_node -> public_key , coin_info [3 ], HASHER_SHA2_RIPEMD , HASHER_SHA2D , buf , buflen );
230
-
231
- strcpy (s_addr_text , buf );
232
- flipbip_scene_1_draw_generic (s_addr_text , 12 );
233
-
234
- //ecdsa_get_wif(addr_node->private_key, WIF_VERSION, HASHER_SHA2D, buf, buflen);
235
-
236
- } else if (coin_info [5 ] == FlipBipCoinETH60 ) { // ETH
237
- // ETH style address
238
- hdnode_get_ethereum_pubkeyhash (s_addr_node , (uint8_t * )buf );
239
- s_addr_text [0 ] = '0' ;
240
- s_addr_text [1 ] = 'x' ;
241
- // Convert the hash to a hex string
242
- flipbip_btox ((uint8_t * )buf , 20 , s_addr_text + 2 );
243
-
244
- flipbip_scene_1_draw_generic (s_addr_text , 12 );
245
- }
246
-
247
- // Clear the address node
248
- memzero (s_addr_node , sizeof (HDNode ));
249
-
250
- //s_busy = false;
251
- }
252
-
253
253
static void flipbip_scene_1_clear_text () {
254
254
memzero ((void * )s_disp_text1 , 30 + 1 );
255
255
memzero ((void * )s_disp_text2 , 30 + 1 );
@@ -282,7 +282,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
282
282
} else if (model -> page == PAGE_XPUB_EXTD ) {
283
283
flipbip_scene_1_draw_generic (model -> xpub_extended , 20 );
284
284
} else if (model -> page >= PAGE_ADDR_BEGIN && model -> page <= PAGE_ADDR_END ) {
285
- flipbip_scene_1_draw_address (model -> node , model -> coin , model -> page - PAGE_ADDR_BEGIN );
285
+ flipbip_scene_1_draw_generic (model -> recv_addresses [ model -> page - PAGE_ADDR_BEGIN ], 12 );
286
286
elements_button_right (canvas , TEXT_SAVE_QR );
287
287
}
288
288
@@ -448,6 +448,13 @@ static int flipbip_scene_1_model_init(
448
448
449
449
model -> node = node ;
450
450
451
+ // Initialize addresses
452
+ for (int a = 0 ; a < NUM_ADDRS ; a ++ ) {
453
+ model -> recv_addresses [a ] = malloc (MAX_ADDR_LEN );
454
+ memzero (model -> recv_addresses [a ], MAX_ADDR_LEN );
455
+ flipbip_scene_1_init_address (model -> recv_addresses [a ], node , coin_info [5 ], a );
456
+ }
457
+
451
458
model -> page = PAGE_INFO ;
452
459
453
460
#if USE_BIP39_CACHE
@@ -519,7 +526,9 @@ bool flipbip_scene_1_input(InputEvent* event, void* context) {
519
526
char qrbuf [90 ] = {0 };
520
527
strcpy (qrbuf , TEXT_QRFILE );
521
528
strcpy (qrbuf + strlen (qrbuf ), COIN_TEXT_ARRAY [model -> coin ][2 ]);
522
- strcpy (qrbuf + strlen (qrbuf ), s_addr_text );
529
+ strcpy (
530
+ qrbuf + strlen (qrbuf ),
531
+ model -> recv_addresses [model -> page - PAGE_ADDR_BEGIN ]);
523
532
flipbip_save_settings (qrbuf , FlipBipFileOther , TEXT_QRFILE_EXT , false);
524
533
}
525
534
},
@@ -560,6 +569,10 @@ void flipbip_scene_1_exit(void* context) {
560
569
free ((void * )model -> xpub_account );
561
570
free ((void * )model -> xprv_extended );
562
571
free ((void * )model -> xpub_extended );
572
+ for (int a = 0 ; a < NUM_ADDRS ; a ++ ) {
573
+ memzero ((void * )model -> recv_addresses [a ], MAX_ADDR_LEN );
574
+ free ((void * )model -> recv_addresses [a ]);
575
+ }
563
576
}
564
577
},
565
578
true);
@@ -654,7 +667,6 @@ FlipBipScene1* flipbip_scene_1_alloc() {
654
667
655
668
// allocate the address node
656
669
s_addr_node = (HDNode * )malloc (sizeof (HDNode ));
657
- s_addr_text = (char * )malloc (MAX_ADDR_LEN );
658
670
659
671
// allocate the display text
660
672
s_disp_text1 = (char * )malloc (30 + 1 );
@@ -676,8 +688,6 @@ void flipbip_scene_1_free(FlipBipScene1* instance) {
676
688
// free the address node
677
689
memzero (s_addr_node , sizeof (HDNode ));
678
690
free (s_addr_node );
679
- memzero (s_addr_text , MAX_ADDR_LEN );
680
- free (s_addr_text );
681
691
682
692
// free the display text
683
693
flipbip_scene_1_clear_text ();
0 commit comments