UUID-keyed lookups in SignalProtocolStore

This commit is contained in:
Fedor Indutny
2021-09-09 19:38:11 -07:00
committed by GitHub
parent 6323aedd9b
commit c7e7d55af4
46 changed files with 2094 additions and 1447 deletions

44
ts/types/UUID.ts Normal file
View File

@@ -0,0 +1,44 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { strictAssert } from '../util/assert';
import { isValidGuid } from '../util/isValidGuid';
export type UUIDStringType = `${string}-${string}-${string}-${string}-${string}`;
export class UUID {
constructor(protected readonly value: string) {
strictAssert(isValidGuid(value), `Invalid UUID: ${value}`);
}
public toString(): UUIDStringType {
return (this.value as unknown) as UUIDStringType;
}
public isEqual(other: UUID): boolean {
return this.value === other.value;
}
public static parse(value: string): UUID {
return new UUID(value);
}
public static lookup(identifier: string): UUID | undefined {
const conversation = window.ConversationController.get(identifier);
const uuid = conversation?.get('uuid');
if (uuid === undefined) {
return undefined;
}
return new UUID(uuid);
}
public static checkedLookup(identifier: string): UUID {
const uuid = UUID.lookup(identifier);
strictAssert(
uuid !== undefined,
`Conversation ${identifier} not found or has no uuid`
);
return uuid;
}
}