From 891ddacd3556727ae842a47f89770557cafe86b1 Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 1 May 2016 14:46:16 -0700 Subject: [PATCH] Remove processPreKey from protocol_wrapper Use SessionBuilder directly instead of protocol_wrapper // FREEBIE --- js/libtextsecure.js | 11 +++-------- libtextsecure/outgoing_message.js | 4 +++- libtextsecure/protocol_wrapper.js | 7 ------- libtextsecure/test/protocol_wrapper_test.js | 6 ++++-- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 317018de703..cb5dbbab827 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -35541,13 +35541,6 @@ Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJ throw e; }); }); - }, - processPreKey: function(preKeyBundle) { - return queueJobForNumber(preKeyBundle.encodedNumber, function() { - var address = libsignal.SignalProtocolAddress.fromString(preKeyBundle.encodedNumber); - var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address); - return builder.processPreKey(preKeyBundle); - }); } }; })(); @@ -37527,7 +37520,9 @@ OutgoingMessage.prototype = { device.identityKey = response.identityKey; device.encodedNumber = number + "." + device.deviceId; if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) { - return textsecure.protocol_wrapper.processPreKey(device).catch(function(error) { + var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber); + var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address); + return builder.processPreKey(device).catch(function(error) { if (error.message === "Identity key changed") { error = new textsecure.OutgoingIdentityKeyError( number, this.message.toArrayBuffer(), diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 8f22089eb5a..aa1521652be 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -55,7 +55,9 @@ OutgoingMessage.prototype = { device.identityKey = response.identityKey; device.encodedNumber = number + "." + device.deviceId; if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) { - return textsecure.protocol_wrapper.processPreKey(device).catch(function(error) { + var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber); + var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address); + return builder.processPreKey(device).catch(function(error) { if (error.message === "Identity key changed") { error = new textsecure.OutgoingIdentityKeyError( number, this.message.toArrayBuffer(), diff --git a/libtextsecure/protocol_wrapper.js b/libtextsecure/protocol_wrapper.js index a10ac0f7f73..45cd3991abb 100644 --- a/libtextsecure/protocol_wrapper.js +++ b/libtextsecure/protocol_wrapper.js @@ -76,13 +76,6 @@ throw e; }); }); - }, - processPreKey: function(preKeyBundle) { - return queueJobForNumber(preKeyBundle.encodedNumber, function() { - var address = libsignal.SignalProtocolAddress.fromString(preKeyBundle.encodedNumber); - var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address); - return builder.processPreKey(preKeyBundle); - }); } }; })(); diff --git a/libtextsecure/test/protocol_wrapper_test.js b/libtextsecure/test/protocol_wrapper_test.js index dbc45c09729..7b8c5854f68 100644 --- a/libtextsecure/test/protocol_wrapper_test.js +++ b/libtextsecure/test/protocol_wrapper_test.js @@ -18,9 +18,11 @@ describe('Protocol Wrapper', function() { }); describe('processPreKey', function() { it('rejects if the identity key changes', function(done) { - return textsecure.protocol_wrapper.processPreKey({ + var address = new libsignal.SignalProtocolAddress(identifier, 1); + var builder = new libsignal.SessionBuilder(store, address); + return builder.processPreKey({ identityKey: textsecure.crypto.getRandomBytes(33), - encodedNumber: identifier + '.1' + encodedNumber: address.toString() }).then(function() { done(new Error('Allowed to overwrite identity key')); }).catch(function(e) {