7
7
// You may not use this file except in accordance with one or both of these
8
8
// licenses.
9
9
10
+ use bitcoin:: secp256k1:: { KeyPair , PublicKey , Secp256k1 , SecretKey , self } ;
10
11
use crate :: utils:: test_logger;
12
+ use core:: convert:: { Infallible , TryFrom } ;
13
+ use lightning:: chain:: keysinterface:: EntropySource ;
14
+ use lightning:: ln:: PaymentHash ;
15
+ use lightning:: ln:: features:: BlindedHopFeatures ;
16
+ use lightning:: offers:: invoice:: { BlindedPayInfo , UnsignedInvoice } ;
11
17
use lightning:: offers:: invoice_request:: InvoiceRequest ;
18
+ use lightning:: offers:: parse:: SemanticError ;
19
+ use lightning:: onion_message:: BlindedPath ;
12
20
use lightning:: util:: ser:: Writeable ;
13
- use std:: convert:: TryFrom ;
14
21
15
22
#[ inline]
16
23
pub fn do_test < Out : test_logger:: Output > ( data : & [ u8 ] , _out : Out ) {
@@ -20,9 +27,71 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
20
27
let mut bytes = Vec :: with_capacity ( data. len ( ) ) ;
21
28
invoice_request. write ( & mut bytes) . unwrap ( ) ;
22
29
assert_eq ! ( data, bytes) ;
30
+
31
+ let secp_ctx = Secp256k1 :: new ( ) ;
32
+ let keys = KeyPair :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
33
+ let mut buffer = Vec :: new ( ) ;
34
+
35
+ if let Ok ( invoice) = build_response ( & invoice_request, & secp_ctx) {
36
+ invoice
37
+ . sign :: < _ , Infallible > (
38
+ |digest| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( digest, & keys) )
39
+ )
40
+ . unwrap ( )
41
+ . write ( & mut buffer)
42
+ . unwrap ( ) ;
43
+ }
23
44
}
24
45
}
25
46
47
+ struct Randomness ;
48
+
49
+ impl EntropySource for Randomness {
50
+ fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] { [ 42 ; 32 ] }
51
+ }
52
+
53
+ fn pubkey ( byte : u8 ) -> PublicKey {
54
+ let secp_ctx = Secp256k1 :: new ( ) ;
55
+ PublicKey :: from_secret_key ( & secp_ctx, & privkey ( byte) )
56
+ }
57
+
58
+ fn privkey ( byte : u8 ) -> SecretKey {
59
+ SecretKey :: from_slice ( & [ byte; 32 ] ) . unwrap ( )
60
+ }
61
+
62
+ fn build_response < ' a , T : secp256k1:: Signing + secp256k1:: Verification > (
63
+ invoice_request : & ' a InvoiceRequest , secp_ctx : & Secp256k1 < T >
64
+ ) -> Result < UnsignedInvoice < ' a > , SemanticError > {
65
+ let entropy_source = Randomness { } ;
66
+ let paths = vec ! [
67
+ BlindedPath :: new( & [ pubkey( 43 ) , pubkey( 44 ) , pubkey( 42 ) ] , & entropy_source, secp_ctx) . unwrap( ) ,
68
+ BlindedPath :: new( & [ pubkey( 45 ) , pubkey( 46 ) , pubkey( 42 ) ] , & entropy_source, secp_ctx) . unwrap( ) ,
69
+ ] ;
70
+
71
+ let payinfo = vec ! [
72
+ BlindedPayInfo {
73
+ fee_base_msat: 1 ,
74
+ fee_proportional_millionths: 1_000 ,
75
+ cltv_expiry_delta: 42 ,
76
+ htlc_minimum_msat: 100 ,
77
+ htlc_maximum_msat: 1_000_000_000_000 ,
78
+ features: BlindedHopFeatures :: empty( ) ,
79
+ } ,
80
+ BlindedPayInfo {
81
+ fee_base_msat: 1 ,
82
+ fee_proportional_millionths: 1_000 ,
83
+ cltv_expiry_delta: 42 ,
84
+ htlc_minimum_msat: 100 ,
85
+ htlc_maximum_msat: 1_000_000_000_000 ,
86
+ features: BlindedHopFeatures :: empty( ) ,
87
+ } ,
88
+ ] ;
89
+
90
+ let payment_paths = paths. into_iter ( ) . zip ( payinfo. into_iter ( ) ) . collect ( ) ;
91
+ let payment_hash = PaymentHash ( [ 42 ; 32 ] ) ;
92
+ invoice_request. respond_with ( payment_paths, payment_hash) ?. build ( )
93
+ }
94
+
26
95
pub fn invoice_request_deser_test < Out : test_logger:: Output > ( data : & [ u8 ] , out : Out ) {
27
96
do_test ( data, out) ;
28
97
}
0 commit comments