Skip to content

Commit

Permalink
refactored encryptSelectionPile
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-av committed Nov 20, 2024
1 parent d0bded2 commit 7131ee3
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/av_client/new_crypto/encrypt_contest_selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
EncryptedPile, SelectionPile
} from "../types";
import { selectionPileToByteArray } from "../encoding/byte_encoding";
import {AVCrypto} from "../../av_crypto";
import { bytesToPoints } from "../encoding/point_encoding";
import { AVCrypto } from "../../av_crypto";

export function encryptContestSelections(
contestConfigs: ContestConfigMap,
Expand Down Expand Up @@ -50,19 +49,13 @@ function encryptSelectionPile(
const crypto = new AVCrypto("secp256k1")

const encodedSelectionPile = selectionPileToByteArray(contestConfig, selectionPile)
const pilePoints = bytesToPoints(encodedSelectionPile)

// TODO: include `transparent` flag into `encryptVote` function; defaults to `false`
const encryptedSelectionPile = crypto.encryptVote(encodedSelectionPile, encryptionKey)
console.log("AV_CRYPTO_ENCRYPT_VOTE_CALLED!")

const encryptedPile: EncryptedPile = {multiplier: selectionPile.multiplier, cryptograms: [], randomizers: []}
pilePoints.map(votePoint => {
// TODO: include `transparent` flag into `encryptVote` function; defaults to `false`
// const randomizerBN = transparent ? new bn(0) : randomBN();
const { cryptograms, randomizers } = crypto.encryptVote(encodedSelectionPile, encryptionKey)

encryptedPile.cryptograms.push(cryptograms[0])
encryptedPile.randomizers.push(randomizers[0])
})

return encryptedPile
return {
multiplier: selectionPile.multiplier,
cryptograms: encryptedSelectionPile.cryptograms,
randomizers: encryptedSelectionPile.randomizers
}
}

0 comments on commit 7131ee3

Please sign in to comment.