Move identity key storage functions to axolotl store
This commit is contained in:
parent
f38b18ef63
commit
20ebc3f890
6 changed files with 37 additions and 71 deletions
|
@ -86,17 +86,6 @@
|
||||||
return textsecure.storage.get('registrationId');
|
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 */
|
/* Returns a prekeypair object or undefined */
|
||||||
getPreKey: function(keyId) {
|
getPreKey: function(keyId) {
|
||||||
var prekey = new PreKey({id: keyId});
|
var prekey = new PreKey({id: keyId});
|
||||||
|
@ -199,7 +188,7 @@
|
||||||
|
|
||||||
return textsecure.storage.devices.getDeviceObject(encodedNumber).then(function(device) {
|
return textsecure.storage.devices.getDeviceObject(encodedNumber).then(function(device) {
|
||||||
if (device === undefined) {
|
if (device === undefined) {
|
||||||
return textsecure.storage.devices.getIdentityKeyForNumber(number).then(function(identityKey) {
|
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
|
||||||
device = { encodedNumber: encodedNumber,
|
device = { encodedNumber: encodedNumber,
|
||||||
//TODO: Remove this duplication
|
//TODO: Remove this duplication
|
||||||
identityKey: identityKey
|
identityKey: identityKey
|
||||||
|
@ -214,6 +203,37 @@
|
||||||
throw new Error("Tried to put session for undefined/null key");
|
throw new Error("Tried to put session for undefined/null key");
|
||||||
return Promise.resolve(textsecure.storage.remove("sessions" + number));
|
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);
|
||||||
|
})());
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
getDeviceObject: function(encodedNumber) {
|
||||||
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
||||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
||||||
|
|
|
@ -241,7 +241,7 @@
|
||||||
throw 'No conflicts to resolve';
|
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) {
|
this.messageCollection.each(function(message) {
|
||||||
if (message.hasKeyConflict(number)) {
|
if (message.hasKeyConflict(number)) {
|
||||||
message.resolveConflict(number);
|
message.resolveConflict(number);
|
||||||
|
|
|
@ -73,8 +73,8 @@
|
||||||
var number = this.model.id;
|
var number = this.model.id;
|
||||||
var view = new Whisper.KeyVerificationView({
|
var view = new Whisper.KeyVerificationView({
|
||||||
model: {
|
model: {
|
||||||
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
their_key: textsecure.storage.axolotl.getIdentityKey(number),
|
||||||
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
|
your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
|
|
|
@ -57,8 +57,8 @@
|
||||||
verify: function(number) {
|
verify: function(number) {
|
||||||
var view = new Whisper.KeyVerificationView({
|
var view = new Whisper.KeyVerificationView({
|
||||||
model: {
|
model: {
|
||||||
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
their_key: textsecure.storage.axolotl.getIdentityKey(number),
|
||||||
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
|
your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
|
|
|
@ -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) {
|
getDeviceObject: function(encodedNumber) {
|
||||||
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
||||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue