Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/av_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class AVClient implements IAVClient {
}

generateProofOfElectionCodes(electionCodes : Array<string>) {
this.proofOfElectionCodes = new ProofOfElectionCodes(electionCodes);
this.proofOfElectionCodes = new ProofOfElectionCodes(electionCodes, this.keyPair.publicKey);
}

setIdentityToken(token: string) {
Expand Down
6 changes: 3 additions & 3 deletions lib/av_client/crypto/proof_of_election_codes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
electionCodeToPrivateKey,
addBigNums,
generateDiscreteLogarithmProof,
generateSchnorrSignature,
generateKeyPair,
} from "../aion_crypto.js";
import {KeyPair} from "../types";
Expand All @@ -10,11 +10,11 @@ export class ProofOfElectionCodes {
readonly proof: string;
readonly mainKeyPair: KeyPair;

constructor(electionCodes : Array<string>) {
constructor(electionCodes : Array<string>, sessionPublicKey: string) {
const privateKey = <string>electionCodes
.map(electionCode => electionCodeToPrivateKey(electionCode))
.reduce(addBigNums);
this.proof = generateDiscreteLogarithmProof(privateKey);
this.proof = generateSchnorrSignature(sessionPublicKey, privateKey);
const { public_key: publicKey } = generateKeyPair(privateKey);
this.mainKeyPair = { privateKey, publicKey }
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.3.3",
"version": "5.0.0-alpha.2",
"name": "@aion-dk/js-client",
"license": "MIT",
"description": "Assembly Voting JS client",
Expand Down
19 changes: 11 additions & 8 deletions test/crypto/proof_of_election_code.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { expect } from "chai";
import { ProofOfElectionCodes } from "../../lib/av_client/crypto/proof_of_election_codes";
import { DiscreteLogarithmProof, Curve } from "../../lib/av_client/aion_crypto.js"
import { pointFromHex } from "../../lib/av_client/crypto/util";
import { SchnorrSignature, Curve } from "../../lib/av_client/aion_crypto.js"
import { pointFromHex, pointToHex } from "../../lib/av_client/crypto/util";

describe("Proof of election codes", () => {

it("converts a single election code into a keyPair", () => {
const electionCode = 's3cr3t5';
const sessionPublicKey = pointToHex(Curve.G);

const proof = new ProofOfElectionCodes([electionCode]);
const proof = new ProofOfElectionCodes([electionCode], sessionPublicKey);

expect(proof.mainKeyPair).to.eql({
privateKey: "631a1838f1e82b7b39f2b620a790de69ca8feb0cfd4ba984350a5fe3a2fda299",
Expand All @@ -18,24 +19,26 @@ describe("Proof of election codes", () => {

it("converts multiple election codes into a keyPair", () => {
const electionCodes = ['s3cr3t5','t0','k33p'];
const sessionPublicKey = pointToHex(Curve.G);

const proof = new ProofOfElectionCodes(electionCodes);
const proof = new ProofOfElectionCodes(electionCodes, sessionPublicKey);

expect(proof.mainKeyPair).to.eql({
privateKey: "e71d8edd52ff20ff8a741a9ae0f651193e183eafd639ebde02c847b2a35f9a8d",
publicKey: "020936bd7dacd0bfc974c717877fff2b0c4257a3ef0ea545b6acca9fa3e7857463"
});
})

it("generates a discrete logarithm proof", () => {
it("generates a schnorr signature", () => {
const electionCodes = ['s3cr3t5','t0','k33p'];
const sessionPublicKey = pointToHex(Curve.G);

const proof = new ProofOfElectionCodes(electionCodes);
const discreteLogarithmProof = DiscreteLogarithmProof.fromString(proof.proof);
const proof = new ProofOfElectionCodes(electionCodes, sessionPublicKey);
const signature = SchnorrSignature.fromString(proof.proof);

expect(proof.proof).to.exist;
const publicKey = pointFromHex(proof.mainKeyPair.publicKey).toEccPoint();
expect(discreteLogarithmProof.verifyWithoutChallenge(Curve.G, publicKey)).to.be.true;
expect(signature.verify(publicKey, sessionPublicKey)).to.be.true;
})
})