Support Aegis URL scheme for NIP-46 login

This commit is contained in:
2026-04-06 12:51:12 +05:30
committed by hodlbod
parent 1d5f91fb6c
commit 5684b4ffc7
3 changed files with 71 additions and 1 deletions
+40 -1
View File
@@ -1,4 +1,4 @@
import {writable} from "svelte/store"
import {get, writable} from "svelte/store"
import type {Nip46ResponseWithResult} from "@welshman/signer"
import {Nip46Broker} from "@welshman/signer"
import {makeSecret} from "@welshman/util"
@@ -11,8 +11,28 @@ import {
} from "@app/core/state"
import {pushToast} from "@app/util/toast"
const APP_SCHEME = "social.flotilla"
type NostrSignerScheme = "aegis" | "nostrsigner"
const makeSignerCallbackUrl = (path: string, sourceAppScheme: string) =>
`${sourceAppScheme}://x-callback-url/${path}`
const makeSignerLaunchUrl = (scheme: NostrSignerScheme, nostrconnectUrl: string) => {
const params = new URLSearchParams({
method: "connect",
nostrconnect: nostrconnectUrl,
"x-source": APP_SCHEME,
"x-success": makeSignerCallbackUrl("authSuccess", APP_SCHEME),
"x-error": makeSignerCallbackUrl("authError", APP_SCHEME),
})
return `${scheme}://x-callback-url/auth/nip46?${params.toString()}`
}
export class Nip46Controller {
url = writable("")
signerUrls = writable<{aegis: string; nostrsigner: string} | undefined>(undefined)
bunker = writable("")
loading = writable(false)
clientSecret = makeSecret()
@@ -33,6 +53,10 @@ export class Nip46Controller {
})
this.url.set(url)
this.signerUrls.set({
aegis: makeSignerLaunchUrl("aegis", url),
nostrsigner: makeSignerLaunchUrl("nostrsigner", url),
})
let response
try {
@@ -54,6 +78,21 @@ export class Nip46Controller {
}
}
launchSigner(scheme: NostrSignerScheme) {
const signerUrl = get(this.signerUrls)?.[scheme]
if (!signerUrl) {
pushToast({
theme: "error",
message: "Unable to open signer app right now. Please try again.",
})
return
}
window.location.href = signerUrl
}
stop() {
this.broker.cleanup()
this.abortController.abort()