WhiteflagProtocol / whiteflag-api

Reference implementation of the Whiteflag protocol in Node.js that acts as an API to connect applications with the underlying blockchains
https://api.whiteflagprotocol.org
Other
4 stars 5 forks source link
bitcoin blockchain blockchain-account ethereum ethereum-blockchain javascript nodejs openapi whiteflag-api whiteflag-messages whiteflag-protocol

Whiteflag API

GitHub latest release GitHub dev version Ubuntu Test Windows Test

Introduction

Whiteflag is a fully neutral and secure communications means based on blockchain technology. It enables near real-time communication in armed conflicts and disasters to exchange early warning and status information to create shared situational awareness.

This Whiteflag Application Programming Interface (API) is a Node.js software implementation of the API layer that provides an interface with the Whiteflag messaging network on one or more underlying blockchains. In other words, it acts as a message transceiver between one or more blockchains and one or more end-user applications. For interaction with an end-user application, two methods are used:

The current version is based on v1-draft.6 of the Whiteflag protocol. The supported Whiteflag protocol features are described in SCOPE.md.

Note that the Whiteflag API is a so called Minimum Viable Product (MVP). This means that it only supports the core features of the Whiteflag protocol and nothing more. As such, it serves as the reference implementation of the Whiteflag protocol, but it is not designed and tested for secure usage and performance in a production environment.

Documentation

More detailed documentation of the API is available at Github Pages

This documentation is also found in the markdown files in the docs/ directory. When the API is running, the server will also provide the OpenAPI definition at the URL root (e.g. http://localhost:5746/).

The repository structure and development guidelines for the source code are described in CONTRIBUTING.md.

License

The Whiteflag API software is dedicated to the public domain under the Creative Commons CC0-1.0 Universal Public Domain Dedication statement. See LICENSE.md for details.

The Whiteflag API software requires third party software packages, which are not part of this distribution and may be licenced differently.

Installation

Prerequisites

To deploy the Whiteflag API, make sure the following prerequisite software is installed:

Since version 1.0.1, the Whiteflag API has a lightweight embedded datastore, making MongoDB an optional dependency:

Deployment and Testing

First, copy the repository to the deployment directory, such as /opt/whiteflag-api. Please use a version tagged commit for a stable version.

After copying the repository, install the required Node.js modules of external software libraries and then create a global link to the package by running the following commands in the deployment directory:

npm install
npm link

To run an automated test of the software, use the following command in the deployment directory:

npm test

Configuration

The API uses three optional environment variables:

Configurable parameters of the API can be found in the TOML files in the config/ directory:

Please see docs/configuration.md for more details.

Running the API

To start the Whitefag API server from the command line, use the wfapi command in the deployment directory:

wfapi

Using the npm start command in the deployment directory should also work.

Alternatively, a service may be created. An example whiteflag-api.service for linux systems using systemctl cound be found in etc/. Enable the and start the service with:

sudo systemctl enable ./etc/whiteflag-api.service
sudo service whiteflag-api start

API Functionality

The detailed OpenAPI definition can be found in static/openapi.json. The API definition is provided in human readible format at the root endpoint by the running API; just go to http://localhost:5746/ with a browser.

Some of the endpoint functionalities (see the API defintion for all details):

Messages

Blockchains

Originators

Signature operations

Testing and Using the API

A minimal set of automated tests is implemented with the Mocha test framework. To do a full test and run all the test scripts, use the following NPM command in the project root:

npm test

Any REST client, such as Postman or cURL can be used for manual testing. This is a simple example using cURL from the command line, sending an A1 message from a file:

curl http://localhost:5746/messages/send -X POST -H "Content-Type:application/json" -d @A1.message.json

The API also exposes a webpage with an embedded client side socket listener that is available on http://localhost:5746/listen (default URL) when the API is running.

When testing on a main blockchain network, the testMessagesOnly in the [tx] section of the whiteflag.toml configuration file should be set to true to prevent the accidental transmission of real messages.