@@ -654,6 +654,22 @@ bool wallet_get_gaservice_path(
654654 return true;
655655}
656656
657+ bool wallet_get_gaservice_root_key (
658+ const struct ext_key * const service , const bool subaccount_root , struct ext_key * gakey )
659+ {
660+ if (!service || !gakey ) {
661+ return false;
662+ }
663+
664+ uint32_t root_path [GASERVICE_ROOT_PATH_LEN ];
665+ wallet_get_gaservice_path_root (subaccount_root , root_path , GASERVICE_ROOT_PATH_LEN );
666+
667+ JADE_WALLY_VERIFY (
668+ bip32_key_from_parent_path (service , root_path , GASERVICE_ROOT_PATH_LEN , BIP32_FLAG_KEY_PUBLIC , gakey ));
669+
670+ return true;
671+ }
672+
657673// Helper to validate the user-path, and fetch the wallet's relevant gait service pubkey
658674static bool wallet_get_gaservice_key (
659675 const char * network , const uint32_t * path , const size_t path_len , struct ext_key * gakey )
@@ -663,37 +679,28 @@ static bool wallet_get_gaservice_key(
663679 JADE_ASSERT (path_len );
664680 JADE_ASSERT (gakey );
665681
666- uint32_t ga_path [MAX_GASERVICE_PATH_LEN ]; // 32 + 3 max
667- size_t ga_path_len = 0 ;
668- if (!wallet_get_gaservice_path (path , path_len , ga_path , MAX_GASERVICE_PATH_LEN , & ga_path_len )) {
669- // Cannot get ga service path from user path
670- return false;
671- }
682+ const keychain_t * const keychain = keychain_get ();
683+ JADE_ASSERT (keychain );
672684
673- // Derive ga account pubkey for the path, except the ptr (so we can log it).
674685 const struct ext_key * const service = networkToGaService (network );
675686 if (!service ) {
676687 JADE_LOGE ("Unknown network: %s" , network );
677688 return false;
678689 }
679- /*
680- // This outputs the parent service xpub to match what the gdk has in its txn data
681- struct ext_key garoot;
682- JADE_WALLY_VERIFY(bip32_key_from_parent_path(service, ga_path, ga_path_len-1, BIP32_FLAG_KEY_PUBLIC |
683- BIP32_FLAG_SKIP_HASH, &garoot));
684690
685- // Log this xpub
686- char *logbuf;
687- JADE_WALLY_VERIFY(bip32_key_to_base58(&garoot, BIP32_FLAG_KEY_PUBLIC, &logbuf));
688- JADE_LOGI("service xpub: %s", logbuf);
689- JADE_WALLY_VERIFY(wally_free_string(logbuf));
691+ uint32_t ga_path_tail [MAX_GASERVICE_PATH_TAIL_LEN ];
692+ size_t ga_path_tail_len = 0 ;
693+ bool is_subaccount_path = false;
694+ if (!wallet_get_gaservice_path_tail (
695+ path , path_len , ga_path_tail , MAX_GASERVICE_PATH_TAIL_LEN , & ga_path_tail_len , & is_subaccount_path )) {
696+ // Path pattern not recognised
697+ return false;
698+ }
699+
700+ const struct ext_key * const cached_service_root = keychain_cached_service (service , is_subaccount_path );
701+ JADE_WALLY_VERIFY (bip32_key_from_parent_path (
702+ cached_service_root , ga_path_tail , ga_path_tail_len , BIP32_FLAG_KEY_PUBLIC | BIP32_FLAG_SKIP_HASH , gakey ));
690703
691- // Derive final part of the path into the output
692- JADE_WALLY_VERIFY(bip32_key_from_parent_path(&garoot, &ga_path[ga_path_len-1], 1, BIP32_FLAG_KEY_PUBLIC |
693- BIP32_FLAG_SKIP_HASH, gakey));
694- */
695- JADE_WALLY_VERIFY (
696- bip32_key_from_parent_path (service , ga_path , ga_path_len , BIP32_FLAG_KEY_PUBLIC | BIP32_FLAG_SKIP_HASH , gakey ));
697704 return true;
698705}
699706
0 commit comments