diff --git a/src/client.ts b/src/client.ts index f1f7295f..02ce76c9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,7 +5,7 @@ import { Buffer } from 'buffer'; import invariant from 'tiny-invariant'; import { AccountCore } from './core/account'; import { ElectionCore } from './core/election'; -import { VoteCore } from './core/vote'; +import { CspProofType, VoteCore } from './core/vote'; import { Account, AllElectionStatus, @@ -863,6 +863,7 @@ export class VocdoniSDKClient { censusProof = { address: await this.wallet.getAddress(), signature: vote.signature, + proof_type: vote.proof_type, }; yield { key: VoteSteps.GET_PROOF, @@ -1005,8 +1006,8 @@ export class VocdoniSDKClient { return this.cspService.cspSign(this.electionId, address, token); } - cspVote(vote: Vote, signature: string) { - return this.cspService.cspVote(vote, signature); + cspVote(vote: Vote, signature: string, proof_type?: CspProofType) { + return this.cspService.cspVote(vote, signature, proof_type); } /** diff --git a/src/core/vote.ts b/src/core/vote.ts index eecc3d74..28820fe4 100644 --- a/src/core/vote.ts +++ b/src/core/vote.ts @@ -31,6 +31,13 @@ export type VotePackage = { votes: VoteValues; }; +export enum CspProofType { + ECDSA = ProofCA_Type.ECDSA, + ECDSA_PIDSALTED = ProofCA_Type.ECDSA_PIDSALTED, + ECDSA_BLIND = ProofCA_Type.ECDSA_BLIND, + ECDSA_BLIND_PIDSALTED = ProofCA_Type.ECDSA_BLIND_PIDSALTED, +} + export abstract class VoteCore extends TransactionCore { /** * Cannot be constructed. @@ -130,7 +137,7 @@ export abstract class VoteCore extends TransactionCore { // Populate the proof const caProof = ProofCA.fromPartial({ - type: ProofCA_Type.ECDSA_BLIND_PIDSALTED, + type: proof.proof_type ? (proof.proof_type as unknown as ProofCA_Type) : ProofCA_Type.ECDSA_BLIND_PIDSALTED, signature: new Uint8Array(Buffer.from(strip0x(proof.signature), 'hex')), bundle: this.cspCaBundle(electionId, proof.address), }); diff --git a/src/services/census.ts b/src/services/census.ts index 503f8799..55357927 100644 --- a/src/services/census.ts +++ b/src/services/census.ts @@ -3,6 +3,7 @@ import { CensusType, ICensusParticipant, PlainCensus, WeightedCensus } from '../ import { CensusAPI, ICensusImportResponse, ICensusPublishResponse, WalletAPI } from '../api'; import { Wallet } from '@ethersproject/wallet'; import invariant from 'tiny-invariant'; +import { CspProofType } from '../core/vote'; interface CensusServiceProperties { auth: CensusAuth; @@ -57,6 +58,7 @@ export type CspCensusProof = { address: string; signature: string; weight?: bigint; + proof_type?: CspProofType; }; export class CensusService extends Service implements CensusServiceProperties { diff --git a/src/services/csp.ts b/src/services/csp.ts index e3e0c126..0a0e9e01 100644 --- a/src/services/csp.ts +++ b/src/services/csp.ts @@ -3,6 +3,7 @@ import invariant from 'tiny-invariant'; import { CensusType, CspVote, Election, Vote } from '../types'; import { CspAPI, ICspInfoResponse } from '../api/csp'; import { CensusBlind, getBlindedPayload } from '../util/blind-signing'; +import { CspProofType } from '../core/vote'; interface CspServiceProperties { info: ICspInfoResponse; @@ -64,11 +65,11 @@ export class CspService extends Service implements CspServiceProperties { ); } - cspVote(vote: Vote, signature: string): CspVote { - return CspService.cspVote(vote, signature); + cspVote(vote: Vote, signature: string, proof_type?: CspProofType): CspVote { + return CspService.cspVote(vote, signature, proof_type); } - static cspVote(vote: Vote, signature: string): CspVote { - return new CspVote(vote.votes, signature); + static cspVote(vote: Vote, signature: string, proof_type?: CspProofType): CspVote { + return new CspVote(vote.votes, signature, proof_type); } } diff --git a/src/types/vote/csp.ts b/src/types/vote/csp.ts index 3b2bfca0..7f0923be 100644 --- a/src/types/vote/csp.ts +++ b/src/types/vote/csp.ts @@ -1,17 +1,21 @@ import { Vote } from './vote'; +import { CspProofType } from '../../core/vote'; export class CspVote extends Vote { private _signature: string; + private _proof_type: CspProofType; /** * Constructs a csp vote * * @param votes The list of votes values * @param signature The CSP signature + * @param proof_type The CSP proof type */ - public constructor(votes: Array, signature: string) { + public constructor(votes: Array, signature: string, proof_type?: CspProofType) { super(votes); this.signature = signature; + this.proof_type = proof_type; } get signature(): string { @@ -21,4 +25,12 @@ export class CspVote extends Vote { set signature(value: string) { this._signature = value; } + + get proof_type(): CspProofType { + return this._proof_type; + } + + set proof_type(value: CspProofType) { + this._proof_type = value; + } } diff --git a/test/integration/csp.test.ts b/test/integration/csp.test.ts index b56f5c7d..b3be6a92 100644 --- a/test/integration/csp.test.ts +++ b/test/integration/csp.test.ts @@ -6,6 +6,7 @@ import { CspCensus } from '../../src'; import { clientParams, setFaucetURL } from './util/client.params'; // @ts-ignore import { waitForElectionReady } from './util/client.utils'; +import { CspProofType } from '../../src/core/vote'; const CSP_URL = process.env.BLINDCSP_URL ?? 'https://csp-dev-simplemath.vocdoni.net/v1'; const CSP_PUBKEY = process.env.BLINDCSP_PUBKEY ?? '025de8cb8de1005aa939c1403e37e1fa165ebc758da49cb37215c6237d01591104'; @@ -66,7 +67,7 @@ describe('CSP tests', () => { step0.authToken )) as ICspFinalStepResponse; const signature = await pClient.cspSign(participant.address, step1.token); - const vote = pClient.cspVote(new Vote([index % 2]), signature); + const vote = pClient.cspVote(new Vote([index % 2]), signature, CspProofType.ECDSA_BLIND_PIDSALTED); return pClient.submitVote(vote); }) );