From c5658f6cc2cfa6eee2a45d206b08933d30f1a275 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 3 Oct 2024 16:54:10 +0000 Subject: [PATCH] Check that the HRPs generated in BOLT 11 `RawHrp` are always valid ...in `debug_assertions`. --- lightning-invoice/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 363708960..f696e3545 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -313,6 +313,7 @@ impl RawHrp { pub fn to_hrp(&self) -> bech32::Hrp { let hrp_str = self.to_string(); let s = core::str::from_utf8(&hrp_str.as_bytes()).expect("HRP bytes should be ASCII"); + debug_assert!(bech32::Hrp::parse(s).is_ok(), "We should always build BIP 173-valid HRPs"); bech32::Hrp::parse_unchecked(s) } } -- 2.39.5