Add isTrustedIdentity to SignalProtocolStore
Adds a new required storage method for the protocol library. // FREEBIE
This commit is contained in:
parent
0dc5a0488c
commit
e659104cbf
2 changed files with 26 additions and 0 deletions
|
@ -250,6 +250,19 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
isTrustedIdentity: function(identifier, publicKey) {
|
||||||
|
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 new Promise(function(resolve) {
|
||||||
|
var identityKey = new IdentityKey({id: number});
|
||||||
|
identityKey.fetch().always(function() {
|
||||||
|
var oldpublicKey = identityKey.get('publicKey');
|
||||||
|
resolve(!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
loadIdentityKey: function(identifier) {
|
loadIdentityKey: function(identifier) {
|
||||||
if (identifier === null || identifier === undefined) {
|
if (identifier === null || identifier === undefined) {
|
||||||
throw new Error("Tried to get identity key for undefined/null key");
|
throw new Error("Tried to get identity key for undefined/null key");
|
||||||
|
|
|
@ -29,6 +29,19 @@ SignalProtocolStore.prototype = {
|
||||||
delete this.store[key];
|
delete this.store[key];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isTrustedIdentity: function(identifier, identityKey) {
|
||||||
|
if (identifier === null || identifier === undefined) {
|
||||||
|
throw new error("tried to check identity key for undefined/null key");
|
||||||
|
}
|
||||||
|
if (!(identityKey instanceof ArrayBuffer)) {
|
||||||
|
throw new error("Expected identityKey to be an ArrayBuffer");
|
||||||
|
}
|
||||||
|
var trusted = this.get('identityKey' + identifier);
|
||||||
|
if (trusted === undefined) {
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
return Promise.resolve(identityKey === trusted);
|
||||||
|
},
|
||||||
loadIdentityKey: function(identifier) {
|
loadIdentityKey: function(identifier) {
|
||||||
if (identifier === null || identifier === undefined)
|
if (identifier === null || identifier === undefined)
|
||||||
throw new Error("Tried to get identity key for undefined/null key");
|
throw new Error("Tried to get identity key for undefined/null key");
|
||||||
|
|
Loading…
Reference in a new issue