@@ -32,6 +32,8 @@ use bitcoin::script::ScriptBuf;
32
32
use bitcoin:: hash_types:: Txid ;
33
33
34
34
use crate :: blinded_path:: payment:: { BlindedPaymentTlvs , ForwardTlvs , ReceiveTlvs , UnauthenticatedReceiveTlvs } ;
35
+ #[ cfg( trampoline) ]
36
+ use crate :: blinded_path:: payment:: { BlindedTrampolineTlvs , TrampolineForwardTlvs } ;
35
37
use crate :: ln:: channelmanager:: Verification ;
36
38
use crate :: ln:: types:: ChannelId ;
37
39
use crate :: types:: payment:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
@@ -1794,6 +1796,8 @@ mod fuzzy_internal_msgs {
1794
1796
use bitcoin:: secp256k1:: PublicKey ;
1795
1797
use crate :: blinded_path:: payment:: { BlindedPaymentPath , PaymentConstraints , PaymentContext , PaymentRelay } ;
1796
1798
use crate :: offers:: invoice_request:: InvoiceRequest ;
1799
+ #[ cfg( trampoline) ]
1800
+ use crate :: routing:: gossip:: NodeId ;
1797
1801
use crate :: types:: payment:: { PaymentPreimage , PaymentSecret } ;
1798
1802
use crate :: types:: features:: { BlindedHopFeatures , Bolt12InvoiceFeatures } ;
1799
1803
use super :: { FinalOnionHopData , TrampolineOnionPacket } ;
@@ -1812,6 +1816,7 @@ mod fuzzy_internal_msgs {
1812
1816
}
1813
1817
1814
1818
#[ cfg( trampoline) ]
1819
+ #[ cfg_attr( trampoline, allow( unused) ) ]
1815
1820
pub struct InboundTrampolineEntrypointPayload {
1816
1821
pub amt_to_forward : u64 ,
1817
1822
pub outgoing_cltv_value : u32 ,
@@ -1852,12 +1857,42 @@ mod fuzzy_internal_msgs {
1852
1857
pub enum InboundOnionPayload {
1853
1858
Forward ( InboundOnionForwardPayload ) ,
1854
1859
#[ cfg( trampoline) ]
1860
+ #[ cfg_attr( trampoline, allow( unused) ) ]
1855
1861
TrampolineEntrypoint ( InboundTrampolineEntrypointPayload ) ,
1856
1862
Receive ( InboundOnionReceivePayload ) ,
1857
1863
BlindedForward ( InboundOnionBlindedForwardPayload ) ,
1858
1864
BlindedReceive ( InboundOnionBlindedReceivePayload ) ,
1859
1865
}
1860
1866
1867
+ #[ cfg( trampoline) ]
1868
+ #[ cfg_attr( trampoline, allow( unused) ) ]
1869
+ pub struct InboundTrampolineForwardPayload {
1870
+ pub next_trampoline : NodeId ,
1871
+ /// The value, in msat, of the payment after this hop's fee is deducted.
1872
+ pub amt_to_forward : u64 ,
1873
+ pub outgoing_cltv_value : u32 ,
1874
+ }
1875
+
1876
+ #[ cfg( trampoline) ]
1877
+ #[ cfg_attr( trampoline, allow( unused) ) ]
1878
+ pub struct InboundTrampolineBlindedForwardPayload {
1879
+ pub next_trampoline : NodeId ,
1880
+ pub payment_relay : PaymentRelay ,
1881
+ pub payment_constraints : PaymentConstraints ,
1882
+ pub features : BlindedHopFeatures ,
1883
+ pub intro_node_blinding_point : Option < PublicKey > ,
1884
+ pub next_blinding_override : Option < PublicKey > ,
1885
+ }
1886
+
1887
+ #[ cfg( trampoline) ]
1888
+ #[ cfg_attr( trampoline, allow( unused) ) ]
1889
+ pub enum InboundTrampolinePayload {
1890
+ Forward ( InboundTrampolineForwardPayload ) ,
1891
+ BlindedForward ( InboundTrampolineBlindedForwardPayload ) ,
1892
+ Receive ( InboundOnionReceivePayload ) ,
1893
+ BlindedReceive ( InboundOnionBlindedReceivePayload ) ,
1894
+ }
1895
+
1861
1896
pub ( crate ) enum OutboundOnionPayload < ' a > {
1862
1897
Forward {
1863
1898
short_channel_id : u64 ,
@@ -3073,6 +3108,134 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
3073
3108
}
3074
3109
}
3075
3110
3111
+ #[ cfg( trampoline) ]
3112
+ impl < NS : Deref > ReadableArgs < ( Option < PublicKey > , NS ) > for InboundTrampolinePayload where NS :: Target : NodeSigner {
3113
+ fn read < R : Read > ( r : & mut R , args : ( Option < PublicKey > , NS ) ) -> Result < Self , DecodeError > {
3114
+ let ( update_add_blinding_point, node_signer) = args;
3115
+
3116
+ let mut amt = None ;
3117
+ let mut cltv_value = None ;
3118
+ let mut payment_data: Option < FinalOnionHopData > = None ;
3119
+ let mut encrypted_tlvs_opt: Option < WithoutLength < Vec < u8 > > > = None ;
3120
+ let mut intro_node_blinding_point = None ;
3121
+ let mut next_trampoline: Option < NodeId > = None ;
3122
+ let mut payment_metadata: Option < WithoutLength < Vec < u8 > > > = None ;
3123
+ let mut total_msat = None ;
3124
+ let mut keysend_preimage: Option < PaymentPreimage > = None ;
3125
+ let mut invoice_request: Option < InvoiceRequest > = None ;
3126
+ let mut custom_tlvs = Vec :: new ( ) ;
3127
+
3128
+ let tlv_len = BigSize :: read ( r) ?;
3129
+ let mut rd = FixedLengthReader :: new ( r, tlv_len. 0 ) ;
3130
+ decode_tlv_stream_with_custom_tlv_decode ! ( & mut rd, {
3131
+ ( 2 , amt, ( option, encoding: ( u64 , HighZeroBytesDroppedBigSize ) ) ) ,
3132
+ ( 4 , cltv_value, ( option, encoding: ( u32 , HighZeroBytesDroppedBigSize ) ) ) ,
3133
+ ( 8 , payment_data, option) ,
3134
+ ( 10 , encrypted_tlvs_opt, option) ,
3135
+ ( 12 , intro_node_blinding_point, option) ,
3136
+ ( 14 , next_trampoline, option) ,
3137
+ ( 16 , payment_metadata, option) ,
3138
+ ( 18 , total_msat, ( option, encoding: ( u64 , HighZeroBytesDroppedBigSize ) ) ) ,
3139
+ ( 77_777 , invoice_request, option) ,
3140
+ // See https://github.com/lightning/blips/blob/master/blip-0003.md
3141
+ ( 5482373484 , keysend_preimage, option)
3142
+ } , |msg_type: u64 , msg_reader: & mut FixedLengthReader <_>| -> Result <bool , DecodeError > {
3143
+ if msg_type < 1 << 16 { return Ok ( false ) }
3144
+ let mut value = Vec :: new( ) ;
3145
+ msg_reader. read_to_limit( & mut value, u64 :: MAX ) ?;
3146
+ custom_tlvs. push( ( msg_type, value) ) ;
3147
+ Ok ( true )
3148
+ } ) ;
3149
+
3150
+ if amt. unwrap_or ( 0 ) > MAX_VALUE_MSAT { return Err ( DecodeError :: InvalidValue ) }
3151
+ if intro_node_blinding_point. is_some ( ) && update_add_blinding_point. is_some ( ) {
3152
+ return Err ( DecodeError :: InvalidValue )
3153
+ }
3154
+
3155
+ if let Some ( blinding_point) = intro_node_blinding_point. or ( update_add_blinding_point) {
3156
+ if next_trampoline. is_some ( ) || payment_data. is_some ( ) || payment_metadata. is_some ( ) {
3157
+ return Err ( DecodeError :: InvalidValue )
3158
+ }
3159
+ let enc_tlvs = encrypted_tlvs_opt. ok_or ( DecodeError :: InvalidValue ) ?. 0 ;
3160
+ let enc_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & blinding_point, None )
3161
+ . map_err ( |_| DecodeError :: InvalidValue ) ?;
3162
+ let rho = onion_utils:: gen_rho_from_shared_secret ( & enc_tlvs_ss. secret_bytes ( ) ) ;
3163
+ let mut s = Cursor :: new ( & enc_tlvs) ;
3164
+ let mut reader = FixedLengthReader :: new ( & mut s, enc_tlvs. len ( ) as u64 ) ;
3165
+ match ChaChaPolyReadAdapter :: read ( & mut reader, rho) ? {
3166
+ ChaChaPolyReadAdapter { readable : BlindedTrampolineTlvs :: Forward ( TrampolineForwardTlvs {
3167
+ next_trampoline, payment_relay, payment_constraints, features, next_blinding_override
3168
+ } ) } => {
3169
+ if amt. is_some ( ) || cltv_value. is_some ( ) || total_msat. is_some ( ) ||
3170
+ keysend_preimage. is_some ( ) || invoice_request. is_some ( )
3171
+ {
3172
+ return Err ( DecodeError :: InvalidValue )
3173
+ }
3174
+ Ok ( Self :: BlindedForward ( InboundTrampolineBlindedForwardPayload {
3175
+ next_trampoline,
3176
+ payment_relay,
3177
+ payment_constraints,
3178
+ features,
3179
+ intro_node_blinding_point,
3180
+ next_blinding_override,
3181
+ } ) )
3182
+ } ,
3183
+ ChaChaPolyReadAdapter { readable : BlindedTrampolineTlvs :: Receive ( receive_tlvs) } => {
3184
+ let ReceiveTlvs { tlvs, authentication : ( hmac, nonce) } = receive_tlvs;
3185
+ let expanded_key = node_signer. get_inbound_payment_key ( ) ;
3186
+ if tlvs. verify_for_offer_payment ( hmac, nonce, & expanded_key) . is_err ( ) {
3187
+ return Err ( DecodeError :: InvalidValue ) ;
3188
+ }
3189
+
3190
+ let UnauthenticatedReceiveTlvs {
3191
+ payment_secret, payment_constraints, payment_context,
3192
+ } = tlvs;
3193
+ if total_msat. unwrap_or ( 0 ) > MAX_VALUE_MSAT { return Err ( DecodeError :: InvalidValue ) }
3194
+ Ok ( Self :: BlindedReceive ( InboundOnionBlindedReceivePayload {
3195
+ sender_intended_htlc_amt_msat : amt. ok_or ( DecodeError :: InvalidValue ) ?,
3196
+ total_msat : total_msat. ok_or ( DecodeError :: InvalidValue ) ?,
3197
+ cltv_expiry_height : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
3198
+ payment_secret,
3199
+ payment_constraints,
3200
+ payment_context,
3201
+ intro_node_blinding_point,
3202
+ keysend_preimage,
3203
+ invoice_request,
3204
+ custom_tlvs,
3205
+ } ) )
3206
+ } ,
3207
+ }
3208
+ } else if let Some ( next_trampoline) = next_trampoline {
3209
+ if payment_data. is_some ( ) || payment_metadata. is_some ( ) || encrypted_tlvs_opt. is_some ( ) ||
3210
+ total_msat. is_some ( ) || invoice_request. is_some ( )
3211
+ { return Err ( DecodeError :: InvalidValue ) }
3212
+ Ok ( Self :: Forward ( InboundTrampolineForwardPayload {
3213
+ next_trampoline,
3214
+ amt_to_forward : amt. ok_or ( DecodeError :: InvalidValue ) ?,
3215
+ outgoing_cltv_value : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
3216
+ } ) )
3217
+ } else {
3218
+ if encrypted_tlvs_opt. is_some ( ) || total_msat. is_some ( ) || invoice_request. is_some ( ) {
3219
+ return Err ( DecodeError :: InvalidValue )
3220
+ }
3221
+ if let Some ( data) = & payment_data {
3222
+ if data. total_msat > MAX_VALUE_MSAT {
3223
+ return Err ( DecodeError :: InvalidValue ) ;
3224
+ }
3225
+ }
3226
+ Ok ( Self :: Receive ( InboundOnionReceivePayload {
3227
+ payment_data,
3228
+ payment_metadata : payment_metadata. map ( |w| w. 0 ) ,
3229
+ keysend_preimage,
3230
+ sender_intended_htlc_amt_msat : amt. ok_or ( DecodeError :: InvalidValue ) ?,
3231
+ cltv_expiry_height : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
3232
+ custom_tlvs,
3233
+ } ) )
3234
+ }
3235
+ }
3236
+ }
3237
+
3238
+
3076
3239
impl Writeable for Ping {
3077
3240
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
3078
3241
self . ponglen . write ( w) ?;
0 commit comments