forked from mystiq/hydrogen-web
cleanup RoomKey to changes and better naming
This commit is contained in:
parent
66a93ee108
commit
1278288a42
1 changed files with 8 additions and 7 deletions
|
@ -85,9 +85,9 @@ abstract class BaseIncomingRoomKey implements IIncomingRoomKey {
|
||||||
if (this._isBetter !== undefined) {
|
if (this._isBetter !== undefined) {
|
||||||
return this._isBetter;
|
return this._isBetter;
|
||||||
}
|
}
|
||||||
let existingKey = loader.cache.get(this.roomId, this.senderKey, this.sessionId);
|
let existingKey = loader.getCachedKey(this.roomId, this.senderKey, this.sessionId);
|
||||||
if (!existingKey) {
|
if (!existingKey) {
|
||||||
const storageKey = await fromStorage(this.roomId, this.senderKey, this.sessionId, txn);
|
const storageKey = await keyFromStorage(this.roomId, this.senderKey, this.sessionId, txn);
|
||||||
// store the event ids that can be decrypted with this key
|
// store the event ids that can be decrypted with this key
|
||||||
// before we overwrite them if called from `write`.
|
// before we overwrite them if called from `write`.
|
||||||
if (storageKey) {
|
if (storageKey) {
|
||||||
|
@ -99,8 +99,9 @@ abstract class BaseIncomingRoomKey implements IIncomingRoomKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existingKey) {
|
if (existingKey) {
|
||||||
|
const key = existingKey;
|
||||||
this._isBetter = await loader.useKey(this, newSession => {
|
this._isBetter = await loader.useKey(this, newSession => {
|
||||||
return loader.useKey(existingKey, (existingSession, pickleKey) => {
|
return loader.useKey(key, (existingSession, pickleKey) => {
|
||||||
const isBetter = isBetterThan(newSession, existingSession);
|
const isBetter = isBetterThan(newSession, existingSession);
|
||||||
if (isBetter && callback) {
|
if (isBetter && callback) {
|
||||||
callback(newSession, pickleKey);
|
callback(newSession, pickleKey);
|
||||||
|
@ -112,7 +113,7 @@ abstract class BaseIncomingRoomKey implements IIncomingRoomKey {
|
||||||
// no previous key, so we're the best \o/
|
// no previous key, so we're the best \o/
|
||||||
this._isBetter = true;
|
this._isBetter = true;
|
||||||
}
|
}
|
||||||
return this._isBetter;
|
return this._isBetter!;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract get roomId(): string;
|
abstract get roomId(): string;
|
||||||
|
@ -195,7 +196,7 @@ class StoredRoomKey implements IRoomKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromDeviceMessage(dr: DecryptionResult): DeviceMessageRoomKey | undefined {
|
export function keyFromDeviceMessage(dr: DecryptionResult): DeviceMessageRoomKey | undefined {
|
||||||
const sessionKey = dr.event.content?.["session_key"];
|
const sessionKey = dr.event.content?.["session_key"];
|
||||||
const key = new DeviceMessageRoomKey(dr);
|
const key = new DeviceMessageRoomKey(dr);
|
||||||
if (
|
if (
|
||||||
|
@ -216,7 +217,7 @@ sessionInfo is a response from key backup and has the following keys:
|
||||||
sender_key
|
sender_key
|
||||||
session_key
|
session_key
|
||||||
*/
|
*/
|
||||||
export function fromBackup(roomId, sessionId, backupInfo): BackupRoomKey | undefined {
|
export function keyFromBackup(roomId, sessionId, backupInfo): BackupRoomKey | undefined {
|
||||||
const sessionKey = backupInfo["session_key"];
|
const sessionKey = backupInfo["session_key"];
|
||||||
const senderKey = backupInfo["sender_key"];
|
const senderKey = backupInfo["sender_key"];
|
||||||
// TODO: can we just trust this?
|
// TODO: can we just trust this?
|
||||||
|
@ -233,7 +234,7 @@ export function fromBackup(roomId, sessionId, backupInfo): BackupRoomKey | undef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fromStorage(roomId: string, senderKey: string, sessionId: string, txn: Transaction): Promise<StoredRoomKey | undefined> {
|
export async function keyFromStorage(roomId: string, senderKey: string, sessionId: string, txn: Transaction): Promise<StoredRoomKey | undefined> {
|
||||||
const existingSessionEntry = await txn.inboundGroupSessions.get(roomId, senderKey, sessionId);
|
const existingSessionEntry = await txn.inboundGroupSessions.get(roomId, senderKey, sessionId);
|
||||||
if (existingSessionEntry) {
|
if (existingSessionEntry) {
|
||||||
return new StoredRoomKey(existingSessionEntry);
|
return new StoredRoomKey(existingSessionEntry);
|
||||||
|
|
Loading…
Reference in a new issue