@@ -59,35 +59,14 @@ impl Writeable for ReceiveTlvs {
5959pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
6060 secp_ctx : & Secp256k1 < T > , unblinded_path : & [ PublicKey ] , session_priv : & SecretKey
6161) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
62- let mut blinded_hops = Vec :: with_capacity ( unblinded_path. len ( ) ) ;
62+ let blinded_tlvs = unblinded_path. iter ( )
63+ . skip ( 1 ) // The first node's TLVs contains the next node's pubkey
64+ . map ( |pk| {
65+ ControlTlvs :: Forward ( ForwardTlvs { next_node_id : * pk, next_blinding_override : None } )
66+ } )
67+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { path_id : None } ) ) ) ;
6368
64- let mut prev_ss_and_blinded_node_id = None ;
65- utils:: construct_keys_callback ( secp_ctx, unblinded_path. iter ( ) , None , session_priv,
66- |blinded_node_id, _, _, encrypted_payload_ss, unblinded_pk, _| {
67- if let Some ( ( prev_ss, prev_blinded_node_id) ) = prev_ss_and_blinded_node_id {
68- if let Some ( pk) = unblinded_pk {
69- let payload = ForwardTlvs {
70- next_node_id : pk,
71- next_blinding_override : None ,
72- } ;
73- blinded_hops. push ( BlindedHop {
74- blinded_node_id : prev_blinded_node_id,
75- encrypted_payload : utils:: encrypt_payload ( payload, prev_ss) ,
76- } ) ;
77- } else { debug_assert ! ( false ) ; }
78- }
79- prev_ss_and_blinded_node_id = Some ( ( encrypted_payload_ss, blinded_node_id) ) ;
80- } ) ?;
81-
82- if let Some ( ( final_ss, final_blinded_node_id) ) = prev_ss_and_blinded_node_id {
83- let final_payload = ReceiveTlvs { path_id : None } ;
84- blinded_hops. push ( BlindedHop {
85- blinded_node_id : final_blinded_node_id,
86- encrypted_payload : utils:: encrypt_payload ( final_payload, final_ss) ,
87- } ) ;
88- } else { debug_assert ! ( false ) }
89-
90- Ok ( blinded_hops)
69+ utils:: construct_blinded_hops ( secp_ctx, unblinded_path. iter ( ) , blinded_tlvs, session_priv)
9170}
9271
9372// Advance the blinded onion message path by one hop, so make the second hop into the new
0 commit comments