use crate::{prng::derive_many_mod_p, Field};
#[derive(Debug, Clone)]
pub struct Transcript {
domain_tag: &'static [u8],
words: Vec<u64>,
counter: u64,
}
impl Transcript {
pub fn new(domain_tag: &'static [u8]) -> Self {
Self {
domain_tag,
words: Vec::new(),
counter: 0,
}
}
pub fn append(&mut self, value: u64) {
self.words.push(value);
}
pub fn append_slice(&mut self, values: &[u64]) {
self.words.extend_from_slice(values);
}
pub fn snapshot(&self) -> &[u64] {
&self.words
}
pub fn challenge(&mut self, field: &Field) -> u64 {
self.words.push(self.counter);
let challenge = derive_many_mod_p(field.modulus(), self.domain_tag, &self.words, 1)[0];
self.words.pop();
self.words.push(challenge);
self.counter = self.counter.wrapping_add(1);
challenge
}
}