Skip to content

Instantly share code, notes, and snippets.

@ZiTAL ZiTAL/telegram.js
Last active Sep 28, 2017

Embed
What would you like to do?
telegram js api
'use strict';
var bin_utils = require('./bin_utils.js');
var tl_utils = require('./tl_utils.js');
var utils = require('./utils.js');
var telegram = function(publisKeysHex)
{
var publicKeysParsed = {};
var prepareRsaKeys = function(publisKeysHex)
{
for (var i = 0; i < publisKeysHex.length; i++)
{
var keyParsed = publisKeysHex[i];
var RSAPublicKey = new tl_utils.TLSerialization();
RSAPublicKey.storeBytes(bin_utils.bytesFromHex(keyParsed.modulus), 'n');
RSAPublicKey.storeBytes(bin_utils.bytesFromHex(keyParsed.exponent), 'e');
var buffer = RSAPublicKey.getBuffer();
var fingerprintBytes = bin_utils.sha1Hash(buffer).slice(-8);
fingerprintBytes.reverse();
publicKeysParsed[bin_utils.bytesToHex(fingerprintBytes)] =
{
modulus: keyParsed.modulus,
exponent: keyParsed.exponent
};
}
};
this.getPublicKeys = function()
{
return publicKeysParsed;
};
var lastMessageId = [0, 0];
var timeOffset = 0;
var generateMessageId = function()
{
var timeTicks = utils.tsNow(),
timeSec = Math.floor(timeTicks / 1000) + timeOffset,
timeMSec = timeTicks % 1000,
random = bin_utils.nextRandomInt(0xFFFF);
var messageId = [timeSec, (timeMSec << 21) | (random << 3) | 4];
if (lastMessageId[0] > messageId[0] || lastMessageId[0] == messageId[0] && lastMessageId[1] >= messageId[1])
messageId = [lastMessageId[0], lastMessageId[1] + 4];
lastMessageId = messageId;
return bin_utils.longFromInts(messageId[0], messageId[1]);
};
this.getLastMessageId = function()
{
return bin_utils.longFromInts(lastMessageId[0], lastMessageId[1]);
};
this.sendCode = function(phone)
{
var self = this;
var messageId = generateMessageID();
var params =
{
phone_number: phone,
sms_type: 0,
api_id: 2496,
api_hash: "8da85b0d5bfe62527e5b244c209159c3"
};
var options =
{
createNetworker: true,
dcID: "4",
messageID: messageId,
resultType: "auth.SentCode"
};
};
this.__construct = function(publisKeysHex)
{
prepareRsaKeys(publisKeysHex);
};
this.__construct(publisKeysHex);
};
var t = new telegram([
{
modulus: 'c150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e3ae97d95c8b19442b3c0a10d8f5633fecedd6926a7f6dab0ddb7d457f9ea81b8465fcd6fffeed114011df91c059caedaf97625f6c96ecc74725556934ef781d866b34f011fce4d835a090196e9a5f0e4449af7eb697ddb9076494ca5f81104a305b6dd27665722c46b60e5df680fb16b210607ef217652e60236c255f6a28315f4083a96791d7214bf64c1df4fd0db1944fb26a2a57031b32eee64ad15a8ba68885cde74a5bfc920f6abf59ba5c75506373e7130f9042da922179251f',
exponent: '010001'
}]);
t.sendCode('12345678901');
@denizsoft

This comment has been minimized.

Copy link

denizsoft commented Aug 16, 2015

how to use this code ? please give me a sample
y4shar@gmail.com
thank you

@zhaohansprt

This comment has been minimized.

Copy link

zhaohansprt commented Sep 28, 2017

hi ! how to calculate the modulus string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.