forked from privacy-scaling-explorations/maci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.sh
executable file
·174 lines (160 loc) · 3.69 KB
/
user.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
# user.sh should not depends on maci repo
# only send http request to server
ProgName=$(basename $0)
DirName=$(dirname $0)
# get request params
GET_URL="http://localhost:8080/get/"
KEY_VAL="?method=ping&pubkey=$cordpk"
GET_URI=$GET_URL$KEY_VAL
# post request params
POST_URI="http://localhost:8080/post/"
# params
version="v1.0"
function help(){
echo "Usage: $ProgName <command> [options]"
echo "commands:"
echo " genkey"
echo " signup -p <maci.pk> -x <maci.addr>"
echo " publish"
echo " verify"
}
function genkey(){
json_fmt='{"method":"%s","version":"%s"}'
json_str=$(printf "$json_fmt" "genkey" "$version")
post_request $json_str
}
function signup(){
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-p|--pubkey)
pubkey="$2"
shift
shift
;;
-x|--maci)
maci="$2"
shift
shift
;;
*)
shift
;;
esac
done
json_fmt='{"method":"%s","pubkey":"%s","maci":"%s","version":"%s"}'
json_str=$(printf "$json_fmt" "signup" "$pubkey" "$maci" "$version")
post_request $json_str
}
function publish(){
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-p|--pubkey)
pubkey="$2"
shift
shift
;;
-x|--maci)
maci="$2"
shift
shift
;;
-sk|--privkey)
privkey="$2"
shift
shift
;;
-i|--state_index)
state_index="$2"
shift
shift
;;
-v|--vote_option_index)
vote_option_index="$2"
shift
shift
;;
-w|--new_vote_weight)
new_vote_weight="$2"
shift
shift
;;
-n|--nonce)
nonce="$2"
shift
shift
;;
-s|--salt)
salt="$2"
shift
shift
;;
-o|--poll_id)
poll_id="$2"
shift
shift
;;
*)
shift
;;
esac
done
json_fmt='{"method":"%s","pubkey":"%s","maci":"%s","privkey":"%s","state_index":"%s","vote_option_index":"%s","new_vote_weight":"%s","nonce":"%s","salt":"%s","poll_id":"%s","version":"%s"}'
json_str=$(printf "$json_fmt" "publish" "$pubkey" "$maci" "$privkey" "$state_index" "$vote_option_index" "$new_vote_weight" "$nonce" "$salt" "$poll_id" "$version")
echo $json_str
post_request $json_str
}
function verify(){
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-t|--tally_file)
tally_file="$2"
shift
shift
;;
-x|--maci)
maci="$2"
shift
shift
;;
-o|--poll_id)
poll_id="$2"
shift
shift
;;
*)
shift
;;
esac
done
json_fmt='{"method":"%s","maci":"%s","tally_file":"%s","poll_id":"%s","version":"%s"}'
json_str=$(printf "$json_fmt" "verify" "$maci" "$tally_file" "$poll_id" "$version")
echo $json_str
post_request $json_str
}
function get_request() {
res=$(curl $GET_URI)
echo $res
}
function post_request() {
res=$(curl -X POST $POST_URI -H 'content-type: application/json' -d "$1")
echo $res
}
command=$1
case $command in
"" | "-h" | "--help")
help
;;
*)
shift
${command} $@
if [ $? = 127 ]; then
echo "Error: '$command' is not a known subcommand." >&2
echo " Run '$ProgName -h' for a list of known subcommands." >&2
exit 1
fi
;;
esac