9
9
10
10
//! Data structures and methods for constructing [`BlindedPaymentPath`]s to send a payment over.
11
11
12
- use bitcoin:: hashes:: hmac:: Hmac ;
13
- use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
14
12
use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
15
13
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
16
14
@@ -20,8 +18,6 @@ use crate::crypto::streams::ChaChaDualPolyReadAdapter;
20
18
use crate :: io;
21
19
use crate :: io:: Cursor ;
22
20
use crate :: ln:: channel_state:: CounterpartyForwardingInfo ;
23
- use crate :: ln:: channelmanager:: Verification ;
24
- use crate :: ln:: inbound_payment:: ExpandedKey ;
25
21
use crate :: ln:: msgs:: DecodeError ;
26
22
use crate :: ln:: onion_utils;
27
23
use crate :: offers:: invoice_request:: InvoiceRequestFields ;
@@ -137,7 +133,7 @@ impl BlindedPaymentPath {
137
133
138
134
let blinded_payinfo = compute_payinfo (
139
135
intermediate_nodes,
140
- & payee_tlvs. tlvs ,
136
+ & payee_tlvs,
141
137
htlc_maximum_msat,
142
138
min_final_cltv_expiry_delta,
143
139
) ?;
@@ -328,26 +324,8 @@ pub struct TrampolineForwardTlvs {
328
324
329
325
/// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
330
326
/// may not be valid if received by another lightning implementation.
331
- ///
332
- /// Can only be constructed by calling [`UnauthenticatedReceiveTlvs::authenticate`].
333
327
#[ derive( Clone , Debug ) ]
334
328
pub struct ReceiveTlvs {
335
- /// The TLVs for which the HMAC in `authentication` is derived.
336
- pub ( crate ) tlvs : UnauthenticatedReceiveTlvs ,
337
- /// An HMAC of `tlvs` along with a nonce used to construct it.
338
- pub ( crate ) authentication : ( Hmac < Sha256 > , Nonce ) ,
339
- }
340
-
341
- impl ReceiveTlvs {
342
- /// Returns the underlying TLVs.
343
- pub fn tlvs ( & self ) -> & UnauthenticatedReceiveTlvs {
344
- & self . tlvs
345
- }
346
- }
347
-
348
- /// An unauthenticated [`ReceiveTlvs`].
349
- #[ derive( Clone , Debug ) ]
350
- pub struct UnauthenticatedReceiveTlvs {
351
329
/// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
352
330
pub payment_secret : PaymentSecret ,
353
331
/// Constraints for the receiver of this payment.
@@ -356,17 +334,6 @@ pub struct UnauthenticatedReceiveTlvs {
356
334
pub payment_context : PaymentContext ,
357
335
}
358
336
359
- impl UnauthenticatedReceiveTlvs {
360
- /// Creates an authenticated [`ReceiveTlvs`], which includes an HMAC and the provide [`Nonce`]
361
- /// that can be use later to verify it authenticity.
362
- pub fn authenticate ( self , nonce : Nonce , expanded_key : & ExpandedKey ) -> ReceiveTlvs {
363
- ReceiveTlvs {
364
- authentication : ( self . hmac_for_offer_payment ( nonce, expanded_key) , nonce) ,
365
- tlvs : self ,
366
- }
367
- }
368
- }
369
-
370
337
/// Data to construct a [`BlindedHop`] for sending a payment over.
371
338
///
372
339
/// [`BlindedHop`]: crate::blinded_path::BlindedHop
@@ -539,19 +506,12 @@ impl Writeable for TrampolineForwardTlvs {
539
506
}
540
507
}
541
508
509
+ // Note: Authentication TLV field was removed in LDK v0.2 following the
510
+ // introduction of `ReceiveAuthKey`-based authentication for inbound
511
+ // `BlindedPaymentPaths`s. Because we do not support receiving to those
512
+ // contexts anymore (they will fail the `ReceiveAuthKey`-based
513
+ // authentication checks), we can reuse those fields here.
542
514
impl Writeable for ReceiveTlvs {
543
- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
544
- encode_tlv_stream ! ( w, {
545
- ( 12 , self . tlvs. payment_constraints, required) ,
546
- ( 65536 , self . tlvs. payment_secret, required) ,
547
- ( 65537 , self . tlvs. payment_context, required) ,
548
- ( 65539 , self . authentication, required) ,
549
- } ) ;
550
- Ok ( ( ) )
551
- }
552
- }
553
-
554
- impl Writeable for UnauthenticatedReceiveTlvs {
555
515
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
556
516
encode_tlv_stream ! ( w, {
557
517
( 12 , self . payment_constraints, required) ,
@@ -586,7 +546,6 @@ impl Readable for BlindedPaymentTlvs {
586
546
( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
587
547
( 65536 , payment_secret, option) ,
588
548
( 65537 , payment_context, option) ,
589
- ( 65539 , authentication, option) ,
590
549
} ) ;
591
550
592
551
if let Some ( short_channel_id) = scid {
@@ -605,12 +564,9 @@ impl Readable for BlindedPaymentTlvs {
605
564
return Err ( DecodeError :: InvalidValue ) ;
606
565
}
607
566
Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
608
- tlvs : UnauthenticatedReceiveTlvs {
609
- payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
610
- payment_constraints : payment_constraints. 0 . unwrap ( ) ,
611
- payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
612
- } ,
613
- authentication : authentication. ok_or ( DecodeError :: InvalidValue ) ?,
567
+ payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
568
+ payment_constraints : payment_constraints. 0 . unwrap ( ) ,
569
+ payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
614
570
} ) )
615
571
}
616
572
}
@@ -626,7 +582,6 @@ impl Readable for BlindedTrampolineTlvs {
626
582
( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
627
583
( 65536 , payment_secret, option) ,
628
584
( 65537 , payment_context, option) ,
629
- ( 65539 , authentication, option) ,
630
585
} ) ;
631
586
632
587
if let Some ( next_trampoline) = next_trampoline {
@@ -645,12 +600,9 @@ impl Readable for BlindedTrampolineTlvs {
645
600
return Err ( DecodeError :: InvalidValue ) ;
646
601
}
647
602
Ok ( BlindedTrampolineTlvs :: Receive ( ReceiveTlvs {
648
- tlvs : UnauthenticatedReceiveTlvs {
649
- payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
650
- payment_constraints : payment_constraints. 0 . unwrap ( ) ,
651
- payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
652
- } ,
653
- authentication : authentication. ok_or ( DecodeError :: InvalidValue ) ?,
603
+ payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
604
+ payment_constraints : payment_constraints. 0 . unwrap ( ) ,
605
+ payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
654
606
} ) )
655
607
}
656
608
}
@@ -737,7 +689,7 @@ where
737
689
}
738
690
739
691
pub ( super ) fn compute_payinfo (
740
- intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & UnauthenticatedReceiveTlvs ,
692
+ intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & ReceiveTlvs ,
741
693
payee_htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 ,
742
694
) -> Result < BlindedPayInfo , ( ) > {
743
695
let ( aggregated_base_fee, aggregated_prop_fee) =
@@ -860,7 +812,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
860
812
mod tests {
861
813
use crate :: blinded_path:: payment:: {
862
814
Bolt12RefundContext , ForwardTlvs , PaymentConstraints , PaymentContext , PaymentForwardNode ,
863
- PaymentRelay , UnauthenticatedReceiveTlvs ,
815
+ PaymentRelay , ReceiveTlvs ,
864
816
} ;
865
817
use crate :: ln:: functional_test_utils:: TEST_FINAL_CLTV ;
866
818
use crate :: types:: features:: BlindedHopFeatures ;
@@ -910,7 +862,7 @@ mod tests {
910
862
htlc_maximum_msat: u64 :: max_value( ) ,
911
863
} ,
912
864
] ;
913
- let recv_tlvs = UnauthenticatedReceiveTlvs {
865
+ let recv_tlvs = ReceiveTlvs {
914
866
payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
915
867
payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
916
868
payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -928,7 +880,7 @@ mod tests {
928
880
929
881
#[ test]
930
882
fn compute_payinfo_1_hop ( ) {
931
- let recv_tlvs = UnauthenticatedReceiveTlvs {
883
+ let recv_tlvs = ReceiveTlvs {
932
884
payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
933
885
payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
934
886
payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -985,7 +937,7 @@ mod tests {
985
937
htlc_maximum_msat: u64 :: max_value( ) ,
986
938
} ,
987
939
] ;
988
- let recv_tlvs = UnauthenticatedReceiveTlvs {
940
+ let recv_tlvs = ReceiveTlvs {
989
941
payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
990
942
payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 3 } ,
991
943
payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1044,7 +996,7 @@ mod tests {
1044
996
htlc_maximum_msat: u64 :: max_value( ) ,
1045
997
} ,
1046
998
] ;
1047
- let recv_tlvs = UnauthenticatedReceiveTlvs {
999
+ let recv_tlvs = ReceiveTlvs {
1048
1000
payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
1049
1001
payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
1050
1002
payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1113,7 +1065,7 @@ mod tests {
1113
1065
htlc_maximum_msat: 10_000 ,
1114
1066
} ,
1115
1067
] ;
1116
- let recv_tlvs = UnauthenticatedReceiveTlvs {
1068
+ let recv_tlvs = ReceiveTlvs {
1117
1069
payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
1118
1070
payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
1119
1071
payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
0 commit comments