Skip to content

Commit 75f2ca0

Browse files
author
David Morcillo
authored
Audit vote using verifier (#171)
1 parent 29e026f commit 75f2ca0

28 files changed

+2111
-589
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,14 @@ VERIFIER_ELECTIONGUARD_PATH = voting_schemes/electionguard/verifier
289289
install_verifier_electionguard_dependencies:
290290
cd ${VERIFIER_ELECTIONGUARD_PATH} && npm i
291291

292-
install_verifier_dependencies: install_verifier_electionguard_dependencies build_electionguard_java
292+
install_verifier_dependencies: install_verifier_electionguard_dependencies
293293
cd ${VERIFIER_PATH} && npm i
294294

295-
test_verifier: install_verifier_dependencies
296-
cd ${VERIFIER_PATH} && bin/verify test/fixtures/electionguard/election-ok.tar
295+
test_verify_election: install_verifier_dependencies build_electionguard_java
296+
cd ${VERIFIER_PATH} && node src/index.js test/fixtures/electionguard/election-ok.tar
297+
298+
test_verify_ballot: install_verifier_dependencies
299+
cd ${VERIFIER_PATH} && node src/index.js test/fixtures/electionguard/ballot-ok.txt
297300

298301
# DEPLOYMENT
299302

verifier/.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"env": {
3+
"test": {
4+
"plugins": ["@babel/plugin-transform-modules-commonjs"]
5+
}
6+
}
7+
}

verifier/.eslintrc.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

verifier/.eslintrc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"jest/globals": true
5+
},
6+
"extends": ["standard", "prettier"],
7+
"plugins": ["jest", "jasmine"],
8+
"parserOptions": {
9+
"ecmaVersion": 12,
10+
"sourceType": "module"
11+
},
12+
"rules": {}
13+
}

verifier/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
tmp
2+
tmp
3+
4+
test/fixtures/electionguard/ballot-ok.txt

verifier/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://jestjs.io/docs/en/configuration.html
44
*/
55

6-
module.exports = {
6+
export default {
77
// All imported modules in your tests should be mocked automatically
88
// automock: false,
99

verifier/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

verifier/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "decidim-bulletin_board-verifier",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "bin/verify.js",
5+
"main": "src/index.js",
6+
"type": "module",
67
"scripts": {
78
"format": "prettier -c src/**/*.js",
89
"lint": "eslint src/**/*.js",
@@ -12,6 +13,7 @@
1213
"author": "",
1314
"license": "ISC",
1415
"devDependencies": {
16+
"@babel/plugin-transform-modules-commonjs": "^7.13.8",
1517
"eslint": "^7.12.1",
1618
"eslint-config-prettier": "^6.15.0",
1719
"eslint-config-standard": "^16.0.1",

verifier/src/ballot/index.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
const chalk = require("chalk");
1+
import chalk from "chalk";
2+
3+
import { parseBallotFile } from "../file-utils.js";
4+
5+
// Verifiers
6+
import { verifyEncryptedDataHash } from "./verifiers/encrypted-data-hash.verifier.js";
7+
import { verifyBallot } from "decidim-bulletin_board-verifier-electionguard";
28

39
/**
4-
* Includes all the business logic to verify an audit ballot file.
10+
* Parse the ballot file and run some verifiers.
511
*
6-
* @module
12+
* @param {String} path - a ballot file path.
13+
* @returns {Promise<undefined>}
714
*/
8-
module.exports = {
9-
/**
10-
* Parse the audit ballot and run some verifiers.
11-
*
12-
* @param {String} path - an audit ballot file path.
13-
* @returns {Promise<undefined>}
14-
*/
15-
verify() {
16-
console.log(`${chalk.yellow("Verifying ballot...")}`);
17-
},
15+
export const verify = async (path) => {
16+
const ballotData = await parseBallotFile(path);
17+
18+
console.log(`${chalk.yellow("Verifying ballot...")}`);
19+
20+
return Promise.all([
21+
verifyEncryptedDataHash(ballotData),
22+
verifyBallot(ballotData),
23+
]);
1824
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import chalk from "chalk";
2+
3+
import { hash } from "../../crypto-utils.js";
4+
5+
/**
6+
* Check if the encrypted data hash is computed properly.
7+
* @returns {Promise<Boolean>}
8+
*/
9+
export const verifyEncryptedDataHash = (ballotData) => {
10+
const { encryptedDataRaw, encryptedDataHash } = ballotData;
11+
12+
return new Promise((resolve) => {
13+
if (hash(encryptedDataRaw) === encryptedDataHash) {
14+
console.log(`\t${chalk.green("[OK]")} Encrypted data hash verified.`);
15+
resolve(true);
16+
} else {
17+
console.log(`\t${chalk.red("[ERROR]")} Encrypted data hash verified.`);
18+
resolve(true);
19+
}
20+
});
21+
};

0 commit comments

Comments
 (0)