diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index d8e9fa48..81eb2d7f 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -74,6 +74,7 @@ import {Pool, AuthStatus, SocketStatus} from "@welshman/net" import {Router} from "@welshman/router" import { pubkey, + sign, signer, session, repository, @@ -253,7 +254,7 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => { export const canEnforceNip70 = async (url: string) => { const socket = Pool.get().get(url) - await socket.auth.attemptAuth(e => signer.get()?.sign(e)) + await socket.auth.attemptAuth(sign) return socket.auth.status !== AuthStatus.None } @@ -272,7 +273,7 @@ export const attemptRelayAccess = async (url: string, claim = "") => { return `Failed to connect` } - await socket.auth.attemptAuth(e => signer.get()?.sign(e)) + await socket.auth.attemptAuth(sign) // Only raise an error if it's not a timeout. // If it is, odds are the problem is with our signer, not the relay @@ -504,9 +505,7 @@ export const createAlert = async (params: CreateAlertParams): Promise signer.get()?.sign(e)) + await Pool.get().get(NOTIFIER_RELAY).auth.attemptAuth(sign) const thunk = await publishAlert(params as AlertParams) const error = await waitForThunkError(thunk) diff --git a/src/app/core/state.ts b/src/app/core/state.ts index 3852220e..5636613f 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -114,6 +114,7 @@ import { userFollows, ensurePlaintext, thunks, + sign, signer, makeOutboxLoader, appContext, @@ -961,12 +962,10 @@ export const deriveTimeout = (timeout: number) => { } export const deriveRelayAuthError = (url: string, claim = "") => { - const $signer = signer.get() - const socket = Pool.get().get(url) const stripPrefix = (m: string) => m.replace(/^\w+: /, "") // Kick off the auth process - socket.auth.attemptAuth($signer.sign) + Pool.get().get(url).auth.attemptAuth(sign) // Attempt to join the relay const thunk = publishThunk({ @@ -989,10 +988,17 @@ export const deriveRelayAuthError = (url: string, claim = "") => { if (error) { const isIgnored = error.startsWith("mute: ") + const isAborted = error.includes("Signing was aborted") const isEmptyInvite = !claim && error.includes("invite code") const isStrictNip29Relay = error.includes("missing group (`h`) tag") - if (!isStrictNip29Relay && !isIgnored && !isEmptyInvite && !isStrictNip29Relay) { + if ( + !isStrictNip29Relay && + !isIgnored && + !isAborted && + !isEmptyInvite && + !isStrictNip29Relay + ) { return stripPrefix(error) || "join request rejected" } } diff --git a/src/app/util/policies.ts b/src/app/util/policies.ts index 2d7b73b5..ecb194f1 100644 --- a/src/app/util/policies.ts +++ b/src/app/util/policies.ts @@ -1,5 +1,4 @@ -import {on, call, dissoc, assoc, uniq} from "@welshman/lib" -import type {StampedEvent} from "@welshman/util" +import {on, always, call, dissoc, assoc, uniq} from "@welshman/lib" import type {Socket, RelayMessage, ClientMessage} from "@welshman/net" import { makeSocketPolicyAuth, @@ -11,7 +10,7 @@ import { isClientEvent, isClientClose, } from "@welshman/net" -import {signer} from "@welshman/app" +import {sign} from "@welshman/app" import { userSettingsValues, getSetting, @@ -19,10 +18,7 @@ import { relaysMostlyRestricted, } from "@app/core/state" -export const authPolicy = makeSocketPolicyAuth({ - sign: (event: StampedEvent) => signer.get()?.sign(event), - shouldAuth: (socket: Socket) => true, -}) +export const authPolicy = makeSocketPolicyAuth({sign, shouldAuth: always(true)}) export const trustPolicy = (socket: Socket) => { const buffer: RelayMessage[] = []