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/package.json b/package.json index b914db29..383925fc 100644 --- a/package.json +++ b/package.json @@ -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", 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; }) })