forked from privacy-scaling-explorations/maci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_v0_10.sh
executable file
·138 lines (125 loc) · 2.93 KB
/
user_v0_10.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
#!/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="v0.10"
function help(){
echo "Usage: $ProgName <command> [options]"
echo "commands:"
echo " genkey"
echo " signup -p <maci.pk> -x <maci.addr>"
echo " publish"
}
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
;;
*)
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","version":"%s"}'
json_str=$(printf "$json_fmt" "publish" "$pubkey" "$maci" "$privkey" "$state_index" "$vote_option_index" "$new_vote_weight" "$nonce" "$salt" "$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