-
Notifications
You must be signed in to change notification settings - Fork 3
Pipe API
KeyChain has an I/O stream (pipe) integration option. Interaction with KeyChain through pipes requires a terminal application as an input module that sends requests (STDIN) to the security layer that shows you the details of your request. When you approve the request through an interative gialogue window, the request goes back through the signing module and gives you an answer (STDOUT).
For detailed description of the process, see Three security layers section.
Each Pipe API message is a json serialized object containing a command with the corresponding parameters.
For full comprehensive descriptions of the commands, acceptable parameters and values, go to the Protocol.
Before you proceed with the integration, you need to install KeyChain for macOS.
When the installation is complete, you can open stream input to start sending json requests through STDIN - STDOUT pipes.
const { spawn } = require('child_process');
const path = require('path');
const keychain = spawn(path.join(__dirname, 'keychain'));
const queue = [];
const sendCommand = (command, callback) => {
keychain.stdin.write(JSON.stringify(command));
queue.push(callback)
};
keychain.stdout.on('data', data => {
queue.shift()(JSON.parse(data))
});
sendCommand({command: 'select_key'}, response => {
const selectedKey = response.result;
console.log('Selected key: ', selectedKey);
const signCommand = {
command: 'sign_trx',
params: {
transaction: 'eb0885098bca5a00825208948ec6977b1255854169e5f9f8f163f371bcf1ffd287038d7ea4c6800080038080',
blockchain_type: 'ethereum',
public_key: selectedKey,
}
};
sendCommand(signCommand, response => console.log('Sign result: ', response));
});
For descriptions of all the commands and parameters, see KeyChain Protocol.