@@ -22,11 +22,12 @@ use bitcoin::blockdata::transaction::Transaction;
22
22
use bitcoin::blockdata::constants::{genesis_block, ChainHash};
23
23
use bitcoin::network::constants::Network;
24
24
25
- use bitcoin::hashes::Hash;
25
+ use bitcoin::hashes::{Hash, HashEngine};
26
+ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
26
27
use bitcoin::hashes::sha256::Hash as Sha256;
27
28
use bitcoin::hash_types::{BlockHash, Txid};
28
29
29
- use bitcoin::secp256k1::{SecretKey, PublicKey};
30
+ use bitcoin::secp256k1::{PublicKey, Scalar, SecretKey };
30
31
use bitcoin::secp256k1::Secp256k1;
31
32
use bitcoin::{LockTime, secp256k1, Sequence};
32
33
@@ -49,7 +50,7 @@ use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Pa
49
50
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
50
51
use crate::ln::msgs;
51
52
use crate::ln::onion_utils;
52
- use crate::ln::onion_utils::HTLCFailReason;
53
+ use crate::ln::onion_utils::{ HTLCFailReason, INVALID_ONION_BLINDING} ;
53
54
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
54
55
#[cfg(test)]
55
56
use crate::ln::outbound_payment;
@@ -2763,13 +2764,26 @@ where
2763
2764
payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata, ..
2764
2765
} =>
2765
2766
(payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata),
2766
- msgs::InboundOnionPayload::Forward { .. } =>
2767
+ msgs::InboundOnionPayload::BlindedReceive {
2768
+ amt_msat, total_msat, outgoing_cltv_value, payment_secret, ..
2769
+ } => {
2770
+ let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat };
2771
+ (Some(payment_data), None, Vec::new(), amt_msat, outgoing_cltv_value, None)
2772
+ }
2773
+ msgs::InboundOnionPayload::Forward { .. } => {
2767
2774
return Err(InboundOnionErr {
2768
2775
err_code: 0x4000|22,
2769
2776
err_data: Vec::new(),
2770
2777
msg: "Got non final data with an HMAC of 0",
2771
- }),
2772
- _ => todo!()
2778
+ })
2779
+ },
2780
+ msgs::InboundOnionPayload::BlindedForward { .. } => {
2781
+ return Err(InboundOnionErr {
2782
+ msg: "Got blinded non final data with an HMAC of 0",
2783
+ err_code: INVALID_ONION_BLINDING,
2784
+ err_data: vec![0; 32],
2785
+ })
2786
+ },
2773
2787
};
2774
2788
// final_incorrect_cltv_expiry
2775
2789
if outgoing_cltv_value > cltv_expiry {
@@ -2882,8 +2896,15 @@ where
2882
2896
return_malformed_err!("invalid ephemeral pubkey", 0x8000 | 0x4000 | 6);
2883
2897
}
2884
2898
2899
+ let blinded_node_id_tweak = msg.blinding_point.map(|bp| {
2900
+ let blinded_tlvs_ss = self.node_signer.ecdh(
2901
+ Recipient::Node, &bp, None).unwrap().secret_bytes();
2902
+ let mut hmac = HmacEngine::<Sha256>::new(b"blinded_node_id");
2903
+ hmac.input(blinded_tlvs_ss.as_ref());
2904
+ Scalar::from_be_bytes(Hmac::from_engine(hmac).into_inner()).unwrap()
2905
+ });
2885
2906
let shared_secret = self.node_signer.ecdh(
2886
- Recipient::Node, &msg.onion_routing_packet.public_key.unwrap(), None
2907
+ Recipient::Node, &msg.onion_routing_packet.public_key.unwrap(), blinded_node_id_tweak.as_ref()
2887
2908
).unwrap().secret_bytes();
2888
2909
2889
2910
if msg.onion_routing_packet.version != 0 {
0 commit comments