mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 02:47:06 +00:00
Update welshman session stuff
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
||||
import {Nip46Broker, getPubkey, makeSecret} from "@welshman/signer"
|
||||
import {addSession} from "@welshman/app"
|
||||
import {Nip46Broker, makeSecret} from "@welshman/signer"
|
||||
import {loginWithNip01, loginWithNip46} from "@welshman/app"
|
||||
import {preventDefault} from "@lib/html"
|
||||
import Spinner from "@lib/components/Spinner.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
@@ -10,31 +10,21 @@
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import BunkerConnect, {BunkerConnectController} from "@app/components/BunkerConnect.svelte"
|
||||
import BunkerUrl from "@app/components/BunkerUrl.svelte"
|
||||
import {loginWithNip46} from "@app/commands"
|
||||
import {loadUserData} from "@app/requests"
|
||||
import {clearModals} from "@app/modal"
|
||||
import {setChecked} from "@app/notifications"
|
||||
import {pushToast} from "@app/toast"
|
||||
import {SIGNER_RELAYS} from "@app/state"
|
||||
import {SIGNER_RELAYS, NIP46_PERMS} from "@app/state"
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const controller = new BunkerConnectController({
|
||||
onNostrConnect: async (response: Nip46ResponseWithResult) => {
|
||||
const userPubkey = await controller.broker.getPublicKey()
|
||||
const pubkey = await controller.broker.getPublicKey()
|
||||
|
||||
await loadUserData(userPubkey)
|
||||
|
||||
addSession({
|
||||
method: "nip46",
|
||||
pubkey: userPubkey,
|
||||
secret: controller.clientSecret,
|
||||
handler: {
|
||||
pubkey: response.event.pubkey,
|
||||
relays: SIGNER_RELAYS,
|
||||
},
|
||||
})
|
||||
await loadUserData(pubkey)
|
||||
|
||||
loginWithNip46(pubkey, controller.clientSecret, response.event.pubkey, SIGNER_RELAYS)
|
||||
setChecked("*")
|
||||
clearModals()
|
||||
},
|
||||
@@ -56,10 +46,17 @@
|
||||
|
||||
try {
|
||||
const {clientSecret} = controller
|
||||
const success = await loginWithNip46({connectSecret, clientSecret, signerPubkey, relays})
|
||||
const broker = Nip46Broker.get({relays, clientSecret, signerPubkey})
|
||||
const result = await broker.connect(connectSecret, NIP46_PERMS)
|
||||
const pubkey = await broker.getPublicKey()
|
||||
|
||||
if (success) {
|
||||
// TODO: remove ack result
|
||||
if (pubkey && ["ack", connectSecret].includes(result)) {
|
||||
controller.stop()
|
||||
|
||||
await loadUserData(pubkey)
|
||||
|
||||
loginWithNip46(pubkey, clientSecret, signerPubkey, relays)
|
||||
} else {
|
||||
return pushToast({
|
||||
theme: "error",
|
||||
@@ -76,9 +73,7 @@
|
||||
$effect(() => {
|
||||
// For testing and for play store reviewers
|
||||
if (controller.bunker === "reviewkey") {
|
||||
const secret = makeSecret()
|
||||
|
||||
addSession({method: "nip01", secret, pubkey: getPubkey(secret)})
|
||||
loginWithNip01(makeSecret())
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {encrypt} from "nostr-tools/nip49"
|
||||
import {hexToBytes} from "@noble/hashes/utils"
|
||||
import {makeSecret, getPubkey} from "@welshman/signer"
|
||||
import {makeSecret} from "@welshman/signer"
|
||||
import {preventDefault, downloadText} from "@lib/html"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
@@ -15,8 +15,6 @@
|
||||
|
||||
const secret = makeSecret()
|
||||
|
||||
const pubkey = getPubkey(secret)
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const next = () => {
|
||||
@@ -31,7 +29,7 @@
|
||||
|
||||
downloadText("Nostr Secret Key.txt", ncryptsec)
|
||||
|
||||
pushModal(SignUpKeyConfirm, {secret, pubkey, ncryptsec})
|
||||
pushModal(SignUpKeyConfirm, {secret, ncryptsec})
|
||||
}
|
||||
|
||||
let password = ""
|
||||
|
||||
@@ -11,11 +11,10 @@
|
||||
|
||||
type Props = {
|
||||
secret: string
|
||||
pubkey: string
|
||||
ncryptsec: string
|
||||
}
|
||||
|
||||
const {secret, pubkey, ncryptsec}: Props = $props()
|
||||
const {secret, ncryptsec}: Props = $props()
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
@@ -25,7 +24,7 @@
|
||||
}
|
||||
|
||||
const next = () => {
|
||||
pushModal(SignUpProfile, {secret, pubkey})
|
||||
pushModal(SignUpProfile, {secret})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<script lang="ts">
|
||||
import type {Profile} from "@welshman/util"
|
||||
import {PROFILE, createProfile, createEvent} from "@welshman/util"
|
||||
import {addSession, publishThunk} from "@welshman/app"
|
||||
import {loginWithNip01, publishThunk} from "@welshman/app"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
|
||||
import {INDEXER_RELAYS} from "@app/state"
|
||||
|
||||
type Props = {
|
||||
secret: string
|
||||
pubkey: string
|
||||
}
|
||||
|
||||
const {secret, pubkey}: Props = $props()
|
||||
const {secret}: Props = $props()
|
||||
|
||||
const onsubmit = (profile: Profile) => {
|
||||
const event = createEvent(PROFILE, createProfile(profile))
|
||||
|
||||
addSession({method: "nip01", secret, pubkey})
|
||||
loginWithNip01(secret)
|
||||
publishThunk({event, relays: INDEXER_RELAYS})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user