From 12fab67961fc9321de43ff5b78fc4938f68bf590 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 29 Oct 2024 14:40:37 -0700 Subject: [PATCH] Add bunker login --- src/app/commands.ts | 23 ++++++- src/app/components/InfoBunker.svelte | 32 ++++++++++ src/app/components/Landing.svelte | 2 +- src/app/components/LogIn.svelte | 10 +-- .../{LogInKey.svelte => LogInBunker.svelte} | 63 ++++++++----------- src/app/components/SignUpKey.svelte | 2 +- src/app/components/SpaceCreate.svelte | 2 +- src/app/components/SpaceCreateExternal.svelte | 2 +- src/assets/icons/CPU.svg | 16 +++++ src/lib/components/Icon.svelte | 2 + 10 files changed, 108 insertions(+), 46 deletions(-) create mode 100644 src/app/components/InfoBunker.svelte rename src/app/components/{LogInKey.svelte => LogInBunker.svelte} (50%) create mode 100644 src/assets/icons/CPU.svg diff --git a/src/app/commands.ts b/src/app/commands.ts index c4e91f70..cd1644cd 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -23,7 +23,8 @@ import { import type {TrustedEvent, EventTemplate, List} from "@welshman/util" import type {SubscribeRequestWithHandlers} from "@welshman/net" import {PublishStatus, AuthStatus, ConnectionStatus} from "@welshman/net" -import {Nip59, stamp} from "@welshman/signer" +import {Nip59, makeSecret, stamp, Nip46Broker} from "@welshman/signer" +import type {Nip46Handler} from "@welshman/signer" import { pubkey, signer, @@ -44,6 +45,8 @@ import { userInboxRelaySelections, nip44EncryptToSelf, loadRelay, + addSession, + nip46Perms, } from "@welshman/app" import { COMMENT, @@ -86,6 +89,24 @@ export const makeIMeta = (url: string, data: Record) => [ ...Object.entries(data).map(([k, v]) => [k, v].join(" ")), ] +// Log in + +export const loginWithNip46 = async (token: string, handler: Nip46Handler) => { + const secret = makeSecret() + const broker = Nip46Broker.get({secret, handler}) + const result = await broker.connect(token, nip46Perms) + + if (!result) return false + + const pubkey = await broker.getPublicKey() + + if (!pubkey) return false + + addSession({method: "nip46", pubkey, secret, handler}) + + return true +} + // Loaders export const loadUserData = ( diff --git a/src/app/components/InfoBunker.svelte b/src/app/components/InfoBunker.svelte new file mode 100644 index 00000000..0af9041f --- /dev/null +++ b/src/app/components/InfoBunker.svelte @@ -0,0 +1,32 @@ + + +
+ +
What is a bunker link?
+
+

+ Nostr uses "keys" instead of + passwords to identify users. This allows users to own their social identity instead of + renting it from a tech company, and can bring it with them from app to app. +

+

+ A good way to manage your keys is to use a remote signing application. These apps can hold + your keys and log you in remotely to as many applications as you like, without increasing + the risk of your keys being stolen. +

+

+ One way to log in with a remote signer is using a "bunker link" which is more secure and + decentralized than other solutions. Check your signer for a link beginning with "bunker://", + copy it into {PLATFORM_NAME}, and you should be good to go! +

+

+ If you don't have a signer yet, nsec.app + is an easy way to get started. +

+ +
diff --git a/src/app/components/Landing.svelte b/src/app/components/Landing.svelte index 384ed02d..e939ed91 100644 --- a/src/app/components/Landing.svelte +++ b/src/app/components/Landing.svelte @@ -17,7 +17,7 @@

Welcome to {PLATFORM_NAME}!

-

The chat app built for sovereign communities.

+

The chat app built for self-hosted communities.

{/each} -
Need an account? diff --git a/src/app/components/LogInKey.svelte b/src/app/components/LogInBunker.svelte similarity index 50% rename from src/app/components/LogInKey.svelte rename to src/app/components/LogInBunker.svelte index 680fbf6f..fb500284 100644 --- a/src/app/components/LogInKey.svelte +++ b/src/app/components/LogInBunker.svelte @@ -1,6 +1,5 @@
Log In
-
Already have a nostr key?
+
Connect your signer app with {PLATFORM_NAME} using a bunker link.
-

Private Key*

+

Bunker Link*

- A nostr nsec or private key. Note that this log in method is not recommended. - + A login link provided by a nostr signing app. +

@@ -79,7 +70,7 @@
diff --git a/src/app/components/SignUpKey.svelte b/src/app/components/SignUpKey.svelte index 0a326009..a0767359 100644 --- a/src/app/components/SignUpKey.svelte +++ b/src/app/components/SignUpKey.svelte @@ -55,7 +55,7 @@ diff --git a/src/app/components/SpaceCreate.svelte b/src/app/components/SpaceCreate.svelte index a01dcfd2..52d8f8ab 100644 --- a/src/app/components/SpaceCreate.svelte +++ b/src/app/components/SpaceCreate.svelte @@ -51,7 +51,7 @@ diff --git a/src/app/components/SpaceCreateExternal.svelte b/src/app/components/SpaceCreateExternal.svelte index c4f1c360..cf8d44a7 100644 --- a/src/app/components/SpaceCreateExternal.svelte +++ b/src/app/components/SpaceCreateExternal.svelte @@ -37,7 +37,7 @@ diff --git a/src/assets/icons/CPU.svg b/src/assets/icons/CPU.svg new file mode 100644 index 00000000..e63a9dba --- /dev/null +++ b/src/assets/icons/CPU.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/lib/components/Icon.svelte b/src/lib/components/Icon.svelte index 236743cc..cc7a59a5 100644 --- a/src/lib/components/Icon.svelte +++ b/src/lib/components/Icon.svelte @@ -34,6 +34,7 @@ import Copy from "@assets/icons/Copy.svg?dataurl" import Compass from "@assets/icons/Compass.svg?dataurl" import CompassBig from "@assets/icons/Compass Big.svg?dataurl" + import CPU from "@assets/icons/CPU.svg?dataurl" import Danger from "@assets/icons/Danger.svg?dataurl" import Exit from "@assets/icons/Exit.svg?dataurl" import File from "@assets/icons/File.svg?dataurl" @@ -111,6 +112,7 @@ copy: Copy, compass: Compass, "compass-big": CompassBig, + cpu: CPU, danger: Danger, exit: Exit, file: File,