diff --git a/js/axolotl_store.js b/js/axolotl_store.js index 86435c50..a8266464 100644 --- a/js/axolotl_store.js +++ b/js/axolotl_store.js @@ -86,17 +86,6 @@ return textsecure.storage.get('registrationId'); }, - getIdentityKey: function(identifier) { - if (identifier === null || identifier === undefined) - throw new Error("Tried to get identity key for undefined/null key"); - return convertToArrayBuffer(textsecure.storage.devices.getIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0])); - }, - putIdentityKey: function(identifier, identityKey) { - if (identifier === null || identifier === undefined) - throw new Error("Tried to put identity key for undefined/null key"); - return textsecure.storage.devices.checkSaveIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0], identityKey); - }, - /* Returns a prekeypair object or undefined */ getPreKey: function(keyId) { var prekey = new PreKey({id: keyId}); @@ -199,7 +188,7 @@ return textsecure.storage.devices.getDeviceObject(encodedNumber).then(function(device) { if (device === undefined) { - return textsecure.storage.devices.getIdentityKeyForNumber(number).then(function(identityKey) { + return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) { device = { encodedNumber: encodedNumber, //TODO: Remove this duplication identityKey: identityKey @@ -214,6 +203,37 @@ throw new Error("Tried to put session for undefined/null key"); return Promise.resolve(textsecure.storage.remove("sessions" + number)); }, + getIdentityKey: function(identifier) { + if (identifier === null || identifier === undefined) + throw new Error("Tried to get identity key for undefined/null key"); + var number = textsecure.utils.unencodeNumber(identifier)[0]; + return Promise.resolve(convertToArrayBuffer(function() { + var map = textsecure.storage.get("devices" + number); + return map === undefined ? undefined : map.identityKey; + }()); + }, + putIdentityKey: function(identifier, identityKey) { + if (identifier === null || identifier === undefined) + throw new Error("Tried to put identity key for undefined/null key"); + var number = textsecure.utils.unencodeNumber(identifier)[0]; + return Promise.resolve((function() { + var map = textsecure.storage.get("devices" + number); + if (map === undefined) + textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey}); + else if (getString(map.identityKey) !== getString(identityKey)) + throw new Error("Attempted to overwrite a different identity key"); + })()); + }, + removeIdentityKey: function(number) { + return Promise.resolve((function() { + var map = textsecure.storage.get("devices" + number); + if (map === undefined) + throw new Error("Tried to remove identity for unknown number"); + textsecure.storage.remove("devices" + number); + return textsecure.storage.axolotl.removeAllSessions(number); + })()); + }, + }; diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 7e76664f..2f8c0932 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38126,33 +38126,6 @@ axolotlInternal.RecipientRecord = function() { })()); }, - getIdentityKeyForNumber: function(number) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - return map === undefined ? undefined : map.identityKey; - })()); - }, - - checkSaveIdentityKeyForNumber: function(number, identityKey) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - if (map === undefined) - textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey}); - else if (getString(map.identityKey) !== getString(identityKey)) - throw new Error("Attempted to overwrite a different identity key"); - })()); - }, - - removeIdentityKeyForNumber: function(number) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - if (map === undefined) - throw new Error("Tried to remove identity for unknown number"); - textsecure.storage.remove("devices" + number); - return textsecure.storage.axolotl.removeAllSessions(number); - })()); - }, - getDeviceObject: function(encodedNumber) { var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) { diff --git a/js/models/conversations.js b/js/models/conversations.js index 8dfc164d..0dc06234 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -241,7 +241,7 @@ throw 'No conflicts to resolve'; } - return textsecure.storage.devices.removeIdentityKeyForNumber(number).then(function() { + return textsecure.storage.axolotl.removeIdentityKey(number).then(function() { this.messageCollection.each(function(message) { if (message.hasKeyConflict(number)) { message.resolveConflict(number); diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 49bae931..7fb154e4 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -73,8 +73,8 @@ var number = this.model.id; var view = new Whisper.KeyVerificationView({ model: { - their_key: textsecure.storage.devices.getIdentityKeyForNumber(number), - your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber()) + their_key: textsecure.storage.axolotl.getIdentityKey(number), + your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber()) } }); this.$el.hide(); diff --git a/js/views/message_detail_view.js b/js/views/message_detail_view.js index 1bfe7504..189d8491 100644 --- a/js/views/message_detail_view.js +++ b/js/views/message_detail_view.js @@ -57,8 +57,8 @@ verify: function(number) { var view = new Whisper.KeyVerificationView({ model: { - their_key: textsecure.storage.devices.getIdentityKeyForNumber(number), - your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber()) + their_key: textsecure.storage.axolotl.getIdentityKey(number), + your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber()) } }); this.$el.hide(); diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index a03dc282..fd21b7f2 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -55,33 +55,6 @@ })()); }, - getIdentityKeyForNumber: function(number) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - return map === undefined ? undefined : map.identityKey; - })()); - }, - - checkSaveIdentityKeyForNumber: function(number, identityKey) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - if (map === undefined) - textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey}); - else if (getString(map.identityKey) !== getString(identityKey)) - throw new Error("Attempted to overwrite a different identity key"); - })()); - }, - - removeIdentityKeyForNumber: function(number) { - return Promise.resolve((function() { - var map = textsecure.storage.get("devices" + number); - if (map === undefined) - throw new Error("Tried to remove identity for unknown number"); - textsecure.storage.remove("devices" + number); - return textsecure.storage.axolotl.removeAllSessions(number); - })()); - }, - getDeviceObject: function(encodedNumber) { var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {