1use super::scalar::Scalar;
2use super::transcript::ProofTranscript;
3use merlin::Transcript;
4use rand::rngs::OsRng;
5
6pub struct RandomTape {
7 tape: Transcript,
8}
9
10impl RandomTape {
11 pub fn new(name: &'static [u8]) -> Self {
12 let tape = {
13 let mut csprng: OsRng = OsRng;
14 let mut tape = Transcript::new(name);
15 tape.append_scalar(b"init_randomness", &Scalar::random(&mut csprng));
16 tape
17 };
18 Self { tape }
19 }
20
21 pub fn random_scalar(&mut self, label: &'static [u8]) -> Scalar {
22 self.tape.challenge_scalar(label)
23 }
24
25 pub fn random_vector(&mut self, label: &'static [u8], len: usize) -> Vec<Scalar> {
26 self.tape.challenge_vector(label, len)
27 }
28}