Skip to content

Commit

Permalink
add operation module into back-end server
Browse files Browse the repository at this point in the history
1.decrypt the password and check if valid or not
  • Loading branch information
Cha0s0000 committed Apr 26, 2018
1 parent 9076103 commit 2c29ac4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
55 changes: 55 additions & 0 deletions NodeServer/api/operation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* operation module
* @authors cha0s0000
* @github https://github.com/Cha0s0000/MicroSteemit
* @webSite https://steemit.com/@cha0s0000
*/

var express = require('express');
var router = express.Router();
var steem = require('steem');
const crypto = require('crypto')

// length of key is 16 of 128 bit. JUST for test the Decrypt
const key = '3454345434543454'
// Hexadecimal number as the secret key offset. JUST for test the Decrypt
const iv = '6666666666666666'

// deal with GET request
router.get('/wif_is_valid', function(req, res) {
var name = req.query.account;
var privWif = aesDecrypt(req.query.key,key,iv);
steem.api.getAccounts([name], function(err, result) {
var pubWif;
try{
pubWif= result[0].posting.key_auths[0][0];
}
catch(e){
pubWif = "none";
}
var isvalid;
try{
isvalid = steem.auth.wifIsValid(privWif, pubWif,'posting');
}
catch(e){
isvalid = 'false';
}
if(isvalid == true){
console.log(name+' Welcome.');
res.json({message:'success'});
}else{
console.log('Wrong! Check your Private key.');
res.json({message:'fail'});
}
});
});


const aesDecrypt = function(data, secretKey, iv) {
const cipherEncoding = 'hex'
const clearEncoding = 'utf8'
const cipher = crypto.createDecipheriv('aes-128-cbc',secretKey, iv)
return cipher.update(data,cipherEncoding,clearEncoding) + cipher.final(clearEncoding)
}

module.exports = router;
5 changes: 3 additions & 2 deletions NodeServer/api/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ router.get('/get_discussions_by_author_before_date', function(req, res) {
});

router.get('/get_discussions_by_comments', function(req, res) {
steem.api.getDiscussionsByComments(req.query, function(err, result) {
steem.api.getDiscussionsByComments(JSON.parse(req.query.query), function(err, result) {
res.send(result).end();
console.log("get_discussions_by_comments");
});
Expand All @@ -74,7 +74,8 @@ router.get('/get_content_replies', function(req, res) {
});

router.get('/get_discussions_by_feed', function(req, res) {
steem.api.getDiscussionsByFeed(req.query, function(err, result) {
steem.api.getDiscussionsByFeed(JSON.parse(req.query.query), function(err, result) {
console.log(result);
res.send(result).end();
console.log("get_discussions_by_feed");
});
Expand Down
8 changes: 7 additions & 1 deletion NodeServer/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ module.exports = function(app){
// app.use('/get_state',general);
// app.use('/get_dynamic_global_properties',general);


var operation = require('../api/operation');
app.use('/operation',operation);





// TO-DEAL api
// https://api.steemjs.com/get_state?path=/@' + author + '/recent-replies
// https://uploadbeta.com/api/steemit/transfer-history/?id=' + account
Expand Down

0 comments on commit 2c29ac4

Please sign in to comment.