tlsn_core/transcript/
hash.rs

1//! Plaintext hash commitments.
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    hash::{impl_domain_separator, Blinder, HashAlgId, HashAlgorithm, TypedHash},
7    transcript::{Direction, Idx},
8};
9
10/// Hashes plaintext with a blinder.
11///
12/// By convention, plaintext is hashed as `H(msg | blinder)`.
13pub fn hash_plaintext(hasher: &dyn HashAlgorithm, msg: &[u8], blinder: &Blinder) -> TypedHash {
14    TypedHash {
15        alg: hasher.id(),
16        value: hasher.hash_prefixed(msg, blinder.as_bytes()),
17    }
18}
19
20/// Hash of plaintext in the transcript.
21#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
22pub struct PlaintextHash {
23    /// Direction of the plaintext.
24    pub direction: Direction,
25    /// Index of plaintext.
26    pub idx: Idx,
27    /// The hash of the data.
28    pub hash: TypedHash,
29}
30
31impl_domain_separator!(PlaintextHash);
32
33/// Secret component of [`PlaintextHash`].
34#[derive(Clone, Serialize, Deserialize)]
35pub struct PlaintextHashSecret {
36    /// Direction of the plaintext.
37    pub direction: Direction,
38    /// Index of plaintext.
39    pub idx: Idx,
40    /// The algorithm of the hash.
41    pub alg: HashAlgId,
42    /// Blinder for the hash.
43    pub blinder: Blinder,
44}
45
46opaque_debug::implement!(PlaintextHashSecret);