Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Adds Into<PaymentHash> for PaymentPreimage #2916

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lightning/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ mod offers_tests;

pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;

use bitcoin::hashes::{sha256::Hash as Sha256, Hash};

/// payment_hash type, use to cross-lock hop
///
/// This is not exported to bindings users as we just use [u8; 32] directly
Expand All @@ -109,6 +111,13 @@ impl core::fmt::Display for PaymentPreimage {
}
}

/// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
impl Into<PaymentHash> for PaymentPreimage {
fn into(self) -> PaymentHash {
PaymentHash(Sha256::hash(&self.0).to_byte_array())
}
}

/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
///
/// This is not exported to bindings users as we just use [u8; 32] directly
Expand Down
Loading