From 22e8576cabbd7916b37839db343bc53f428f243c Mon Sep 17 00:00:00 2001 From: Rodrigo Pinto Date: Sun, 1 Dec 2024 00:23:21 -0300 Subject: [PATCH] Replaced TOTP with cap key - Replaced TOTP with an implementation of a cap key to better align with Tahoe's way of handling user / data. --- packages/package.json | 4 - packages/pnpm-lock.yaml | 25 ---- packages/src/lib/components/nav-bar.svelte | 2 +- packages/src/lib/utils.js | 20 --- packages/src/routes/+layout.svelte | 11 ++ packages/src/routes/+page.svelte | 2 +- .../src/routes/auth/login/+page.server.js | 15 -- packages/src/routes/auth/login/+page.svelte | 50 ------- packages/src/routes/dashboard/+page.server.js | 12 ++ packages/src/routes/dashboard/+page.svelte | 136 ++++++++++++++++++ 10 files changed, 161 insertions(+), 116 deletions(-) delete mode 100644 packages/src/lib/utils.js delete mode 100644 packages/src/routes/auth/login/+page.server.js delete mode 100644 packages/src/routes/auth/login/+page.svelte create mode 100644 packages/src/routes/dashboard/+page.server.js create mode 100644 packages/src/routes/dashboard/+page.svelte diff --git a/packages/package.json b/packages/package.json index 1f26553..1aa2ec1 100644 --- a/packages/package.json +++ b/packages/package.json @@ -22,9 +22,5 @@ "svelte": "^5.0.0", "vite": "^5.0.3", "vitest": "^2.0.4" - }, - "dependencies": { - "@paulmillr/qr": "^0.3.0", - "otpauth": "^9.3.5" } } diff --git a/packages/pnpm-lock.yaml b/packages/pnpm-lock.yaml index 7292531..500f8fc 100644 --- a/packages/pnpm-lock.yaml +++ b/packages/pnpm-lock.yaml @@ -7,13 +7,6 @@ settings: importers: .: - dependencies: - '@paulmillr/qr': - specifier: ^0.3.0 - version: 0.3.0 - otpauth: - specifier: ^9.3.5 - version: 9.3.5 devDependencies: '@sveltejs/adapter-auto': specifier: ^3.0.0 @@ -208,13 +201,6 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@noble/hashes@1.5.0': - resolution: {integrity: sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==} - engines: {node: ^14.21.3 || >=16} - - '@paulmillr/qr@0.3.0': - resolution: {integrity: sha512-3s/cagXuoXTA2gWSfSfJNanNgm2ifmqgoX8WLOs5//3qrIJ3WWHFjqFqCxvYGf46Afwv6PctT9eAOXLDGwp96Q==} - '@polka/url@1.0.0-next.28': resolution: {integrity: sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw==} @@ -506,9 +492,6 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - otpauth@9.3.5: - resolution: {integrity: sha512-jQyqOuQExeIl4YIiOUz4TdEcamgAgPX6UYeeS9Iit4lkvs7bwHb0JNDqchGRccbRfvWHV6oRwH36tOsVmc+7hQ==} - pathe@1.1.2: resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} @@ -775,10 +758,6 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@noble/hashes@1.5.0': {} - - '@paulmillr/qr@0.3.0': {} - '@polka/url@1.0.0-next.28': {} '@rollup/rollup-android-arm-eabi@4.25.0': @@ -1042,10 +1021,6 @@ snapshots: nanoid@3.3.7: {} - otpauth@9.3.5: - dependencies: - '@noble/hashes': 1.5.0 - pathe@1.1.2: {} pathval@2.0.0: {} diff --git a/packages/src/lib/components/nav-bar.svelte b/packages/src/lib/components/nav-bar.svelte index 3ab1b74..0b4e043 100644 --- a/packages/src/lib/components/nav-bar.svelte +++ b/packages/src/lib/components/nav-bar.svelte @@ -11,7 +11,7 @@ diff --git a/packages/src/lib/utils.js b/packages/src/lib/utils.js deleted file mode 100644 index 7108523..0000000 --- a/packages/src/lib/utils.js +++ /dev/null @@ -1,20 +0,0 @@ -import * as OTPAuth from 'otpauth' - -let secret = new OTPAuth.Secret({ size: 20 }) - -export const totp = () => { - let totp = new OTPAuth.TOTP({ - issuer: 'Private data', - label: 'otp', - algorithm: 'SHA256', - digits: 6, - period: 300, - secret - }) - - let token = totp.generate() - let seconds = totp.period - (Math.floor(Date.now() / 1000) % totp.period) - let uri = totp.toString() - - return { token, seconds, uri } -} diff --git a/packages/src/routes/+layout.svelte b/packages/src/routes/+layout.svelte index cec6efe..ca6ba13 100644 --- a/packages/src/routes/+layout.svelte +++ b/packages/src/routes/+layout.svelte @@ -13,6 +13,7 @@ --border-color: #3b3b3b; --font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif; --navbar-height: 3em; + --shade-color: #ccc; --theme-background: white; --theme-color: #444; } @@ -54,4 +55,14 @@ color: light-dark(rgba(16, 16, 16, 0.3), rgba(255, 255, 255, 0.3)); border-color: light-dark(rgba(118, 118, 118, 0.3), rgba(195, 195, 195, 0.3)); } + + :global(input) { + font-size: 0.9em; + font-weight: 400; + padding: 0 1em; + height: 3em; + border: none; + border-radius: 2px; + outline: solid thin var(--border-color); + } diff --git a/packages/src/routes/+page.svelte b/packages/src/routes/+page.svelte index fbe11e5..1113195 100644 --- a/packages/src/routes/+page.svelte +++ b/packages/src/routes/+page.svelte @@ -10,5 +10,5 @@

Private facts

- +
diff --git a/packages/src/routes/auth/login/+page.server.js b/packages/src/routes/auth/login/+page.server.js deleted file mode 100644 index 687058e..0000000 --- a/packages/src/routes/auth/login/+page.server.js +++ /dev/null @@ -1,15 +0,0 @@ -import { totp } from '$lib/utils' - -export const load = () => { - const { token, seconds, uri } = totp() - - return { token, seconds, uri } -} - -export const actions = { - getTotp: async ({ request }) => { - const { token, seconds, uri } = totp() - - return { token, seconds, uri } - } -} diff --git a/packages/src/routes/auth/login/+page.svelte b/packages/src/routes/auth/login/+page.svelte deleted file mode 100644 index 3ab596a..0000000 --- a/packages/src/routes/auth/login/+page.svelte +++ /dev/null @@ -1,50 +0,0 @@ - - - - Login page - - - -
-

Login

- -

Token: {form?.token ?? data.token}.

-

Valid for {count}s.

- - {#if qrCode} -
- {@html qrCode} -
- {/if} - -
-
-
- - diff --git a/packages/src/routes/dashboard/+page.server.js b/packages/src/routes/dashboard/+page.server.js new file mode 100644 index 0000000..31d7b35 --- /dev/null +++ b/packages/src/routes/dashboard/+page.server.js @@ -0,0 +1,12 @@ +import { fail } from '@sveltejs/kit' + +export const actions = { + createCapKey: async ({ request }) => { + try { + return { success: true, endpoint: 'createCapKey', capKey: 123 } + } catch (err) { + console.log({ err }) + return fail(500, { endpoint: 'createCapKey', error: err }) + } + } +} diff --git a/packages/src/routes/dashboard/+page.svelte b/packages/src/routes/dashboard/+page.svelte new file mode 100644 index 0000000..12e2e50 --- /dev/null +++ b/packages/src/routes/dashboard/+page.svelte @@ -0,0 +1,136 @@ + + + + Private Facts dashboard + + +

Dashboard

+ +{#if !capKey && !newCapKey} +
+
+ + + +
+ +
+ +
+
+{:else if !capKey && newCapKey} +
+ + + +
+

Attention!

+ +

This is your new cap key. You need it to access your folders and files. It will not be saved nor ever shown again.

+ +

Copy it now and save it somewhere safe.

+ +

If you lose your cap key you will not be able to access your files anymore. You will have to create a new cap key and upload new files and folders.

+ +
+ + +
+ + +
+
+{:else} +

File tree

+

{capKey}

+{/if} + +