diff --git a/Gruntfile.js b/Gruntfile.js
index e0a4910bb..12de6da8f 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -86,6 +86,7 @@ module.exports = function(grunt) {
},
libtextsecure: {
src: [
+ 'libtextsecure/axolotl_wrapper.js',
'libtextsecure/libaxolotl_concat.js',
'libtextsecure/storage.js',
diff --git a/libaxolotl/groups_storage.js b/libaxolotl/groups_storage.js
index 45642b57c..5dc0e9551 100644
--- a/libaxolotl/groups_storage.js
+++ b/libaxolotl/groups_storage.js
@@ -20,23 +20,23 @@
/*********************
*** Group Storage ***
*********************/
- window.textsecure = window.textsecure || {};
- window.textsecure.storage = window.textsecure.storage || {};
+ window.axolotl = window.axolotl || {};
+ window.axolotl.storage = window.axolotl.storage || {};
- window.textsecure.storage.groups = {
+ window.axolotl.storage.groups = {
createNewGroup: function(numbers, groupId) {
- if (groupId !== undefined && textsecure.storage.getEncrypted("group" + groupId) !== undefined)
+ if (groupId !== undefined && axolotl.api.storage.get("group" + groupId) !== undefined)
throw new Error("Tried to recreate group");
- while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined)
- groupId = getString(textsecure.crypto.getRandomBytes(16));
+ while (groupId === undefined || axolotl.api.storage.get("group" + groupId) !== undefined)
+ groupId = getString(axolotl.crypto.getRandomBytes(16));
- var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
+ var me = axolotl.api.getMyIdentifier();
var haveMe = false;
var finalNumbers = [];
for (var i in numbers) {
var number = numbers[i];
- if (!textsecure.utils.isNumberSane(number))
+ if (!axolotl.api.isIdentifierSane(number))
throw new Error("Invalid number in group");
if (number == me)
haveMe = true;
@@ -51,13 +51,13 @@
for (var i in finalNumbers)
groupObject.numberRegistrationIds[finalNumbers[i]] = {};
- textsecure.storage.putEncrypted("group" + groupId, groupObject);
+ axolotl.api.storage.put("group" + groupId, groupObject);
return {id: groupId, numbers: finalNumbers};
},
getNumbers: function(groupId) {
- var group = textsecure.storage.getEncrypted("group" + groupId);
+ var group = axolotl.api.storage.get("group" + groupId);
if (group === undefined)
return undefined;
@@ -65,11 +65,11 @@
},
removeNumber: function(groupId, number) {
- var group = textsecure.storage.getEncrypted("group" + groupId);
+ var group = axolotl.api.storage.get("group" + groupId);
if (group === undefined)
return undefined;
- var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
+ var me = axolotl.api.getMyIdentifier();
if (number == me)
throw new Error("Cannot remove ourselves from a group, leave the group instead");
@@ -77,20 +77,20 @@
if (i > -1) {
group.numbers.slice(i, 1);
delete group.numberRegistrationIds[number];
- textsecure.storage.putEncrypted("group" + groupId, group);
+ axolotl.api.storage.put("group" + groupId, group);
}
return group.numbers;
},
addNumbers: function(groupId, numbers) {
- var group = textsecure.storage.getEncrypted("group" + groupId);
+ var group = axolotl.api.storage.get("group" + groupId);
if (group === undefined)
return undefined;
for (var i in numbers) {
var number = numbers[i];
- if (!textsecure.utils.isNumberSane(number))
+ if (!axolotl.api.isIdentifierSane(number))
throw new Error("Invalid number in set to add to group");
if (group.numbers.indexOf(number) < 0) {
group.numbers.push(number);
@@ -98,16 +98,16 @@
}
}
- textsecure.storage.putEncrypted("group" + groupId, group);
+ axolotl.api.storage.put("group" + groupId, group);
return group.numbers;
},
deleteGroup: function(groupId) {
- textsecure.storage.removeEncrypted("group" + groupId);
+ axolotl.api.storage.remove("group" + groupId);
},
getGroup: function(groupId) {
- var group = textsecure.storage.getEncrypted("group" + groupId);
+ var group = axolotl.api.storage.get("group" + groupId);
if (group === undefined)
return undefined;
@@ -115,7 +115,7 @@
},
needUpdateByDeviceRegistrationId: function(groupId, number, encodedNumber, registrationId) {
- var group = textsecure.storage.getEncrypted("group" + groupId);
+ var group = axolotl.api.storage.get("group" + groupId);
if (group === undefined)
throw new Error("Unknown group for device registration id");
@@ -127,9 +127,14 @@
var needUpdate = group.numberRegistrationIds[number][encodedNumber] !== undefined;
group.numberRegistrationIds[number][encodedNumber] = registrationId;
- textsecure.storage.putEncrypted("group" + groupId, group);
+ axolotl.api.storage.put("group" + groupId, group);
return needUpdate;
},
};
+ //TODO: RM
+ window.textsecure = window.textsecure || {};
+ window.textsecure.storage = window.textsecure.storage || {};
+ window.textsecure.storage.groups = window.axolotl.storage.groups;
+
})();
diff --git a/libaxolotl/protocol.js b/libaxolotl/protocol.js
index 3c15519d8..60347875f 100644
--- a/libaxolotl/protocol.js
+++ b/libaxolotl/protocol.js
@@ -752,7 +752,8 @@ window.textsecure.protocol = function() {
}
//TODO: Dont always update prekeys here
- if (textsecure.storage.getEncrypted("lastSignedKeyUpdate", Date.now()) < Date.now() - MESSAGE_LOST_THRESHOLD_MS) {
+ //XXX: This is busted as fuck
+ if (axolotl.api.storage.get("lastSignedKeyUpdate", Date.now()) < Date.now() - MESSAGE_LOST_THRESHOLD_MS) {
new Promise(function(resolve) { resolve(self.generateKeys()); });
}
diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js
new file mode 100644
index 000000000..2c9948ef3
--- /dev/null
+++ b/libtextsecure/axolotl_wrapper.js
@@ -0,0 +1,26 @@
+//TODO: Remove almost everything here...
+
+'use strict';
+
+;(function() {
+ window.axolotl = window.axolotl || {};
+ window.axolotl.api = {
+ getMyIdentifier: function() {
+ return textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
+ },
+ isIdentifierSane: function(identifier) {
+ return textsecure.utils.isNumberSane(identifier);
+ },
+ storage: {
+ put: function(key, value) {
+ return textsecure.storage.putEncrypted(key, value);
+ },
+ get: function(key, defaultValue) {
+ return textsecure.storage.getEncrypted(key, defaultValue);
+ },
+ remove: function(key) {
+ return textsecure.storage.removeEncrypted(key);
+ },
+ },
+ };
+})();
diff --git a/libtextsecure/test/index.html b/libtextsecure/test/index.html
index 905fa5883..501aeb9c7 100644
--- a/libtextsecure/test/index.html
+++ b/libtextsecure/test/index.html
@@ -34,6 +34,7 @@
+