Allow users to opt-in to spaces that strip signatures

This commit is contained in:
Jon Staab
2025-09-03 09:02:54 -07:00
parent a94883089e
commit 99defc6d79
13 changed files with 281 additions and 58 deletions
+34 -1
View File
@@ -1,7 +1,17 @@
import {nwc} from "@getalby/sdk"
import * as nip19 from "nostr-tools/nip19"
import {get} from "svelte/store"
import {randomId, flatten, poll, uniq, equals, TIMEZONE, LOCALE} from "@welshman/lib"
import {
randomId,
append,
remove,
flatten,
poll,
uniq,
equals,
TIMEZONE,
LOCALE,
} from "@welshman/lib"
import type {Feed} from "@welshman/feeds"
import type {TrustedEvent, EventContent} from "@welshman/util"
import {
@@ -19,6 +29,7 @@ import {
ALERT_WEB,
ALERT_IOS,
ALERT_ANDROID,
APP_DATA,
isSignedEvent,
makeEvent,
displayProfile,
@@ -56,13 +67,16 @@ import {
tagEventForQuote,
getThunkError,
} from "@welshman/app"
import type {SettingsValues} from "@app/core/state"
import {
SETTINGS,
PROTECTED,
userMembership,
INDEXER_RELAYS,
NOTIFIER_PUBKEY,
NOTIFIER_RELAY,
userRoomsByUrl,
userSettingsValues,
} from "@app/core/state"
// Utils
@@ -461,6 +475,25 @@ export const makeAlert = async (params: AlertParams) => {
export const publishAlert = async (params: AlertParams) =>
publishThunk({event: await makeAlert(params), relays: [NOTIFIER_RELAY]})
// Settings
export const makeSettings = async (params: Partial<SettingsValues>) => {
const json = JSON.stringify({...userSettingsValues.get(), ...params})
const content = await signer.get().nip44.encrypt(pubkey.get()!, json)
const tags = [["d", SETTINGS]]
return makeEvent(APP_DATA, {content, tags})
}
export const publishSettings = async (params: Partial<SettingsValues>) =>
publishThunk({event: await makeSettings(params), relays: Router.get().FromUser().getUrls()})
export const addTrustedRelay = async (url: string) =>
publishSettings({trusted_relays: append(url, userSettingsValues.get().trusted_relays)})
export const removeTrustedRelay = async (url: string) =>
publishSettings({trusted_relays: remove(url, userSettingsValues.get().trusted_relays)})
// Lightning
export const getWebLn = () => (window as any).webln
+28 -15
View File
@@ -1,6 +1,6 @@
import twColors from "tailwindcss/colors"
import {Capacitor} from "@capacitor/core"
import {get, derived} from "svelte/store"
import {get, derived, writable} from "svelte/store"
import * as nip19 from "nostr-tools/nip19"
import {
on,
@@ -23,7 +23,7 @@ import {
always,
} from "@welshman/lib"
import type {Socket} from "@welshman/net"
import {Pool, load, AuthStateEvent, SocketEvent} from "@welshman/net"
import {Pool, load, AuthStateEvent, SocketEvent, netContext} from "@welshman/net"
import {
collection,
custom,
@@ -56,6 +56,7 @@ import {
ALERT_IOS,
ALERT_ANDROID,
ALERT_STATUS,
APP_DATA,
getGroupTags,
getRelayTagValues,
getPubkeyTagValues,
@@ -68,6 +69,7 @@ import {
getTag,
getTagValue,
getTagValues,
verifyEvent,
} from "@welshman/util"
import type {TrustedEvent, SignedEvent, PublishedList, List, Filter} from "@welshman/util"
import {Nip59, decrypt} from "@welshman/signer"
@@ -304,6 +306,9 @@ appContext.dufflepudUrl = DUFFLEPUD_URL
routerContext.getIndexerRelays = always(INDEXER_RELAYS)
netContext.isEventValid = (event: TrustedEvent, url: string) =>
getSetting<string[]>("trusted_relays").includes(url) || verifyEvent(event)
// Settings
export const canDecrypt = synced({
@@ -312,23 +317,27 @@ export const canDecrypt = synced({
storage: localStorageProvider,
})
export const SETTINGS = 38489
export const SETTINGS = "flotilla/settings"
export type SettingsValues = {
show_media: boolean
hide_sensitive: boolean
trusted_relays: string[]
report_usage: boolean
report_errors: boolean
send_delay: number
font_size: number
}
export type Settings = {
event: TrustedEvent
values: {
show_media: boolean
hide_sensitive: boolean
report_usage: boolean
report_errors: boolean
send_delay: number
font_size: number
}
values: SettingsValues
}
export const defaultSettings = {
show_media: true,
hide_sensitive: true,
trusted_relays: [],
report_usage: true,
report_errors: true,
send_delay: 3000,
@@ -336,7 +345,7 @@ export const defaultSettings = {
}
export const settings = deriveEventsMapped<Settings>(repository, {
filters: [{kinds: [SETTINGS]}],
filters: [{kinds: [APP_DATA], "#d": [SETTINGS]}],
itemToEvent: item => item.event,
eventToItem: async (event: TrustedEvent) => ({
event,
@@ -352,9 +361,13 @@ export const {
name: "settings",
store: settings,
getKey: settings => settings.event.pubkey,
load: makeOutboxLoader(SETTINGS),
load: makeOutboxLoader(APP_DATA, {"#d": [SETTINGS]}),
})
// Relays sending events with empty signatures that the user has to choose to trust
export const relaysPendingTrust = writable<string[]>([])
// Alerts
export type Alert = {
@@ -610,11 +623,11 @@ export const userSettings = withGetter(
}),
)
export const userSettingValues = withGetter(
export const userSettingsValues = withGetter(
derived(userSettings, $s => $s?.values || defaultSettings),
)
export const getSetting = <T>(key: keyof Settings["values"]) => userSettingValues.get()[key] as T
export const getSetting = <T>(key: keyof Settings["values"]) => userSettingsValues.get()[key] as T
export const userMembership = withGetter(
derived([pubkey, membershipsByPubkey], ([$pubkey, $membershipsByPubkey]) => {