declare module '@nomyx/decentranet' { import { EventEmitter } from 'events'; export type Context = 'browser' | 'server' | 'peer'; export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; export type SyncPriority = 'low' | 'normal' | 'high'; export interface ComponentMetadata { id: string; name: string; version: string; author: string; description: string; tags: string[]; dependencies: { [key: string]: string }; acl: AccessControlList; signature: string; } export interface AccessControlList { type: 'public' | 'private' | 'shared'; allowedUsers?: string[]; } export interface ComponentPackage { metadata: ComponentMetadata; code: string; state?: any; schema?: SchemaDefinition; } export interface EncryptedComponentPackage { metadata: string; code: string; state?: string; encryptedKey: { [userPubKey: string]: string }; } export interface ComponentInstance { component: Component; state: DistributedState; } export interface ComponentUpdateEvent { id: string; version: string; changes: string[]; } export interface GunDataProviderOptions { peers?: string[]; localStorage?: boolean; radisk?: boolean; multicast?: boolean; } export interface AuthCredentials { username: string; password: string; } export interface User { alias: string; pub: string; } export interface EncryptedData { ct: string; iv: string; s: string; } export interface LogEntry { level: LogLevel; message: string; timestamp: number; context?: string; data?: any; } export interface PeerInfo { id: string; url: string; lastSeen: number; } export interface SyncStatus { lastSyncTime: number; pendingChanges: number; priority: SyncPriority; isPaused: boolean; } export interface PluginMetadata { name: string; version: string; description: string; author: string; } export interface Plugin { metadata: PluginMetadata; initialize: () => Promise; destroy: () => Promise; } export interface SchemaDefinition { [key: string]: 'string' | 'number' | 'boolean' | 'object' | 'array' | SchemaDefinition; } export interface QueryOptions { limit?: number; skip?: number; sort?: {[key: string]: 'asc' | 'desc'}; } export interface NetworkStats { peers: number; inbound: number; outbound: number; latency: number; } export type Unsubscribe = () => void; export interface ErrorInfo { code: string; message: string; stack?: string; context?: string; } export type ErrorCategory = 'TYPE_ERROR' | 'REFERENCE_ERROR' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR'; export type ErrorHandlingStrategy = (error: Error, errorInfo: ErrorInfo) => void; export interface ErrorReportingConfig { endpoint: string; } export interface ContextState { active: boolean; data: Record; context: Context; } export interface ContextTransition { from: Context; to: Context; } export interface RouteContext { path: string; params: RouteParams; data?: any; context: Context; peerManager: PeerManager; } export interface Middleware { (context: RouteContext): Promise; } export interface RouteOptions { auth?: boolean; middleware?: Middleware[]; } export interface RouteConfig { handler: RouteHandler; options: RouteOptions; } export interface RouteParams { [key: string]: string; } export type RouteHandler = (context: RouteContext) => Promise | any; // ComponentState export interface ComponentState { [key: string]: any; } // ComponentProps export interface ComponentProps { [key: string]: any; } export class Component extends MultiContextObject { protected ui: ReactiveUI; protected state: DistributedState; public props: P; protected peerManager: PeerManager; protected syncManager: SyncManager; constructor( contexts: Context[], dataProvider: GunDataProvider, schema: SchemaDefinition, initialState: S, props: P, peerManager: PeerManager, syncManager: SyncManager ); render(): string; publish(registry: ComponentRegistry, currentUserPair: any, schema: SchemaDefinition): Promise; onMount(): void; onUnmount(): void; onUpdate(prevProps: any, prevState: any): void; protected setState(newState: Partial, broadcast?: boolean): void; update(): void; mount(element: HTMLElement): void; unmount(): void; updateProps(newProps: Partial

): void; static load( address: string, registry: ComponentRegistry, userPair: any, dataProvider: GunDataProvider, syncManager: SyncManager, schema: SchemaDefinition ): Promise; } export class ComponentRegistry extends EventEmitter { constructor(gun: GunDataProvider); getComponent(address: string, userPair: any): Promise; getComponentSchema(address: string, userPair: any): Promise; searchComponents(query: string, limit?: number): Promise; publishComponent(component: ComponentPackage, currentUserPair: any): Promise; updateComponentAccess(componentId: string, newAcl: AccessControlList, currentUserPair: any): Promise; } export class DecentralizedApp extends MultiContextObject { constructor(gun: GunDataProvider); initialize(): Promise; start(): Promise; stop(): Promise; getAuthManager(): AuthManager; getSyncManager(): SyncManager; getPeerManager(): PeerManager; getPluginSystem(): PluginSystem; getContextRouter(): ContextRouter; getDevTools(): DevTools; getDataProvider(): GunDataProvider; createDistributedState(initialState: T, path: string, schema: SchemaDefinition): DistributedState; route(path: string, data?: any): Promise; broadcastRoute(path: string, data?: any): Promise; executeInPeer(peerId: string, func: Function): Promise; onPeerMessage(callback: (peerId: string, message: any) => void): void; broadcastToPeers(message: any): void; getCurrentUserPair(): any; publishComponent(component: Component, schema: SchemaDefinition): Promise; loadComponent(address: string, schema: SchemaDefinition): Promise; searchComponents(query: string, limit?: number): Promise; getLoadedComponent(address: string): ComponentInstance | undefined; unloadComponent(address: string): Promise; } export class MultiContextObject extends EventEmitter { constructor(contexts: Context[]); isValidContext(context: Context): boolean; getCurrentContext(): Context; getContextState(context: Context): ContextState | undefined; setContextData(context: Context, key: string, value: any): void; getContextData(context: Context, key: string): any; switchContext(newContext: Context): Promise; executeInContext(context: Context, func: () => Promise | T): Promise; executeInAllContexts(func: (context: Context) => Promise | T): Promise>; executeInMultipleContexts(contexts: Context[], func: (context: Context) => Promise | T): Promise>; onContextActivated(callback: (context: Context) => void): void; onContextDeactivated(callback: (context: Context) => void): void; onBeforeContextSwitch(callback: (transition: ContextTransition) => void): void; onAfterContextSwitch(callback: (transition: ContextTransition) => void): void; withContext(context: Context, func: () => Promise | T): Promise; isContextActive(context: Context): boolean; getActiveContexts(): Context[]; broadcastToActiveContexts(func: (context: Context) => Promise | T): Promise>; } export class PluginSystem extends EventEmitter { registerPlugin(plugin: Plugin): Promise; unregisterPlugin(pluginName: string): Promise; getPlugin(pluginName: string): Plugin | undefined; getAllPlugins(): Plugin[]; registerHook(hookName: string, callback: Function): void; unregisterHook(hookName: string, callback: Function): void; broadcastToPlugins(event: string, ...args: any[]): void; executeHook(hookName: string, ...args: any[]): Promise; initializeAllPlugins(): Promise; destroyAllPlugins(): Promise; isPluginRegistered(pluginName: string): boolean; getPluginMetadata(pluginName: string): PluginMetadata | undefined; getAllPluginMetadata(): PluginMetadata[]; reloadPlugin(pluginName: string): Promise; getHooks(): string[]; clearHooks(): void; } export class ContextRouter extends EventEmitter { constructor(peerManager: PeerManager); addRoute(path: string, context: Context, handler: RouteHandler, options?: RouteOptions): void; use(middleware: Middleware): void; route(path: string, multiContextObject: MultiContextObject, data?: any): Promise; broadcastRoute(path: string, multiContextObject: MultiContextObject, data?: any): Promise; routeToPeer(peerId: string, path: string, data?: any): Promise; getRoutes(): Map>; clearRoutes(): void; removeRoute(path: string, context?: Context): void; } export class VNode { constructor(tag: string, props: Record, children: VNode[], key?: string); static create(tag: string, props: Record, children: VNode[], key?: string): VNode; } export class ReactiveUI extends EventEmitter { constructor(); mount(element: HTMLElement): void; unmount(): void; update(newVDOM: VNode): void; getComponentInstance(id: string): Component | undefined; updateComponentProps(id: string, newProps: any): void; } export class DistributedState extends EventEmitter { constructor(gunDataProvider: GunDataProvider, path: string, schema: SchemaDefinition); get(): Promise; set(data: Partial): Promise; update(updater: (currentState: T) => Partial): Promise; subscribe(listener: (state: T, oldState: T) => void): Unsubscribe; getSchema(): SchemaDefinition; validate(data: any): boolean; reset(): Promise; getId(): string; transaction(transactionFn: (currentState: T) => Partial): Promise; getCurrentState(): T; refresh(): Promise; } export class GunDataProvider extends EventEmitter { constructor(options?: GunDataProviderOptions); getNode(path: string): GunNode; createQuery(path: string): GunQuery; put(path: string, data: any): Promise; get(path: string): Promise; set(path: string, data: any): Promise; onUpdate(path: string, callback: (data: any) => void): void; offUpdate(path: string, callback: (data: any) => void): void; createUser(username: string, password: string): Promise; login(username: string, password: string): Promise; logout(): void; getCurrentUser(): any; isAuthenticated(): boolean; generateUuid(): string; getServerTime(): Promise; } export class GunNode extends EventEmitter { constructor(gun: any, path: string); put(data: Partial): Promise; get(): Promise; set(data: T): Promise; map(): GunNode; each(callback: (data: T, key: string) => void | Promise): Promise; } export class GunQuery { constructor(node: GunNode); find(predicate: (item: T) => boolean, options?: QueryOptions): Promise; findOne(predicate: (item: T) => boolean): Promise; count(predicate?: (item: T) => boolean): Promise; update(predicate: (item: T) => boolean, updateFn: (item: T) => Partial): Promise; delete(predicate: (item: T) => boolean): Promise; map(mapper: (item: T) => R): GunQuery; filter(predicate: (item: T) => boolean): GunQuery; } export class IndexedDBAdapter { constructor(dbName: string, dbVersion: number, stores: string[]); connect(): Promise; put(storeName: string, data: any): Promise; get(storeName: string, id: string): Promise; delete(storeName: string, id: string): Promise; getAll(storeName: string): Promise; clear(storeName: string): Promise; disconnect(): void; } export class TypedSchema { constructor(schema: SchemaDefinition); validate(data: any): boolean; cast(data: any): any; getDefaultValue(): any; } export class AuthManager extends EventEmitter { constructor(gunDataProvider: GunDataProvider); register(credentials: AuthCredentials): Promise; login(credentials: AuthCredentials): Promise; logout(): void; getCurrentUser(): User | null; isAuthenticated(): boolean; changePassword(currentPassword: string, newPassword: string): Promise; resetPassword(username: string, resetToken: string, newPassword: string): Promise; requestPasswordReset(username: string): Promise; } export class CryptoUtils { static encrypt(data: string, key?: string): Promise; static decrypt(encryptedData: EncryptedData): Promise; static hash(data: string): Promise; static generateRandomId(length?: number): string; } export class SEA { static pair(): Promise; static encrypt(data: any, pair: any): Promise; static decrypt(encryptedData: string, pair: any): Promise; static sign(data: any, pair: any): Promise; static verify(signedData: string, pair: any): Promise; static work(data: string, salt: string, options?: any): Promise; static certify(certificants: string | string[], policy: any, authority: any, expiry?: number, cb?: any): Promise; static recall(props: any, cb?: any): Promise; static secret(key: any, pair: any, cb?: any): Promise; static derive(passphrase: string, salt?: string, options?: any): Promise<{ epriv: string; epub: string }>; static authenticateUser(alias: string, password: string): Promise; static createUser(alias: string, password: string): Promise; } export class NetworkMonitor extends EventEmitter { constructor(gunDataProvider: GunDataProvider, checkInterval?: number, pingEndpoint?: string); getStats(): NetworkStats; isNetworkOnline(): boolean; setCheckInterval(interval: number): void; stopMonitoring(): void; destroy(): void; simulateLatency(latency: number): void; setBandwidthLimit(limit: number | null): void; getPeerInfo(): PeerInfo[]; setPingEndpoint(endpoint: string): void; } export class NetworkGraph { nodes: { id: string; label: string; group: number }[]; edges: { from: string; to: string }[]; } export class TopologyAnalysis { averageDegree: number; averageClusteringCoefficient: number; averageShortestPath: number; diameter: number; density: number; connectedComponents: number; } export class PeerManager extends EventEmitter { constructor(gunDataProvider: GunDataProvider); generateNetworkGraph(): NetworkGraph; analyzeTopology(): TopologyAnalysis; measureLatency(peerId: string): Promise; connectToPeer(peerId: string, peerUrl: string): void; disconnectFromPeer(peerId: string): void; sendToPeer(peerId: string, message: any): void; broadcast(message: any): void; getCurrentPeerId(): string; executeInPeerContext(peerId: string, callback: (peer: any) => void): void; getPeerLatency(peerId: string): number; getConnectedPeerIds(): string[]; getPeers(): PeerInfo[]; sendMessage(peerId: string, message: any): void; broadcastMessage(message: any): void; listenToPeer(peerId: string, callback: (message: any) => void): void; listenToBroadcasts(callback: (message: any) => void): void; authenticate(alias: string, password: string): Promise; createAccount(alias: string, password: string): Promise; getCurrentPeerPublicKey(): string | null; stop(): void; } export class SyncManager extends EventEmitter { constructor(gunDataProvider: GunDataProvider); startSync(path: string, priority?: SyncPriority): void; stopSync(path: string): void; getSyncedPaths(): string[]; getSyncStatus(path: string): SyncStatus | undefined; getDistributedState(path: string): DistributedState | null; fetchStateFromPeers(path: string): Promise; syncState(path: string, schema: SchemaDefinition): DistributedState; persistState(path: string, schema: SchemaDefinition): DistributedState; loadPersistedState(path: string): Promise; forceSyncAll(): Promise; forceSync(path: string): Promise; getPendingChangesCount(): number; isSyncInProgress(): boolean; pauseSync(path: string): void; resumeSync(path: string): void; stop(): void; } export class WebRTCAdapter extends EventEmitter { constructor(gunDataProvider: GunDataProvider); createOffer(peerId: string): Promise; getCurrentPeerIds(): Promise; getCurrentPeerId(): Promise; handleOffer(peerId: string, offer: RTCSessionDescriptionInit): Promise; handleAnswer(peerId: string, answer: RTCSessionDescriptionInit): Promise; addIceCandidate(peerId: string, candidate: RTCIceCandidateInit): Promise; sendMessage(peerId: string, message: string): void; close(peerId: string): void; listenForSignaling(): void; initiateWebRTCConnection(peerId: string): Promise; isWebRTCSupported(): boolean; getConnectionState(peerId: string): RTCPeerConnectionState | null; restartIce(peerId: string): Promise; addDataChannel(peerId: string, label: string): RTCDataChannel | null; getDataChannels(peerId: string): RTCDataChannel[]; sendFile(peerId: string, file: File): Promise; } export class DevTools extends EventEmitter { constructor( logger: Logger, networkMonitor: NetworkMonitor, peerManager: PeerManager, syncManager: SyncManager, pluginSystem: PluginSystem, gunDataProvider: GunDataProvider, authManager: AuthManager, contextRouter: ContextRouter ); getLogs(filter?: { level?: string; context?: string }): LogEntry[]; getNetworkStats(): NetworkStats; getPeers(): PeerInfo[]; getSyncStatus(): { path: string; status: SyncStatus }[]; inspectDistributedState(statePath: string): DistributedState | null; monitorStateChanges(statePath: string, callback: (newState: any) => void): Unsubscribe; generateNetworkGraph(): NetworkGraph; analyzeNetworkTopology(): TopologyAnalysis; measurePeerLatency(peerId: string): Promise; startPerformanceProfile(label: string): void; stopPerformanceProfile(label: string): any; injectFault(faultType: string, options: any): void; simulatePeerDisconnection(peerId: string): void; simulateNetworkLatency(latency: number): void; startRecording(): void; stopRecording(): any[]; replayEvents(events: any[]): void; getLoadedPlugins(): Plugin[]; inspectPlugin(pluginName: string): Plugin | undefined; inspectGunData(path: string): Promise; getCurrentUser(): User | null; getRoutes(): Map>; clearLogs(): void; exportDevToolsState(): any; importDevToolsState(state: any): void; enableRemoteDebugging(port: number): void; sendRemoteCommand(command: string, params: any): Promise; } export class Logger { static getInstance(): Logger; setLogLevel(level: LogLevel): void; debug(message: string, context?: string, data?: any): void; info(message: string, context?: string, data?: any): void; warn(message: string, context?: string, data?: any): void; error(message: string, context?: string, data?: any): void; getLogs(): LogEntry[]; clearLogs(): void; exportLogs(): string; importLogs(logsJson: string): void; } export class ErrorHandler { static getInstance(): ErrorHandler; handleError(error: Error, context?: string): void; handleAsyncError(promise: Promise, context?: string): Promise; registerGlobalErrorHandlers(): void; setStrategy(category: ErrorCategory, strategy: ErrorHandlingStrategy): void; configureErrorReporting(config: ErrorReportingConfig): void; attemptErrorRecovery(error: Error): boolean; } export class Performance extends EventEmitter { startTiming(label: string): void; endTiming(label: string): number; recordMetric(name: string, value: number): void; trackMemoryUsage(interval?: number): () => void; getTimings(label: string): { start: number; end: number; duration: number }[]; getMetric(name: string): { count: number; total: number; min: number; max: number; average: number } | undefined; getAllMetrics(): Map; clearTimings(): void; clearMetrics(): void; generateReport(): string; measureAsync(label: string, fn: () => Promise): Promise; measure(label: string, fn: () => T): T; startProfiling(label: string): void; endProfiling(label: string): void; } export class FaultInjector extends EventEmitter { addFault(name: string, config: { probability: number; type: string; details?: any }): void; removeFault(name: string): void; injectFault(name: string, options?: any): Promise; getAllFaults(): { name: string; config: { probability: number; type: string; details?: any } }[]; clearAllFaults(): void; injectRandomFault(): Promise; setGlobalFaultProbability(probability: number): void; } export class SandboxedEnvironment { constructor(); evaluate(code: string): any; runFunction(func: Function, ...args: any[]): any; setGlobal(key: string, value: any): void; getGlobal(key: string): any; } export function contextMethod(context: Context): MethodDecorator; export function multiContext(...contexts: Context[]): MethodDecorator; export function logMethod(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor; export function retry(maxAttempts?: number, delay?: number): MethodDecorator; export function memoize(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor; export function debounce(delay?: number): MethodDecorator; export function throttle(limit?: number): MethodDecorator; export const BROWSER_CONTEXT: Context; export const SERVER_CONTEXT: Context; export const PEER_CONTEXT: Context; export function isBrowserContext(): boolean; export function executeInBrowserContext(func: Function): any; export function isServerContext(): boolean; export function executeInServerContext(func: Function): any; export function isPeerContext(): boolean; export function executeInPeerContext(func: Function): any; }