@@ -459,14 +459,15 @@ mod tests {
459
459
460
460
use bitcoin:: blockdata:: constants:: ChainHash ;
461
461
use bitcoin:: network:: constants:: Network ;
462
- use bitcoin:: secp256k1:: { KeyPair , Message , PublicKey , Secp256k1 , SecretKey } ;
462
+ use bitcoin:: secp256k1:: { KeyPair , Message , PublicKey , Secp256k1 , SecretKey , self } ;
463
463
use bitcoin:: secp256k1:: schnorr:: Signature ;
464
464
use core:: convert:: { Infallible , TryFrom } ;
465
465
use core:: num:: NonZeroU64 ;
466
466
#[ cfg( feature = "std" ) ]
467
467
use core:: time:: Duration ;
468
468
use crate :: ln:: features:: InvoiceRequestFeatures ;
469
469
use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
470
+ use crate :: offers:: merkle:: SignError ;
470
471
use crate :: offers:: offer:: { OfferBuilder , Quantity } ;
471
472
use crate :: offers:: parse:: { ParseError , SemanticError } ;
472
473
use crate :: util:: ser:: { BigSize , Writeable } ;
@@ -477,16 +478,22 @@ mod tests {
477
478
KeyPair :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) )
478
479
}
479
480
480
- fn payer_sign ( digest : & Message ) -> Signature {
481
+ fn payer_sign ( digest : & Message ) -> Result < Signature , Infallible > {
481
482
let secp_ctx = Secp256k1 :: new ( ) ;
482
483
let keys = KeyPair :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
483
- secp_ctx. sign_schnorr_no_aux_rand ( digest, & keys)
484
+ Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest, & keys) )
484
485
}
485
486
486
487
fn payer_pubkey ( ) -> PublicKey {
487
488
payer_keys ( ) . public_key ( )
488
489
}
489
490
491
+ fn recipient_sign ( digest : & Message ) -> Result < Signature , Infallible > {
492
+ let secp_ctx = Secp256k1 :: new ( ) ;
493
+ let keys = KeyPair :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) ) ;
494
+ Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest, & keys) )
495
+ }
496
+
490
497
fn recipient_pubkey ( ) -> PublicKey {
491
498
let secp_ctx = Secp256k1 :: new ( ) ;
492
499
KeyPair :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) ) . public_key ( )
@@ -840,6 +847,31 @@ mod tests {
840
847
assert_eq ! ( tlv_stream. payer_note, Some ( & String :: from( "baz" ) ) ) ;
841
848
}
842
849
850
+ #[ test]
851
+ fn fails_signing_invoice_request ( ) {
852
+ match OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
853
+ . amount_msats ( 1000 )
854
+ . build ( ) . unwrap ( )
855
+ . request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) )
856
+ . build ( ) . unwrap ( )
857
+ . sign ( |digest| Err ( ( ) ) )
858
+ {
859
+ Ok ( _) => panic ! ( "expected error" ) ,
860
+ Err ( e) => assert_eq ! ( e, SignError :: Signing ( ( ) ) ) ,
861
+ }
862
+
863
+ match OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
864
+ . amount_msats ( 1000 )
865
+ . build ( ) . unwrap ( )
866
+ . request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) )
867
+ . build ( ) . unwrap ( )
868
+ . sign ( recipient_sign)
869
+ {
870
+ Ok ( _) => panic ! ( "expected error" ) ,
871
+ Err ( e) => assert_eq ! ( e, SignError :: Verification ( secp256k1:: Error :: InvalidSignature ) ) ,
872
+ }
873
+ }
874
+
843
875
#[ test]
844
876
fn fails_parsing_invoice_request_with_extra_tlv_records ( ) {
845
877
let secp_ctx = Secp256k1 :: new ( ) ;
0 commit comments