Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vote encoding - part 2 (Type changes) #173

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/av_client/actions/construct_ballot_cryptograms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CastVoteRecord,
ClientState,
ContestMap,
MarkingType,
OpenableEnvelope
} from '../types';

Expand All @@ -20,11 +21,14 @@ import {
} from '../errors';
import { generatePedersenCommitment } from '../crypto/pedersen_commitment';

const DEFAULT_MARKING_TYPE = {
style: "regular",
codeSize: 1,
const DEFAULT_MARKING_TYPE: MarkingType = {
minMarks: 1,
maxMarks: 1
maxMarks: 1,
encoding: {
codeSize: 1,
maxSize: 1,
cryptogramCount: 1
}
};

const _getEncodingTypes = (cvr: CastVoteRecord, ballots: Ballot[]) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/av_client/crypto/vote_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const VOTE_ENCODING_TYPE = Object.freeze({
const getEncodingTypeFromMarkingType = (markingType: MarkingType) => {
const { minMarks, maxMarks } = markingType;

if(markingType.style === "regular" &&
minMarks === 1 &&
if(minMarks === 1 &&
maxMarks === 1) {
return VOTE_ENCODING_TYPE.TEXT_UTF8
}
Expand Down
11 changes: 9 additions & 2 deletions lib/av_client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export interface Option {
title: LocalString;
subtitle: LocalString;
description: LocalString;
writeIn?: {
maxSize: number
encoding: 'utf8'
}
}

export interface LocalString {
Expand Down Expand Up @@ -261,10 +265,13 @@ export type ContestConfig = {
}

export type MarkingType = {
style: string
codeSize: number
minMarks: number
maxMarks: number
encoding: {
codeSize: 1 | 2
maxSize: number
cryptogramCount: number
}
}

export interface ElectionConfig {
Expand Down
13 changes: 8 additions & 5 deletions lib/av_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CAST_REQUEST_ITEM, MAX_POLL_ATTEMPTS, POLLING_INTERVAL_MS, SPOIL_REQUES
import { randomKeyPair } from './av_client/generate_key_pair';
import { signPayload } from './av_client/sign';
import { decrypt } from './av_client/decrypt_vote';
import { VerifierItem, BoardCommitmentOpeningItem, VoterCommitmentOpeningItem, BallotCryptogramItem, ElectionConfig, ContestMap } from './av_client/types';
import { VerifierItem, BoardCommitmentOpeningItem, VoterCommitmentOpeningItem, BallotCryptogramItem, ElectionConfig, ContestMap, MarkingType } from './av_client/types';
import { hexToShortCode, shortCodeToHex } from './av_client/short_codes';

import {
Expand Down Expand Up @@ -103,11 +103,14 @@ export class AVVerifier {
validateCommmitmentOpening(boardCommitmentOpening, this.boardCommitment, 'Board commitment not valid')
validateCommmitmentOpening(voterCommitmentOpening, this.voterCommitment, 'Voter commitment not valid')

const defaultMarkingType = {
style: "regular",
codeSize: 1,
const defaultMarkingType: MarkingType = {
minMarks: 1,
maxMarks: 1
maxMarks: 1,
encoding: {
codeSize: 1,
maxSize: 1,
cryptogramCount: 1
}
}

return decrypt(
Expand Down
19 changes: 12 additions & 7 deletions test/cvr_validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { validateCvr } from '../lib/av_client/cvr_validation';
import { Option } from '../lib/av_client/types';
import { MarkingType, Option } from '../lib/av_client/types';
import { expect } from 'chai';

const markingType: MarkingType = {
minMarks: 1,
maxMarks: 1,
encoding: {
codeSize: 1,
maxSize: 1,
cryptogramCount: 1
}
}

const template = {
vote_encoding_type: 0,
description: {},
write_in: false,
markingType: {
style: "regular",
codeSize: 1,
minMarks: 1,
maxMarks: 1
},
markingType: markingType,
resultType: {
name: "Something"
},
Expand Down
22 changes: 14 additions & 8 deletions test/verifier/decrypt_ballot.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { decrypt } from "../../lib/av_client/decrypt_vote";
import { ContestConfigMap } from "../../lib/av_client/types";
import { ContestConfigMap, MarkingType } from "../../lib/av_client/types";
import { expect } from 'chai';
const contestConfig : ContestConfigMap = {
"contest ref 1": {
"reference": "contest ref 1",
"markingType": {
"style": "regular",
"codeSize": 1,
"minMarks": 1,
"maxMarks": 1
"maxMarks": 1,
"encoding": {
"codeSize": 1,
"maxSize": 1,
"cryptogramCount": 1,
}
},
"options": [
{
Expand Down Expand Up @@ -77,11 +80,14 @@ const voterCommitmentOpening = {
}
}

const defaultMarkingType = {
style: "regular",
codeSize: 1,
const defaultMarkingType: MarkingType = {
minMarks: 1,
maxMarks: 1
maxMarks: 1,
encoding: {
codeSize: 1,
maxSize: 1,
cryptogramCount: 1
}
}


Expand Down