use super::*;
impl<N: Network> Record<N, Plaintext<N>> {
pub fn to_commitment(
&self,
program_id: &ProgramID<N>,
record_name: &Identifier<N>,
record_view_key: &Field<N>,
) -> Result<Field<N>> {
let input = to_bits_le![program_id, record_name, self];
let input_v0 = input[..input.len() - 8].to_vec();
let digest = N::hash_bhp1024(&input_v0)?;
let mut input_v1 = digest.to_bits_le();
input_v1.extend_from_slice(&input[input.len() - 8..]);
match !self.is_hiding() {
true => Ok(digest),
false => {
let cm_nonce = N::hash_to_scalar_psd2(&[N::commitment_domain(), *record_view_key])?;
N::commit_bhp512(&input_v1, &cm_nonce)
}
}
}
}
impl<N: Network> Record<N, Ciphertext<N>> {
pub fn to_commitment(
&self,
_program_id: &ProgramID<N>,
_record_name: &Identifier<N>,
_record_view_key: &Field<N>,
) -> Result<Field<N>> {
bail!("Illegal operation: Record::to_commitment() cannot be invoked on the `Ciphertext` variant.")
}
}