@@ -72,12 +72,26 @@ pub fn descriptor(
7272 xpub : & Xpub ,
7373 fg : & Fingerprint ,
7474 multipath : u32 ,
75+ network : Network ,
7576) -> Descriptor < DescriptorPublicKey > {
76- let descr_str = format ! ( "wpkh([{}/84'/0'/0']{}/{}/*)" , fg, xpub, multipath) ;
77+ let descr_str = format ! (
78+ "wpkh([{}{}]{}/{}/*)" ,
79+ fg,
80+ deriv_path( network) ,
81+ xpub,
82+ multipath
83+ ) ;
7784
7885 Descriptor :: < DescriptorPublicKey > :: from_str ( & descr_str) . expect ( "descriptor" )
7986}
8087
88+ pub fn deriv_path ( network : Network ) -> & ' static str {
89+ match network {
90+ Network :: Bitcoin => "/84'/0'/0'" ,
91+ _ => "/84'/1'/0'" ,
92+ }
93+ }
94+
8195impl WpkhHotSigner {
8296 /// Create a new [`WpkhHotSigner`] instance from the Xpriv key.
8397 ///
@@ -88,10 +102,11 @@ impl WpkhHotSigner {
88102 let secp = secp256k1:: Secp256k1 :: new ( ) ;
89103 let fingerprint = xpriv. fingerprint ( & secp) ;
90104
105+ let deriv_path_str = format ! ( "m{}" , deriv_path( network) ) ;
91106 let secret_key = DescriptorMultiXKey {
92107 origin : Some ( (
93108 fingerprint,
94- DerivationPath :: from_str ( "m/84'/0'/0'" ) . expect ( "hardcoded" ) ,
109+ DerivationPath :: from_str ( & deriv_path_str ) . expect ( "hardcoded" ) ,
95110 ) ) ,
96111 xkey : xpriv,
97112 derivation_paths : DerivPaths :: new ( vec ! [
@@ -174,7 +189,7 @@ impl WpkhHotSigner {
174189 if let Some ( index) = coin_path. index {
175190 let fingerprint = self . master_xpriv . fingerprint ( self . secp ( ) ) ;
176191 let xpub = Xpub :: from_priv ( self . secp ( ) , & self . master_xpriv ) ;
177- let descriptor = descriptor ( & xpub, & fingerprint, coin_path. depth ) ;
192+ let descriptor = descriptor ( & xpub, & fingerprint, coin_path. depth , self . network ) ;
178193 let definite = descriptor. at_derivation_index ( index) . expect ( "wildcard" ) ;
179194 Ok ( definite. address ( self . network ) . expect ( "wpkh" ) )
180195 } else {
0 commit comments