1#![cfg_attr(not(feature = "std"), no_std)]
10#![deny(missing_docs)]
11#[cfg(test)]
12extern crate std;
13
14#[cfg(any(not(feature = "std"), target_has_atomic = "ptr"))]
15#[doc(hidden)]
16extern crate alloc;
17
18use ark_std::rand::{CryptoRng, RngCore};
19use core::fmt::Debug;
20use serde::{Deserialize, Serialize};
21use zeroize::Zeroize;
22
23pub mod blsvrf;
24
25pub trait Vrf {
27 type PublicParameter;
29
30 type PublicKey: Debug
32 + Clone
33 + Send
34 + Sync
35 + for<'a> Deserialize<'a>
36 + Serialize
37 + PartialEq
38 + Eq;
39
40 type SecretKey: Debug + Clone + Send + Sync + Zeroize + PartialEq + Eq;
42
43 type Proof: Debug + Clone + Send + Sync + for<'a> Deserialize<'a> + Serialize + PartialEq + Eq;
45
46 type Input: Debug + Clone + Send + Sync + for<'a> Deserialize<'a> + Serialize + PartialEq + Eq;
48
49 type Output: Debug + Clone + Send + Sync + for<'a> Deserialize<'a> + Serialize + PartialEq + Eq;
51
52 type Error: ark_std::error::Error;
54
55 fn param_gen<R: CryptoRng + RngCore>(
62 &self,
63 prng: Option<&mut R>,
64 ) -> Result<Self::PublicParameter, Self::Error>;
65
66 fn key_gen<R: CryptoRng + RngCore>(
68 &self,
69 pp: &Self::PublicParameter,
70 prng: &mut R,
71 ) -> Result<(Self::SecretKey, Self::PublicKey), Self::Error>;
72
73 fn prove<R: CryptoRng + RngCore>(
75 &self,
76 pp: &Self::PublicParameter,
77 secret_key: &Self::SecretKey,
78 input: &Self::Input,
79 prng: &mut R,
80 ) -> Result<Self::Proof, Self::Error>;
81
82 fn proof_to_hash(
84 &mut self,
85 pp: &Self::PublicParameter,
86 proof: &Self::Proof,
87 ) -> Result<Self::Output, Self::Error>;
88
89 fn evaluate<R: CryptoRng + RngCore>(
91 &mut self,
92 pp: &Self::PublicParameter,
93 secret_key: &Self::SecretKey,
94 input: &Self::Input,
95 prng: &mut R,
96 ) -> Result<Self::Output, Self::Error> {
97 let proof = self.prove(pp, secret_key, input, prng)?;
98 self.proof_to_hash(pp, &proof)
99 }
100
101 #[must_use = "Output must be used"]
103 fn verify(
104 &mut self,
105 pp: &Self::PublicParameter,
106 proof: &Self::Proof,
107 public_key: &Self::PublicKey,
108 input: &Self::Input,
109 ) -> Result<(bool, Option<Self::Output>), Self::Error>;
110}