forked from kingswisdom/SteemMessenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLara.js
52 lines (50 loc) · 1.88 KB
/
Lara.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const steem = require('steem');
const crypto = require('./assets/js/crypto');
const LaraPrivateKey = "";
exports.checkLogin = function(data, out){
console.log("server side calling crypto");
rawContainer = steem.memo.decode(LaraPrivateKey, data.encodedmsg);
raw = rawContainer.split("");
raw.shift();
raw = raw.join("");
var decodedContainer = JSON.parse(raw);
steem.api.getAccounts([decodedContainer.user], function(err, result){
if(result.length > 0) {
pubWif = result[0]["memo_key"];
var sessionKeys = crypto.generate_session_keys(LaraPrivateKey, pubWif);
console.log(decodedContainer.token);
var isvalid = crypto.verify_client_authentication(decodedContainer.token, sessionKeys.authenticationKey);
if(isvalid) {
console.log('Lara : Connexion approved !')
out({name: decodedContainer.user});
}
else {
console.log("Lara : Someone just tried to bypass authentication check as @" + decodedContainer.user);
out(undefined);
}
}
});
}
exports.checkIdentity = function(data, out){
rawContainer = steem.memo.decode(LaraPrivateKey, data.message);
raw = rawContainer.split("");
raw.shift();
raw = raw.join("");
var decodedContainer = JSON.parse(raw);
steem.api.getAccounts([decodedContainer.user], function(err, result){
if(result.length > 0) {
pubWif = result[0]["memo_key"];
var sessionKeys = crypto.generate_session_keys(LaraPrivateKey, pubWif);
console.log(decodedContainer.token);
var isvalid = crypto.verify_client_authentication(decodedContainer.token, sessionKeys.authenticationKey);
if(isvalid) {
console.log('Lara : Identity confirmed ! The message will be processed securely to the recipient !')
out({name: decodedContainer.user, to: decodedContainer.to, message: decodedContainer.message});
}
else {
console.log("Lara : Someone just tried to forge a message as @" + decodedContainer.user);
out(undefined);
}
}
});
};