commit 816486689532ece16835dec14d008b00b1a92722
parent e6915316461b1424f1742f4009857db1a7f1ca92
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Sun, 25 Aug 2024 12:33:56 +0000
Add keystore/preferences nostr key persistence and /conf routes
Diffstat:
5 files changed, 95 insertions(+), 13 deletions(-)
diff --git a/src/app.css b/src/app.css
@@ -2,7 +2,11 @@
@tailwind components;
@tailwind utilities;
-@layer components {}
+@layer components {
+ .button-simple {
+ @apply flex flex-row h-line w-line justify-center items-center bg-layer-1-surface font-mono text-sm lowercase text-layer-2-glyph;
+ }
+}
@layer base {
:root {
diff --git a/src/lib/conf.ts b/src/lib/conf.ts
@@ -0,0 +1,5 @@
+import { PUBLIC_PREF_NOSTR_KEY_ACTIVE } from "$env/static/public";
+
+export const _cf = {
+ pref_key_active: PUBLIC_PREF_NOSTR_KEY_ACTIVE
+};
+\ No newline at end of file
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte
@@ -1,24 +1,58 @@
<script lang="ts">
import { cl } from "$lib/client";
+ import { _cf } from "$lib/conf";
import { t } from "@radroots/svelte-lib";
</script>
-<div class={`flex flex-col w-full pt-16 justify-center items-center`}>
+<div class={`flex flex-col w-full pt-16 gap-8 justify-center items-center`}>
<button
- class={`flex flex-row justify-center items-center text-white`}
+ class={`button-simple`}
onclick={async () => {
- const res = await cl.dialog.alert(
- `Hi! You're platform is ${cl.platform}`,
+ await cl.dialog.alert(`Hi! You're platform is ${cl.platform}`);
+ }}
+ >
+ {$t(`app.name`)}
+ </button>
+ <button
+ class={`button-simple`}
+ onclick={async () => {
+ const public_key = await cl.preferences.get(_cf.pref_key_active);
+ await cl.dialog.alert(
+ `Hi! This is your nostr public key ${public_key}`,
+ );
+ }}
+ >
+ {"test #1"}
+ </button>
+ <button
+ class={`button-simple`}
+ onclick={async () => {
+ const public_key = await cl.preferences.get(_cf.pref_key_active);
+ const secret_key = await cl.keystore.get(`nostr:key:${public_key}`);
+ await cl.dialog.alert(
+ `Hi! This is your nostr secret key ${secret_key}`,
+ );
+ }}
+ >
+ {"test #2"}
+ </button>
+ <button
+ class={`button-simple`}
+ onclick={async () => {
+ const confirm = await cl.dialog.confirm(
+ `Hi! This will delete your nostr key.`,
);
- console.log(`res `, res);
+ if (confirm) {
+ const public_key = await cl.preferences.get(
+ _cf.pref_key_active,
+ );
+ const key_removed = await cl.keystore.remove(
+ `nostr:key:${public_key}`,
+ );
+ if (key_removed) location.reload();
+ }
}}
>
- <div
- class={`flex flex-col h-line w-line justify-center items-center bg-layer-1-surface`}
- >
- <p class={`font-mono text-sm lowercase text-layer-2-glyph`}>
- {$t(`app.name`)}
- </p>
- </div>
+ {"test #3"}
</button>
</div>
diff --git a/src/routes/(conf)/conf/nostr/+page.svelte b/src/routes/(conf)/conf/nostr/+page.svelte
@@ -0,0 +1,34 @@
+<script lang="ts">
+ import { goto } from "$app/navigation";
+ import { cl, nt } from "$lib/client";
+ import { _cf } from "$lib/conf";
+</script>
+
+<div class={`flex flex-col w-full pt-16 justify-center items-center`}>
+ <button
+ class={`flex flex-row justify-center items-center text-white`}
+ onclick={async () => {
+ const sk_hex = nt.generate_key();
+ const pk_hex = nt.public_key(sk_hex);
+ const new_key_added = await cl.keystore.set(
+ `nostr:key:${pk_hex}`,
+ sk_hex,
+ );
+ if (new_key_added) {
+ const key_pref_added = await cl.preferences.set(
+ _cf.pref_key_active,
+ pk_hex,
+ );
+ if (key_pref_added) await goto("/");
+ }
+ }}
+ >
+ <div
+ class={`flex flex-col h-line w-line justify-center items-center bg-layer-1-surface`}
+ >
+ <p class={`font-mono text-sm lowercase text-layer-2-glyph`}>
+ {`create nostr keys`}
+ </p>
+ </div>
+ </button>
+</div>
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
@@ -72,6 +72,10 @@
const nostr_key = await cl.keystore.get(`nostr:key:${key_active}`);
console.log(`nostr_key `, nostr_key);
if(typeof nostr_key === `string` && nostr_key) app_key.set(nostr_key);
+ else {
+ await goto(`/conf/nostr`);
+ return;
+ }
} catch (e) {
console.log(`(app_config) error `, e);
} finally {