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