Move group storage into window.axolotl
This commit is contained in:
parent
83c6fe9008
commit
849fdb7ae4
5 changed files with 55 additions and 21 deletions
|
@ -86,6 +86,7 @@ module.exports = function(grunt) {
|
|||
},
|
||||
libtextsecure: {
|
||||
src: [
|
||||
'libtextsecure/axolotl_wrapper.js',
|
||||
'libtextsecure/libaxolotl_concat.js',
|
||||
|
||||
'libtextsecure/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;
|
||||
|
||||
})();
|
||||
|
|
|
@ -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()); });
|
||||
}
|
||||
|
||||
|
|
26
libtextsecure/axolotl_wrapper.js
Normal file
26
libtextsecure/axolotl_wrapper.js
Normal file
|
@ -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);
|
||||
},
|
||||
},
|
||||
};
|
||||
})();
|
|
@ -34,6 +34,7 @@
|
|||
<script type="text/javascript" src="../protobufs.js" data-cover></script>
|
||||
<script type="text/javascript" src="../errors.js" data-cover></script>
|
||||
<script type="text/javascript" src="../storage.js" data-cover></script>
|
||||
<script type="text/javascript" src="../axolotl_wrapper.js" data-cover></script>
|
||||
<script type="text/javascript" src="../libaxolotl_concat.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../websocket.js" data-cover></script>
|
||||
|
|
Loading…
Reference in a new issue