@@ -327,6 +327,24 @@ impl DescriptorMultiXKey<bip32::Xpriv> {
327
327
}
328
328
}
329
329
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
+ impl error:: Error for NonDefiniteKeyError { }
347
+
330
348
/// Kinds of malformed key data
331
349
#[ derive( Debug , PartialEq , Clone ) ]
332
350
#[ non_exhaustive]
@@ -346,7 +364,6 @@ pub enum MalformedKeyDataKind {
346
364
NoKeyAfterOrigin ,
347
365
NoMasterFingerprintFound ,
348
366
UnclosedSquareBracket ,
349
- WildcardAsDerivedDescriptorKey ,
350
367
}
351
368
352
369
impl fmt:: Display for MalformedKeyDataKind {
@@ -366,7 +383,6 @@ impl fmt::Display for MalformedKeyDataKind {
366
383
Self :: NoKeyAfterOrigin => "no key after origin" ,
367
384
Self :: NoMasterFingerprintFound => "no master fingerprint found after '['" ,
368
385
Self :: UnclosedSquareBracket => "unclosed '['" ,
369
- Self :: WildcardAsDerivedDescriptorKey => "cannot parse key with a wilcard as a DerivedDescriptorKey" ,
370
386
} ;
371
387
372
388
f. write_str ( err)
@@ -401,6 +417,8 @@ pub enum DescriptorKeyParseError {
401
417
/// The underlying parse error
402
418
err : bitcoin:: hex:: HexToArrayError ,
403
419
} ,
420
+ /// Attempt to construct a [`DefiniteDescriptorKey`] from an ambiguous key.
421
+ NonDefiniteKey ( NonDefiniteKeyError ) ,
404
422
/// Error while parsing a simple public key.
405
423
FullPublicKey ( bitcoin:: key:: ParsePublicKeyError ) ,
406
424
/// Error while parsing a WIF private key.
@@ -423,6 +441,7 @@ impl fmt::Display for DescriptorKeyParseError {
423
441
Self :: MasterFingerprint { fingerprint, err } => {
424
442
write ! ( f, "on master fingerprint '{fingerprint}': {err}" )
425
443
}
444
+ Self :: NonDefiniteKey ( err) => err. fmt ( f) ,
426
445
Self :: FullPublicKey ( err) => err. fmt ( f) ,
427
446
Self :: WifPrivateKey ( err) => err. fmt ( f) ,
428
447
Self :: XonlyPublicKey ( err) => err. fmt ( f) ,
@@ -440,6 +459,7 @@ impl error::Error for DescriptorKeyParseError {
440
459
| Self :: DeriveHardenedKey ( err)
441
460
| Self :: MasterDerivationPath ( err) => Some ( err) ,
442
461
Self :: MasterFingerprint { err, .. } => Some ( err) ,
462
+ Self :: NonDefiniteKey ( err) => Some ( err) ,
443
463
Self :: FullPublicKey ( err) => Some ( err) ,
444
464
Self :: WifPrivateKey ( err) => Some ( err) ,
445
465
Self :: XonlyPublicKey ( err) => Some ( err) ,
@@ -1284,9 +1304,8 @@ impl FromStr for DefiniteDescriptorKey {
1284
1304
1285
1305
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1286
1306
let inner = DescriptorPublicKey :: from_str ( s) ?;
1287
- DefiniteDescriptorKey :: new ( inner) . ok_or ( DescriptorKeyParseError :: MalformedKeyData (
1288
- MalformedKeyDataKind :: WildcardAsDerivedDescriptorKey ,
1289
- ) )
1307
+ DefiniteDescriptorKey :: new ( inner)
1308
+ . ok_or ( DescriptorKeyParseError :: NonDefiniteKey ( NonDefiniteKeyError :: Wildcard ) )
1290
1309
}
1291
1310
}
1292
1311
0 commit comments