Skip to content

Commit 5988f8e

Browse files
committed
Clarify vote receipt verification
1 parent 421330d commit 5988f8e

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

astra_app/core/static/verify-ballot-hash.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Verify your ballot hash (local check)
44
5-
Copy the values from your voting receipt into the variables below. This script
5+
Copy the values from your vote receipt email into the variables below. This script
66
re-computes the ballot hash and compares it to the hash shown on your receipt.
77
A match means the receipt details you entered produce the same hash the system recorded.
88
@@ -40,10 +40,10 @@ def compute_ballot_hash(
4040
return hashlib.sha256(data).hexdigest()
4141

4242
# ===== YOUR BALLOT DETAILS =====
43-
# Copy/paste these values from your voting receipt and the "Verify ballot receipt" page.
43+
# Copy/paste these values from your vote receipt and the "Verify ballot receipt" page.
4444

4545
election_id = 1
46-
credential_public_id = "your-credential-id-here"
46+
voting_credential = "your-credential-id-here"
4747

4848
# Candidate IDs are what the system hashes, but voters usually think in usernames.
4949
# The verify page provides a complete username -> ID mapping for the election.
@@ -53,26 +53,31 @@ def compute_ballot_hash(
5353
"carol": 3,
5454
}
5555

56-
# Your vote choices are secret. You must fill your own ranking locally.
56+
# Your vote choices are secret. You must fill your own ranking locally
57+
# as a comma-separated list of candidate usernames in your preferred order.
5758
# Example: if you ranked alice then bob, use:
58-
# ranking = [candidate_ids_by_username["alice"], candidate_ids_by_username["bob"]]
59-
ranking = [candidate_ids_by_username["alice"]]
59+
# ranking = "alice,bob"
60+
ranking = "alice"
6061

61-
weight = 1 # Usually 1 (check your receipt if different)
62-
nonce = "your-nonce-from-receipt-email"
62+
weight = 1 # The weight value from your vote receipt email
63+
submission_nonce = "your-nonce-from-receipt-email"
6364
expected_ballot_hash = "your-ballot-hash-from-receipt-email"
6465

66+
# ===== END OF USER INPUT =====
67+
68+
ranking = [candidate_ids_by_username[x.strip()] for x in ranking.split(',')]
69+
6570
if __name__ == "__main__":
6671
if not isinstance(election_id, int) or election_id <= 0:
6772
raise SystemExit("election_id must be a positive integer")
68-
if not str(credential_public_id or "").strip():
69-
raise SystemExit("credential_public_id must be set")
73+
if not str(voting_credential or "").strip():
74+
raise SystemExit("voting_credential must be set")
7075
if not isinstance(ranking, list) or not all(isinstance(cid, int) for cid in ranking):
7176
raise SystemExit("ranking must be a list of candidate IDs (integers)")
7277
if not isinstance(weight, int) or weight <= 0:
7378
raise SystemExit("weight must be a positive integer")
74-
if not str(nonce or "").strip():
75-
raise SystemExit("nonce must be set")
79+
if not str(submission_nonce or "").strip():
80+
raise SystemExit("submission_nonce must be set")
7681

7782
expected = str(expected_ballot_hash or "")
7883
if len(expected) != 64:
@@ -86,18 +91,18 @@ def compute_ballot_hash(
8691

8792
computed_hash = compute_ballot_hash(
8893
election_id=election_id,
89-
credential_public_id=credential_public_id,
94+
credential_public_id=voting_credential,
9095
ranking=ranking,
9196
weight=weight,
92-
nonce=nonce,
97+
nonce=submission_nonce,
9398
)
9499

95100
print("Ballot Hash Verification")
96101
print("=" * 60)
97102
print(f"Election ID: {election_id}")
98103
print(f"Your ranking: {ranking}")
99104
print(f"Weight: {weight}")
100-
print(f"Nonce: {nonce}")
105+
print(f"Nonce: {submission_nonce}")
101106
print()
102107
print(f"Computed hash: {computed_hash}")
103108
print(f"Expected hash: {expected_ballot_hash}")

astra_app/core/templates/core/ballot_verify.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h3 class="card-title">Ballot receipt verification</h3>
4040

4141
<form method="get" action="{% url 'ballot-verify' %}" class="mb-4" novalidate>
4242
<div class="form-group">
43-
<label for="id_receipt">Receipt</label>
43+
<label for="id_receipt">Ballot receipt code</label>
4444
<input
4545
type="text"
4646
class="form-control"
@@ -128,7 +128,7 @@ <h5>Ballot Information</h5>
128128
<h5>Copy/paste constants for local verification</h5>
129129
<p class="text-muted">
130130
Copy/paste the block below into <strong><a href="{% static 'verify-ballot-hash.py' %}">verify-ballot-hash.py</a></strong>. It includes the election ID,
131-
candidate username-to-ID mapping, and where to find your credential public ID. You still need to enter your own vote choices
131+
candidate username-to-ID mapping, and where to find your voting credential. You still need to enter your own vote choices
132132
in the script (vote choices are secret and are not shown on this page).
133133
</p>
134134
<pre class="bg-light p-3"><code>{{ verification_snippet }}</code></pre>

astra_app/core/templates/core/election_vote.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ <h3 class="card-title">Ballot</h3>
9393
<div class="alert d-none" id="election-vote-result" role="alert"></div>
9494

9595
<div class="d-none" id="election-receipt-box">
96-
<label class="text-muted" for="election-receipt">Receipt (ballot hash)</label>
96+
<label class="text-muted" for="election-receipt">Ballot receipt code</label>
9797
<div class="input-group">
9898
<input id="election-receipt" class="form-control" type="text" readonly />
9999
<div class="input-group-append">
@@ -106,7 +106,7 @@ <h3 class="card-title">Ballot</h3>
106106
</div>
107107

108108
<div class="mt-2">
109-
<label class="text-muted" for="election-nonce">Ballot Nonce</label>
109+
<label class="text-muted" for="election-nonce">Submission Nonce</label>
110110
<input id="election-nonce" class="form-control" type="text" readonly />
111111
<div class="form-text text-muted">Save this together with your receipt.</div>
112112
</div>

astra_app/core/views_elections/ballot_verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def ballot_verify(request):
9898
lines: list[str] = [
9999
"# Copy/paste these values into verify-ballot-hash.py",
100100
f"election_id = {election.id}",
101-
"# Locate your credential_public_id in the voting credential email you received.",
101+
f"# Locate your voting credential in the first email you received, titled 'Your voting credential for {election.name}'.",
102102
"candidate_ids_by_username = {",
103103
]
104104
for username in sorted(candidate_ids_by_username.keys(), key=str.lower):

0 commit comments

Comments
 (0)