User control messages. (#56)

This commit is contained in:
Ravin Perera
2019-11-11 15:06:25 +05:30
committed by GitHub
parent 403f2e1b21
commit 39031c3157
10 changed files with 155 additions and 72 deletions

View File

@@ -54,6 +54,29 @@ function main() {
ws.close()
});
function create_input_container(inp) {
let inp_container = {
nonce: (new Date()).getTime().toString(),
input: Buffer.from(inp).toString('hex'),
max_ledger_seqno: 9999999
}
let inp_container_bytes = JSON.stringify(inp_container);
let sig_bytes = sodium.crypto_sign_detached(inp_container_bytes, keys.privateKey);
let signed_inp_container = {
type: "contract_input",
content: inp_container_bytes.toString('hex'),
sig: Buffer.from(sig_bytes).toString('hex')
}
return JSON.stringify(signed_inp_container);
}
function create_status_request() {
let statreq = { type: 'stat' }
return JSON.stringify(statreq);
}
ws.on('message', (m) => {
console.log("-----Received raw message-----")
console.log(m.toString())
@@ -76,8 +99,7 @@ function main() {
// sign the challenge and send back the response
var sigbytes = sodium.crypto_sign_detached(m.challenge, keys.privateKey);
var response = {
version: '0.1',
type: 'challenge_response',
type: 'challenge_resp',
challenge: m.challenge,
sig: Buffer.from(sigbytes).toString('hex'),
pubkey: pkhex
@@ -96,22 +118,13 @@ function main() {
var input_pump = () => {
rl.question('\nProvide an input: ', (inp) => {
let inp_container = {
nonce: (new Date()).getTime().toString(),
input: Buffer.from(inp).toString('hex'),
maxledgerseqno: 9999999
}
let inp_container_bytes = JSON.stringify(inp_container);
let sig_bytes = sodium.crypto_sign_detached(inp_container_bytes, keys.privateKey);
let msgtosend = "";
let signed_inp_container = {
version: "0.1",
type: "contract_input",
content: inp_container_bytes.toString('hex'),
sig: Buffer.from(sig_bytes).toString('hex')
}
let msgtosend = JSON.stringify(signed_inp_container);
if (inp == "stat")
msgtosend = create_status_request();
else
msgtosend = create_input_container(inp);
console.log("Sending message: " + msgtosend);
ws.send(msgtosend)

View File

@@ -83,8 +83,7 @@ function main() {
// sign the challenge and send back the response
var sigbytes = sodium.crypto_sign_detached(m.challenge, keys.privateKey);
var response = {
version: '0.1',
type: 'challenge_response',
type: 'challenge_resp',
challenge: m.challenge,
sig: Buffer.from(sigbytes).toString('hex'),
pubkey: pkhex