From c8891f31091843de8643fbda5a942ee6212ca19e Mon Sep 17 00:00:00 2001 From: silberengel Date: Sun, 13 Jul 2025 00:37:14 +0200 Subject: [PATCH] Amber and npub-only login implemented --- package-lock.json | 17 +- package.json | 2 +- src/lib/components/Login.svelte | 338 ++++++++++++++--- src/lib/components/LoginMenu.svelte | 480 +++++++++++++++++++++++++ src/lib/components/Navigation.svelte | 4 +- src/lib/components/util/Profile.svelte | 8 - src/lib/utils/nostrUtils.ts | 2 +- 7 files changed, 772 insertions(+), 79 deletions(-) create mode 100644 src/lib/components/LoginMenu.svelte diff --git a/package-lock.json b/package-lock.json index b631ab9..095e9ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "alexandria", "version": "0.0.6", "dependencies": { - "@nostr-dev-kit/ndk": "2.11.x", + "@nostr-dev-kit/ndk": "^2.14.32", "@nostr-dev-kit/ndk-cache-dexie": "2.5.x", "@popperjs/core": "2.11.x", "@tailwindcss/forms": "0.5.x", @@ -568,8 +568,9 @@ } }, "node_modules/@nostr-dev-kit/ndk": { - "version": "2.11.2", - "license": "MIT", + "version": "2.14.32", + "resolved": "https://registry.npmjs.org/@nostr-dev-kit/ndk/-/ndk-2.14.32.tgz", + "integrity": "sha512-LUBO35RCB9/emBYsXNDece7m/WO2rGYR8j4SD0Crb3z8GcKTJq6P8OjpZ6+Kr+sLNo8N0uL07XxtAvEBnp2OqQ==", "dependencies": { "@noble/curves": "^1.6.0", "@noble/hashes": "^1.5.0", @@ -577,14 +578,14 @@ "@scure/base": "^1.1.9", "debug": "^4.3.6", "light-bolt11-decoder": "^3.2.0", - "nostr-tools": "^2.7.1", - "tseep": "^1.2.2", - "typescript-lru-cache": "^2.0.0", - "utf8-buffer": "^1.0.0", - "websocket-polyfill": "^0.0.3" + "tseep": "^1.3.1", + "typescript-lru-cache": "^2" }, "engines": { "node": ">=16" + }, + "peerDependencies": { + "nostr-tools": "^2" } }, "node_modules/@nostr-dev-kit/ndk-cache-dexie": { diff --git a/package.json b/package.json index 787d2e7..cb2a5d9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "vitest" }, "dependencies": { - "@nostr-dev-kit/ndk": "2.11.x", + "@nostr-dev-kit/ndk": "^2.14.32", "@nostr-dev-kit/ndk-cache-dexie": "2.5.x", "@popperjs/core": "2.11.x", "@tailwindcss/forms": "0.5.x", diff --git a/src/lib/components/Login.svelte b/src/lib/components/Login.svelte index e0d1171..8ea7dda 100644 --- a/src/lib/components/Login.svelte +++ b/src/lib/components/Login.svelte @@ -1,76 +1,296 @@ -
- {#if $ndkSignedIn} - - {:else} - - -
- - {#if signInFailed} -
- {errorMessage} + {#if isLoading} + 🔄 Generating QR code... + {:else} + 🔗 Connect with Amber + {/if} + + +
+

Click to generate a QR code for your mobile Amber app

+
+ {:else} +
+
+

Scan with Amber

+

Open Amber on your phone and scan this QR code

+
+ + + {#if qrCodeDataUrl} +
+ Nostr Connect QR Code +
+ {/if} + + +
+ +
+ + +
+
+ +
+

1. Open Amber on your phone

+

2. Scan the QR code above

+

3. Approve the connection in Amber

- {/if} - + ✍️ Test Sign Event + + + +
+ {/if} + + {#if result} +
+ {result}
- - {/if} + {/if} +
diff --git a/src/lib/components/LoginMenu.svelte b/src/lib/components/LoginMenu.svelte new file mode 100644 index 0000000..b7b8c74 --- /dev/null +++ b/src/lib/components/LoginMenu.svelte @@ -0,0 +1,480 @@ + + +
+ {#if !npub} + +
+ + +
+

Login with...

+ + + +
+
+ {#if result} +
+ {result} + +
+ {/if} +
+ {:else} + +
+ + +
+
+

{profileHandle || shortenNpub(npub)}

+
    +
  • + +
  • +
  • + +
  • +
+
+
+
+
+ {/if} +
+ +{#if showQrCode && qrCodeDataUrl} + +
+
+
+

Scan with Amber

+

Open Amber on your phone and scan this QR code

+ +
+ Nostr Connect QR Code +
+ +
+ +
+ + +
+
+ +
+

1. Open Amber on your phone

+

2. Scan the QR code above

+

3. Approve the connection in Amber

+
+ + +
+
+
+{/if} \ No newline at end of file diff --git a/src/lib/components/Navigation.svelte b/src/lib/components/Navigation.svelte index 4fefd1a..e634c55 100644 --- a/src/lib/components/Navigation.svelte +++ b/src/lib/components/Navigation.svelte @@ -7,7 +7,7 @@ NavHamburger, NavBrand, } from "flowbite-svelte"; - import Login from "./Login.svelte"; + import LoginMenu from "./LoginMenu.svelte"; let { class: className = "" } = $props(); @@ -19,7 +19,7 @@
- +
diff --git a/src/lib/components/util/Profile.svelte b/src/lib/components/util/Profile.svelte index 9d75bd5..402eb3b 100644 --- a/src/lib/components/util/Profile.svelte +++ b/src/lib/components/util/Profile.svelte @@ -80,14 +80,6 @@ function shortenNpub(long: string|undefined) { Sign out - {:else} - {/if} diff --git a/src/lib/utils/nostrUtils.ts b/src/lib/utils/nostrUtils.ts index 9d80b1c..b85dbb9 100644 --- a/src/lib/utils/nostrUtils.ts +++ b/src/lib/utils/nostrUtils.ts @@ -87,7 +87,7 @@ export async function getUserMetadata(identifier: string): Promise name: profile?.name || fallback.name, displayName: profile?.displayName, nip05: profile?.nip05, - picture: profile?.image, + picture: profile?.picture || profile?.image, about: profile?.about, banner: profile?.banner, website: profile?.website,