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 ) ?;
@@ -334,26 +330,8 @@ pub struct TrampolineForwardTlvs {
334330
335331/// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
336332/// may not be valid if received by another lightning implementation.
337- ///
338- /// Can only be constructed by calling [`UnauthenticatedReceiveTlvs::authenticate`].
339333#[ derive( Clone , Debug ) ]
340334pub struct ReceiveTlvs {
341- /// The TLVs for which the HMAC in `authentication` is derived.
342- pub ( crate ) tlvs : UnauthenticatedReceiveTlvs ,
343- /// An HMAC of `tlvs` along with a nonce used to construct it.
344- pub ( crate ) authentication : ( Hmac < Sha256 > , Nonce ) ,
345- }
346-
347- impl ReceiveTlvs {
348- /// Returns the underlying TLVs.
349- pub fn tlvs ( & self ) -> & UnauthenticatedReceiveTlvs {
350- & self . tlvs
351- }
352- }
353-
354- /// An unauthenticated [`ReceiveTlvs`].
355- #[ derive( Clone , Debug ) ]
356- pub struct UnauthenticatedReceiveTlvs {
357335 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
358336 pub payment_secret : PaymentSecret ,
359337 /// Constraints for the receiver of this payment.
@@ -362,17 +340,6 @@ pub struct UnauthenticatedReceiveTlvs {
362340 pub payment_context : PaymentContext ,
363341}
364342
365- impl UnauthenticatedReceiveTlvs {
366- /// Creates an authenticated [`ReceiveTlvs`], which includes an HMAC and the provide [`Nonce`]
367- /// that can be use later to verify it authenticity.
368- pub fn authenticate ( self , nonce : Nonce , expanded_key : & ExpandedKey ) -> ReceiveTlvs {
369- ReceiveTlvs {
370- authentication : ( self . hmac_for_offer_payment ( nonce, expanded_key) , nonce) ,
371- tlvs : self ,
372- }
373- }
374- }
375-
376343/// Data to construct a [`BlindedHop`] for sending a payment over.
377344///
378345/// [`BlindedHop`]: crate::blinded_path::BlindedHop
@@ -545,19 +512,12 @@ impl Writeable for TrampolineForwardTlvs {
545512 }
546513}
547514
515+ // Note: The `authentication` TLV field was removed in LDK v0.3 following
516+ // the introduction of `ReceiveAuthKey`-based authentication for inbound
517+ // `BlindedPaymentPaths`s. Because we do not support receiving to those
518+ // contexts anymore (they will fail the `ReceiveAuthKey`-based
519+ // authentication checks), we can reuse that field here.
548520impl Writeable for ReceiveTlvs {
549- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
550- encode_tlv_stream ! ( w, {
551- ( 12 , self . tlvs. payment_constraints, required) ,
552- ( 65536 , self . tlvs. payment_secret, required) ,
553- ( 65537 , self . tlvs. payment_context, required) ,
554- ( 65539 , self . authentication, required) ,
555- } ) ;
556- Ok ( ( ) )
557- }
558- }
559-
560- impl Writeable for UnauthenticatedReceiveTlvs {
561521 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
562522 encode_tlv_stream ! ( w, {
563523 ( 12 , self . payment_constraints, required) ,
@@ -592,7 +552,6 @@ impl Readable for BlindedPaymentTlvs {
592552 ( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
593553 ( 65536 , payment_secret, option) ,
594554 ( 65537 , payment_context, option) ,
595- ( 65539 , authentication, option) ,
596555 } ) ;
597556
598557 if let Some ( short_channel_id) = scid {
@@ -611,12 +570,9 @@ impl Readable for BlindedPaymentTlvs {
611570 return Err ( DecodeError :: InvalidValue ) ;
612571 }
613572 Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
614- tlvs : UnauthenticatedReceiveTlvs {
615- payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
616- payment_constraints : payment_constraints. 0 . unwrap ( ) ,
617- payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
618- } ,
619- authentication : authentication. ok_or ( DecodeError :: InvalidValue ) ?,
573+ payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
574+ payment_constraints : payment_constraints. 0 . unwrap ( ) ,
575+ payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
620576 } ) )
621577 }
622578 }
@@ -632,7 +588,6 @@ impl Readable for BlindedTrampolineTlvs {
632588 ( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
633589 ( 65536 , payment_secret, option) ,
634590 ( 65537 , payment_context, option) ,
635- ( 65539 , authentication, option) ,
636591 } ) ;
637592
638593 if let Some ( next_trampoline) = next_trampoline {
@@ -651,19 +606,15 @@ impl Readable for BlindedTrampolineTlvs {
651606 return Err ( DecodeError :: InvalidValue ) ;
652607 }
653608 Ok ( BlindedTrampolineTlvs :: Receive ( ReceiveTlvs {
654- tlvs : UnauthenticatedReceiveTlvs {
655- payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
656- payment_constraints : payment_constraints. 0 . unwrap ( ) ,
657- payment_context : payment_context. ok_or ( DecodeError :: InvalidValue ) ?,
658- } ,
659- authentication : authentication. ok_or ( DecodeError :: InvalidValue ) ?,
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 ) ?,
660612 } ) )
661613 }
662614 }
663615}
664616
665- /// Represents the padding round off size (in bytes) that
666- /// is used to pad payment bilnded path's [`BlindedHop`]
617+ /// Represents the padding round-off size (in bytes) used to pad payment blinded path's [`BlindedHop`].
667618pub ( crate ) const PAYMENT_PADDING_ROUND_OFF : usize = 30 ;
668619
669620/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
@@ -743,7 +694,7 @@ where
743694}
744695
745696pub ( super ) fn compute_payinfo (
746- intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & UnauthenticatedReceiveTlvs ,
697+ intermediate_nodes : & [ PaymentForwardNode ] , payee_tlvs : & ReceiveTlvs ,
747698 payee_htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 ,
748699) -> Result < BlindedPayInfo , ( ) > {
749700 let ( aggregated_base_fee, aggregated_prop_fee) =
@@ -866,7 +817,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
866817mod tests {
867818 use crate :: blinded_path:: payment:: {
868819 Bolt12RefundContext , ForwardTlvs , PaymentConstraints , PaymentContext , PaymentForwardNode ,
869- PaymentRelay , UnauthenticatedReceiveTlvs ,
820+ PaymentRelay , ReceiveTlvs ,
870821 } ;
871822 use crate :: ln:: functional_test_utils:: TEST_FINAL_CLTV ;
872823 use crate :: types:: features:: BlindedHopFeatures ;
@@ -916,7 +867,7 @@ mod tests {
916867 htlc_maximum_msat : u64:: max_value ( ) ,
917868 } ,
918869 ] ;
919- let recv_tlvs = UnauthenticatedReceiveTlvs {
870+ let recv_tlvs = ReceiveTlvs {
920871 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
921872 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
922873 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -934,7 +885,7 @@ mod tests {
934885
935886 #[ test]
936887 fn compute_payinfo_1_hop ( ) {
937- let recv_tlvs = UnauthenticatedReceiveTlvs {
888+ let recv_tlvs = ReceiveTlvs {
938889 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
939890 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
940891 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -991,7 +942,7 @@ mod tests {
991942 htlc_maximum_msat : u64:: max_value ( ) ,
992943 } ,
993944 ] ;
994- let recv_tlvs = UnauthenticatedReceiveTlvs {
945+ let recv_tlvs = ReceiveTlvs {
995946 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
996947 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 3 } ,
997948 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1050,7 +1001,7 @@ mod tests {
10501001 htlc_maximum_msat : u64:: max_value ( ) ,
10511002 } ,
10521003 ] ;
1053- let recv_tlvs = UnauthenticatedReceiveTlvs {
1004+ let recv_tlvs = ReceiveTlvs {
10541005 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
10551006 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
10561007 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
@@ -1119,7 +1070,7 @@ mod tests {
11191070 htlc_maximum_msat : 10_000 ,
11201071 } ,
11211072 ] ;
1122- let recv_tlvs = UnauthenticatedReceiveTlvs {
1073+ let recv_tlvs = ReceiveTlvs {
11231074 payment_secret : PaymentSecret ( [ 0 ; 32 ] ) ,
11241075 payment_constraints : PaymentConstraints { max_cltv_expiry : 0 , htlc_minimum_msat : 1 } ,
11251076 payment_context : PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ,
0 commit comments