Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mjal committed May 9, 2024
1 parent dce4ac1 commit 7a0d0ee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
9 changes: 9 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ body {
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.succes {
color: green;
}

.error {
color: red;
}

12 changes: 5 additions & 7 deletions src/checkBallot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sjcl from "sjcl";
import { ed25519 } from '@noble/curves/ed25519';
import { assert, log } from './utils.js';
import { assert, logSuccess } from './utils.js';
import { g, l, rev, erem } from './math.js';

export default function(state, ballot) {
Expand Down Expand Up @@ -49,7 +49,7 @@ function hashWithoutSignature(ballot) {
export function checkSignature(ballot) {
assert(ballot.payload.signature.hash
== hashWithoutSignature(ballot));
log("Hashes are equal");
logSuccess("ballots", "Hashes are equal");

const credential = ed25519.ExtendedPoint.fromHex(rev(ballot.payload.credential));

Expand All @@ -71,7 +71,7 @@ export function checkSignature(ballot) {
const hexReducedVerificationHash = erem(BigInt('0x'+verificationHash), l).toString(16);

assert(challenge.toString(16) == hexReducedVerificationHash);
log("Valid signature");
logSuccess("ballots", "Valid signature");
}

export function checkIndividualProofs(state, ballot) {
Expand Down Expand Up @@ -107,7 +107,7 @@ export function checkIndividualProofs(state, ballot) {
const hexReducedVerificationHash = erem(BigInt('0x'+verificationHash), l).toString(16);

assert(sum_challenges.toString(16) == hexReducedVerificationHash);
log("Valid individual proof");
logSuccess("ballots", "Valid individual proof");
}
}
}
Expand All @@ -117,8 +117,6 @@ export function checkOverallProof(state, ballot) {
y = ed25519.ExtendedPoint.fromHex(rev(y));

for (let i = 0; i < ballot.payload.answers.length; i++) {
console.log(ballot);
console.log(state.setup);
let answer = ballot.payload.answers[i];

let sumc = {
Expand Down Expand Up @@ -155,6 +153,6 @@ export function checkOverallProof(state, ballot) {
const hexReducedVerificationHash = erem(BigInt('0x'+verificationHash), l).toString(16);

assert(sum_challenges.toString(16) == hexReducedVerificationHash);
log("Valid overall proof");
logSuccess("ballots", "Valid overall proof");
}
}
4 changes: 2 additions & 2 deletions src/checkFiles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { log, assert } from "./utils.js";
import { logSuccess, assert } from "./utils.js";

export default function(state) {
// TODO: Check hash correspond to content
Expand All @@ -17,7 +17,7 @@ export default function(state) {
}
}

log(`Checked ${nEvent} events`);
logSuccess("database", `Checked ${nEvent} events`);
}


23 changes: 20 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,25 @@ export function findData(entries, hash) {
}
}

export function log(message) {
export function log(section, message, classeName = "", prefix = "") {
let p = document.createElement("p");
p.textContent = message;
document.getElementById("content").appendChild(p);
p.className = classeName;
p.textContent = prefix + message;
document.getElementById(section).appendChild(p);
}

export function logSuccess(section, message) {
log(section, message, "success", "✔ ");
}

export function logError(section, message) {
log(section, message, "error", "✘ ");
}

export function check(section, message, test) {
if (test) {
logSuccess(section, message);
} else {
logError(section, message);
}
}

0 comments on commit 7a0d0ee

Please sign in to comment.