@@ -60,11 +60,35 @@ impl Key {
6060 & self ,
6161 secp : & secp256k1_zkp:: Secp256k1 < C > ,
6262 spk : & elements:: Script ,
63- ) -> secp256k1_zkp:: PublicKey {
63+ ) -> Result < secp256k1_zkp:: PublicKey , Error > {
6464 match * self {
65- Key :: Slip77 ( ref mbk) => mbk. blinding_key ( secp, spk) ,
66- Key :: Bare ( ref pk) => bare:: tweak_key ( secp, spk, & pk. clone ( ) . at_derivation_index ( 0 ) . expect ( "FIXME deal with derivation paths properly" ) ) ,
67- Key :: View ( ref sk) => bare:: tweak_key ( secp, spk, & sk. to_public ( secp) . expect ( "view keys cannot be multipath keys" ) . at_derivation_index ( 0 ) . expect ( "FIXME deal with derivation paths properly" ) ) ,
65+ Key :: Slip77 ( ref mbk) => Ok ( mbk. blinding_key ( secp, spk) ) ,
66+ Key :: Bare ( ref pk) => {
67+ if pk. is_multipath ( ) {
68+ Err ( Error :: Unexpected ( "multipath blinding key" . into ( ) ) )
69+ } else if pk. has_wildcard ( ) {
70+ Err ( Error :: Unexpected ( "wildcard blinding key" . into ( ) ) )
71+ } else {
72+ // Convert into a DefiniteDescriptorKey, note that we are deriving the xpub
73+ // since there is not wildcard.
74+ // Consider adding DescriptorPublicKey::to_definite_descriptor
75+ let pk = pk. clone ( ) . at_derivation_index ( 0 ) . expect ( "single or xpub without wildcards" ) ;
76+ Ok ( bare:: tweak_key ( secp, spk, & pk) )
77+ }
78+ } ,
79+ Key :: View ( ref sk) => {
80+ if sk. is_multipath ( ) {
81+ Err ( Error :: Unexpected ( "multipath blinding key" . into ( ) ) )
82+ } else {
83+ let pk = sk. to_public ( secp) . expect ( "single or xprv" ) ;
84+ if pk. has_wildcard ( ) {
85+ Err ( Error :: Unexpected ( "wildcard blinding key" . into ( ) ) )
86+ } else {
87+ let pk = pk. at_derivation_index ( 0 ) . expect ( "single or xprv without wildcards" ) ;
88+ Ok ( bare:: tweak_key ( secp, spk, & pk) )
89+ }
90+ }
91+ } ,
6892 }
6993 }
7094}
@@ -148,7 +172,7 @@ impl<Pk: MiniscriptKey + ToPublicKey, T: Extension + ParseableExt> Descriptor<Pk
148172 ) -> Result < elements:: Address , Error > {
149173 let spk = self . descriptor . script_pubkey ( ) ;
150174 self . descriptor
151- . blinded_address ( self . key . to_public_key ( secp, & spk) , params)
175+ . blinded_address ( self . key . to_public_key ( secp, & spk) ? , params)
152176 }
153177}
154178
@@ -215,7 +239,7 @@ mod tests {
215239 )
216240 . unwrap ( ) ,
217241 ) ;
218- addr. blinding_pubkey = Some ( key. to_public_key ( & secp, & addr. script_pubkey ( ) ) ) ;
242+ addr. blinding_pubkey = Some ( key. to_public_key ( & secp, & addr. script_pubkey ( ) ) . unwrap ( ) ) ;
219243 assert_eq ! (
220244 addr. to_string( ) ,
221245 "VTpt7krqRQPJwqe3XQXPg2cVdEKYVFbuprTr7es7pNRMe8mndnq2iYWddxJWYowhLAwoDF8QrZ1v2EXv"
0 commit comments