Star Notary service allows users to claim ownership of their favorite star in the night sky.
Star Notary Service is provided to make sure:
- Proof of existence
- Proof of ownership
- Security of assets
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
memory-cache
to handle user sessions- crypto-js library to encrypt blocks
bitcoinjs-message
to validate signature
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
Some libraries also require MS Build Tools, you can install it using following command.
npm install --global --production windows-build-tools
- 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
You should see this message Welcome to Star Notary Service
Application is structured in 3 layers:
- Controllers
Controllers are the entry points of this application. Endpoints are defined in controllers (./routes folder) - Services
Services are actual implementation of -blockchain- concepts e.g. (hashing, validation, integrity etc...) - Database
Level DB is used to persist actual -blockchain- data.
Application is divided into 3 different modules.
- Validation Service
To validate user's address (blockchain ID) - Blockchain Service
To save stars information in registry - Star Service
Provides convenient methods to lookup stars by (address/hash)
- User needs to validate himself everytime he wants to register a star
- Validation window time is 300 sec, after expiry [s]he needs to re-start validation process
- Star story text lenght should not exceeds 250 words
Following APIs are implemented. Use any REST client to test below APIs
http://localhost:8000/validation/requestValidation
Allows users to request validation for Star Registry
.
-
URL
/validation/requestValidation
-
Method:
POST
-
Request Body
{"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7"}
-
-
Success Response:
- Code: 200
- Content:
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"requestTimeStamp": "1532296090",
"message": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7:1532296090:starRegistry",
"validationWindow": 300
}
-
Error Response:
- Code: 500
- Content:
{
"code":"500",
"status":"Internal Server Error",
"message":"Error: Validation window time expired, please restart validation process
}
http://localhost:8000/validation/validate
After receiving the response, users will prove their blockchain identity by signing a message with their wallet. Once they sign this message, the application will validate their request and grant access to register a star.
-
URL
/validation/validate
-
Method:
POST
-
Request Body
-
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"signature": "ILRRa2Ul2NzgEuVDMSZwTsMBPW1UsCtrZwduCIouK4HVId8g3UyQKkgsPO2MZokqokClTnU8FVbXzMqb6sN89mQ="
}
-
Success Response:
- Code: 200
- Content:
{
"registerStar": true,
"status":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"requestTimeStamp": "1532296090",
"message": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7:1532296090:starRegistry",
"validationWindow": 193,
"messageSignature": "valid"
}
}
- Error Response:
- Code: 500
- Content:
{
"code": "500",
"status": "Internal Server Error",
"message": "Error: Error, Unable to validate signature. You may need to request validation first."
}
http://localhost:8000/block
Allows users to register their star
-
URL
/block
-
Method:
POST
-
Request Body
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"dec": "-26° 29'\'' 24.9",
"ra": "16h 29m 1.0s",
"story": "Found star using https://www.google.com/sky/"
}
}
-
Success Response:
- Code: 200
- Content:
{
"hash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f",
"height": 1,
"body":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"ra": "16h 29m 1.0s",
"dec": "-26° 29' 24.9",
"story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f"
}
},
"time": "1532296234",
"previousBlockHash": "49cce61ec3e6ae664514d5fa5722d86069cf981318fc303750ce66032d0acff3"
}
-
Error Response:
- Code: 500 Internal Server Error
- Content:
{
"code": "500",
"status": "Internal Server Error",
"message": "Error: Error, Unable to validate signature. You may need to request validation first."
}
http://localhost:8000/block/1
Returns Star at particular block height
-
URL
/block/:height
-
Method:
GET
-
Request Param
height[integer] -
Success Response:
- Code: 200
- Content:
{
"hash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f",
"height": 1,
"body":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"ra": "16h 29m 1.0s",
"dec": "-26° 29' 24.9",
"story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f"
}
},
"time": "1532296234",
"previousBlockHash": "49cce61ec3e6ae664514d5fa5722d86069cf981318fc303750ce66032d0acff3"
}
-
Error Response:
- Code: 500 Internal Server Error
- Content:
{
"code": "500",
"status": "Internal Server Error",
"message": "Error: Block not found with height : 33"
}
http://localhost:8000/stars/address:1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7
Returns all stars owned by address [blockchainID]
-
URL
/stars/address:address
-
Method:
GET
-
Request Param
address[string] -
Success Response:
- Code: 200
- Content:
[
{
"hash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f",
"height": 1,
"body":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"ra": "16h 29m 1.0s",
"dec": "-26° 29' 24.9",
"story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f",
"storyDecoded": "Found star using https://www.google.com/sky/"
}
},
"time": "1532296234",
"previousBlockHash": "49cce61ec3e6ae664514d5fa5722d86069cf981318fc303750ce66032d0acff3"
},
{
"hash": "6ef99fc533b9725bf194c18bdf79065d64a971fa41b25f098ff4dff29ee531d0",
"height": 2,
"body":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"ra": "17h 22m 13.1s",
"dec": "-27° 14' 8.2",
"story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f",
"storyDecoded": "Found star using https://www.google.com/sky/"
}
},
"time": "1532330848",
"previousBlockHash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f"
}
]
-
Error Response:
- Code: 500 Internal Server Error
- Content:
{
"code": "500",
"status": "Internal Server Error",
"message": "{Runtime Error}"
}
http://localhost:8000/stars/hash:a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f
Returns star info by blockHash
-
URL
/stars/hash:blockHash
-
Method:
GET
-
Request Param
blockHash[string] -
Success Response:
- Code: 200
- Content:
{
"hash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f",
"height": 1,
"body":
{
"address": "1CYgQ8wbdWZPGEWgbxZLq5JUe5e1ECWPe7",
"star":
{
"ra": "16h 29m 1.0s",
"dec": "-26° 29' 24.9",
"story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f",
"storyDecoded": "Found star using https://www.google.com/sky/"
}
},
"time": "1532296234",
"previousBlockHash": "49cce61ec3e6ae664514d5fa5722d86069cf981318fc303750ce66032d0acff3"
}
-
Error Response:
- Code: 500 Internal Server Error
- Content:
{
"code": "500",
"status": "Internal Server Error",
"message": "Error: Star not found with hash."
}
http://localhost:8000/block/validate
Validate blockchain integrity
-
URL
/block/validate
-
Method:
GET
-
Success Response:
- Code: 200
- Content:
Great!! Blockchain is valid
-
Error Response:
- Code: 200
- Content:
Opps!! Blockchain is Invalid