created ewelink class

This commit is contained in:
Martín M
2019-06-23 18:37:55 -03:00
parent 77b8f3f131
commit 11be3e0d58
3 changed files with 172 additions and 1 deletions

71
lib/helper.js Normal file
View File

@@ -0,0 +1,71 @@
const crypto = require('crypto');
const random = require('random');
const nonce = require('nonce')();
const makeFakeIMEI = () => {
const num1 = random.int(1000, 9999);
const num2 = random.int(1000, 9999);
return `DF7425A0-${num1}-${num2}-9F5E-3BC9179E48FB`;
};
const loginPayload = ({ email, password }) => ({
email,
password,
version: 6,
ts: `${Math.round(new Date().getTime() / 1000)}`,
nonce: `${nonce()}`,
appid: 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq',
imei: makeFakeIMEI(),
os: 'iOS',
model: 'iPhone10,6',
romVersion: '11.1.2',
appVersion: '3.5.3',
});
const wssLoginPayload = ({ at, apiKey }) => {
const timeStamp = new Date() / 1000;
const ts = Math.floor(timeStamp);
const sequence = Math.floor(timeStamp * 1000);
const payload = {
action: 'userOnline',
userAgent: 'app',
version: 6,
nonce: `${nonce()}`,
apkVesrion: '1.8',
os: 'ios',
at,
apikey: apiKey,
ts: `${ts}`,
model: 'iPhone10,6',
romVersion: '11.1.2',
sequence,
};
return JSON.stringify(payload);
};
const wssUpdatePayload = ({ apiKey, deviceId, params }) => {
const timeStamp = new Date() / 1000;
const sequence = Math.floor(timeStamp * 1000);
const payload = {
action: 'update',
userAgent: 'app',
apikey: apiKey,
deviceid: `${deviceId}`,
params,
sequence,
};
return JSON.stringify(payload);
};
const makeAuthorizationSign = body =>
crypto
.createHmac('sha256', '6Nz4n0xA8s8qdxQf2GqurZj2Fs55FUvM')
.update(JSON.stringify(body))
.digest('base64');
module.exports = {
makeAuthorizationSign,
loginPayload,
wssLoginPayload,
wssUpdatePayload,
};