ecvrf_rs/proof.rs
1use crate::{
2 errors::VRFError,
3 keys::{PublicKey, SecretKey},
4 utils::{prove, verify_proof},
5};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct Proof {
9 pub signer: PublicKey,
10 pub message_bytes: Vec<u8>,
11 pub proof_bytes: Vec<u8>,
12}
13
14impl Proof {
15 /// Creates a new [`Proof`] from the given [`PublicKey`] and `message` bytes.
16 ///
17 /// # Errors
18 ///
19 /// This function will return an error if the secret key is invalid.
20 pub fn new(secret_key: &SecretKey, message: impl AsRef<[u8]>) -> Result<Self, VRFError> {
21 prove(secret_key, message.as_ref())
22 }
23
24 /// Verifies this [`Proof`].
25 ///
26 /// # Errors
27 ///
28 /// This function will return an error if the proof is invalid.
29 pub fn verify(&self) -> Result<[u8; 64], VRFError> {
30 verify_proof(self)
31 }
32}