Coder Social home page Coder Social logo

fabric-rest's Introduction

REST API server for Hyperledger Fabric 1.x

This server provides a convenient REST interface for web applications to transact on Hyperledger Fabric 1.x network. It uses Node.js SDK API to call peers, orderer and CA servers of network's members.

The server can be instantiated from a docker image and run alongside other services like peers and ca servers on a member's host.

REST Server

The API server is meant to be run by each member organization. It manages user authentication, interacts with peers and passes events to the client.

See the example calls in REST.md.

Authentication

The server connects to the organization's CA server to get certs for end users and passes these certs to authenticate to blockchain peers. User requests coming from a web app authenticate with a Bearer JWT token for which the server finds a corresponding key cached locally and signs user transactions with it when it passes them to peers.

To enable pre-auth feature, please add index.js file to server/middleware-auth folder. Example can be found below:

//3rd-party auth-store
const credentials = [{
  username: 'test',
  password: undefined,
  org: 'a'
}];

module.exports = function auth(username, password, orgname) {
  const user = credentials.find(obj => obj.username === username && obj.org === orgname && obj.password === password);
  return user ? Promise.resolve(user) : Promise.reject({status: 401, message: 'invalid credentials'});
};

Events

Block events coming from peers are sent to clients with a popular socket.io library to be consumed by browser or other clients.

Admin Web Application

Admin web application is served from the http endpoint for developers to invoke chaincodes and view transaction and block info. Please note that connection to the API server and the test web app is not password protected.

invoke page info page

Network

Please use Fabric-Starter for the network setup.

Config

Environment

  • PORT - api/web interface port (default is 4000)
  • ORG - organization id. No default value, you have to set it explicitly
  • CONFIG_FILE - ledger config file (default is ../artifacts/network-config.json)
  • WEB_DIR - location of web application (default is www)
  • MIDDLEWARE_CONFIG_FILE - middleware map file (default is ./middleware/map.json)

Launch

Api web-interface become available on http://localhost:4000 after launching:

  npm install
  ORG=org1 npm start
  # or: ORG=org2 npm start

Known issues

  • peer ID should be started with 'peer' word (specified in network-config.json).

    RIGHT:

   ...
        "org1": {
			...
			"peer1": { ... },
			"peer2.example.com": { ... },
			"peer": { ... },
		},
   ...

WRONG:

   ...
        "org1": {
			...
			"n1.peer": { ... },
			"host2.example.com": { ... },
		},
   ...
  • orderer should be named "orderer". No options, you cannot rename it.

  • endpoints /channels/<channelName>/config and /genesis are not work properly

  • chaincode instantiate works with peer1 exactly. no options here

  • admin UI uses peer1 to get common info

fabric-rest's People

Contributors

altoros-admin avatar olegabu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.