Merge pull request #2432 from jkczyz/2023-07-bolt12-node-signer
[rust-lightning] / lightning / src / blinded_path / mod.rs
index 97d3a408cdb083603cbebca15fa40f0dda3dd1f0..c52df1651fe3a5b3a8aaf137113881a31478147f 100644 (file)
@@ -11,9 +11,7 @@
 
 pub(crate) mod utils;
 
-use bitcoin::hashes::{Hash, HashEngine};
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
+use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
 
 use crate::sign::{EntropySource, NodeSigner, Recipient};
 use crate::onion_message::ControlTlvs;
@@ -36,14 +34,14 @@ pub struct BlindedPath {
        /// message or payment's next hop and forward it along.
        ///
        /// [`encrypted_payload`]: BlindedHop::encrypted_payload
-       pub(crate) introduction_node_id: PublicKey,
+       pub introduction_node_id: PublicKey,
        /// Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
        /// message or payment.
        ///
        /// [`encrypted_payload`]: BlindedHop::encrypted_payload
-       pub(crate) blinding_point: PublicKey,
+       pub blinding_point: PublicKey,
        /// The hops composing the blinded path.
-       pub(crate) blinded_hops: Vec<BlindedHop>,
+       pub blinded_hops: Vec<BlindedHop>,
 }
 
 /// Used to construct the blinded hops portion of a blinded path. These hops cannot be identified
@@ -51,11 +49,11 @@ pub struct BlindedPath {
 #[derive(Clone, Debug, Hash, PartialEq, Eq)]
 pub struct BlindedHop {
        /// The blinded node id of this hop in a blinded path.
-       pub(crate) blinded_node_id: PublicKey,
+       pub blinded_node_id: PublicKey,
        /// The encrypted payload intended for this hop in a blinded path.
        // The node sending to this blinded path will later encode this payload into the onion packet for
        // this hop.
-       pub(crate) encrypted_payload: Vec<u8>,
+       pub encrypted_payload: Vec<u8>,
 }
 
 impl BlindedPath {
@@ -97,14 +95,8 @@ impl BlindedPath {
                                let mut new_blinding_point = match next_blinding_override {
                                        Some(blinding_point) => blinding_point,
                                        None => {
-                                               let blinding_factor = {
-                                                       let mut sha = Sha256::engine();
-                                                       sha.input(&self.blinding_point.serialize()[..]);
-                                                       sha.input(control_tlvs_ss.as_ref());
-                                                       Sha256::from_engine(sha).into_inner()
-                                               };
-                                               self.blinding_point.mul_tweak(secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap())
-                                                       .map_err(|_| ())?
+                                               onion_utils::next_hop_pubkey(secp_ctx, self.blinding_point,
+                                                       control_tlvs_ss.as_ref()).map_err(|_| ())?
                                        }
                                };
                                mem::swap(&mut self.blinding_point, &mut new_blinding_point);