diff --git a/eslint.config.js b/eslint.config.js index 14a13b9..cdf066a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,5 +12,5 @@ export default antfu({ svelte: true, jsonc: true, - ignores: ['**/node_modules', '**/dist', '**/build', '**/.svelte-kit'], + ignores: ['**/node_modules', '**/dist', '**/build', '**/.svelte-kit', '!services/frontend/src/lib'], }) diff --git a/services/frontend/src/lib/popup/PopupManager.svelte b/services/frontend/src/lib/popup/PopupManager.svelte index d0de7b7..12bc7fd 100644 --- a/services/frontend/src/lib/popup/PopupManager.svelte +++ b/services/frontend/src/lib/popup/PopupManager.svelte @@ -1,12 +1,12 @@ - {#if $currentPopup} -
+
{#if $currentPopup.type === 'device-verification'} {/if}
-{/if} \ No newline at end of file +{/if} diff --git a/services/frontend/src/lib/popup/index.ts b/services/frontend/src/lib/popup/index.ts index b82cb07..2191ee1 100644 --- a/services/frontend/src/lib/popup/index.ts +++ b/services/frontend/src/lib/popup/index.ts @@ -1,4 +1,5 @@ -import { writable } from "svelte/store" +import type { ShowSasCallbacks } from 'matrix-js-sdk/lib/crypto-api' +import { writable } from 'svelte/store' export type Popup = DeviceVerificationPopup @@ -8,8 +9,13 @@ export function createPopup(popup: Popup) { currentPopup.set(popup) } +export function clearPopup() { + currentPopup.set(null) +} + // Popups export interface DeviceVerificationPopup { - type: "device-verification" -} \ No newline at end of file + type: 'device-verification' + sas: ShowSasCallbacks +} diff --git a/services/frontend/src/lib/popup/popups/DeviceVerificationPopup.svelte b/services/frontend/src/lib/popup/popups/DeviceVerificationPopup.svelte index 912c07e..cfa6ba2 100644 --- a/services/frontend/src/lib/popup/popups/DeviceVerificationPopup.svelte +++ b/services/frontend/src/lib/popup/popups/DeviceVerificationPopup.svelte @@ -1,7 +1,24 @@ - -

Device verification

\ No newline at end of file +

Device verification

+ +
+ {#each sas.sas.emoji ?? [] as emoji} +
+

{emoji[0]}

+

{emoji[1]}

+
+ {/each} +
+ + +
+
diff --git a/services/frontend/src/lib/views/pages/SettingsPage.svelte b/services/frontend/src/lib/views/pages/SettingsPage.svelte index 2ab3036..bd5e377 100644 --- a/services/frontend/src/lib/views/pages/SettingsPage.svelte +++ b/services/frontend/src/lib/views/pages/SettingsPage.svelte @@ -1,66 +1,28 @@ - - -
-

Settings

-
-

Security

-

Cross-signing

+
+

Settings

+
+

Security

+

Cross-signing

- {#await client.getCrypto()?.isCrossSigningReady() } + {#await client.getCrypto()?.isCrossSigningReady()} Loading... - {:then sign} + {:then sign} {#if sign}

Cross-signing is ready

{:else} @@ -69,9 +31,9 @@ {/await}
-

Secure backup

+

Secure backup

- {#await Promise.all([client.getCrypto()?.getActiveSessionBackupVersion()]) } + {#await Promise.all([client.getCrypto()?.getActiveSessionBackupVersion()])} Loading... {:then [version]} {#if version === null} @@ -86,22 +48,22 @@ {/await}
-

Devices

+

Devices

-
+
{#await client.getDevices()} Loading... - {:then devices} - {#each devices.devices ?? [] as device (device['device_id'])} -
- + {:then devices} + {#each devices.devices ?? [] as device (device.device_id)} +
+
-

{ device['display_name'] }

-

{device['device_id']}

+

{device.display_name}

+

{device.device_id}

- {#if !client.checkDeviceTrust(client.getUserId() ?? '', device['device_id']).isVerified()} - + {#if !client.checkDeviceTrust(client.getUserId() ?? '', device.device_id).isVerified()} + {/if}
{/each} @@ -110,6 +72,4 @@
- - -
\ No newline at end of file +
diff --git a/services/frontend/src/matrix/listeners/index.ts b/services/frontend/src/matrix/listeners/index.ts index af3ce32..e973765 100644 --- a/services/frontend/src/matrix/listeners/index.ts +++ b/services/frontend/src/matrix/listeners/index.ts @@ -1,6 +1,7 @@ import { ClientEvent, CryptoEvent, HttpApiEvent, type MatrixClient } from 'matrix-js-sdk' import { stateStore } from '../../stores/matrixState.store' import { matrixLogout } from '..' +import { startVerification } from '../verification' export function registerListeners(client: MatrixClient) { // Sync state with state store, which is used to show loading spinners @@ -14,14 +15,7 @@ export function registerListeners(client: MatrixClient) { client.on(CryptoEvent.VerificationRequestReceived, async (request) => { await request.accept() - const verifier = await request.startVerification('m.sas.v1') - - // @ts-expect-error: sad but necessary for missing import - verifier.on('show_sas', async (sas: any) => { - await sas.confirm() - }) - - await verifier.verify() + await startVerification(client, request) }) // Log out handler, if logged out from the homeserver, clean old tokens and data diff --git a/services/frontend/src/matrix/verification.ts b/services/frontend/src/matrix/verification.ts new file mode 100644 index 0000000..941958d --- /dev/null +++ b/services/frontend/src/matrix/verification.ts @@ -0,0 +1,15 @@ +import type { MatrixClient } from 'matrix-js-sdk' +import { type VerificationRequest, VerifierEvent } from 'matrix-js-sdk/lib/crypto-api' +import { createPopup } from '$lib/popup' + +export async function startVerification(_client: MatrixClient, req: VerificationRequest) { + const verifier = await req.startVerification('m.sas.v1') + verifier.on(VerifierEvent.ShowSas, async (sas) => { + createPopup({ + type: 'device-verification', + sas, + }) + }) + + await verifier.verify() +} diff --git a/services/frontend/src/routes/login/+page.svelte b/services/frontend/src/routes/login/+page.svelte index 8ce6339..d0b00ed 100644 --- a/services/frontend/src/routes/login/+page.svelte +++ b/services/frontend/src/routes/login/+page.svelte @@ -58,7 +58,7 @@ user, }, password, - initial_device_display_name: 'Libretrix', + initial_device_display_name: `${window.location.host} | Libretrix`, }) const baseUrl = result?.well_known?.['m.homeserver']?.base_url ?? client.baseUrl