fedimint_ln_common/preimage_auth.rs
1use bitcoin::hashes::{Hash as _, sha256};
2use subtle::ConstantTimeEq as _;
3
4/// Authorization value a client presents before receiving an LNv1 preimage.
5#[derive(Clone, Copy)]
6pub struct PreimageAuth(sha256::Hash);
7
8impl PreimageAuth {
9 /// Creates an authorization verifier for a stored LNv1 preimage
10 /// authorization value.
11 pub const fn new(expected: sha256::Hash) -> Self {
12 Self(expected)
13 }
14
15 /// Returns whether the supplied value authorizes access to the LNv1
16 /// preimage.
17 pub fn verifies(self, supplied: sha256::Hash) -> bool {
18 bool::from(self.0.as_byte_array().ct_eq(supplied.as_byte_array()))
19 }
20}
21
22#[cfg(test)]
23mod tests;