@@ -73,6 +73,8 @@ pub(super) fn gen_ammag_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] {
73
73
Hmac :: from_engine ( hmac) . into_inner ( )
74
74
}
75
75
76
+ pub ( super ) fn next_hop_packet_pubkey ( packet_pubkey : & PublicKey , packet_shared_secret : & SharedSecret ) -> Result < PublicKey , secp256k1:: Error > { }
77
+
76
78
/// Used in the construction of keys to build the onion routing packet for payments and onion
77
79
/// messages, in `construct_onion_keys_callback`.
78
80
///
@@ -547,15 +549,25 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
547
549
} else { unreachable ! ( ) ; }
548
550
}
549
551
552
+ /// Used in the decoding of inbound payments' and onion messages' routing packets. This enum allows
553
+ /// us to use `decode_next_hop` for returning the payloads and next hop packet bytes of both
554
+ /// payments and onion messages.
555
+ pub ( crate ) enum Payload {
556
+ /// This payload was for an incoming payment.
557
+ Payment ( msgs:: OnionPayload ) ,
558
+ /// This payload was for an incoming onion message.
559
+ Message ( msgs:: OnionMsgPayload ) ,
560
+ }
561
+
550
562
/// Data decrypted from the onion payload.
551
563
pub ( crate ) enum HopPayload {
552
- /// This onion payload was for us, not for forwarding to a next-hop. Contains information for
553
- /// verifying the incoming payment.
554
- Receive ( msgs :: OnionHopData ) ,
564
+ /// This onion payload was for us, not for forwarding to a next-hop. If we're receiving a payment,
565
+ /// this contains information for verifying the incoming payment.
566
+ Receive ( Payload ) ,
555
567
/// This onion payload needs to be forwarded to a next-hop.
556
568
Forward {
557
- /// Onion payload data used in forwarding the payment.
558
- next_hop_data : msgs :: OnionHopData ,
569
+ /// Onion payload data used in forwarding the payment or onion message .
570
+ next_hop_data : Payload ,
559
571
/// HMAC of the next hop's onion packet.
560
572
next_hop_hmac : [ u8 ; 32 ] ,
561
573
/// Bytes of the onion packet we're forwarding.
@@ -577,7 +589,18 @@ pub(crate) enum OnionDecodeErr {
577
589
} ,
578
590
}
579
591
580
- pub ( crate ) fn decode_next_hop ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , payment_hash : PaymentHash ) -> Result < Hop , OnionDecodeErr > {
592
+ /// Used in the decoding of inbound payments' and onion messages' routing packets. This enum
593
+ /// indicates whether the incoming packet corresponds to a payment or an onion message.
594
+ pub ( crate ) enum Onion {
595
+ /// We're receiving an inbound payment, so the payment hash is provided as associated data for
596
+ /// calculating the packet hmac.
597
+ Payment ( PaymentHash ) ,
598
+ /// We're receiving an inbound onion message, so the `rho` is provided for decrypting the onion
599
+ /// message's `encrypted_data` field.
600
+ Message ( [ u8 ; 32 ] ,
601
+ }
602
+
603
+ pub ( crate ) fn decode_next_hop ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , onion_type : Onion ) -> Result < Hop , OnionDecodeErr > {
581
604
let ( rho, mu) = gen_rho_mu_from_shared_secret ( & shared_secret) ;
582
605
let mut hmac = HmacEngine :: < Sha256 > :: new ( & mu) ;
583
606
hmac. input ( hop_data) ;
0 commit comments