Merge pull request #43 from Discreetly/room-encryption

Room Encryption
This commit is contained in:
Tanner
2023-12-05 22:16:58 +03:00
committed by GitHub
2 changed files with 12 additions and 9 deletions

View File

@@ -49,8 +49,10 @@
};
}
let unsubscribeStore = currentSelectedRoom.subscribe((currentValue) => {
let unsubscribeStore = currentSelectedRoom.subscribe(async (currentValue) => {
await Promise.resolve();
updateMessages($selectedServer, roomId);
getKey().then((k) => {
key = k;
});
@@ -192,7 +194,8 @@
{#key $currentSelectedRoom.roomId}
<Conversation
{roomRateLimit}
{getKey} />
{getKey}
{roomId} />
{/key}
<InputPrompt
{socket}
@@ -207,7 +210,8 @@
{#key $currentSelectedRoom.roomId}
<Conversation
{roomRateLimit}
{getKey} />
{getKey}
{roomId} />
{/key}
<InputPrompt
{socket}

View File

@@ -1,17 +1,17 @@
<script lang="ts">
import { currentRoomMessages } from '$lib/stores';
import { currentRoomMessages, roomKeyStore, roomPassStore } from '$lib/stores';
import { getEpochFromTimestamp, getTimestampFromEpoch } from '$lib/utils/rateLimit';
import type { MessageI } from 'discreetly-interfaces';
import { onMount } from 'svelte';
import BubbleText from './BubbleText.svelte';
import { minidenticon } from 'minidenticons';
import { bubbleBgFromSessionId } from '$lib/utils/color';
import { decrypt } from '$lib/crypto/crypto';
import { decrypt, deriveKey } from '$lib/crypto/crypto';
export let roomRateLimit: number;
export let getKey: () => Promise<CryptoKey>;
export let roomId: string;
let key: CryptoKey;
let elemChat: HTMLElement;
$: {
@@ -26,12 +26,11 @@
async function decryptText(text: string): Promise<string> {
if (!key) {
return getKey().then(async (k) => {
key = k;
key = await getKey();
const result = await decrypt(text, key);
return result ? result : text;
});
} else if (key) {
key = await deriveKey($roomPassStore[roomId].password, roomId);
const result = await decrypt(text, key);
return result ? result : text;
} else {