From 4f63e3e13f32f7c563f1b4a11127531f026fed9d Mon Sep 17 00:00:00 2001 From: reya <123083837+reyamir@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:58:35 +0700 Subject: [PATCH] feat: disable login with nostr-connect --- src-tauri/src/commands/account.rs | 31 +++++------------------------- src/routes/create-account.lazy.tsx | 2 +- src/routes/import-key.lazy.tsx | 2 +- src/routes/index.lazy.tsx | 4 +--- src/routes/new.lazy.tsx | 8 +++++--- src/routes/nostr-connect.lazy.tsx | 9 +-------- 6 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src-tauri/src/commands/account.rs b/src-tauri/src/commands/account.rs index b492f91..6deb72a 100644 --- a/src-tauri/src/commands/account.rs +++ b/src-tauri/src/commands/account.rs @@ -212,45 +212,24 @@ pub async fn set_inbox(relays: Vec, state: State<'_, Nostr>) -> Result<( #[specta::specta] pub async fn login( id: String, - bunker: Option, state: State<'_, Nostr>, handle: tauri::AppHandle, ) -> Result { let client = &state.client; let public_key = PublicKey::parse(&id).map_err(|e| e.to_string())?; let hex = public_key.to_hex(); - let keyring = Entry::new("coop", &id).expect("Unexpected."); + let keyring = Entry::new("coop", &id).map_err(|e| e.to_string())?; let password = match keyring.get_password() { Ok(pw) => pw, Err(_) => return Err("Cancelled".into()), }; - match bunker { - Some(uri) => { - let app_keys = - Keys::parse(password).expect("Secret Key is modified, please check again."); + let keys = Keys::parse(password).map_err(|e| e.to_string())?; + let signer = NostrSigner::Keys(keys); - match NostrConnectURI::parse(uri) { - Ok(bunker_uri) => { - match Nip46Signer::new(bunker_uri, app_keys, Duration::from_secs(30), None) - .await - { - Ok(signer) => client.set_signer(Some(signer.into())).await, - Err(err) => return Err(err.to_string()), - } - } - Err(err) => return Err(err.to_string()), - } - } - None => { - let keys = Keys::parse(password).expect("Secret Key is modified, please check again."); - let signer = NostrSigner::Keys(keys); - - // Update signer - client.set_signer(Some(signer)).await; - } - } + // Update signer + client.set_signer(Some(signer)).await; let inbox = Filter::new().kind(Kind::Custom(10050)).author(public_key).limit(1); diff --git a/src/routes/create-account.lazy.tsx b/src/routes/create-account.lazy.tsx index 3b942e5..688f997 100644 --- a/src/routes/create-account.lazy.tsx +++ b/src/routes/create-account.lazy.tsx @@ -93,7 +93,7 @@ function Screen() { {isPending ? : "Continue"} - Back + Go back to previous screen diff --git a/src/routes/import-key.lazy.tsx b/src/routes/import-key.lazy.tsx index a13b4c2..1ecc5a7 100644 --- a/src/routes/import-key.lazy.tsx +++ b/src/routes/import-key.lazy.tsx @@ -115,7 +115,7 @@ function Screen() { {isPending ? : "Continue"} - Back + Go back to previous screen diff --git a/src/routes/index.lazy.tsx b/src/routes/index.lazy.tsx index 0065868..6b4ce51 100644 --- a/src/routes/index.lazy.tsx +++ b/src/routes/index.lazy.tsx @@ -31,9 +31,7 @@ function Screen() { const loginWith = async (npub: string) => { setValue(npub); startTransition(async () => { - const bunker: string = localStorage.getItem(`${npub}_bunker`); - const verifyBunker = bunker?.length && bunker?.startsWith("bunker://"); - const res = await commands.login(npub, verifyBunker ? bunker : null); + const res = await commands.login(npub); if (res.status === "ok") { navigate({ diff --git a/src/routes/new.lazy.tsx b/src/routes/new.lazy.tsx index d5f741b..c5f2b32 100644 --- a/src/routes/new.lazy.tsx +++ b/src/routes/new.lazy.tsx @@ -13,7 +13,7 @@ function Screen() {

- Direct Message client for Nostr. + Direct Message on Nostr.

@@ -24,17 +24,19 @@ function Screen() { Create a new identity - Login with Nostr Connect + Login with Private Key + {/* Login with Private Key (not recommended) + */}
diff --git a/src/routes/nostr-connect.lazy.tsx b/src/routes/nostr-connect.lazy.tsx index 54accff..ef0f486 100644 --- a/src/routes/nostr-connect.lazy.tsx +++ b/src/routes/nostr-connect.lazy.tsx @@ -35,13 +35,6 @@ function Screen() { const res = await commands.connectAccount(uri); if (res.status === "ok") { - const npub = res.data; - const parsed = new URL(uri); - parsed.searchParams.delete("secret"); - - // save connection string - localStorage.setItem(`${npub}_bunker`, parsed.toString()); - navigate({ to: "/", replace: true }); } else { await message(res.error, { title: "Nostr Connect", kind: "error" }); @@ -103,7 +96,7 @@ function Screen() {

) : ( - Back + Go back to previous screen )}