diff options
| author | Adam Soltys <[email protected]> | 2024-12-30 21:53:52 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-30 21:53:52 -0800 |
| commit | 38e786c0d3c2280dd69f22ddf7cdf6ca804e6048 (patch) | |
| tree | 48893b5eb0253104dfb2847fd0ac371eb1b492ce /src | |
| parent | d96e1580757a1d0531fec0854e4238214ec8c00b (diff) | |
| download | coinos-ui-38e786c0d3c2280dd69f22ddf7cdf6ca804e6048.tar.gz coinos-ui-38e786c0d3c2280dd69f22ddf7cdf6ca804e6048.zip | |
scrap key generation
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Payments.svelte | 22 | ||||
| -rw-r--r-- | src/lib/nostr.ts | 25 | ||||
| -rw-r--r-- | src/routes/(app)/+layout.server.ts | 5 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/+page.svelte | 18 | ||||
| -rw-r--r-- | src/routes/(app)/generate/+page.svelte | 64 | ||||
| -rw-r--r-- | src/routes/(app)/generate/+server.ts | 12 | ||||
| -rw-r--r-- | src/routes/(app)/payments/[...page]/+page.svelte | 17 | ||||
| -rw-r--r-- | src/routes/(static)/login/+page.svelte | 1 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.server.ts | 4 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.svelte | 3 |
10 files changed, 41 insertions, 130 deletions
diff --git a/src/components/Payments.svelte b/src/components/Payments.svelte index fbe88ce6..a4331a42 100644 --- a/src/components/Payments.svelte +++ b/src/components/Payments.svelte @@ -4,7 +4,7 @@ import { get, f, s, si, sat, loc, sats, types } from "$lib/utils"; import { format } from "date-fns"; import { t } from "$lib/translations"; - + import locales from "$lib/locales"; const { fund, locale, payments } = $props(); </script> @@ -20,7 +20,8 @@ <div class="whitespace-nowrap my-auto col-span-3"> <div class="font-bold flex items-center"> <div class="flex items-center"> - <iconify-icon noobserver + <iconify-icon + noobserver icon="ph:lightning-fill" width="24" class="text-yellow-300" @@ -56,7 +57,8 @@ {:else} <a href={`/fund/${p.memo}`}> <div class="text-secondary flex"> - <iconify-icon noobserver + <iconify-icon + noobserver icon="ph:lightning-fill" class="text-yellow-300 text-3xl" ></iconify-icon> @@ -77,14 +79,16 @@ {:else} <div class="text-secondary flex items-center gap-1"> {#if p.type === types.lightning || p.type === types.bolt12} - <iconify-icon noobserver + <iconify-icon + noobserver icon="ph:lightning-fill" class="text-yellow-300 text-3xl" ></iconify-icon> {:else if p.type === types.ecash} <img src="/images/cash.png" class="w-12" /> {:else if p.type === types.reconcile} - <iconify-icon noobserver icon="ph:scales-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:scales-bold" width="32" + ></iconify-icon> {:else if p.type === types.bitcoin} <iconify-icon noobserver icon="logos:bitcoin" class="text-3xl" ></iconify-icon> @@ -107,10 +111,14 @@ <div class="text-secondary text-right text-sm my-auto col-span-3"> <div> - {format(new Date(p.created), "h:mm aaa", { locale })} + {format(new Date(p.created), "h:mm aaa", { + locale: locales[user.language], + })} </div> <div> - {format(new Date(p.created), "MMM d, yy", { locale })} + {format(new Date(p.created), "MMM d, yy", { + locale: locales[user.language], + })} </div> </div> </div> diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts index bba46ef4..e45ce634 100644 --- a/src/lib/nostr.ts +++ b/src/lib/nostr.ts @@ -17,10 +17,10 @@ import { } from "nostr-tools/nip49"; import { bech32m, hex } from "@scure/base"; -import { entropyToMnemonic, mnemonicToEntropy } from "@scure/bip39"; +import { entropyToMnemonic } from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english"; -import { generateSeedWords, privateKeyFromSeedWords } from "nostr-tools/nip06"; +import { privateKeyFromSeedWords } from "nostr-tools/nip06"; type User = { [key: string]: any; @@ -34,27 +34,6 @@ type EncryptParams = { const { encode, decode, toWords, fromWords } = bech32m; -export const generate = async (user: any) => { - const p = get(pin); - if (p && p.length !== 6) return; - - const salt = crypto.getRandomValues(new Uint8Array(16)); - const mnemonic = generateSeedWords(); - const sk = privateKeyFromSeedWords(mnemonic); - - const bytes = new Uint8Array( - await crypto.subtle.encrypt( - { name: "AES-GCM", iv: new Uint8Array(16) }, - await stretch(await getPassword(), salt), - mnemonicToEntropy(mnemonic, wordlist), - ), - ); - - user.pubkey = getPublicKey(sk); - user.cipher = encode("en", toWords(bytes), 180); - user.salt = Buffer.from(salt).toString("hex"); -}; - export const encrypt = async ({ message, recipient, user }: EncryptParams) => { const sk = await getPrivateKey(user); return nip04.encrypt(sk, recipient, message); diff --git a/src/routes/(app)/+layout.server.ts b/src/routes/(app)/+layout.server.ts index acf19ada..ef25388d 100644 --- a/src/routes/(app)/+layout.server.ts +++ b/src/routes/(app)/+layout.server.ts @@ -45,11 +45,6 @@ export async function load({ cookies, request, url, params }) { redirect(307, `/${user.username}`); } - if (user && !user.pubkey && !pathname.includes("generate")) { - console.log("user missing pubkey", user); - redirect(303, "/generate"); - } - const theme = cookies.get("theme") || "light"; return { user, token, subject, theme }; } diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index 36a63a9b..5d6ca777 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -26,7 +26,9 @@ let show = $state(); let toggle = () => (show = !show); let href = $derived(encodeURIComponent($page.url.href)); - let withdrawUrl = encoder.encode(`${$page.url.origin}/api/fund/${id}/withdraw`); + let withdrawUrl = encoder.encode( + `${$page.url.origin}/api/fund/${id}/withdraw`, + ); let lnurlw = bech32.encode("lnurl", bech32.toWords(withdrawUrl), 20000); </script> @@ -51,7 +53,8 @@ <div class="grow"> <a href={`/send/fund/${id}`}> <button class="btn"> - <iconify-icon noobserver icon="ph:plus-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:plus-bold" width="32" + ></iconify-icon> {$t("payments.addFunds")} </button> </a> @@ -59,7 +62,8 @@ <div class="grow"> <a href={`/fund/${id}/withdraw`}> <button class="btn"> - <iconify-icon noobserver + <iconify-icon + noobserver icon="ph:hand-coins-bold" width="32" flip="horizontal" @@ -71,11 +75,13 @@ </div> <div class="flex gap-2" data-sveltekit-prefetch="off"> <a href={`/qr/${href}`} class="btn !w-auto grow"> - <iconify-icon noobserver icon="ph:link-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:link-bold" width="32" + ></iconify-icon> <div class="my-auto">{$t("payments.shareLink")}</div> </a> <a href={`/qr/${lnurlw}`} class="btn !w-auto grow"> - <iconify-icon noobserver + <iconify-icon + noobserver icon="ph:lightning-fill" width="24" class="text-yellow-300" @@ -83,7 +89,7 @@ {$t("payments.lnurlw")} </a> </div> - <Payments {payments} fund={true} /> + <Payments {payments} fund={true} {locale} /> </div> </div> </div> diff --git a/src/routes/(app)/generate/+page.svelte b/src/routes/(app)/generate/+page.svelte deleted file mode 100644 index 72ca2485..00000000 --- a/src/routes/(app)/generate/+page.svelte +++ /dev/null @@ -1,64 +0,0 @@ -<script> - import { run } from 'svelte/legacy'; - - import { fail, post, wait } from "$lib/utils"; - import { onMount } from "svelte"; - import { goto, invalidate } from "$app/navigation"; - import Pin from "$comp/Pin.svelte"; - import Spinner from "$comp/Spinner.svelte"; - import { loginRedirect, pin, password } from "$lib/store"; - import { generate } from "$lib/nostr"; - import { browser } from "$app/environment"; - - let { data } = $props(); - let { user } = $state(data); - - let loaded = $state(); - let gen = async () => { - if (!browser) return; - - if (user.pubkey) { - goto($loginRedirect || `/${user.username}`, { invalidateAll: true }); - return; - } - - try { - await generate(user); - } catch (e) { - console.log("error generating", e); - } - - try { - user.pin = $pin; - await post(`/generate`, user); - goto($loginRedirect || `/${user.username}`, { invalidateAll: true }); - } catch (e) { - $pin = ""; - if (e.message?.startsWith("Pin")) { - fail("Wrong pin, try again"); - } else { - fail("Failed to generate keys"); - goto("/"); - } - } - }; - - onMount(() => browser && setTimeout(() => (loaded = true) && gen(), 50)); - - run(() => { - $pin?.length === 6 && gen(user); - }); -</script> - -{#if loaded && user?.haspin && $pin?.length !== 6} - <Pin /> -{/if} - -<div class="container px-4 text-center mx-auto"> - <h1 class="text-3xl md:text-4xl font-bold mb-6"> - Generating new account keys - </h1> - <div class="flex w-full py-5 max-w-[200px] mx-auto bg-black rounded-2xl"> - <Spinner /> - </div> -</div> diff --git a/src/routes/(app)/generate/+server.ts b/src/routes/(app)/generate/+server.ts deleted file mode 100644 index b16d0b37..00000000 --- a/src/routes/(app)/generate/+server.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { auth, post } from "$lib/utils"; -import { error, json } from "@sveltejs/kit"; - -export async function POST({ cookies, request }) { - try { - const body = await request.json(); - return json(await post("/user", body, auth(cookies))); - } catch (e: any) { - console.log(e); - error(500, e.message); - } -} diff --git a/src/routes/(app)/payments/[...page]/+page.svelte b/src/routes/(app)/payments/[...page]/+page.svelte index ccdfa34c..9ef38df5 100644 --- a/src/routes/(app)/payments/[...page]/+page.svelte +++ b/src/routes/(app)/payments/[...page]/+page.svelte @@ -9,7 +9,6 @@ import { page } from "$app/stores"; import { differenceInDays, getUnixTime, sub } from "date-fns"; import { goto, invalidate } from "$app/navigation"; - import locales from "$lib/locales"; let { data } = $props(); let { start, @@ -22,8 +21,7 @@ page: p, } = $derived(data); - let locale = locales[user.language]; - let userLocale = loc(user); + let locale = loc(user); let change = ({ target: { value } }) => goto(value); let link = (p) => { @@ -203,7 +201,7 @@ {/if} </div> - <Payments {payments} /> + <Payments {payments} locale={locale} /> <div class="grid grid-cols-3 w-full text-center text-lg"> {#each Object.keys(incoming) as c} @@ -230,18 +228,18 @@ >{$t("payments.income")}</span > <!-- <span><b>{subtotalIn ? f(subtotalIn, c) : "-"}</b></span> --> - <span><b>{tipsIn > 0 ? f(tipsIn, c, userLocale) : "-"}</b></span> + <span><b>{tipsIn > 0 ? f(tipsIn, c, locale) : "-"}</b></span> <span class="text-right" - ><b>{totalIn > 0 ? f(totalIn, c, userLocale) : "-"}</b></span + ><b>{totalIn > 0 ? f(totalIn, c, locale) : "-"}</b></span > <span class="text-left text-base text-secondary" >{$t("payments.expenditure")}</span > <!-- <span><b>{subtotalOut ? f(subtotalOut, c) : "-"}</b></span> --> - <span><b>{tipsOut > 0 ? f(tipsOut, c, userLocale) : "-"}</b></span> + <span><b>{tipsOut > 0 ? f(tipsOut, c, locale) : "-"}</b></span> <span class="text-right" - ><b>{totalOut > 0 ? f(totalOut, c, userLocale) : "-"}</b></span + ><b>{totalOut > 0 ? f(totalOut, c, locale) : "-"}</b></span > {/each} </div> @@ -249,7 +247,8 @@ <div class="flex justify-center"> <button class="btn !w-auto" onclick={csv}> - <iconify-icon noobserver icon="ph:floppy-disk-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:floppy-disk-bold" width="32" + ></iconify-icon> <div class="my-auto">{$t("payments.export")}</div> </button> </div> diff --git a/src/routes/(static)/login/+page.svelte b/src/routes/(static)/login/+page.svelte index b49ba036..e64434fb 100644 --- a/src/routes/(static)/login/+page.svelte +++ b/src/routes/(static)/login/+page.svelte @@ -13,7 +13,6 @@ import { password, pin, loginRedirect } from "$lib/store"; import { t } from "$lib/translations"; import { page } from "$app/stores"; - import { generate } from "$lib/nostr"; import { invalidateAll } from "$app/navigation"; let nostr = $state(); diff --git a/src/routes/(static)/register/+page.server.ts b/src/routes/(static)/register/+page.server.ts index 1781602f..4cff0ed9 100644 --- a/src/routes/(static)/register/+page.server.ts +++ b/src/routes/(static)/register/+page.server.ts @@ -23,13 +23,17 @@ export const actions = { if (loginRedirect === "undefined") loginRedirect = undefined; try { + console.log("ST", Date.now()); await post("/register", { user }, { "cf-connecting-ip": ip }); + console.log("END", Date.now()); } catch (e) { ({ message: error } = e as Error); } try { + console.log("ST", Date.now()); await login(user, cookies, ip); + console.log("END", Date.now()); error = null; } catch (e) { const { message } = e as Error; diff --git a/src/routes/(static)/register/+page.svelte b/src/routes/(static)/register/+page.svelte index fee19ec6..4a4a3c57 100644 --- a/src/routes/(static)/register/+page.svelte +++ b/src/routes/(static)/register/+page.svelte @@ -15,7 +15,6 @@ import { avatar, password, loginRedirect } from "$lib/store"; import { t } from "$lib/translations"; import { page } from "$app/stores"; - import { generate } from "$lib/nostr"; import { NumberDictionary, uniqueNamesGenerator, @@ -86,8 +85,6 @@ let data = new FormData(this); let user = Object.fromEntries(data); - await generate(user); - for (let k in user) { data.set(k, user[k]); } |
