From 590e69c1f4484b85c7fb121cd390b2e95fee4a47 Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Tue, 6 May 2025 08:32:52 +0200 Subject: [PATCH] fix login with Extension, formatting --- src/lib/index.js | 62 +++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/lib/index.js b/src/lib/index.js index 221c4b5..cb829ed 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -1,33 +1,35 @@ -import { NDKNip07Signer, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk"; -import { ndk } from "$lib/stores"; -import { get } from "svelte/store"; +import { NDKNip07Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk'; +import { ndk } from '$lib/stores'; +import { get } from 'svelte/store'; export async function login() { - if (window.nostr) { - const signer = new NDKNip07Signer(); - get(ndk).signer = signer; - signer.user(); - } else { - console.log("no extension") - const storedPrivateKey = window.localStorage.getItem('nostrPrivateKey'); - if (storedPrivateKey) { - const privateKey = JSON.parse(storedPrivateKey); - console.log("stored private key", privateKey) - const signer = new NDKPrivateKeySigner(privateKey); - ndk.update((ndk) => { - ndk.signer = signer; - return ndk; - }); - // get(ndk).signer = signer; - signer.user(); - } else { - console.log('No private key found, generating a new one...'); - const privateKey = NDKPrivateKeySigner.generate(); - const signer = new NDKPrivateKeySigner(privateKey.privateKey); - console.log('Generated Private Key:', privateKey); - signer.user(); - window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey)); - get(ndk).signer = signer; - } - } + if (window.nostr) { + const signer = new NDKNip07Signer(); + ndk.update((ndk) => { + ndk.signer = signer; + return ndk; + }); + signer.user(); + } else { + console.log('no extension'); + const storedPrivateKey = window.localStorage.getItem('nostrPrivateKey'); + if (storedPrivateKey) { + const privateKey = JSON.parse(storedPrivateKey); + console.log('stored private key', privateKey); + const signer = new NDKPrivateKeySigner(privateKey); + ndk.update((ndk) => { + ndk.signer = signer; + return ndk; + }); + signer.user(); + } else { + console.log('No private key found, generating a new one...'); + const privateKey = NDKPrivateKeySigner.generate(); + const signer = new NDKPrivateKeySigner(privateKey.privateKey); + console.log('Generated Private Key:', privateKey); + signer.user(); + window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey)); + get(ndk).signer = signer; + } + } }