No description
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
sripwoud 00c395a0ed Merge pull request #5 from r1oga/dependabot/npm_and_yarn/esm-3.2.25
build(deps): Bump esm from 3.0.84 to 3.2.25
2020-07-24 08:53:57 +02:00
img Add images for POSTMAN GET responses 2019-01-06 18:59:41 +01:00
test test: User can't submit a second block without revalidating address 2019-01-06 19:07:58 +01:00
.gitignore Add test folder 2019-01-05 20:42:42 +01:00
app.js Set up project structure 2019-01-03 13:07:40 +01:00
Block.js Add files 2018-12-16 17:46:05 +01:00
BlockChain.js fix: Return object from requestValidation 2019-01-06 17:46:50 +01:00
BlockController.js fix: Check validation of wallet before allowing star registration 2019-01-06 18:52:26 +01:00
LevelDB.js feat: Reduce validation time window when resubmitting a request 2019-01-05 14:57:14 +01:00
LICENSE Initial commit 2018-12-16 17:27:43 +01:00
MemPool.js fix: Check validation of wallet before allowing star registration 2019-01-06 18:52:26 +01:00
package-lock.json Merge pull request #5 from r1oga/dependabot/npm_and_yarn/esm-3.2.25 2020-07-24 08:53:57 +02:00
package.json test: Perform test for second POST endpoint 2019-01-03 16:46:36 +01:00
README.md Update README 2019-01-06 19:18:49 +01:00
Request.js feat: Add POST endpoint to submit a validation request 2019-01-03 14:56:49 +01:00

Star Notary Service

This Star Notary Service is built on top of the private blockchain I previously created. It include a Web API allowing users to interact with the blockchain and especially claim ownership of their favorite star in the night sky.

Describe stars: celestial coordinates

Here is an example of how star coordinates are represented:

RA 13h 03m 33.35sec, Dec -49° 31’ 38.1” Mag 4.83 Cen
  • RA: Right Ascension
  • Dec: Declination
  • CEN: Centaurus
  • MAG: Magnitude

Find stars

Night Sky

Project architecture and files

Sequence Diagram

  • Web API: Defines API endpoints' routes and handlers.
    • BlockController.js
  • Mempool: to manage validation requests to grant users the right to register a star.
    • MemPool.js
    • Request.js
  • Blockchain: to store and persist star blocks
    • Blockchain.js
    • LevelDB.js
    • Block.js

Getting Started

  1. Download or clone the repository
  2. Install project dependencies: npm install
  3. Start the web service: node app.js

Web API

The server runs locally by default on port 8000.
You may select a different one by updating the PORT parameter of the BlockAPI constructor in app.js.

Submit a validation request

First the user needs to request validation of their wallet address before being able to register any stars.
METHOD: POST
URL: /requestValidation
PARAMETER

  • address: user's wallet address

RESPONSE

{
    "walletAddress": "19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL",
    "requestTimeStamp": "1541605128",
    "message": "19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL:1541605128:starRegistry",
    "validationWindow": 300
}

Prove ownership of wallet

After submitting a validation request, the user needs to prove that he is the owner of the considered address by providing the signature of the message returned in the previous step.

To get the required message signature, one could use the sign function of the bitcoinjs-message library or the sign feature of a wallet like electrum.

METHOD: POST
URL: /message-signature/validate
PARAMETERS

  • address
  • signature

RESPONSE

{
  "registerStar": true,
  "status": {
    "address": "19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL",
    "requestTimeStamp": "1541605128",
    "message": "19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL:1541605128:starRegistry",
    "validationWindow": 200,
    "messageSignature": true
  }
}

Register star

After validation of the signature, the user can now register a star.
METHOD: POST
URL: /block
PARAMETERS

  • address
  • star:
{
  "dec": "68° 52' 56.9",
  "ra": "16h 29m 1.0s",
  "story": "Found star using https://www.google.com/sky/"
}

RESPONSE

{
 "hash": "a59e9e399bc17c2db32a7a87379a8012f2c8e08dd661d7c0a6a4845d4f3ffb9f",
  "height": 1,
  "body": {
    "address": "142BDCeSGbXjWKaAnYXbMpZ6sbrSAo3DpZ",
    "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"
}

Retrieve stars

By height

METHOD: GET
URL: /block/[HEIGHT]
get star by height response POSTMAN

By hash

METHOD: GET
URL: /stars/[HASH]
get star by hash response POSTMAN

By wallet address

METHOD: GET
URL: /stars/[ADDRESS]
get stars by wallet response POSTMAN

Tests

Run npx ava to perform the tests defined in test.js.

Resources