/** * SecureEventBus class implementing the singleton pattern for secure event communication. * Provides authentication-based event dispatching to prevent unauthorized external access. */ declare class SecureEventBus { private static instance; private listeners; private readonly authToken; private eventCounter; /** * Private constructor to enforce singleton pattern. * Generates a unique authentication token for this session. */ private constructor(); /** * Get the singleton instance of SecureEventBus. * Creates a new instance if one doesn't exist. * * @returns The singleton instance of SecureEventBus * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * ``` */ static getInstance(): SecureEventBus; /** * Generate a cryptographically secure authentication token. * Uses crypto.getRandomValues when available, falls back to Math.random. * * @private * @returns A 64-character hexadecimal string representing the authentication token */ private generateAuthToken; /** * Get the authentication token for this SecureEventBus instance. * This token is required for dispatching events and should only be used internally. * * @returns The authentication token string * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * const token = eventBus.getAuthToken(); * eventBus.dispatch('myEvent', { data: 'value' }, token); * ``` */ getAuthToken(): string; /** * Dispatch an event with authentication to all registered listeners. * Verifies the authentication token before dispatching to prevent unauthorized access. * * @param eventName - The name of the event to dispatch * @param payload - The data to send with the event (optional) * @param token - Authentication token (must match the internal token) * @returns true if event was successfully dispatched, false if unauthorized or error occurred * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * const token = eventBus.getAuthToken(); * * // Dispatch with payload * const success = eventBus.dispatch('userAction', { action: 'click', target: 'button' }, token); * * // Dispatch without payload * eventBus.dispatch('windowClosed', undefined, token); * ``` */ dispatch(eventName: string, payload?: any, token?: string): boolean; /** * Subscribe to an event with a callback function. * The callback will be executed whenever the specified event is dispatched. * * @param eventName - The name of the event to listen for * @param callback - The function to execute when the event is fired * @returns A function that can be called to unsubscribe from the event * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * * // Subscribe to an event * const unsubscribe = eventBus.subscribe('chatMessage', (message) => { * console.log('New message:', message.text); * console.log('From user:', message.userId); * }); * * // Later, unsubscribe * unsubscribe(); * ``` */ subscribe(eventName: string, callback: (payload: any) => void): () => void; /** * Remove all listeners for a specific event. * This completely removes the event from the internal listeners map. * * @param eventName - The name of the event to remove all listeners for * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * * // Remove all listeners for 'chatClosed' event * eventBus.removeAllListeners('chatClosed'); * ``` */ removeAllListeners(eventName: string): void; /** * Clear all listeners for all events. * This resets the entire event bus to its initial state. * Useful for cleanup during application shutdown or testing. * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * * // Clear all event listeners * eventBus.clear(); * ``` */ clear(): void; /** * Get the number of listeners for a specific event. * Useful for debugging and monitoring purposes. * * @param eventName - The name of the event to count listeners for * @returns The number of listeners registered for the event * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * * // Check how many listeners are registered for 'userAction' * const count = eventBus.getListenerCount('userAction'); * console.log(`${count} listeners registered for userAction`); * ``` */ getListenerCount(eventName: string): number; /** * Get all registered event names. * Returns an array of event names that currently have listeners. * Useful for debugging and monitoring purposes. * * @returns An array of event names that have registered listeners * * @example * ```typescript * const eventBus = SecureEventBus.getInstance(); * * // Get all registered events * const events = eventBus.getRegisteredEvents(); * console.log('Active events:', events); * // Output: ['userAction', 'chatMessage', 'windowResize'] * ``` */ getRegisteredEvents(): string[]; } export default SecureEventBus;