go-dvote/cmd/censushttp/README.md
cmd/censushttp/README.mdRaw
1## Census HTTP service
2
3Reference implementation of a voting census service running on the Vocdoni platform
4
5#### Compile
6
7In a GO ready environment:
8
9```
10go get -u github.com/vocdoni/dvote-census
11go build -o censusHttpService github.com/vocdoni/dvote-census/cmd/censushttp
12```
13
14#### Usage
15
16`./censusHttpService <port> <namespace>[:pubKey] [<namespace>[:pubKey] ...]`
17
18Example:
19
20```
21./censusHttpService 1500 Got_Favorite
222019/02/01 20:01:15 Starting process HTTP service on port 1500 for namespace GoT_Favorite
232019/02/01 20:01:15 Starting server in http mode
24```
25
26#### add claims
27
28```
29curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/addClaim
30
31{"error":false,"response":""}
32```
33
34If public key authentication enabled, `signature` field is required using Nancl signature.
35
36The signed message is expected to be a concatenation of the following fields: `censusID, claimData, timeStamp`
37
38There is a time window of 10 seconds while the signature is considered valid.
39
40```
41curl -d '{"censusID":"GoT_Favorite",
42"claimData":"Jon Snow",
43"timeStamp":"1547814675",
44"signature":"a117c4ce12b29090884112ffe57e664f007e7ef142a1679996e2d34fd2b852fe76966e47932f1e9d3a54610d0f361383afe2d9aab096e15d136c236abb0a0d0e"}' http://localhost:1500/addClaim
45
46{"error":false,"response":""}
47```
48
49
50#### generate proof
51
52```
53curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/genProof
54
55{"error":false,"response":"0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"}
56```
57
58#### check proof
59
60```
61curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x0000000000000000000000000000000000000000000000000000000000000000000123"}' http://localhost:1500/checkProof
62
63{"error":false,"response":"invalid"}
64```
65
66```
67curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"}' http://localhost:1500/checkProof
68
69{"error":false,"response":"valid"}
70```
71
72#### make snapshot
73
74Snapshots are static and unmutable copies of a specific census
75
76```
77curl -d '{"censusID":"GoT_Favorite"}' http://localhost:1500/snapshot
78
79{"error":false,"response":"0x8647692e073a10980d821764c65ca3fddbc606bb936f9812a7a806bfa97df152"}
80```
81
82The name for the snapshot is "0x8647692e073a10980d821764c65ca3fddbc606bb936f9812a7a806bfa97df152" which represents the Root Hash.
83
84Now you can use it as censusID for checkProof, getRoot, genProof and dump. But addClaim is not longer allowed.
85
86#### dump
87
88Dump contents of a specific censusID (values)
89
90```
91curl -d '{"censusID":"GoT_Favorite"}' http://localhost:1500/dump
92{"error":false,"response":"[\"Tyrion\",\"Jon Snow\"]"}
93```
94
95
96
97
98
99
100
101
102
103
104
105
106##### add claims
107
108```
109curl -d '{"processID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/addClaim
110{"error":false,"response":""}
111```
112
113```
114curl -d '{"processID":"GoT_Favorite","claimData":"Tyrion"}' http://localhost:1500/addClaim
115{"error":false,"response":""}
116```
117
118##### generate proof
119
120```
121curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/genProof
122{"error":false,"response":"0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"}
123```
124
125##### check proof
126
127```
128curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x0000000000000000000000000000000000000000000000000000000000000000000123"}' http://localhost:1500/checkProof
129{"error":false,"response":"invalid"}
130```
131
132```
133curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"}' http://localhost:1500/checkProof
134{"error":false,"response":"valid"}
135```
136