diff --git a/src/app/commands.ts b/src/app/commands.ts
index 53d8757..31ab89a 100644
--- a/src/app/commands.ts
+++ b/src/app/commands.ts
@@ -32,7 +32,7 @@ import {
} from "@welshman/util"
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
-import {Nip59, makeSecret, stamp, Nip46Broker} from "@welshman/signer"
+import {Nip59, stamp} from "@welshman/signer"
import {
pubkey,
signer,
@@ -49,7 +49,6 @@ import {
userInboxRelaySelections,
nip44EncryptToSelf,
loadRelay,
- addSession,
clearStorage,
dropSession,
tagEventForComment,
@@ -62,13 +61,11 @@ import {
PROTECTED,
userMembership,
INDEXER_RELAYS,
- NIP46_PERMS,
ALERT,
NOTIFIER_PUBKEY,
NOTIFIER_RELAY,
userRoomsByUrl,
} from "@app/state"
-import {loadUserData} from "@app/requests"
// Utils
@@ -112,38 +109,6 @@ export const prependParent = (parent: TrustedEvent | undefined, {content, tags}:
return {content, tags}
}
-// Log in
-
-export const loginWithNip46 = async ({
- relays,
- signerPubkey,
- clientSecret = makeSecret(),
- connectSecret = "",
-}: {
- relays: string[]
- signerPubkey: string
- clientSecret?: string
- connectSecret?: string
-}) => {
- const broker = Nip46Broker.get({relays, clientSecret, signerPubkey})
- const result = await broker.connect(connectSecret, NIP46_PERMS)
-
- // TODO: remove ack result
- if (!["ack", connectSecret].includes(result)) return false
-
- const pubkey = await broker.getPublicKey()
-
- if (!pubkey) return false
-
- await loadUserData(pubkey)
-
- const handler = {relays, pubkey: signerPubkey}
-
- addSession({method: "nip46", pubkey, secret: clientSecret, handler})
-
- return true
-}
-
// Log out
export const logout = async () => {
diff --git a/src/app/components/BunkerConnect.svelte b/src/app/components/BunkerConnect.svelte
index def39b5..f90d135 100644
--- a/src/app/components/BunkerConnect.svelte
+++ b/src/app/components/BunkerConnect.svelte
@@ -26,7 +26,7 @@
let response
try {
- response = await this.broker.waitForNostrconnect(this.url, this.abortController)
+ response = await this.broker.waitForNostrconnect(this.url, this.abortController.signal)
} catch (errorResponse: any) {
if (errorResponse?.error) {
pushToast({
diff --git a/src/app/components/LogIn.svelte b/src/app/components/LogIn.svelte
index 026eec5..91e80ea 100644
--- a/src/app/components/LogIn.svelte
+++ b/src/app/components/LogIn.svelte
@@ -2,7 +2,7 @@
import {onMount} from "svelte"
import {Capacitor} from "@capacitor/core"
import {getNip07, getNip55, Nip55Signer} from "@welshman/signer"
- import {addSession, type Session} from "@welshman/app"
+ import {addSession, type Session, makeNip07Session, makeNip55Session} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Link from "@lib/components/Link.svelte"
import Button from "@lib/components/Button.svelte"
@@ -39,7 +39,7 @@
const pubkey = await getNip07()?.getPublicKey()
if (pubkey) {
- await onSuccess({method: "nip07", pubkey})
+ await onSuccess(makeNip07Session(pubkey))
} else {
pushToast({
theme: "error",
@@ -59,7 +59,7 @@
const pubkey = await signer.getPubkey()
if (pubkey) {
- await onSuccess({method: "nip55", pubkey, signer: app.packageName})
+ await onSuccess(makeNip55Session(pubkey, app.packageName))
} else {
pushToast({
theme: "error",
diff --git a/src/app/components/LogInBunker.svelte b/src/app/components/LogInBunker.svelte
index 5c152cc..419f948 100644
--- a/src/app/components/LogInBunker.svelte
+++ b/src/app/components/LogInBunker.svelte
@@ -1,7 +1,7 @@
diff --git a/src/app/components/LogInPassword.svelte b/src/app/components/LogInPassword.svelte
index cd76832..a72a18a 100644
--- a/src/app/components/LogInPassword.svelte
+++ b/src/app/components/LogInPassword.svelte
@@ -3,7 +3,7 @@
import {postJson, stripProtocol} from "@welshman/lib"
import {Nip46Broker, makeSecret} from "@welshman/signer"
import {normalizeRelayUrl} from "@welshman/util"
- import {addSession} from "@welshman/app"
+ import {addSession, makeNip46Session} from "@welshman/app"
import {preventDefault} from "@lib/html"
import Spinner from "@lib/components/Spinner.svelte"
import Button from "@lib/components/Button.svelte"
@@ -68,7 +68,7 @@
let response
try {
- response = await broker.waitForNostrconnect(url, abortController)
+ response = await broker.waitForNostrconnect(url, abortController.signal)
} catch (errorResponse: any) {
if (errorResponse?.error) {
pushToast({
@@ -83,17 +83,12 @@
if (response) {
loading = true
- const userPubkey = await broker.getPublicKey()
+ const pubkey = await broker.getPublicKey()
+ const session = makeNip46Session(pubkey, clientSecret, response.event.pubkey, relays)
- await loadUserData(userPubkey)
+ await loadUserData(pubkey)
- addSession({
- email,
- method: "nip46",
- pubkey: userPubkey,
- secret: clientSecret,
- handler: {pubkey: response.event.pubkey, relays},
- })
+ addSession({...session, email})
setChecked("*")
clearModals()
diff --git a/src/app/components/SignUpKey.svelte b/src/app/components/SignUpKey.svelte
index 6e521f6..9afbacc 100644
--- a/src/app/components/SignUpKey.svelte
+++ b/src/app/components/SignUpKey.svelte
@@ -1,7 +1,7 @@
diff --git a/src/app/components/SignUpProfile.svelte b/src/app/components/SignUpProfile.svelte
index 863e5a0..4532366 100644
--- a/src/app/components/SignUpProfile.svelte
+++ b/src/app/components/SignUpProfile.svelte
@@ -1,22 +1,21 @@
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 1564c72..3918556 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -10,7 +10,7 @@
import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
import type {TrustedEvent, StampedEvent} from "@welshman/util"
import {WRAP} from "@welshman/util"
- import {Nip46Broker, getPubkey, makeSecret} from "@welshman/signer"
+ import {Nip46Broker, makeSecret} from "@welshman/signer"
import type {Socket} from "@welshman/net"
import {request, defaultSocketPolicies, makeSocketPolicyAuth} from "@welshman/net"
import {
@@ -25,7 +25,8 @@
dropSession,
getRelayUrls,
userInboxRelaySelections,
- addSession,
+ loginWithNip01,
+ loginWithNip46,
} from "@welshman/app"
import * as lib from "@welshman/lib"
import * as util from "@welshman/util"
@@ -40,7 +41,6 @@
import {theme} from "@app/theme"
import {INDEXER_RELAYS, userMembership, ensureUnwrapped, canDecrypt} from "@app/state"
import {loadUserData, listenForNotifications} from "@app/requests"
- import {loginWithNip46} from "@app/commands"
import * as commands from "@app/commands"
import * as requests from "@app/requests"
import * as notifications from "@app/notifications"
@@ -81,14 +81,21 @@
try {
if (login?.startsWith("bunker://")) {
- success = await loginWithNip46({
- clientSecret: makeSecret(),
- ...Nip46Broker.parseBunkerUrl(login),
- })
- } else if (login) {
- const secret = nsecDecode(login)
+ const clientSecret = makeSecret()
+ const {signerPubkey, connectSecret, relays} = Nip46Broker.parseBunkerUrl(login)
+ const broker = Nip46Broker.get({relays, clientSecret, signerPubkey})
+ const result = await broker.connect(connectSecret, appState.NIP46_PERMS)
+ const pubkey = await broker.getPublicKey()
- addSession({method: "nip01", secret, pubkey: getPubkey(secret)})
+ // TODO: remove ack result
+ if (pubkey && ["ack", connectSecret].includes(result)) {
+ await loadUserData(pubkey)
+
+ loginWithNip46(pubkey, clientSecret, signerPubkey, relays)
+ success = true
+ }
+ } else if (login) {
+ loginWithNip01(nsecDecode(login))
success = true
}
} catch (e) {