use curve25519_dalek::{EdwardsPoint, Scalar};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Domain(pub &'static [u8; 32]);
const DEF: Domain = Domain(&[0; 32]);
impl Default for Domain {
fn default() -> Self {
DEF
}
}
impl AsRef<[u8; 32]> for Domain {
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl Domain {
pub(crate) fn hash_to_scalar(&self, r: &EdwardsPoint, msg: &[u8]) -> Scalar {
Scalar::from_bytes_mod_order(self.hash(r.compress().as_bytes(), msg))
}
pub(crate) fn hash(&self, prefix: &[u8; 32], msg: &[u8]) -> [u8; 32] {
*blake3::Hasher::new_keyed(&self.0)
.update(prefix)
.update(msg)
.finalize()
.as_bytes()
}
}