mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Update welshman session stuff
This commit is contained in:
@@ -32,7 +32,7 @@ import {
|
|||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
|
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
|
||||||
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
|
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
|
||||||
import {Nip59, makeSecret, stamp, Nip46Broker} from "@welshman/signer"
|
import {Nip59, stamp} from "@welshman/signer"
|
||||||
import {
|
import {
|
||||||
pubkey,
|
pubkey,
|
||||||
signer,
|
signer,
|
||||||
@@ -49,7 +49,6 @@ import {
|
|||||||
userInboxRelaySelections,
|
userInboxRelaySelections,
|
||||||
nip44EncryptToSelf,
|
nip44EncryptToSelf,
|
||||||
loadRelay,
|
loadRelay,
|
||||||
addSession,
|
|
||||||
clearStorage,
|
clearStorage,
|
||||||
dropSession,
|
dropSession,
|
||||||
tagEventForComment,
|
tagEventForComment,
|
||||||
@@ -62,13 +61,11 @@ import {
|
|||||||
PROTECTED,
|
PROTECTED,
|
||||||
userMembership,
|
userMembership,
|
||||||
INDEXER_RELAYS,
|
INDEXER_RELAYS,
|
||||||
NIP46_PERMS,
|
|
||||||
ALERT,
|
ALERT,
|
||||||
NOTIFIER_PUBKEY,
|
NOTIFIER_PUBKEY,
|
||||||
NOTIFIER_RELAY,
|
NOTIFIER_RELAY,
|
||||||
userRoomsByUrl,
|
userRoomsByUrl,
|
||||||
} from "@app/state"
|
} from "@app/state"
|
||||||
import {loadUserData} from "@app/requests"
|
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
|
|
||||||
@@ -112,38 +109,6 @@ export const prependParent = (parent: TrustedEvent | undefined, {content, tags}:
|
|||||||
return {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
|
// Log out
|
||||||
|
|
||||||
export const logout = async () => {
|
export const logout = async () => {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
let response
|
let response
|
||||||
try {
|
try {
|
||||||
response = await this.broker.waitForNostrconnect(this.url, this.abortController)
|
response = await this.broker.waitForNostrconnect(this.url, this.abortController.signal)
|
||||||
} catch (errorResponse: any) {
|
} catch (errorResponse: any) {
|
||||||
if (errorResponse?.error) {
|
if (errorResponse?.error) {
|
||||||
pushToast({
|
pushToast({
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {Capacitor} from "@capacitor/core"
|
import {Capacitor} from "@capacitor/core"
|
||||||
import {getNip07, getNip55, Nip55Signer} from "@welshman/signer"
|
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 Icon from "@lib/components/Icon.svelte"
|
||||||
import Link from "@lib/components/Link.svelte"
|
import Link from "@lib/components/Link.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
const pubkey = await getNip07()?.getPublicKey()
|
const pubkey = await getNip07()?.getPublicKey()
|
||||||
|
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
await onSuccess({method: "nip07", pubkey})
|
await onSuccess(makeNip07Session(pubkey))
|
||||||
} else {
|
} else {
|
||||||
pushToast({
|
pushToast({
|
||||||
theme: "error",
|
theme: "error",
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
const pubkey = await signer.getPubkey()
|
const pubkey = await signer.getPubkey()
|
||||||
|
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
await onSuccess({method: "nip55", pubkey, signer: app.packageName})
|
await onSuccess(makeNip55Session(pubkey, app.packageName))
|
||||||
} else {
|
} else {
|
||||||
pushToast({
|
pushToast({
|
||||||
theme: "error",
|
theme: "error",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
||||||
import {Nip46Broker, getPubkey, makeSecret} from "@welshman/signer"
|
import {Nip46Broker, makeSecret} from "@welshman/signer"
|
||||||
import {addSession} from "@welshman/app"
|
import {loginWithNip01, loginWithNip46} from "@welshman/app"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
@@ -10,31 +10,21 @@
|
|||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
import BunkerConnect, {BunkerConnectController} from "@app/components/BunkerConnect.svelte"
|
import BunkerConnect, {BunkerConnectController} from "@app/components/BunkerConnect.svelte"
|
||||||
import BunkerUrl from "@app/components/BunkerUrl.svelte"
|
import BunkerUrl from "@app/components/BunkerUrl.svelte"
|
||||||
import {loginWithNip46} from "@app/commands"
|
|
||||||
import {loadUserData} from "@app/requests"
|
import {loadUserData} from "@app/requests"
|
||||||
import {clearModals} from "@app/modal"
|
import {clearModals} from "@app/modal"
|
||||||
import {setChecked} from "@app/notifications"
|
import {setChecked} from "@app/notifications"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
import {SIGNER_RELAYS} from "@app/state"
|
import {SIGNER_RELAYS, NIP46_PERMS} from "@app/state"
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const controller = new BunkerConnectController({
|
const controller = new BunkerConnectController({
|
||||||
onNostrConnect: async (response: Nip46ResponseWithResult) => {
|
onNostrConnect: async (response: Nip46ResponseWithResult) => {
|
||||||
const userPubkey = await controller.broker.getPublicKey()
|
const pubkey = await controller.broker.getPublicKey()
|
||||||
|
|
||||||
await loadUserData(userPubkey)
|
await loadUserData(pubkey)
|
||||||
|
|
||||||
addSession({
|
|
||||||
method: "nip46",
|
|
||||||
pubkey: userPubkey,
|
|
||||||
secret: controller.clientSecret,
|
|
||||||
handler: {
|
|
||||||
pubkey: response.event.pubkey,
|
|
||||||
relays: SIGNER_RELAYS,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
|
loginWithNip46(pubkey, controller.clientSecret, response.event.pubkey, SIGNER_RELAYS)
|
||||||
setChecked("*")
|
setChecked("*")
|
||||||
clearModals()
|
clearModals()
|
||||||
},
|
},
|
||||||
@@ -56,10 +46,17 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const {clientSecret} = controller
|
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()
|
controller.stop()
|
||||||
|
|
||||||
|
await loadUserData(pubkey)
|
||||||
|
|
||||||
|
loginWithNip46(pubkey, clientSecret, signerPubkey, relays)
|
||||||
} else {
|
} else {
|
||||||
return pushToast({
|
return pushToast({
|
||||||
theme: "error",
|
theme: "error",
|
||||||
@@ -76,9 +73,7 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
// For testing and for play store reviewers
|
// For testing and for play store reviewers
|
||||||
if (controller.bunker === "reviewkey") {
|
if (controller.bunker === "reviewkey") {
|
||||||
const secret = makeSecret()
|
loginWithNip01(makeSecret())
|
||||||
|
|
||||||
addSession({method: "nip01", secret, pubkey: getPubkey(secret)})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import {postJson, stripProtocol} from "@welshman/lib"
|
import {postJson, stripProtocol} from "@welshman/lib"
|
||||||
import {Nip46Broker, makeSecret} from "@welshman/signer"
|
import {Nip46Broker, makeSecret} from "@welshman/signer"
|
||||||
import {normalizeRelayUrl} from "@welshman/util"
|
import {normalizeRelayUrl} from "@welshman/util"
|
||||||
import {addSession} from "@welshman/app"
|
import {addSession, makeNip46Session} from "@welshman/app"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
let response
|
let response
|
||||||
try {
|
try {
|
||||||
response = await broker.waitForNostrconnect(url, abortController)
|
response = await broker.waitForNostrconnect(url, abortController.signal)
|
||||||
} catch (errorResponse: any) {
|
} catch (errorResponse: any) {
|
||||||
if (errorResponse?.error) {
|
if (errorResponse?.error) {
|
||||||
pushToast({
|
pushToast({
|
||||||
@@ -83,17 +83,12 @@
|
|||||||
if (response) {
|
if (response) {
|
||||||
loading = true
|
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({
|
addSession({...session, email})
|
||||||
email,
|
|
||||||
method: "nip46",
|
|
||||||
pubkey: userPubkey,
|
|
||||||
secret: clientSecret,
|
|
||||||
handler: {pubkey: response.event.pubkey, relays},
|
|
||||||
})
|
|
||||||
|
|
||||||
setChecked("*")
|
setChecked("*")
|
||||||
clearModals()
|
clearModals()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {encrypt} from "nostr-tools/nip49"
|
import {encrypt} from "nostr-tools/nip49"
|
||||||
import {hexToBytes} from "@noble/hashes/utils"
|
import {hexToBytes} from "@noble/hashes/utils"
|
||||||
import {makeSecret, getPubkey} from "@welshman/signer"
|
import {makeSecret} from "@welshman/signer"
|
||||||
import {preventDefault, downloadText} from "@lib/html"
|
import {preventDefault, downloadText} from "@lib/html"
|
||||||
import Link from "@lib/components/Link.svelte"
|
import Link from "@lib/components/Link.svelte"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
@@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
const secret = makeSecret()
|
const secret = makeSecret()
|
||||||
|
|
||||||
const pubkey = getPubkey(secret)
|
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
@@ -31,7 +29,7 @@
|
|||||||
|
|
||||||
downloadText("Nostr Secret Key.txt", ncryptsec)
|
downloadText("Nostr Secret Key.txt", ncryptsec)
|
||||||
|
|
||||||
pushModal(SignUpKeyConfirm, {secret, pubkey, ncryptsec})
|
pushModal(SignUpKeyConfirm, {secret, ncryptsec})
|
||||||
}
|
}
|
||||||
|
|
||||||
let password = ""
|
let password = ""
|
||||||
|
|||||||
@@ -11,11 +11,10 @@
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
secret: string
|
secret: string
|
||||||
pubkey: string
|
|
||||||
ncryptsec: string
|
ncryptsec: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const {secret, pubkey, ncryptsec}: Props = $props()
|
const {secret, ncryptsec}: Props = $props()
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
pushModal(SignUpProfile, {secret, pubkey})
|
pushModal(SignUpProfile, {secret})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Profile} from "@welshman/util"
|
import type {Profile} from "@welshman/util"
|
||||||
import {PROFILE, createProfile, createEvent} 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 Button from "@lib/components/Button.svelte"
|
||||||
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
|
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
|
||||||
import {INDEXER_RELAYS} from "@app/state"
|
import {INDEXER_RELAYS} from "@app/state"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
secret: string
|
secret: string
|
||||||
pubkey: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {secret, pubkey}: Props = $props()
|
const {secret}: Props = $props()
|
||||||
|
|
||||||
const onsubmit = (profile: Profile) => {
|
const onsubmit = (profile: Profile) => {
|
||||||
const event = createEvent(PROFILE, createProfile(profile))
|
const event = createEvent(PROFILE, createProfile(profile))
|
||||||
|
|
||||||
addSession({method: "nip01", secret, pubkey})
|
loginWithNip01(secret)
|
||||||
publishThunk({event, relays: INDEXER_RELAYS})
|
publishThunk({event, relays: INDEXER_RELAYS})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
|
import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
|
||||||
import type {TrustedEvent, StampedEvent} from "@welshman/util"
|
import type {TrustedEvent, StampedEvent} from "@welshman/util"
|
||||||
import {WRAP} 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 type {Socket} from "@welshman/net"
|
||||||
import {request, defaultSocketPolicies, makeSocketPolicyAuth} from "@welshman/net"
|
import {request, defaultSocketPolicies, makeSocketPolicyAuth} from "@welshman/net"
|
||||||
import {
|
import {
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
dropSession,
|
dropSession,
|
||||||
getRelayUrls,
|
getRelayUrls,
|
||||||
userInboxRelaySelections,
|
userInboxRelaySelections,
|
||||||
addSession,
|
loginWithNip01,
|
||||||
|
loginWithNip46,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import * as lib from "@welshman/lib"
|
import * as lib from "@welshman/lib"
|
||||||
import * as util from "@welshman/util"
|
import * as util from "@welshman/util"
|
||||||
@@ -40,7 +41,6 @@
|
|||||||
import {theme} from "@app/theme"
|
import {theme} from "@app/theme"
|
||||||
import {INDEXER_RELAYS, userMembership, ensureUnwrapped, canDecrypt} from "@app/state"
|
import {INDEXER_RELAYS, userMembership, ensureUnwrapped, canDecrypt} from "@app/state"
|
||||||
import {loadUserData, listenForNotifications} from "@app/requests"
|
import {loadUserData, listenForNotifications} from "@app/requests"
|
||||||
import {loginWithNip46} from "@app/commands"
|
|
||||||
import * as commands from "@app/commands"
|
import * as commands from "@app/commands"
|
||||||
import * as requests from "@app/requests"
|
import * as requests from "@app/requests"
|
||||||
import * as notifications from "@app/notifications"
|
import * as notifications from "@app/notifications"
|
||||||
@@ -81,14 +81,21 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (login?.startsWith("bunker://")) {
|
if (login?.startsWith("bunker://")) {
|
||||||
success = await loginWithNip46({
|
const clientSecret = makeSecret()
|
||||||
clientSecret: makeSecret(),
|
const {signerPubkey, connectSecret, relays} = Nip46Broker.parseBunkerUrl(login)
|
||||||
...Nip46Broker.parseBunkerUrl(login),
|
const broker = Nip46Broker.get({relays, clientSecret, signerPubkey})
|
||||||
})
|
const result = await broker.connect(connectSecret, appState.NIP46_PERMS)
|
||||||
} else if (login) {
|
const pubkey = await broker.getPublicKey()
|
||||||
const secret = nsecDecode(login)
|
|
||||||
|
|
||||||
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
|
success = true
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user