Skip to content

WebSocket API

Avvrik edited this page Dec 4, 2018 · 73 revisions

KeyChain contains a WebSocket API. This API can be used to stream information from a KeyChain instance to any client that implements WebSockets. Implementations in different languages:

  • NodeJS
  • Python
  • JavaScript/HTML
  • etc

Connect your WebSocket implementation to http://localhost:16384/.

Demo pages in JavaScript

For testing commands

On this demo page you can test all the KeyChain commands.

Here you will find the code of the KeyChain demo page. It will be automatically installed together with the KeyChain.

For signing transactions

Here you can try out signing Ethereum transactions with KeyChain.

You can find an example of the code here.

Message format

Each WebSocket API message is a json serialized object containing a command with the corresponding parameters.

For example, here is a request for generating keys:

{
  "command": "create",
  "params":
   {
      "keyname": "my key",
      "encrypted": true,
      "curve": "secp256k1",
      "cipher": "aes256"
  }
}

For full comprehensive descriptions of the commands, acceptable parameters and values, go to the Protocol.

WebSocket integration guide

NodeJS integration example

The following will show the usage of websocket connections. We make use of the wscat application available via npm:

$ npm install -g wscat

A simple call would take the form:

$ wscat -c ws://127.0.0.1:16384
> { "command": "list"}

Successful Calls

The API will return a properly JSON formated response carrying the same id as the request to distinguish subsequent calls.

{"result":  ..data..}

Errors

In case of an error, the resulting answer will carry an error attribute and a description in human-readable format:

{"error":"Error: keyfile could not found by keyname"}

JavaScript integration example

Before you proceed with the integration, you need to download and install KeyChain.

After installing KeyChain, open the browser and connect to http://localhost:16384/.

  1. Success scenario

When the connection is established, you will see the following KeyChain page:

prtscr

If you click on one of the commands on the left panel, you will see its json request and response in the white boxes below:

prtscr

  1. Something went wrong

If the installation was not successful, you will experience problems connecting to the KeyChain page correctly. It will have white background instead of a green one and - most importantly - you will not be able to see responses in the "Response" box below.

prtscr

You can find the code for the demo page and the page itself up in the Demo page in JavaScript section.

Clone this wiki locally