From 64db1f8ed197245b0e25fc7d49cb540c9ca27957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Patachi?= Date: Tue, 26 Nov 2024 14:52:41 +0100 Subject: [PATCH 1/3] replace discrete logarithm proof with a schnorr signature --- lib/av_client.ts | 2 +- .../crypto/proof_of_election_codes.ts | 6 +++--- test/crypto/proof_of_election_code.test.ts | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/av_client.ts b/lib/av_client.ts index ea123433..c4287ee7 100644 --- a/lib/av_client.ts +++ b/lib/av_client.ts @@ -198,7 +198,7 @@ export class AVClient implements IAVClient { } generateProofOfElectionCodes(electionCodes : Array) { - this.proofOfElectionCodes = new ProofOfElectionCodes(electionCodes); + this.proofOfElectionCodes = new ProofOfElectionCodes(electionCodes, this.keyPair.publicKey); } setIdentityToken(token: string) { diff --git a/lib/av_client/crypto/proof_of_election_codes.ts b/lib/av_client/crypto/proof_of_election_codes.ts index 6d424077..715082dc 100644 --- a/lib/av_client/crypto/proof_of_election_codes.ts +++ b/lib/av_client/crypto/proof_of_election_codes.ts @@ -1,7 +1,7 @@ import { electionCodeToPrivateKey, addBigNums, - generateDiscreteLogarithmProof, + generateSchnorrSignature, generateKeyPair, } from "../aion_crypto.js"; import {KeyPair} from "../types"; @@ -10,11 +10,11 @@ export class ProofOfElectionCodes { readonly proof: string; readonly mainKeyPair: KeyPair; - constructor(electionCodes : Array) { + constructor(electionCodes : Array, sessionPublicKey: string) { const privateKey = 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 } } diff --git a/test/crypto/proof_of_election_code.test.ts b/test/crypto/proof_of_election_code.test.ts index 869b247c..fd8a790b 100644 --- a/test/crypto/proof_of_election_code.test.ts +++ b/test/crypto/proof_of_election_code.test.ts @@ -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", @@ -18,8 +19,9 @@ 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", @@ -27,15 +29,16 @@ describe("Proof of election codes", () => { }); }) - 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; }) }) From 25fe249766149581ea39e39ee67145e8ccce01ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Patachi?= Date: Tue, 26 Nov 2024 15:37:16 +0100 Subject: [PATCH 2/3] v5.0.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b914db29..757b1e87 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "4.3.3", + "version": "5.0.0-alpha.1", "name": "@aion-dk/js-client", "license": "MIT", "description": "Assembly Voting JS client", From 90fa8fcda2701c19af209f0eef546a8c033d2f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Patachi?= Date: Wed, 27 Nov 2024 10:27:28 +0100 Subject: [PATCH 3/3] bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 757b1e87..383925fc 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "5.0.0-alpha.1", + "version": "5.0.0-alpha.2", "name": "@aion-dk/js-client", "license": "MIT", "description": "Assembly Voting JS client",