@@ -327,6 +327,25 @@ impl DescriptorMultiXKey<bip32::Xpriv> {
327327 }
328328}
329329
330+ /// Kinds of malformed key data
331+ #[ derive( Debug , PartialEq , Clone ) ]
332+ #[ non_exhaustive]
333+ #[ allow( missing_docs) ]
334+ pub enum NonDefiniteKeyError {
335+ Wildcard ,
336+ }
337+
338+ impl fmt:: Display for NonDefiniteKeyError {
339+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
340+ match * self {
341+ Self :: Wildcard => f. write_str ( "key with a wildcard cannot be a DerivedDescriptorKey" ) ,
342+ }
343+ }
344+ }
345+
346+ #[ cfg( feature = "std" ) ]
347+ impl error:: Error for NonDefiniteKeyError { }
348+
330349/// Kinds of malformed key data
331350#[ derive( Debug , PartialEq , Clone ) ]
332351#[ non_exhaustive]
@@ -346,7 +365,6 @@ pub enum MalformedKeyDataKind {
346365 NoKeyAfterOrigin ,
347366 NoMasterFingerprintFound ,
348367 UnclosedSquareBracket ,
349- WildcardAsDerivedDescriptorKey ,
350368}
351369
352370impl fmt:: Display for MalformedKeyDataKind {
@@ -366,7 +384,6 @@ impl fmt::Display for MalformedKeyDataKind {
366384 Self :: NoKeyAfterOrigin => "no key after origin" ,
367385 Self :: NoMasterFingerprintFound => "no master fingerprint found after '['" ,
368386 Self :: UnclosedSquareBracket => "unclosed '['" ,
369- Self :: WildcardAsDerivedDescriptorKey => "cannot parse key with a wilcard as a DerivedDescriptorKey" ,
370387 } ;
371388
372389 f. write_str ( err)
@@ -401,6 +418,8 @@ pub enum DescriptorKeyParseError {
401418 /// The underlying parse error
402419 err : bitcoin:: hex:: HexToArrayError ,
403420 } ,
421+ /// Attempt to construct a [`DefiniteDescriptorKey`] from an ambiguous key.
422+ NonDefiniteKey ( NonDefiniteKeyError ) ,
404423 /// Error while parsing a simple public key.
405424 FullPublicKey ( bitcoin:: key:: ParsePublicKeyError ) ,
406425 /// Error while parsing a WIF private key.
@@ -423,6 +442,7 @@ impl fmt::Display for DescriptorKeyParseError {
423442 Self :: MasterFingerprint { fingerprint, err } => {
424443 write ! ( f, "on master fingerprint '{fingerprint}': {err}" )
425444 }
445+ Self :: NonDefiniteKey ( err) => err. fmt ( f) ,
426446 Self :: FullPublicKey ( err) => err. fmt ( f) ,
427447 Self :: WifPrivateKey ( err) => err. fmt ( f) ,
428448 Self :: XonlyPublicKey ( err) => err. fmt ( f) ,
@@ -440,6 +460,7 @@ impl error::Error for DescriptorKeyParseError {
440460 | Self :: DeriveHardenedKey ( err)
441461 | Self :: MasterDerivationPath ( err) => Some ( err) ,
442462 Self :: MasterFingerprint { err, .. } => Some ( err) ,
463+ Self :: NonDefiniteKey ( err) => Some ( err) ,
443464 Self :: FullPublicKey ( err) => Some ( err) ,
444465 Self :: WifPrivateKey ( err) => Some ( err) ,
445466 Self :: XonlyPublicKey ( err) => Some ( err) ,
@@ -1284,9 +1305,8 @@ impl FromStr for DefiniteDescriptorKey {
12841305
12851306 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
12861307 let inner = DescriptorPublicKey :: from_str ( s) ?;
1287- DefiniteDescriptorKey :: new ( inner) . ok_or ( DescriptorKeyParseError :: MalformedKeyData (
1288- MalformedKeyDataKind :: WildcardAsDerivedDescriptorKey ,
1289- ) )
1308+ DefiniteDescriptorKey :: new ( inner)
1309+ . ok_or ( DescriptorKeyParseError :: NonDefiniteKey ( NonDefiniteKeyError :: Wildcard ) )
12901310 }
12911311}
12921312
0 commit comments