@@ -106,7 +106,6 @@ pub enum Bolt11ParseError {
106
106
InvalidSegWitProgramLength ,
107
107
InvalidPubKeyHashLength ,
108
108
InvalidScriptHashLength ,
109
- InvalidRecoveryId ,
110
109
// Invalid length, with actual length, expected length, and name of the element
111
110
InvalidSliceLength ( usize , usize , & ' static str ) ,
112
111
@@ -1011,31 +1010,19 @@ impl SignedRawBolt11Invoice {
1011
1010
}
1012
1011
1013
1012
/// Checks if the signature is valid for the included payee public key or if none exists if it's
1014
- /// valid for the recovered signature (which should always be true?) .
1013
+ /// possible to recover the public key from the signature .
1015
1014
pub fn check_signature ( & self ) -> bool {
1016
- let included_pub_key = self . raw_invoice . payee_pub_key ( ) ;
1015
+ match self . raw_invoice . payee_pub_key ( ) {
1016
+ Some ( pk) => {
1017
+ let hash = Message :: from_digest ( self . hash ) ;
1017
1018
1018
- let mut recovered_pub_key = Option :: None ;
1019
- if recovered_pub_key. is_none ( ) {
1020
- let recovered = match self . recover_payee_pub_key ( ) {
1021
- Ok ( pk) => pk,
1022
- Err ( _) => return false ,
1023
- } ;
1024
- recovered_pub_key = Some ( recovered) ;
1025
- }
1019
+ let secp_context = Secp256k1 :: new ( ) ;
1020
+ let verification_result =
1021
+ secp_context. verify_ecdsa ( & hash, & self . signature . to_standard ( ) , pk) ;
1026
1022
1027
- let pub_key =
1028
- included_pub_key. or ( recovered_pub_key. as_ref ( ) ) . expect ( "One is always present" ) ;
1029
-
1030
- let hash = Message :: from_digest ( self . hash ) ;
1031
-
1032
- let secp_context = Secp256k1 :: new ( ) ;
1033
- let verification_result =
1034
- secp_context. verify_ecdsa ( & hash, & self . signature . to_standard ( ) , pub_key) ;
1035
-
1036
- match verification_result {
1037
- Ok ( ( ) ) => true ,
1038
- Err ( _) => false ,
1023
+ verification_result. is_ok ( )
1024
+ } ,
1025
+ None => self . recover_payee_pub_key ( ) . is_ok ( ) ,
1039
1026
}
1040
1027
}
1041
1028
}
@@ -1410,19 +1397,8 @@ impl Bolt11Invoice {
1410
1397
}
1411
1398
}
1412
1399
1413
- /// Check that the invoice is signed correctly and that key recovery works
1400
+ /// Check that the invoice is signed correctly
1414
1401
pub fn check_signature ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1415
- match self . signed_invoice . recover_payee_pub_key ( ) {
1416
- Err ( bitcoin:: secp256k1:: Error :: InvalidRecoveryId ) => {
1417
- return Err ( Bolt11SemanticError :: InvalidRecoveryId )
1418
- } ,
1419
- Err ( bitcoin:: secp256k1:: Error :: InvalidSignature ) => {
1420
- return Err ( Bolt11SemanticError :: InvalidSignature )
1421
- } ,
1422
- Err ( e) => panic ! ( "no other error may occur, got {:?}" , e) ,
1423
- Ok ( _) => { } ,
1424
- }
1425
-
1426
1402
if !self . signed_invoice . check_signature ( ) {
1427
1403
return Err ( Bolt11SemanticError :: InvalidSignature ) ;
1428
1404
}
@@ -1873,9 +1849,6 @@ pub enum Bolt11SemanticError {
1873
1849
/// The invoice's features are invalid
1874
1850
InvalidFeatures ,
1875
1851
1876
- /// The recovery id doesn't fit the signature/pub key
1877
- InvalidRecoveryId ,
1878
-
1879
1852
/// The invoice's signature is invalid
1880
1853
InvalidSignature ,
1881
1854
@@ -1893,7 +1866,6 @@ impl Display for Bolt11SemanticError {
1893
1866
Bolt11SemanticError :: NoPaymentSecret => f. write_str ( "The invoice is missing the mandatory payment secret" ) ,
1894
1867
Bolt11SemanticError :: MultiplePaymentSecrets => f. write_str ( "The invoice contains multiple payment secrets" ) ,
1895
1868
Bolt11SemanticError :: InvalidFeatures => f. write_str ( "The invoice's features are invalid" ) ,
1896
- Bolt11SemanticError :: InvalidRecoveryId => f. write_str ( "The recovery id doesn't fit the signature/pub key" ) ,
1897
1869
Bolt11SemanticError :: InvalidSignature => f. write_str ( "The invoice's signature is invalid" ) ,
1898
1870
Bolt11SemanticError :: ImpreciseAmount => f. write_str ( "The invoice's amount was not a whole number of millisatoshis" ) ,
1899
1871
}
0 commit comments