Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Oct 17, 2024
1 parent 22ae80d commit 88b0f2a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/sign/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ fn main() -> Result<(), Box<dyn Error>> {

let cli = Cli::parse();

let mut rng = ChaCha20Rng::from_entropy();
match cli {
Cli::V1(args) => v1_exec(args, &mut rng),
Cli::V2(args) => v2_exec(args, &mut rng),
Cli::V1(args) => v1_exec(args),
Cli::V2(args) => v2_exec(args),
}
}

/// Number of voting options
const VOTING_OPTIONS: u8 = 2;

fn v1_exec(args: CliArgs, rng: &mut ChaCha20Rng) -> Result<(), Box<dyn Error>> {
fn v1_exec(args: CliArgs) -> Result<(), Box<dyn Error>> {
let mut rng = ChaCha20Rng::from_entropy();
let pk = hex::decode(args.public_key)?;
let mut sk = hex::decode(args.private_key)?;

Expand All @@ -99,7 +99,7 @@ fn v1_exec(args: CliArgs, rng: &mut ChaCha20Rng) -> Result<(), Box<dyn Error>> {
let ek = ElectionPublicKey::from_bytes(&election_pk)
.ok_or("unable to parse election pub key".to_string())?;

let (ciphertexts, proof) = ek.encrypt_and_prove_vote(rng, &crs, vote);
let (ciphertexts, proof) = ek.encrypt_and_prove_vote(&mut rng, &crs, vote);
let (proof, encrypted_vote) = compose_encrypted_vote_part(ciphertexts.clone(), proof)?;

let fragment_bytes = generate_vote_fragment(
Expand All @@ -118,7 +118,7 @@ fn v1_exec(args: CliArgs, rng: &mut ChaCha20Rng) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn v2_exec(args: CliArgs, rng: &mut ChaCha20Rng) -> Result<(), Box<dyn Error>> {
fn v2_exec(args: CliArgs) -> Result<(), Box<dyn Error>> {
let sk_bytes = hex::decode(args.private_key)?;

// Election pub key published as a Bech32_encoded address
Expand Down Expand Up @@ -146,14 +146,13 @@ fn v2_exec(args: CliArgs, rng: &mut ChaCha20Rng) -> Result<(), Box<dyn Error>> {
let proposal_index = args.proposal;
let choice = args.choice;

let tx = catalyst_voting::txs::v1::Tx::new_private(
let tx = catalyst_voting::txs::v1::Tx::new_private_with_default_rng(
vote_plan_id,
proposal_index,
VOTING_OPTIONS,
choice,
&election_public_key,
&private_key,
rng,
)?;

// fragment in hex: output consumed as input to another program
Expand Down

0 comments on commit 88b0f2a

Please sign in to comment.