-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoting_input.json
43 lines (35 loc) · 1.06 KB
/
voting_input.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
from starkware.crypto.signature.signature import (
pedersen_hash, private_to_stark_key, sign)
# Set an identifier that will represent what we're voting for.
# This will appear in the user's signature to distinguish
# between different polls.
POLL_ID = 10018
# Generate key pairs.
priv_keys = []
pub_keys = []
for i in range(10):
priv_key = 123456 * i + 654321 # See "Safety note" below.
priv_keys.append(priv_key)
pub_key = private_to_stark_key(priv_key)
pub_keys.append(pub_key)
# Generate 3 votes of voters 3, 5, and 8.
votes = []
for (voter_id, vote) in [(3, 0), (5, 1), (8, 0)]:
r, s = sign(
msg_hash=pedersen_hash(POLL_ID, vote),
priv_key=priv_keys[voter_id])
votes.append({
'voter_id': voter_id,
'vote': vote,
'r': hex(r),
's': hex(s),
})
# Write the data (public keys and votes) to a JSON file.
input_data = {
'public_keys': list(map(hex, pub_keys)),
'votes': votes,
}
with open('voting_input.json', 'w') as f:
json.dump(input_data, f, indent=4)
f.write('\n')