diff --git a/lib/telegram.link.js b/lib/telegram.link.js index 4e1c5aa..9edde02 100644 --- a/lib/telegram.link.js +++ b/lib/telegram.link.js @@ -103,6 +103,30 @@ function retrieveAuthKey(authKeyBuffer, authKeyPassword) { return mt.auth.AuthKey.decryptAuthKey(authKeyBuffer, authKeyPassword); } +// *** +// **Function:** telegramLink.**authKeyWithSaltToStorableBuffer(authKey, serverSalt)** + +// Concatenates the buffers to one long buffer which is returned and can be stored in a file. + +// The code: +function authKeyWithSaltToStorableBuffer(authKey, serverSalt) +{ + return Buffer.concat([authKey.id, authKey.value, serverSalt], 272); +} + +// *** +// **Function:** telegramLink.**restoreAuthKeyWithSaltFromStorableBuffer(buffer)** + +// Splits the buffer into the needed pieces and returns it as an array. +// returnedArray[0] ... authKey.id +// returnedArray[1] ... authKey.value +// returnedArray[2] ... serverSalt + +// The code: +function restoreAuthKeyWithSaltFromStorableBuffer(buffer) +{ + return [buffer.slice(0,8), buffer.slice(8,264), buffer.slice(264,272)]; +} // *** // **Class:** telegramLink.**Client** @@ -122,7 +146,11 @@ function Client(app, dataCenter) { this._connection = new mt.net.HttpConnection(dataCenter); } - if (app.authKey) { + if (app.authKey && app.serverSalt) + { + this._channel = createEncryptedChannel(this._connection, app, app.authKey, app.serverSalt); + } + else if (app.authKey) { this._channel = createEncryptedChannel(this._connection, app, app.authKey, NULL_SERVER_SALT); } @@ -191,6 +219,16 @@ Client.prototype.createAuthKey = function (callback) { } }; +// *** +// telegramLink.**newAuthKey(id, value)** + +// Creates a new AuthKey object with the given /id/ and /value/. + +// The code: +function newAuthKey(id, value) +{ + return new mt.auth.AuthKey(id,value); +} // *** // client.**getDataCenterList([callback])** @@ -405,9 +443,12 @@ function connect() { // Export the internals. exports.createClient = createClient; exports.retrieveAuthKey = retrieveAuthKey; +exports.authKeyWithSaltToStorableBuffer = authKeyWithSaltToStorableBuffer; +exports.restoreAuthKeyWithSaltFromStorableBuffer = restoreAuthKeyWithSaltFromStorableBuffer; +exports.newAuthKey = newAuthKey; var staticInfo = require('./static'); exports.TEST_PRIMARY_DC = staticInfo.telegram.test.primaryDataCenter; exports.PROD_PRIMARY_DC = staticInfo.telegram.prod.primaryDataCenter; // Export all the API types. (no methods) -exports.type = api.type; \ No newline at end of file +exports.type = api.type;