use predicate_credential_system::pcs::{Predicate, PredicateCredentialSystem, SetupParams};
pub use vti_vetting_pcs::scheme::{Base, E, Fr, G1, Hvk, Open, Tag, key_text, point_text};
use crate::{VotingError, election::ElectionId};
pub fn deployment_label(community: &str) -> Vec<u8> {
format!("{community}#voting-pcs").into_bytes()
}
pub fn voter_predicate(election: &ElectionId) -> Predicate {
Predicate::root(format!("voter/{}", election.as_str()).into_bytes())
}
pub fn open(community: &str) -> Result<Open, VotingError> {
Ok(Open::setup(SetupParams::new(deployment_label(community)))?)
}
#[derive(Clone)]
pub struct VotingParams {
community: String,
open: Open,
hvk: Hvk,
}
impl std::fmt::Debug for VotingParams {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VotingParams")
.field("community", &self.community)
.finish_non_exhaustive()
}
}
impl VotingParams {
pub fn new(community: &str, hvk: Hvk) -> Result<Self, VotingError> {
crate::election::check_community(community)?;
Ok(Self {
community: community.to_string(),
open: open(community)?,
hvk,
})
}
pub fn community(&self) -> &str {
&self.community
}
pub fn open(&self) -> &Open {
&self.open
}
pub fn hvk(&self) -> &Hvk {
&self.hvk
}
}