@@ -32,7 +32,8 @@ static bool key_iter_is_supported_taproot(const key_iter* iter, const struct wal
3232 return true; // One key, no merkle root, no scripts: OK
3333}
3434
35- static bool key_iter_init (const struct wally_psbt * psbt , const size_t index , const bool is_input , key_iter * iter )
35+ static bool key_iter_init (
36+ const struct wally_psbt * psbt , const size_t index , const bool is_input , const bool is_private , key_iter * iter )
3637{
3738 JADE_ASSERT (psbt );
3839 JADE_ASSERT (index <= (is_input ? psbt -> num_inputs : psbt -> num_outputs ));
@@ -42,6 +43,7 @@ static bool key_iter_init(const struct wally_psbt* psbt, const size_t index, con
4243 iter -> key_index = 0 ;
4344 -- iter -> key_index ; // Incrementing will wrap around to 0 i.e. the first key
4445 iter -> is_input = is_input ;
46+ iter -> is_private = is_private ;
4547 // We are a taproot key iterator only if we have taproot keypaths
4648 if (is_input ) {
4749 iter -> is_taproot = psbt -> inputs [index ].taproot_leaf_paths .num_items != 0 ;
@@ -54,12 +56,12 @@ static bool key_iter_init(const struct wally_psbt* psbt, const size_t index, con
5456
5557bool key_iter_input_begin (const struct wally_psbt * psbt , const size_t index , key_iter * iter )
5658{
57- return key_iter_init (psbt , index , true, iter );
59+ return key_iter_init (psbt , index , /* is_input */ true, /* is_private */ true, iter );
5860}
5961
60- bool key_iter_output_begin (const struct wally_psbt * psbt , const size_t index , key_iter * iter )
62+ bool key_iter_output_begin_public (const struct wally_psbt * psbt , const size_t index , key_iter * iter )
6163{
62- return key_iter_init (psbt , index , false, iter );
64+ return key_iter_init (psbt , index , /* is_input */ false, /* is_private */ false, iter );
6365}
6466
6567static const struct wally_map * key_iter_get_keypaths (const key_iter * iter )
@@ -83,8 +85,15 @@ bool key_iter_next(key_iter* iter)
8385 iter -> is_valid = key_iter_is_supported_taproot (iter , keypaths );
8486 }
8587 if (iter -> is_valid ) {
86- JADE_WALLY_VERIFY (wally_map_keypath_get_bip32_key_from (
87- keypaths , iter -> key_index , & keychain_get ()-> xpriv , & iter -> hdkey , & key_index ));
88+ int ret ;
89+ if (iter -> is_private ) {
90+ ret = wally_map_keypath_get_bip32_key_from (
91+ keypaths , iter -> key_index , & keychain_get ()-> xpriv , & iter -> hdkey , & key_index );
92+ } else {
93+ ret = wally_map_keypath_get_bip32_public_key_from (
94+ keypaths , iter -> key_index , & keychain_get ()-> xpriv , & iter -> hdkey , & key_index );
95+ }
96+ JADE_WALLY_VERIFY (ret );
8897 if (key_index ) {
8998 iter -> is_valid = true; // Found
9099 iter -> key_index = key_index - 1 ; // Adjust to 0-based index
0 commit comments