-
Notifications
You must be signed in to change notification settings - Fork 3
WebSocket API
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/
.
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.
Here you can try out signing Ethereum transactions with KeyChain.
You can find an example of the code here.
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.
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"}
The API will return a properly JSON formated response carrying the same id as the request to distinguish subsequent calls.
{"result": ..data..}
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"}
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/.
- Success scenario
When the connection is established, you will see the following KeyChain page:
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:
- 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.
You can find the code for the demo page and the page itself up in the Demo page in JavaScript section.