cardano_serialization_lib/protocol_types/crypto/
vrf_cert.rs

1use crate::*;
2
3#[wasm_bindgen]
4#[derive(
5    Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema,
6)]
7pub struct VRFCert {
8    pub(crate) output: Vec<u8>,
9    pub(crate) proof: Vec<u8>,
10}
11
12impl VRFCert {
13    pub const PROOF_LEN: usize = 80;
14}
15
16impl_to_from!(VRFCert);
17
18#[wasm_bindgen]
19impl VRFCert {
20    pub fn output(&self) -> Vec<u8> {
21        self.output.clone()
22    }
23
24    pub fn proof(&self) -> Vec<u8> {
25        self.proof.clone()
26    }
27
28    pub fn new(output: Vec<u8>, proof: Vec<u8>) -> Result<VRFCert, JsError> {
29        if proof.len() != Self::PROOF_LEN {
30            return Err(JsError::from_str(&format!(
31                "proof len must be {} - found {}",
32                Self::PROOF_LEN,
33                proof.len()
34            )));
35        }
36        Ok(Self {
37            output: output,
38            proof: proof,
39        })
40    }
41}