From 61a1b14f166e2f97be8c02418883d76172cd00d7 Mon Sep 17 00:00:00 2001 From: Chuks Agbakuru Date: Tue, 17 Mar 2026 19:57:36 +0100 Subject: [PATCH] Expose Display, Debug, and Eq for HRN bindings Following the LDK 0.2-upgrade and the addition of a Display implementation for HumanReadableName in rust-lightning#3829, this commit exposes the Display, Debug, and Eq traits to UniFFI. This allows downstream users (Swift, Kotlin, Python) to compare names and print BIP 353 formatted strings natively. Added unit tests to verify trait implementation and BIP 353 prefix rendering. --- src/ffi/types.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ffi/types.rs b/src/ffi/types.rs index f39f3bca7..06dce4948 100644 --- a/src/ffi/types.rs +++ b/src/ffi/types.rs @@ -382,7 +382,8 @@ impl std::fmt::Display for Offer { /// This struct can also be used for LN-Address recipients. /// /// [Homograph Attacks]: https://en.wikipedia.org/wiki/IDN_homograph_attack -#[derive(uniffi::Object)] +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, uniffi::Object)] +#[uniffi::export(Debug, Display, Eq)] pub struct HumanReadableName { pub(crate) inner: LdkHumanReadableName, } @@ -439,6 +440,12 @@ impl AsRef for HumanReadableName { } } +impl std::fmt::Display for HumanReadableName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.inner) + } +} + /// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`]. /// /// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to @@ -1987,4 +1994,21 @@ mod tests { assert_eq!(ldk_invoice.signable_hash().to_vec(), wrapped_invoice.signable_hash()); } + + #[test] + fn test_hrn_traits() { + let encoded = "alice@lightning.space"; + let hrn1 = HumanReadableName::from_encoded(encoded).unwrap(); + let hrn2 = HumanReadableName::from_encoded(encoded).unwrap(); + + assert_eq!(hrn1.to_string(), "â‚¿alice@lightning.space"); + + assert_eq!(hrn1, hrn2); + + let debug_output = format!("{:?}", hrn1); + assert!(debug_output.contains("HumanReadableName")); + + let hrn3 = hrn1; + assert_eq!(hrn1, hrn3); + } }