diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 14cb15a1d..fc06cae33 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38811,7 +38811,14 @@ OutgoingMessage.prototype = { var address = new libsignal.SignalProtocolAddress(number, deviceId); var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); ciphers[address.getDeviceId()] = sessionCipher; - return this.encryptToDevice(address, paddedPlaintext, sessionCipher); + return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) { + return { + type : ciphertext.type, + destinationDeviceId : address.getDeviceId(), + destinationRegistrationId : ciphertext.registrationId, + content : btoa(ciphertext.body) + }; + }); }.bind(this))).then(function(jsonData) { return this.transmitMessage(number, jsonData, this.timestamp).then(function() { this.successfulNumbers[this.successfulNumbers.length] = number; @@ -38845,25 +38852,6 @@ OutgoingMessage.prototype = { }.bind(this)); }, - encryptToDevice: function(address, plaintext, sessionCipher) { - return sessionCipher.encrypt(plaintext).then(function(ciphertext) { - return this.toJSON(address, ciphertext); - }.bind(this)); - }, - - toJSON: function(address, encryptedMsg) { - var json = { - type : encryptedMsg.type, - destinationDeviceId : address.getDeviceId(), - destinationRegistrationId : encryptedMsg.registrationId - }; - - var content = btoa(encryptedMsg.body); - json.content = content; - - return json; - }, - getStaleDeviceIdsForNumber: function(number) { return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) { if (deviceIds.length === 0) { diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 293569b90..446085637 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -132,7 +132,14 @@ OutgoingMessage.prototype = { var address = new libsignal.SignalProtocolAddress(number, deviceId); var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); ciphers[address.getDeviceId()] = sessionCipher; - return this.encryptToDevice(address, paddedPlaintext, sessionCipher); + return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) { + return { + type : ciphertext.type, + destinationDeviceId : address.getDeviceId(), + destinationRegistrationId : ciphertext.registrationId, + content : btoa(ciphertext.body) + }; + }); }.bind(this))).then(function(jsonData) { return this.transmitMessage(number, jsonData, this.timestamp).then(function() { this.successfulNumbers[this.successfulNumbers.length] = number; @@ -166,25 +173,6 @@ OutgoingMessage.prototype = { }.bind(this)); }, - encryptToDevice: function(address, plaintext, sessionCipher) { - return sessionCipher.encrypt(plaintext).then(function(ciphertext) { - return this.toJSON(address, ciphertext); - }.bind(this)); - }, - - toJSON: function(address, encryptedMsg) { - var json = { - type : encryptedMsg.type, - destinationDeviceId : address.getDeviceId(), - destinationRegistrationId : encryptedMsg.registrationId - }; - - var content = btoa(encryptedMsg.body); - json.content = content; - - return json; - }, - getStaleDeviceIdsForNumber: function(number) { return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) { if (deviceIds.length === 0) {