You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.2 KiB

  1. ## Census HTTP service
  2. Reference implementation of a voting census service running on the Vocdoni platform
  3. ## Compile
  4. In a GO ready environment:
  5. ```
  6. go get -u github.com/vocdoni/dvote-census/...
  7. go build -o censusHttpService github.com/vocdoni/dvote-census/cmd/censushttp
  8. ```
  9. ## Usage
  10. `./censusHttpService <port> <censusId>[:pubKey] [<censusId>[:pubKey] ...]`
  11. Example
  12. ```
  13. ./censusHttpService 1500 Got_Favorite
  14. 2019/02/12 10:20:16 Starting process HTTP service on port 1500 for namespace GoT_Favorite
  15. 2019/02/12 10:20:16 Starting server in http mode
  16. ```
  17. ## API
  18. A HTTP jSON endpoint is available with the following possible fields: `censusId`, `claimData`, `rootHash` and `proofData`.
  19. If `pubKey` has been configured for a specific `censusId`, then two more methods are available (`timeStamp` and `signature`) to provide authentication.
  20. The next table shows the available methods and its relation with the fields.
  21. | method | censusId | claimData | rootHash | proofData | protected? | description |
  22. |------------|-----------|-----------|----------|-----------|------------|------------|
  23. | `addCLaim` | mandatory | mandatory | none | none | yes | adds a new claim to the merkle tree |
  24. | `getRoot` | mandatory | none | none | none | no | get the current merkletree root hash
  25. | `genProof` | mandatory | mandatory | optional | none | no | generate the merkle proof for a given claim
  26. | `checkProof` | mandatory | mandatory | optional | mandatory | no | check a claim and its merkle proof
  27. | `getIdx` | mandatory | mandatory | optional | none | no | get the merkletree data index of a given claim
  28. | `dump` | mandatory | none | optional | none | yes | list the contents of the census for a given hash
  29. ## Signature
  30. The signature provides authentication by signing a concatenation of the following strings (even if empty) without spaces: `censusId rootHash claimData timeStamp`.
  31. The `timeStamp` when received on the server side must not differ more than 10 seconds from the current UNIX time.
  32. ## Examples
  33. #### add claims
  34. Add two new claims, one for `Jon Snow` and another for `Tyrion`.
  35. ```
  36. curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/addClaim
  37. {"error":false,"response":""}
  38. ```
  39. ```
  40. curl -d '{"censusID":"GoT_Favorite","claimData":"Tyrion"}' http://localhost:1500/addClaim
  41. {"error":false,"response":""}
  42. ```
  43. In case signature is enabled:
  44. ```
  45. curl -d '{
  46. "censusID":"GoT_Favorite",
  47. "claimData":"Jon Snow",
  48. "timeStamp":"1547814675",
  49. "signature":"a117c4ce12b29090884112ffe57e664f007e7ef142a1679996e2d34fd2b852fe76966e47932f1e9d3a54610d0f361383afe2d9aab096e15d136c236abb0a0d0e" }' http://localhost:1500/addClaim
  50. {"error":false,"response":""}
  51. ```
  52. #### generate proof
  53. Generate a merkle proof for the claim `Jon Snow`
  54. ```
  55. curl -d '{"censusID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/genProof
  56. {"error":false,"response":"0x000200000000000000000000000000000000000000000000000000000000000212f8134039730791388a9bd0460f9fbd0757327212a64b3a2b0f0841ce561ee3"}
  57. ```
  58. If `rootHash` is specified, the proof will be calculated for the given root hash.
  59. #### get root
  60. The previous merkle proof is valid only for the current root hash. Let's get it
  61. ```
  62. curl -d '{"censusID":"GoT_Favorite"}' http://localhost:1500/getRoot
  63. {"error":false,"response":"0x2f0ddde5cb995eae23dc3b75a5c0333f1cc89b73f3a00b0fe71996fb90fef04b"}
  64. ```
  65. #### check proof
  66. Now let's check if the proof is valid
  67. ```
  68. curl -d '{
  69. "censusID":"GoT_Favorite","claimData":"Jon Snow",
  70. "rootHash":"0x2f0ddde5cb995eae23dc3b75a5c0333f1cc89b73f3a00b0fe71996fb90fef04b",
  71. "proofData":"0x000200000000000000000000000000000000000000000000000000000000000212f8134039730791388a9bd0460f9fbd0757327212a64b3a2b0f0841ce561ee3"}' http://localhost:1500/checkProof
  72. {"error":false,"response":"valid"}
  73. ```
  74. If `rootHash` is not specified, the current root hash is used.
  75. #### dump
  76. Dump contents of a specific censusId (values)
  77. ```
  78. curl -d '{"censusID":"GoT_Favorite"}' http://localhost:1500/dump
  79. {"error":false,"response":"[\"Tyrion\",\"Jon Snow\"]"}
  80. ```
  81. If `rootHash` is specified, dump will return the values for the merkle tree with the given root hash.