import { StampedEvent, SignedEvent } from "@welshman/util"; import { Socket, SocketPolicy } from "./socket.js"; import type { Unsubscriber } from "./util.js"; /** * Handles auth-related message management: * - Remembers messages sent before auth completes so they can be replayed once it succeeds * - Withholds the relay's auth-required refusals of those messages from the caller, since the * replay will be answered instead * - Hands a withheld answer over if the replay never happens: auth failed, or the message fell * out of the buffer * @param socket - a Socket object * @return a cleanup function */ export declare const socketPolicyAuthBuffer: (socket: Socket) => () => void; /** * Drops subscriptions that are closed before they've been sent, along with the close * message itself. Besides saving a round trip, this keeps a prioritized close from * jumping ahead of its own req, which would leave the subscription open on the relay. * @param socket - a Socket object * @return a cleanup function */ export declare const socketPolicyCancelUnsent: (socket: Socket) => () => void; /** * Auto-connects a closed socket when a message is sent unless there was a recent error * @param socket - a Socket object * @return a cleanup function */ export declare const socketPolicyConnectOnSend: (socket: Socket) => () => void; /** * Owns a socket's lifecycle: closes it once nothing needs it, checks the relay is still there * when something does, reopens it, and catches up on what it missed. * @param socket - a Socket object * @return a cleanup function */ export declare const socketPolicyLifecycle: (socket: Socket) => () => void; export type SocketPolicyAuthOptions = { sign: (event: StampedEvent) => Promise; shouldAuth?: (socket: Socket) => boolean; recheck?: { subscribe: (run: () => void) => Unsubscriber; }; }; /** * Factory function for a policy which may authenticate the socket * @param options - SocketPolicyAuthOptions object * @return a socket policy */ export declare const makeSocketPolicyAuth: (options: SocketPolicyAuthOptions) => (socket: Socket) => () => void; export type SocketPolicyRefusalsOptions = { onAllowed: (socket: Socket) => void; onRefused: (socket: Socket, reason: string) => void; }; /** * Factory function for a policy which reports how the relay answers each request and publish: * allowed when it serves one, refused when it turns one away as "restricted:" or "blocked:" * (NIP-01's reasons for lacking access). Other failures report nothing, including an * auth-required refusal, since the message is sent again once auth completes. * @param options - SocketPolicyRefusalsOptions object * @return a socket policy */ export declare const makeSocketPolicyRefusals: (options: SocketPolicyRefusalsOptions) => (socket: Socket) => () => void; export declare const defaultSocketPolicies: SocketPolicy[]; //# sourceMappingURL=policy.d.ts.map