amarts / ceramic-anchor-service

Layer 2 service for anchoring batches of Ceramic commits into a single blockchain transaction.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ceramic anchor service - PoC

FOSSA Status

Ceramic anchor service is a PoC implementation of an anchor service according to the Ceramic specification.

This implementation currently uses the Ethereum blockchain but is built in order to be blockchain agnostic. It is fairly easy to add more modules to support other blockchains as well.

Prerequisites

In order to run the simulation you need to install Node.js.

Installing

Configuration file is located under ./config directory.

In order to build the application start the IPFS node locally and run the following commands:

docker-compose up -d

npm run build

npm run start

RESTful APIs

RESTful APIs are enabled on http://localhost:3000/api/v0/ by default.


Create Anchor Request

Creates CID anchor request.

  • URL

    /requests

  • Method:

    POST

  • Data Params

    • Content:
        {
        	"cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
        	"docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa" 
        }
  • Success Response:

    • Code: 201
      Content:
      {
          "id": "06a483c9-eb73-4e08-a019-7b5665588172",
          "status": "PENDING",
          "message": "Request is pending.",
          "cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
          "docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa",
          "createdAt": 1586438625,
          "updatedAt": 1586438625,
          "scheduledAt": 1586438625
      }

Get CID anchor request information

Creates CID anchor request.

  • URL

    /requests/:cid

  • Method:

    GET

  • URL Params

    Required:

    cid=[string]

  • Data Params

    None

  • Success Response - PENDING:

    • Code: 200
      Content:
      {
          "id": "06a483c9-eb73-4e08-a019-7b5665588172",
          "status": "PENDING",
          "message": "Request is pending.",
          "cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
          "docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa",
          "createdAt": 1586438625,
          "updatedAt": 1586438625,
          "scheduledAt": 1586438625
      }
  • Success Response - PROCESSING:

    • Code: 200
      Content:
      {
          "id": "06a483c9-eb73-4e08-a019-7b5665588172",
          "status": "PROCESSING",
          "message": "Request is processing.",
          "cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
          "docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa",
          "createdAt": "2020-04-08T12:10:06.000Z",
          "updatedAt": "2020-04-08T12:10:07.000Z"
      }
  • Success Response - FAILED:

    • Code: 200
      Content:
      {
          "id": "06a483c9-eb73-4e08-a019-7b5665588172",
          "status": "FAILED",
          "message": "Request failed. Staled request.",
          "cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
          "docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa",
          "createdAt": 1586438625,
          "updatedAt": 1586438625
      }
  • Success Response - COMPLETED:

    • Code: 200
      Content:
      {
          "id": "06a483c9-eb73-4e08-a019-7b5665588172",
          "status": "COMPLETED",
          "message": "CID successfully anchored.",
          "cid": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
          "docId": "doc_875c56f9-9d5d-4031-8d3d-d171a91b15aa",
          "createdAt": 1586438625,
          "updatedAt": 1586438625,
          "anchorRecord": {
              "cid": "bafyreicq6rwooyi2dk24p52nutgysi4gpu2lvoeilooekqypk4h4f32wpy",
              "content": {
                  "path": "L/L",
                  "prev": "bafyreihgmyh2srmmyiw7fdihrc2lw2uodvpxb2hbpyxo7w2jlqizga6pne",
                  "proof": "bafyreid3fjhoybtbgzdt2afdrxzikprbmgvufn3z7oavodd37k2tnof5ry"
              }
          }
      }
  • Error Response - NOT FOUND:

    • Code: 404 (NOT FOUND)
      Content: { error : "Request doesn't exist" }

      Indicates that no anchor request was found for the given CID.

  • Error Response - BAD REQUEST:

    • Code: 400 (BAD REQUEST)
      Content: { error : "error message" }

      Indicates that the request was malformed or missing necessary arguments like the CID.


Get Chain ID

Returns the CAIP-2 chain id of the configured blockchain.

  • URL

    /service-info/chainid

  • Method:

    GET

  • Success Response:

    • Code: 200
      Content:
      {
          "chainId": "eip155:1"
      }

Healthcheck

Perform a healthcheck against the anchor service itself

  • URL

    /healthcheck

  • Method:

    GET

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 503

IPFS explorer visualization

The image below represents requested CID IPLD document.

CID IPLD document

The image below represents anchor record IPLD document.

Anchor IPLD document

The image below represents anchor proof IPLD document.

Anchor IPLD document

Running the tests

Tests are located in the test directory. In order to run test start the following command:

npm run test

In order to run tests with coverage run:

npm run coverage

Maintainers

@simonovic86

Built With

License

Apache-2.0 OR MIT

FOSSA Status

Team

Built with from 3Box team.

About

Layer 2 service for anchoring batches of Ceramic commits into a single blockchain transaction.

License:Other


Languages

Language:TypeScript 95.7%Language:JavaScript 3.6%Language:Shell 0.5%Language:Dockerfile 0.2%