Skip to content

Commit 8c1ce0a

Browse files
committed
util: Adds Into<PaymentHash> for PaymentPreimage
This seems like a useful interface to have for downstream users
1 parent affe557 commit 8c1ce0a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightning/src/ln/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod channel;
3434
#[cfg(not(fuzzing))]
3535
pub(crate) mod channel;
3636

37+
use bitcoin::secp256k1::ThirtyTwoByteHash;
3738
// Re-export ChannelId
3839
pub use channel_id::ChannelId;
3940

@@ -85,6 +86,8 @@ mod offers_tests;
8586

8687
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
8788

89+
use bitcoin::hashes::{sha256::Hash as Sha256, Hash};
90+
8891
/// payment_hash type, use to cross-lock hop
8992
///
9093
/// This is not exported to bindings users as we just use [u8; 32] directly
@@ -109,6 +112,12 @@ impl core::fmt::Display for PaymentPreimage {
109112
}
110113
}
111114

115+
impl Into<PaymentHash> for PaymentPreimage {
116+
fn into(self) -> PaymentHash {
117+
PaymentHash(Sha256::hash(&self.0).into_32())
118+
}
119+
}
120+
112121
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
113122
///
114123
/// This is not exported to bindings users as we just use [u8; 32] directly

0 commit comments

Comments
 (0)