askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
60 lines (59 loc) • 2.14 kB
TypeScript
/**
* Relay utilities for NIP-174
*/
import { SimplePool, Event, Filter } from "nostr-tools";
interface Sub {
close: () => void;
}
/**
* Publishes an event to multiple relays
*
* @param event - The event to publish
* @param relays - Array of relay URLs
* @param timeout - Timeout in milliseconds (default: 5000)
* @returns Promise resolving to array of relay URLs where the event was successfully published
*/
export declare function publishToRelays(event: Event, relays: string[], pool: SimplePool, timeout?: number): Promise<string[]>;
/**
* Subscribes to events from multiple relays
*
* @param filters - Array of filters
* @param relays - Array of relay URLs
* @param options - Subscription options
* @returns Subscription object
*/
export declare function subscribeToRelays(filters: Filter[], relays: string[], pool: SimplePool, options?: {
onevent?: (event: Event) => void;
oneose?: () => void;
}): Sub;
/**
* Fetches events from multiple relays
*
* @param filters - Array of filters
* @param relays - Array of relay URLs
* @param timeout - Timeout in milliseconds (default: 5000)
* @returns Promise resolving to array of events
*/
export declare function fetchFromRelays(filter: Filter, relays: string[], pool: SimplePool, timeout?: number): Promise<Event[]>;
/**
* Waits for a specific event matching the filter
*
* @param filter - Filter to match events
* @param relays - Array of relay URLs
* @param timeout - Timeout in milliseconds (default: 30000)
* @returns Promise resolving to the matched event or null if timeout
*/
export declare function waitForEvent(filter: Filter, relays: string[], pool: SimplePool, timeout?: number): Promise<Event | null>;
/**
* Creates an async iterable for events matching the filter
*
* @param filter - Filter to match events
* @param relays - Array of relay URLs
* @param options - Options for the subscription
* @returns Async iterable yielding events
*/
export declare function createEventStream(filter: Filter, relays: string[], pool: SimplePool, options?: {
closeOnEose?: boolean;
timeout?: number;
}): AsyncIterable<Event>;
export {};