99
1010//! Data structures and methods for constructing [`BlindedPaymentPath`]s to send a payment over.
1111
12- use bitcoin:: hashes:: hmac:: Hmac ;
13- use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
1412use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
1513use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
1614
@@ -20,8 +18,6 @@ use crate::crypto::streams::ChaChaDualPolyReadAdapter;
2018use crate :: io;
2119use crate :: io:: Cursor ;
2220use crate :: ln:: channel_state:: CounterpartyForwardingInfo ;
23- use crate :: ln:: channelmanager:: Verification ;
24- use crate :: ln:: inbound_payment:: ExpandedKey ;
2521use crate :: ln:: msgs:: DecodeError ;
2622use crate :: ln:: onion_utils;
2723use crate :: offers:: invoice_request:: InvoiceRequestFields ;
@@ -137,7 +133,7 @@ impl BlindedPaymentPath {
137133
138134 let blinded_payinfo = compute_payinfo (
139135 intermediate_nodes,
140- & payee_tlvs. tlvs ,
136+ & payee_tlvs,
141137 htlc_maximum_msat,
142138 min_final_cltv_expiry_delta,
143139 ) ?;
@@ -328,26 +324,8 @@ pub struct TrampolineForwardTlvs {
328324
329325/// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
330326/// may not be valid if received by another lightning implementation.
331- ///
332- /// Can only be constructed by calling [`UnauthenticatedReceiveTlvs::authenticate`].
333327#[ derive( Clone , Debug ) ]
334328pub 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 {
351329 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
352330 pub payment_secret : PaymentSecret ,
353331 /// Constraints for the receiver of this payment.
@@ -356,17 +334,6 @@ pub struct UnauthenticatedReceiveTlvs {
356334 pub payment_context : PaymentContext ,
357335}
358336
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-
370337/// Data to construct a [`BlindedHop`] for sending a payment over.
371338///
372339/// [`BlindedHop`]: crate::blinded_path::BlindedHop
@@ -539,19 +506,12 @@ impl Writeable for TrampolineForwardTlvs {
539506 }
540507}
541508
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.
542514impl 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 {
555515 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
556516 encode_tlv_stream ! ( w, {
557517 ( 12 , self . payment_constraints, required) ,
@@ -586,7 +546,6 @@ impl Readable for BlindedPaymentTlvs {
586546 ( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
587547 ( 65536 , payment_secret, option) ,
588548 ( 65537 , payment_context, option) ,
589- ( 65539 , authentication, option) ,
590549 } ) ;
591550
592551 if let Some ( short_channel_id) = scid {
@@ -605,12 +564,9 @@ impl Readable for BlindedPaymentTlvs {
605564 return Err ( DecodeError :: InvalidValue ) ;
606565 }
607566 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 ) ?,
614570 } ) )
615571 }
616572 }
@@ -626,7 +582,6 @@ impl Readable for BlindedTrampolineTlvs {
626582 ( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
627583 ( 65536 , payment_secret, option) ,
628584 ( 65537 , payment_context, option) ,
629- ( 65539 , authentication, option) ,
630585 } ) ;
631586
632587 if let Some ( next_trampoline) = next_trampoline {
@@ -645,12 +600,9 @@ impl Readable for BlindedTrampolineTlvs {
645600 return Err ( DecodeError :: InvalidValue ) ;
646601 }
647602 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 ) ?,
654606 } ) )
655607 }
656608 }
@@ -737,7 +689,7 @@ where
737689}
738690
739691pub ( super ) fn compute_payinfo (
740- intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & UnauthenticatedReceiveTlvs ,
692+ intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & ReceiveTlvs ,
741693 payee_htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 ,
742694) -> Result < BlindedPayInfo , ( ) > {
743695 let ( aggregated_base_fee, aggregated_prop_fee) =
@@ -860,7 +812,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
860812mod tests {
861813 use crate :: blinded_path:: payment:: {
862814 Bolt12RefundContext , ForwardTlvs , PaymentConstraints , PaymentContext , PaymentForwardNode ,
863- PaymentRelay , UnauthenticatedReceiveTlvs ,
815+ PaymentRelay , ReceiveTlvs ,
864816 } ;
865817 use crate :: ln:: functional_test_utils:: TEST_FINAL_CLTV ;
866818 use crate :: types:: features:: BlindedHopFeatures ;
@@ -910,7 +862,7 @@ mod tests {
910862 htlc_maximum_msat: u64 :: max_value( ) ,
911863 } ,
912864 ] ;
913- let recv_tlvs = UnauthenticatedReceiveTlvs {
865+ let recv_tlvs = ReceiveTlvs {
914866 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
915867 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
916868 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -928,7 +880,7 @@ mod tests {
928880
929881 #[ test]
930882 fn compute_payinfo_1_hop ( ) {
931- let recv_tlvs = UnauthenticatedReceiveTlvs {
883+ let recv_tlvs = ReceiveTlvs {
932884 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
933885 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
934886 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -985,7 +937,7 @@ mod tests {
985937 htlc_maximum_msat: u64 :: max_value( ) ,
986938 } ,
987939 ] ;
988- let recv_tlvs = UnauthenticatedReceiveTlvs {
940+ let recv_tlvs = ReceiveTlvs {
989941 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
990942 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 3 } ,
991943 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1044,7 +996,7 @@ mod tests {
1044996 htlc_maximum_msat: u64 :: max_value( ) ,
1045997 } ,
1046998 ] ;
1047- let recv_tlvs = UnauthenticatedReceiveTlvs {
999+ let recv_tlvs = ReceiveTlvs {
10481000 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
10491001 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
10501002 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1113,7 +1065,7 @@ mod tests {
11131065 htlc_maximum_msat: 10_000 ,
11141066 } ,
11151067 ] ;
1116- let recv_tlvs = UnauthenticatedReceiveTlvs {
1068+ let recv_tlvs = ReceiveTlvs {
11171069 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
11181070 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
11191071 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
0 commit comments