Skip to content

Commit bf3bc42

Browse files
authored
Merge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash
util: Adds Into<PaymentHash> for PaymentPreimage
2 parents cfb4391 + d2ffcbc commit bf3bc42

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
@@ -85,6 +85,8 @@ mod offers_tests;
8585

8686
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
8787

88+
use bitcoin::hashes::{sha256::Hash as Sha256, Hash};
89+
8890
/// payment_hash type, use to cross-lock hop
8991
///
9092
/// This is not exported to bindings users as we just use [u8; 32] directly
@@ -109,6 +111,13 @@ impl core::fmt::Display for PaymentPreimage {
109111
}
110112
}
111113

114+
/// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
115+
impl Into<PaymentHash> for PaymentPreimage {
116+
fn into(self) -> PaymentHash {
117+
PaymentHash(Sha256::hash(&self.0).to_byte_array())
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)