Skip to content

Commit

Permalink
Added some functions to store the authKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Morawetz committed Nov 14, 2015
1 parent dc6ece3 commit 14351a5
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions lib/telegram.link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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);
}

Expand Down Expand Up @@ -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])**
Expand Down Expand Up @@ -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;
exports.type = api.type;

0 comments on commit 14351a5

Please sign in to comment.