This is a simple blockchain web service to store data in private blockchain.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. Following technologies are used in this project:
- Node.js
- Express framework for web services
express-generator
, to quickly create an application skeleton.- LevelDB to persist blocks
- crypto-js library to encrypt blocks
Installing Node and NPM is pretty straightforward using the installer package available from the (Node.js® web site)[https://nodejs.org/en/].
- Test your node installation by typing below command in terminal
node --version
It should return node version e.g. v8.9.4
- Installing project dependencies
npm install
- Start the application and browse it at : http://localhost:8000
Note :npm start
will invoke./bin/www
script which contains web service startup script
npm start
Following APIs are implemented. Use any REST client to test below APIs
http://localhost:8000/gateway/hash
Returns SHA256 hash of data
-
URL
/gateway/hash
-
Method:
POST
-
Request Body
{"data":"any type of data in string"}
-
Success Response:
- Code: 200
Content:{"hash": "3e50d150f89b90f5ddac34b9131380bfed94cf5db8a8de6c8161393b8d5ec5b0"}
- Code: 200
-
Error Response:
- Code: 500 Internal Server Error
Content:{"code":"500","status":"Internal Server Error","message":"data is undefind"}
- Code: 500 Internal Server Error
http://localhost:8000/gateway/sign/generate
Generates signature of data by using provided private key
-
URL
/sign/generate
-
Method:
POST
-
Request Body
{"data": "My secret message", "privateKey": "L4ZYGVyypC1riua7f8SBgVrN6bswk7ufNubaSh7NMLJTpWqcSJv3"}
-
Success Response:
- Code: 200
Content:{"signature":"Hw10mwhAH7RaHD1f+aeMt5AcZQHu2e4+H3cF5QTW+g4qTtZoCATg8UKdSR9pbf/DyhFvfwXyIZ6C7qbOcMBpQkM="}
- Code: 200
-
Error Response:
- Code: 500 Internal Server Error
Content:{"code":"500","status":"Internal Server Error","message":"Missing parameters"}
- Code: 500 Internal Server Error
http://localhost:8000/gateway/sign/validate
Validate signature
-
URL
/sign/validate
-
Method:
POST
-
Request Body
{"data" : "My secret message", "walletAddress" : "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7", "signature" : "Hw10mwhAH7RaHD1f+aeMt5AcZQHu2e4+H3cF5QTW+g4qTtZoCATg8UKdSR9pbf/DyhFvfwXyIZ6C7qbOcMBpQkM="}
-
Success Response:
- Code: 200
Content:{"isValid":true}
- Code: 200
-
Error Response:
- Code: 500 Internal Server Error
Content:{"code":"500","status":"Internal Server Error","message":"Missing parameters"}
- Code: 500 Internal Server Error
http://localhost:8000/block/{BLOCK_HEIGHT} Returns json data about a single block at height.
-
URL
/block/:height
-
Method:
GET
-
URL Params
Required:
height=[integer]
-
Success Response:
- Code: 200
Content:{"hash":"910bb1155fecdc5cf22f4b70f7805186f9f6de8f5c8d2e05f01f222e82cdea9d","height":0,"body":"First block in the chain - Genesis block","time":"1535137099","previousBlockHash":""}
- Code: 200
-
Error Response:
- Code: 500 Internal Server Error
Content:{"code":"500","status":"Internal Server Error","message":"Block with provided height does not exist"}
- Code: 500 Internal Server Error
http://localhost:8000/block
Returns json data of added block
-
URL
/block
-
Method:
POST
-
Request Body
{"body":"block body contents"}
-
Success Response:
- Code: 200
Content:{"hash":"910bb1155fecdc5cf22f4b70f7805186f9f6de8f5c8d2e05f01f222e82cdea9d","height":0,"body":""New block 1","time":"1535137099","previousBlockHash":"910bb1155fecdc5cf22f4b70f7805186f9f6de8f5c8d2e05f01f222e82cdea9d"}
- Code: 200
-
Error Response:
- Code: 500 Internal Server Error
Content:{"code":"500","status":"Internal Server Error","message":"New block not added"}
- Code: 500 Internal Server Error