From ac21c53d88aa88792f230f3429af988bff452b03 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 3 Aug 2021 19:41:06 +0530 Subject: [PATCH] Update Server.js --- src/Server.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Server.js b/src/Server.js index 3b756b9..cb32413 100644 --- a/src/Server.js +++ b/src/Server.js @@ -1,10 +1,10 @@ const http = require('http'); const floCrypto = require('./floCrypto'); -module.exports = function startServer(port){ +module.exports = function startServer(port) { const httpServer = http.createServer((req, res) => { res.setHeader("Access-Control-Allow-Origin", "*"); - if(req.method === "GET") + if (req.method === "GET") res.end(""); else if (req.method === "POST") { //POST: All data processing (required JSON input) @@ -12,20 +12,22 @@ module.exports = function startServer(port){ req.on('data', chunk => data += chunk); req.on('end', () => { //process verification - let result = {}; + let result = { + success: false + }; try { var d = JSON.parse(data); - if(!floCrypto.validateAddr(d.floID)) - result.failed = "Invalid floID"; - else if(floCrypto.getFloID(d.pubKey) !== d.floID) - result.failed = "Public key mismatched"; + if (!floCrypto.validateAddr(d.floID)) + result.reason = "Invalid floID"; + else if (floCrypto.getFloID(d.pubKey) !== d.floID) + result.reason = "Public key mismatched"; else if (!floCrypto.verifySign(d.message, d.sign, d.pubKey)) - result.failed = "Signature not verified"; + result.reason = "Signature not verified"; else result.success = true; } catch (error) { - result.Error = "Invalid request"; - }finally{ + result.reason = "Invalid request"; + } finally { res.end(JSON.stringify(result)); }; }); @@ -41,4 +43,4 @@ module.exports = function startServer(port){ Object.defineProperty(this, "http", { get: () => httpServer }); -}; +}; \ No newline at end of file