Re-work connection auth
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import {ctx, uniq, noop, always} from '@welshman/lib'
|
||||
import {matchFilters, unionFilters, isSignedEvent, hasValidSignature} from '@welshman/util'
|
||||
import type {Filter, TrustedEvent} from '@welshman/util'
|
||||
import type {StampedEvent, SignedEvent, Filter, TrustedEvent} from '@welshman/util'
|
||||
import {Pool} from "./Pool"
|
||||
import {Executor} from "./Executor"
|
||||
import {AuthMode} from "./ConnectionAuth"
|
||||
import {Relays} from "./target/Relays"
|
||||
import type {Subscription, RelaysAndFilters} from "./Subscribe"
|
||||
|
||||
export type NetContext = {
|
||||
pool: Pool
|
||||
getExecutor: (relays: string[]) => Executor
|
||||
authMode: AuthMode,
|
||||
onEvent: (url: string, event: TrustedEvent) => void
|
||||
onAuth: (url: string, challenge: string) => void
|
||||
signEvent: (event: StampedEvent) => Promise<SignedEvent>
|
||||
getExecutor: (relays: string[]) => Executor
|
||||
isDeleted: (url: string, event: TrustedEvent) => boolean
|
||||
isValid: (url: string, event: TrustedEvent) => boolean
|
||||
matchFilters: (url: string, filters: Filter[], event: TrustedEvent) => boolean
|
||||
@@ -27,9 +29,10 @@ export const defaultOptimizeSubscriptions = (subs: Subscription[]) =>
|
||||
})
|
||||
|
||||
export const getDefaultNetContext = (overrides: Partial<NetContext> = {}) => ({
|
||||
onAuth: noop,
|
||||
onEvent: noop,
|
||||
pool: new Pool(),
|
||||
authMode: AuthMode.Implicit,
|
||||
onEvent: noop,
|
||||
signEvent: noop,
|
||||
isDeleted: always(false),
|
||||
isValid: (url: string, event: TrustedEvent) => isSignedEvent(event) && hasValidSignature(event),
|
||||
getExecutor: (relays: string[]) => new Executor(new Relays(relays.map((relay: string) => ctx.net.pool.get(relay)))),
|
||||
|
||||
Reference in New Issue
Block a user