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