Skip to content

Commit

Permalink
Send receipt electa flow (#259)
Browse files Browse the repository at this point in the history
* Send receipt electa flow
  • Loading branch information
av-mads authored Oct 14, 2023
1 parent aa36f89 commit b0e422b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lib/av_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export class AVClient implements IAVClient {
throw new InvalidConfigError(`Unknown authorization mode of voter authorizer: '${authorizationMode}'`)
}

const { authToken } = authorizationResponse.data;
const { authToken, authorizationUuid } = authorizationResponse.data;
this.authorizationSessionId = this.authorizationSessionId ? this.authorizationSessionId : authorizationUuid

const decoded = jwtDecode<JwtPayload>(authToken); // TODO: Verify against dbb pubkey: this.getLatestConfig().services.voterAuthorizer.public_key);

Expand Down Expand Up @@ -468,7 +469,7 @@ export class AVClient implements IAVClient {
const voterAuthorizerContextUuid = this.getLatestConfig().items.voterAuthorizerConfig.content.voterAuthorizer.contextUuid;
const coordinator = new VoterAuthorizationCoordinator(coordinatorURL, voterAuthorizerContextUuid);
try {
coordinator.sendReceipt(clientReceipt.trackingCode, this.authorizationSessionId);
coordinator.sendReceipt(clientReceipt, this.authorizationSessionId);
} catch(e) {
console.error(e)
}
Expand Down Expand Up @@ -563,6 +564,10 @@ export class AVClient implements IAVClient {
return this.voterSession
}

public getSessionUuid(): string {
return this.authorizationSessionId
}

public getVoterBallotConfig(): BallotConfig {
const voterSession = this.getVoterSession()
const { items: { ballotConfigs } } = this.getLatestConfig()
Expand Down
8 changes: 5 additions & 3 deletions lib/av_client/connectors/voter_authorization_coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { AxiosInstance, AxiosResponse } from 'axios'
import { IdentityConfirmationToken } from "./otp_provider";
import { EmailDoesNotMatchVoterRecordError, NetworkError, UnsupportedServerReplyError, VoterRecordNotFoundError } from "../errors";
import { ProofOfElectionCodes } from "../crypto/proof_of_election_codes";
import { BallotBoxReceipt } from '../types';

export default class VoterAuthorizationCoordinator {
private backend: AxiosInstance;
Expand Down Expand Up @@ -47,11 +48,12 @@ export default class VoterAuthorizationCoordinator {
});
}

sendReceipt(trackingCode: string, authorizationSessionId: string): Promise<AxiosResponse> {
sendReceipt(receipt: BallotBoxReceipt, authorizationSessionId: string ): Promise<AxiosResponse> {
return this.backend.post('send_receipt', {
trackingCode: trackingCode,
trackingCode: receipt.trackingCode,
electionContextUuid: this.electionContextUuid,
authorizationSessionId: authorizationSessionId
authorizationSessionId: authorizationSessionId,
receipt: receipt.receipt
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aion-dk/js-client",
"version": "3.1.9",
"version": "3.1.10",
"license": "MIT",
"description": "Assembly Voting JS client",
"main": "dist/lib/av_client.js",
Expand Down

0 comments on commit b0e422b

Please sign in to comment.