diff --git a/README.md b/README.md index a7217e8..437a0d4 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ This project is a fork of [Ciquidus Explorer](https://github.com/suprnurd/ciquid - **getvotelist:** Returns an object with details regarding the current vote list - **getmasternodecount:** Returns a json object containing the total number of masternodes on the network - **getmasternodelist:** Returns a json array containing status information for all masternodes on the network + - **verifymessage:** Verify a signed message. Must accept the following arguments: + - **address:** The wallet address to use for the signature. + - **signature:** The signature provided by the signer in base 64 encoding. + - **message:** The message that was signed. ### See it in action diff --git a/app.js b/app.js index 2215c7f..6941420 100644 --- a/app.js +++ b/app.js @@ -286,23 +286,18 @@ app.use('/ext/getaddresstxs/:address/:start/:length', function(req,res) { }); }); -app.post('/address/:hash/claim', function(req, res){ - var address = req.body.address; - var signature = req.body.signature; - var message = req.body.message; - - request({ url: 'http://127.0.0.1:' + settings.port + '/api/verifymessage?address='+address+ '&signature='+ signature + '&message=' + message, method: 'GET'}, function(error, response, body) { - if (body == 'There was an error. Check your console.') - res.json({"status": "failed", "error": true, "message": body}); - else if (body == "false") { - res.json({"status": "failed", "error": true, "message": error}); - } else if(body == "true") { - db.update_label(address, message, function() { - res.json({"status": "success"}); +app.post('/address/:hash/claim', function(req, res) { + lib.verify_message(req.body.address, req.body.signature, req.body.message, function(body) { + if (body == false) { + res.json({'status': 'failed', 'error': true, 'message': 'Invalid signature'}); + } else if (body == true) { + db.update_label(req.body.address, req.body.message, function() { + res.json({'status': 'success'}); }); - } + } else + res.json({'status': 'failed', 'error': true, 'message': 'There was an error. Check your console.'}); }); -}) +}); app.use('/ext/connections', function(req,res){ db.get_peers(function(peers){ diff --git a/lib/explorer.js b/lib/explorer.js index 916a248..0a99069 100644 --- a/lib/explorer.js +++ b/lib/explorer.js @@ -760,7 +760,35 @@ module.exports = { // cmd not in use. return null. return cb(null); } - }, + }, + + verify_message: function(address, signature, message, cb) { + var cmd = prepareRpcCommand(settings.api_cmds.verifymessage, [address, signature, message]); + + if (!(cmd.method == '' && cmd.parameters.length == 0)) { + if (settings.use_rpc) { + rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) { + // check if an error msg was received from the rpc server + if (response == 'There was an error. Check your console.') + return cb(null); + else + return cb(response); + }); + } else { + var uri = base_url + 'verifymessage?address=' + address + '&signature=' + signature + '&message=' + message; + request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) { + // check if an error msg was received from the web api server + if (body == 'There was an error. Check your console.') + return cb(null); + else + return cb(body); + }); + } + } else { + // cmd not in use. return null. + return cb(null); + } + }, get_geo_location: function(address, cb) { request({uri: 'https://freegeoip.app/json/' + address, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, geo) { diff --git a/lib/nodeapi.js b/lib/nodeapi.js index 93e77e4..f7370e4 100644 --- a/lib/nodeapi.js +++ b/lib/nodeapi.js @@ -188,6 +188,9 @@ module.exports = function(){ } } } + var cmd = prepareRpcCommand(settings.api_cmds.verifymessage, params); + method_name = cmd.method; + params = cmd.parameters; break; case 'sendmany': var after_account = false; diff --git a/lib/settings.js b/lib/settings.js index 17a88dc..0b5731f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -206,7 +206,8 @@ exports.api_cmds = { "getnextrewardwhenstr": "getnextrewardwhenstr", "getvotelist": "masternodelist votes", "getmasternodecount": "getmasternodecount", - "getmasternodelist": "listmasternodes" + "getmasternodelist": "listmasternodes", + "verifymessage": "verifymessage" }; exports.reloadSettings = function reloadSettings() { diff --git a/settings.json.template b/settings.json.template index 806f823..4a11312 100644 --- a/settings.json.template +++ b/settings.json.template @@ -282,6 +282,10 @@ // getvotelist: Returns an object with details regarding the current vote list. // getmasternodecount: Returns a json object containing the total number of masternodes on the network. // getmasternodelist: Returns a json array containing status information for all masternodes on the network. + // verifymessage: Verify a signed message. Must accept the following arguments: + // address: The wallet address to use for the signature. + // signature: The signature provided by the signer in base 64 encoding. + // message: The message that was signed. "api_cmds": { "getnetworkhashps": "getnetworkhashps", "getmininginfo": "getmininginfo", @@ -305,5 +309,6 @@ "getvotelist": "masternodelist votes", "getmasternodecount": "getmasternodecount", "getmasternodelist": "listmasternodes" + "verifymessage": "verifymessage" } } \ No newline at end of file