From 8ce438c3885bebf2258cd227e79f7fbd3e6f8711 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Mon, 24 Mar 2025 22:54:12 +0100 Subject: [PATCH] rename from_raw to from_blinded_path This adds the option to initialize a `BlindedMessagePath` from its constituent parts. Useful when you need to reconstruct a blinded path from previously serialized components. The `from_blinded_path` function is made public. --- lightning/src/blinded_path/message.rs | 11 +++++++++-- lightning/src/offers/invoice.rs | 10 +++++----- lightning/src/offers/offer.rs | 12 ++++++------ lightning/src/offers/refund.rs | 10 +++++----- lightning/src/offers/static_invoice.rs | 2 +- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 5a5821043c8..0e3977ab68e 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -202,8 +202,15 @@ impl BlindedMessagePath { &mut self.0.introduction_node } - #[cfg(test)] - pub fn from_raw( + /// Creates a new [`BlindedMessagePath`] from its constituent parts. + /// + /// Useful when you need to reconstruct a blinded path from previously serialized components. + /// + /// Parameters: + /// * `introduction_node_id`: The public key of the introduction node in the path + /// * `blinding_point`: The public key used for blinding the path + /// * `blinded_hops`: The encrypted routing information for each hop in the path + pub fn from_blinded_path( introduction_node_id: PublicKey, blinding_point: PublicKey, blinded_hops: Vec, ) -> Self { Self(BlindedPath { diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 5d49f1a7be3..cc7e8a8ab27 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -2181,7 +2181,7 @@ mod tests { let secp_ctx = Secp256k1::new(); let payment_id = PaymentId([1; 32]); - let blinded_path = BlindedMessagePath::from_raw( + let blinded_path = BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -2276,7 +2276,7 @@ mod tests { let entropy = FixedEntropy {}; let secp_ctx = Secp256k1::new(); - let blinded_path = BlindedMessagePath::from_raw( + let blinded_path = BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -2982,7 +2982,7 @@ mod tests { let payment_id = PaymentId([1; 32]); let paths = vec![ - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -2990,7 +2990,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ], ), - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -3532,7 +3532,7 @@ mod tests { .sign(recipient_sign) .unwrap(); - let blinded_path = BlindedMessagePath::from_raw( + let blinded_path = BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 52aa782da1d..fee7b6fe486 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -1462,7 +1462,7 @@ mod tests { let secp_ctx = Secp256k1::new(); let payment_id = PaymentId([1; 32]); - let blinded_path = BlindedMessagePath::from_raw( + let blinded_path = BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1643,7 +1643,7 @@ mod tests { #[test] fn builds_offer_with_paths() { let paths = vec![ - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1651,7 +1651,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ], ), - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1856,7 +1856,7 @@ mod tests { #[test] fn parses_offer_with_paths() { let offer = OfferBuilder::new(pubkey(42)) - .path(BlindedMessagePath::from_raw( + .path(BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1864,7 +1864,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ], )) - .path(BlindedMessagePath::from_raw( + .path(BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1879,7 +1879,7 @@ mod tests { } let offer = OfferBuilder::new(pubkey(42)) - .path(BlindedMessagePath::from_raw( + .path(BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index c5c4f498002..ec7477e24a6 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -1219,7 +1219,7 @@ mod tests { let secp_ctx = Secp256k1::new(); let payment_id = PaymentId([1; 32]); - let blinded_path = BlindedMessagePath::from_raw( + let blinded_path = BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1332,7 +1332,7 @@ mod tests { #[test] fn builds_refund_with_paths() { let paths = vec![ - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1340,7 +1340,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ], ), - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1585,7 +1585,7 @@ mod tests { fn parses_refund_with_optional_fields() { let past_expiry = Duration::from_secs(0); let paths = vec![ - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ @@ -1593,7 +1593,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ], ), - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![ diff --git a/lightning/src/offers/static_invoice.rs b/lightning/src/offers/static_invoice.rs index e61ae781bc1..0ebf33a23dc 100644 --- a/lightning/src/offers/static_invoice.rs +++ b/lightning/src/offers/static_invoice.rs @@ -779,7 +779,7 @@ mod tests { } fn blinded_path() -> BlindedMessagePath { - BlindedMessagePath::from_raw( + BlindedMessagePath::from_blinded_path( pubkey(40), pubkey(41), vec![