@@ -138,7 +138,6 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
138138 case WIRE_HSMD_LOCK_OUTPOINT :
139139 return (client -> capabilities & HSM_PERM_LOCK_OUTPOINT ) != 0 ;
140140
141- case WIRE_HSMD_DERIVE_BIP86_KEY :
142141 case WIRE_HSMD_CHECK_BIP86_PUBKEY :
143142 case WIRE_HSMD_INIT :
144143 case WIRE_HSMD_DEV_PREINIT :
@@ -209,7 +208,6 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
209208 case WIRE_HSMD_PREAPPROVE_KEYSEND_CHECK_REPLY :
210209 case WIRE_HSMD_DERIVE_SECRET_REPLY :
211210 case WIRE_HSMD_CHECK_PUBKEY_REPLY :
212- case WIRE_HSMD_DERIVE_BIP86_KEY_REPLY :
213211 case WIRE_HSMD_CHECK_BIP86_PUBKEY_REPLY :
214212 case WIRE_HSMD_SIGN_ANCHORSPEND_REPLY :
215213 case WIRE_HSMD_SIGN_HTLC_TX_MINGLE_REPLY :
@@ -542,26 +540,9 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey,
542540 hsmd_status_debug ("Derived public key %s from unilateral close" ,
543541 fmt_pubkey (tmpctx , pubkey ));
544542 } else {
545- /* Check if this is a BIP86 UTXO by examining the scriptPubkey */
546- const size_t script_len = tal_bytelen (utxo -> scriptPubkey );
547- bool is_bip86 = false;
548-
549- /* For P2TR scripts, we need to determine if it's BIP86 or regular P2TR
550- * But BIP86 derivation requires mnemonic-based secrets */
551- if (is_p2tr (utxo -> scriptPubkey , script_len , NULL ) &&
552- use_bip86_derivation (tal_bytelen (secretstuff .bip32_seed ))) {
553- /* Try BIP86 derivation first and see if it matches */
554- struct pubkey test_pubkey ;
555- bip86_key (NULL , & test_pubkey , utxo -> keyindex );
556-
557- /* Create P2TR scriptpubkey from BIP86 key and compare */
558- const u8 * bip86_script = scriptpubkey_p2tr (tmpctx , & test_pubkey );
559- if (memeq (utxo -> scriptPubkey , script_len , bip86_script , tal_bytelen (bip86_script ))) {
560- is_bip86 = true;
561- }
562- }
563-
564- if (is_bip86 ) {
543+ /* Modern HSMs use bip86 for p2tr. */
544+ if (is_p2tr (utxo -> scriptPubkey , tal_bytelen (utxo -> scriptPubkey ), NULL )
545+ && use_bip86_derivation (tal_bytelen (secretstuff .bip32_seed ))) {
565546 /* Use BIP86 derivation */
566547 bip86_key (privkey , pubkey , utxo -> keyindex );
567548 } else {
@@ -2316,7 +2297,6 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
23162297 return handle_derive_secret (client , msg );
23172298 case WIRE_HSMD_CHECK_PUBKEY :
23182299 return handle_check_pubkey (client , msg );
2319- case WIRE_HSMD_DERIVE_BIP86_KEY :
23202300 case WIRE_HSMD_CHECK_BIP86_PUBKEY :
23212301 /* This should be handled by hsmd.c, not libhsmd */
23222302 return hsmd_status_bad_request_fmt (
@@ -2373,7 +2353,6 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
23732353 case WIRE_HSMD_PREAPPROVE_KEYSEND_REPLY :
23742354 case WIRE_HSMD_PREAPPROVE_INVOICE_CHECK_REPLY :
23752355 case WIRE_HSMD_PREAPPROVE_KEYSEND_CHECK_REPLY :
2376- case WIRE_HSMD_DERIVE_BIP86_KEY_REPLY :
23772356 case WIRE_HSMD_CHECK_PUBKEY_REPLY :
23782357 case WIRE_HSMD_CHECK_BIP86_PUBKEY_REPLY :
23792358 case WIRE_HSMD_SIGN_ANCHORSPEND_REPLY :
@@ -2610,8 +2589,13 @@ u8 *hsmd_init(const u8 *secret_data, size_t secret_len, const u64 hsmd_version,
26102589 */
26112590 /* Create TLV with HSM secret type */
26122591 struct tlv_hsmd_init_reply_v4_tlvs * tlvs = tlv_hsmd_init_reply_v4_tlvs_new (tmpctx );
2613- tlvs -> hsm_secret_type = tal (tlvs , u8 );
2614- * tlvs -> hsm_secret_type = hsm_secret_type ;
2592+ tlvs -> hsm_secret_type = tal_dup (tlvs , u8 , & hsm_secret_type );
2593+
2594+ /* If we have a mnemonic-based HSM, include the BIP86 base key */
2595+ if (use_bip86_derivation (tal_bytelen (secretstuff .bip32_seed ))) {
2596+ tlvs -> bip86_base = tal (tlvs , struct ext_key );
2597+ derive_bip86_base_key (tlvs -> bip86_base );
2598+ }
26152599
26162600 return take (towire_hsmd_init_reply_v4 (
26172601 NULL , hsmd_version , caps ,
0 commit comments