Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit ee00f08

Browse files
committed
Resolve true if saveIdentity overwrote a key
Reflect whether a saveIdentity operation reflects a replacement of an existing key or not. The return value can be used by the caller to decide whether they should clear sessions for the recipient.
1 parent 63d2536 commit ee00f08

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/InMemorySignalProtocolStore.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ SignalProtocolStore.prototype = {
5555
saveIdentity: function(identifier, identityKey) {
5656
if (identifier === null || identifier === undefined)
5757
throw new Error("Tried to put identity key for undefined/null key");
58-
return Promise.resolve(this.put('identityKey' + identifier, identityKey));
58+
59+
var existing = this.get('identityKey' + identifier);
60+
this.put('identityKey' + identifier, identityKey)
61+
62+
if (existing && util.toString(identityKey) !== util.toString(existing)) {
63+
return Promise.resolve(true);
64+
} else {
65+
return Promise.resolve(false);
66+
}
67+
5968
},
6069

6170
/* Returns a prekeypair object or undefined */

0 commit comments

Comments
 (0)