Skip to content

Commit

Permalink
Nostrconnect (#467)
Browse files Browse the repository at this point in the history
* Get nostrconnect basically working

* Re-work login to use nostrconnect flow

* Load feeds more eagerly, not just on feed list page

* remove some community utils

* Move initNip46 to commands

* Bump welshman

* Small tweaks

* Move some nostrconnect stuff around, remove nostrconnect login

---------

Co-authored-by: Jon Staab <[email protected]>
  • Loading branch information
staab and Jon Staab authored Nov 12, 2024
1 parent 20826be commit df0d7b1
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 286 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
"@types/ramda": "^0.30.2",
"@types/throttle-debounce": "^5.0.2",
"@vite-pwa/assets-generator": "^0.2.6",
"@welshman/app": "~0.0.23",
"@welshman/app": "~0.0.24",
"@welshman/content": "~0.0.12",
"@welshman/dvm": "~0.0.10",
"@welshman/feeds": "~0.0.23",
"@welshman/feeds": "~0.0.25",
"@welshman/lib": "~0.0.24",
"@welshman/net": "~0.0.33",
"@welshman/signer": "~0.0.11",
"@welshman/net": "~0.0.34",
"@welshman/signer": "~0.0.12",
"@welshman/store": "~0.0.12",
"@welshman/util": "~0.0.45",
"autoprefixer": "^10.4.20",
Expand Down
32 changes: 11 additions & 21 deletions src/app/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import {ctx, ago, max, sleep, memoize} from "@welshman/lib"
import * as lib from "@welshman/lib"
import * as util from "@welshman/util"
import {
relaysByUrl,
getRelayQuality,
getPubkeyRelays,
trackRelayStats,
loadRelay,
} from "@welshman/app"
import {getRelayQuality, getPubkeyRelays, trackRelayStats, loadRelay} from "@welshman/app"
import * as app from "@welshman/app"
import logger from "src/util/logger"
import * as misc from "src/util/misc"
Expand Down Expand Up @@ -447,20 +441,16 @@
slowConnections.set(getPubkeyRelays($pubkey).filter(url => getRelayQuality(url) < 0.5))
// Prune connections we haven't used in a while
for (const url of ctx.net.pool.data.keys()) {
const relay = relaysByUrl.get().get(url)
if (relay?.stats) {
const lastActivity = max([
relay.stats.last_open,
relay.stats.last_publish,
relay.stats.last_request,
relay.stats.last_event,
])
if (lastActivity < ago(30)) {
ctx.net.pool.remove(url)
}
for (const connection of ctx.net.pool.data.values()) {
const lastActivity = max([
connection.stats.lastOpen,
connection.stats.lastPublish,
connection.stats.lastRequest,
connection.stats.lastEvent,
])
if (lastActivity && lastActivity < ago(30)) {
ctx.net.pool.remove(connection.url)
}
}
}, 5_000)
Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/EditBolt11.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<NodeViewWrapper class="inline">
<Anchor on:click={copy} class={cx("link-content", {"link-content-selected": selected})}>
<i class="fas fa-bolt inline-block translate-y-px"></i>
<i class="fas fa-xs fa-bolt inline-block translate-y-px"></i>
{node.attrs.lnbc.slice(0, 16)}...
</Anchor>
</NodeViewWrapper>
6 changes: 3 additions & 3 deletions src/app/editor/EditLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import cx from "classnames"
import type {NodeViewProps} from "@tiptap/core"
import {NodeViewWrapper} from "svelte-tiptap"
import {displayUrl} from "@welshman/lib"
import {displayUrl, normalizeUrl} from "@welshman/lib"
export let node: NodeViewProps["node"]
export let selected: NodeViewProps["selected"]
Expand All @@ -12,9 +12,9 @@
<a
target="_blank"
rel="noopener noreferrer"
href={node.attrs.url}
href={normalizeUrl(node.attrs.url)}
class={cx("link-content", {"link-content-selected": selected})}>
<i class="fas fa-link inline-block"></i>
<i class="fas fa-xs fa-link inline-block"></i>
{displayUrl(node.attrs.url)}
</a>
</NodeViewWrapper>
2 changes: 1 addition & 1 deletion src/app/editor/EditMedia.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"link-content-selected": selected,
})}>
<span class:loading={node.attrs.uploading}>
<i class="fas fa-paperclip"></i>
<i class="fas fa-xs fa-paperclip"></i>
{node.attrs.file?.name || node.attrs.src}
</span>
</NodeViewWrapper>
4 changes: 0 additions & 4 deletions src/app/shared/FeedFormSectionKinds.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
EVENT_RSVP,
HANDLER_RECOMMENDATION,
HANDLER_INFORMATION,
COMMUNITY,
GROUP,
FILE_METADATA,
RELAYS,
} from "@welshman/util"
Expand Down Expand Up @@ -57,8 +55,6 @@
{label: "Calendar event RSVP", kind: EVENT_RSVP},
{label: "Handler recommendation", kind: HANDLER_RECOMMENDATION},
{label: "Handler information", kind: HANDLER_INFORMATION},
{label: "Community definition", kind: COMMUNITY},
{label: "Group definition", kind: GROUP},
{label: "Image", kind: FILE_METADATA},
{label: "Relay selections", kind: RELAYS},
])
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/RelayStatus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {onMount} from "svelte"
import {ctx} from "@welshman/lib"
import {SocketStatus, AuthStatus} from "@welshman/net"
import {getRelayQuality} from "@welshman/app"
import Popover from "src/partials/Popover.svelte"
export let url
Expand Down Expand Up @@ -35,6 +36,9 @@
} else if (cxn.socket.status === SocketStatus.New) {
className = "bg-neutral-600"
description = "Not connected"
} else if (getRelayQuality(cxn.url) < 0.5) {
className = "bg-warning"
description = "Unstable connection"
} else {
className = "bg-success"
description = "Connected"
Expand Down
13 changes: 10 additions & 3 deletions src/app/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {writable} from "svelte/store"
import {writable, get} from "svelte/store"
import {uniq} from "@welshman/lib"
import {COMMUNITIES, FEEDS, APP_DATA} from "@welshman/util"
import {FEEDS, APP_DATA, getAddressTagValues, getIdFilters, getListTags} from "@welshman/util"
import {
pubkey,
loadZapper,
Expand All @@ -26,6 +26,7 @@ import {
loadNotifications,
loadFeedsAndLists,
listenForNotifications,
userFeedFavorites,
getSetting,
} from "src/engine"

Expand Down Expand Up @@ -65,16 +66,22 @@ export const loadUserData = async (hints: string[] = []) => {
// Load less important user data
loadZapper($pubkey)
loadHandle($pubkey)

// Load user feed selections, app data, and feeds that were favorited by the user
load({
relays,
filters: [
{authors: [$pubkey], kinds: [COMMUNITIES, FEEDS]},
{authors: [$pubkey], kinds: [FEEDS]},
{
authors: [$pubkey],
kinds: [APP_DATA],
"#d": Object.values(appDataKeys),
},
],
}).then(() => {
const addrs = getAddressTagValues(getListTags(get(userFeedFavorites)))

load({filters: getIdFilters(addrs)})
})

// Load enough to figure out web of trust
Expand Down
3 changes: 0 additions & 3 deletions src/app/views/FeedList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
userFeeds,
feedSearch,
userListFeeds,
feedFavorites,
userFavoritedFeeds,
userFollows,
addSinceToFilter,
Expand Down Expand Up @@ -59,8 +58,6 @@
sortBy(displayFeed, [...$userFeeds, ...$userListFeeds, ...$userFavoritedFeeds]),
)
loadFeeds($feedFavorites.flatMap(s => getAddressTagValues(s.event.tags)))
load({
skipCache: true,
forcePlatform: false,
Expand Down
20 changes: 19 additions & 1 deletion src/app/views/Help.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export let topic
const topics = ["web-of-trust", "nip-17-dms"]
const topics = ["web-of-trust", "nip-17-dms", "remote-signers"]
const nip17Url = "https://github.com/nostr-protocol/nips/blob/master/17.md"
</script>

Expand All @@ -27,6 +27,24 @@
You can set a minimum web of trust score on your content settings page, which will
automatically mute anyone with a lower score than your threshold.
</p>
{:else if topic === "remote-signers"}
<p>
Nostr uses cryptographic key pairs instead of passwords to authenticate users. This means that
you and nobody else controls your social identity - however it also requires some care to
avoid losing your keys, or having them stolen.
</p>
<p>
Instead of pasting your private key (also known as an "nsec") into every nostr app you use,
it's wise to choose a single signer application to keep them for you.
</p>
<p>
These signer apps may live on the internet, in which case you can simply log in by specifying
the signer's url. You can also run your own signer on your phone or computer. This method is
more secure, but a little more complicated to manage.
</p>
<Anchor external button tall low href="https://nostrapps.com/#Signers">
<i class="fa fa-compass" /> Browse Signer Apps
</Anchor>
{:else if topic === "nip-17-dms"}
<p>
<Anchor underline external href={nip17Url}>NIP 17</Anchor> improves upon the old NIP 04 direct
Expand Down
Loading

0 comments on commit df0d7b1

Please sign in to comment.