@@ -930,6 +930,9 @@ static gui_activity_t* make_export_xpub_prompt_activity(void) {
930
930
931
931
static bool export_usb_xpub_fn (const usbstorage_action_context_t * ctx ) {
932
932
933
+ bool ok = false;
934
+ char * fphex = NULL ;
935
+ char * xpub = NULL ;
933
936
uint32_t qr_flags = storage_get_qr_flags ();
934
937
935
938
while (true) {
@@ -943,19 +946,16 @@ static bool export_usb_xpub_fn(const usbstorage_action_context_t* ctx) {
943
946
handle_xpub_options (& qr_flags );
944
947
}
945
948
else if (ev == BTN_SETTINGS_USBSTORAGE_EXPORT_XPUB_ACTION ) {
946
-
947
- goto DO_EXPORT ;
949
+ break ;
948
950
}
949
951
else if (ev == BTN_SETTINGS_EXPORT_XPUB_BACK ) {
950
- goto EXIT_EXPORT_XPUB ;
952
+ return true ;
951
953
}
952
954
else {
953
955
return false;
954
956
}
955
957
956
958
}
957
-
958
- DO_EXPORT :
959
959
const script_variant_t script_variant = xpub_script_variant_from_flags (qr_flags );
960
960
const uint16_t account_index = qr_flags >> ACCOUNT_INDEX_FLAGS_SHIFT ;
961
961
@@ -980,31 +980,34 @@ static bool export_usb_xpub_fn(const usbstorage_action_context_t* ctx) {
980
980
EXPORT_XPUB_PATH_LEN ,
981
981
& path_len );
982
982
983
- char * xpub = NULL ;
984
983
network_t network_id ;
985
984
if (keychain_get_network_type_restriction () == NETWORK_TYPE_TEST ) {
986
985
network_id = NETWORK_BITCOIN_TESTNET ;
987
986
} else {
988
987
network_id = NETWORK_BITCOIN ;
989
988
}
989
+
990
990
if (!wallet_get_xpub (network_id , path , path_len , & xpub ) || xpub == NULL ) {
991
- //await_error_activity((const char*[]){"Unable to derive xpub"}, 1);
992
- return false;
991
+ const char * msg [] = { "unable to get" , "xpub from path" };
992
+ await_error_activity (msg , 2 );
993
+ goto cleanup ;
993
994
}
994
995
995
996
char pathstr [MAX_PATH_STR_LEN (EXPORT_XPUB_PATH_LEN )];
996
997
const bool ret = wallet_bip32_path_as_str (path , path_len , pathstr , sizeof (pathstr ));
997
998
998
999
JADE_ASSERT (ret );
999
1000
1000
- // get fingerprint
1001
- // then take the whole string and put it together with
1002
- // scriptvariant([fingerprint/84'/0'accountindex]xpub/0/*)
1003
1001
uint8_t user_fingerprint [BIP32_KEY_FINGERPRINT_LEN ];
1004
1002
wallet_get_fingerprint (user_fingerprint , sizeof (user_fingerprint ));
1005
1003
1006
- char * fphex = NULL ;
1007
- wally_hex_from_bytes (user_fingerprint , sizeof (user_fingerprint ), & fphex );
1004
+ JADE_WALLY_VERIFY (wally_hex_from_bytes (user_fingerprint , sizeof (user_fingerprint ), & fphex ));
1005
+ if (!fphex ) {
1006
+ const char * msg [] = { "unable to get" , "fingerprint from wallet" };
1007
+ await_error_activity (msg , 2 );
1008
+ goto cleanup ;
1009
+ };
1010
+
1008
1011
map_string (fphex , toupper );
1009
1012
1010
1013
char descriptor [512 ];
@@ -1027,7 +1030,7 @@ static bool export_usb_xpub_fn(const usbstorage_action_context_t* ctx) {
1027
1030
if (written != (size_t )n ) {
1028
1031
const char * msg [] = { "Failed to save" , "xpub file" };
1029
1032
await_error_activity (msg , 2 );
1030
- return false ;
1033
+ goto cleanup ;
1031
1034
}
1032
1035
1033
1036
size_t mountlen = strlen (USBSTORAGE_MOUNT_POINT );
@@ -1036,9 +1039,11 @@ static bool export_usb_xpub_fn(const usbstorage_action_context_t* ctx) {
1036
1039
outpath + mountlen + 1
1037
1040
};
1038
1041
await_message_activity (msg , 2 );
1039
- return true;
1040
- EXIT_EXPORT_XPUB :
1041
- return true;
1042
+ ok = true;
1043
+ cleanup :
1044
+ if (xpub ) wally_free_string (xpub );
1045
+ if (fphex ) wally_free_string (fphex );
1046
+ return ok ;
1042
1047
}
1043
1048
1044
1049
bool usbstorage_export_xpub (const char * extra_path ) {
0 commit comments