fix: only add protected tag on relays that advertise NIP-70 support (#305)
Co-authored-by: userAdityaa <aditya.chaudhary1558@gmail.com> Co-committed-by: userAdityaa <aditya.chaudhary1558@gmail.com>
This commit was merged in pull request #305.
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
const relays = url ? [url] : Router.get().Event(event).getUrls()
|
const relays = url ? [url] : Router.get().Event(event).getUrls()
|
||||||
|
|
||||||
const shouldProtect = url ? canEnforceNip70(url) : Promise.resolve(false)
|
const shouldProtect = url ? canEnforceNip70(url) : false
|
||||||
|
|
||||||
const deleteReaction = async (event: TrustedEvent) =>
|
const deleteReaction = async (event: TrustedEvent) =>
|
||||||
publishDelete({relays, event, protect: await shouldProtect})
|
publishDelete({relays, event, protect: await shouldProtect})
|
||||||
|
|||||||
+12
-8
@@ -24,7 +24,14 @@ import {
|
|||||||
uniq,
|
uniq,
|
||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import {throttled} from "@welshman/store"
|
import {throttled} from "@welshman/store"
|
||||||
import {loadRelay, manageRelay, publishThunk, sign, waitForThunkError} from "@welshman/app"
|
import {
|
||||||
|
getRelay,
|
||||||
|
loadRelay,
|
||||||
|
manageRelay,
|
||||||
|
publishThunk,
|
||||||
|
sign,
|
||||||
|
waitForThunkError,
|
||||||
|
} from "@welshman/app"
|
||||||
import {checkRelayHasLivekit} from "$lib/livekit"
|
import {checkRelayHasLivekit} from "$lib/livekit"
|
||||||
import {stripPrefix} from "@lib/util"
|
import {stripPrefix} from "@lib/util"
|
||||||
import {relaysMostlyRestricted} from "@app/policies"
|
import {relaysMostlyRestricted} from "@app/policies"
|
||||||
@@ -35,6 +42,9 @@ export const hasNip29 = (relay?: RelayProfile) =>
|
|||||||
export const hasNip50 = (relay?: RelayProfile) =>
|
export const hasNip50 = (relay?: RelayProfile) =>
|
||||||
Boolean(relay?.supported_nips?.map?.(String)?.includes?.("50"))
|
Boolean(relay?.supported_nips?.map?.(String)?.includes?.("50"))
|
||||||
|
|
||||||
|
export const hasNip70 = (relay?: RelayProfile) =>
|
||||||
|
Boolean(relay?.supported_nips?.map?.(String)?.includes?.("70"))
|
||||||
|
|
||||||
export const encodeRelay = (url: string) =>
|
export const encodeRelay = (url: string) =>
|
||||||
encodeURIComponent(
|
encodeURIComponent(
|
||||||
normalizeRelayUrl(url)
|
normalizeRelayUrl(url)
|
||||||
@@ -151,13 +161,7 @@ export const requestRelayClaims = async (urls: string[]) =>
|
|||||||
fromPairs(await Promise.all(urls.map(async url => [url, await requestRelayClaim(url)]))),
|
fromPairs(await Promise.all(urls.map(async url => [url, await requestRelayClaim(url)]))),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const canEnforceNip70 = async (url: string) => {
|
export const canEnforceNip70 = (url: string) => hasNip70(getRelay(url))
|
||||||
const socket = Pool.get().get(url)
|
|
||||||
|
|
||||||
await socket.auth.attemptAuth(sign)
|
|
||||||
|
|
||||||
return socket.auth.status !== AuthStatus.None
|
|
||||||
}
|
|
||||||
|
|
||||||
export const attemptRelayAccess = async (url: string, claim = "") => {
|
export const attemptRelayAccess = async (url: string, claim = "") => {
|
||||||
const socket = Pool.get().get(url)
|
const socket = Pool.get().get(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user