// Type definitions for libp2p 0.28.3 // Project: https://github.com/libp2p/js-libp2p // Definitions by: Jaco Greeff // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// /// /// /// /// /// /// declare namespace LibP2p { export type OptionsConfig = { contentRouting?: {}, dht?: { kBucketSize?: number }, peerDiscovery?: { autoDial?: boolean, enabled?: boolean, bootstrap?: { enabled?: boolean, list: Array, interval?: number, }, mdns?: { enabled?: boolean, broadcast?: boolean, interval?: number, peerId: import("peer-id"), port?: number, serviceTag?: string }, webRTCStar?: { interval?: number enabled?: boolean }, websocketStar?: { enabled?: boolean } }, peerRouting?: {}, pubsub?: { enabled?: boolean, emitSelf?: boolean, signMessages?: boolean, strictSigning?: boolean }, relay?: { enabled?: boolean, hop?: { enabled?: boolean, active?: boolean } } }; export type OptionsModules = { connEncryption?: Array, streamMuxer: Array, dht?: typeof LibP2pKadDht, peerDiscovery: Array, transport: LibP2pTransport[] }; export type Options = { config: OptionsConfig, modules: OptionsModules, peerId?: import("peer-id"), addresses?: {listen?: string[], announce?: string[], noAnnounce?: string[]}, }; export interface ConnectionEncryption { protocol: string, secureInbound(localPeer: import("peer-id"), connection: LibP2pConnection, remotePeer: import("peer-id")): Promise; secureOutbound(localPeer: import("peer-id"), connection: LibP2pConnection, remotePeer?: import("peer-id")): Promise; } export interface SecureConnection { conn: LibP2pConnection, remotePeer: import("peer-id") } export type Events = 'peer:discovery' | 'start' | 'stop'; export type ConnectionEvents = 'peer:connect' | 'peer:disconnect'; } declare class AddressBook { add(peerId: import("peer-id"), multiaddrs: import("multiaddr")[]): void; getMultiaddrsForPeer(peerId: import("peer-id")): import("multiaddr")[]; } declare class PeerStore { readonly peers: Map; readonly addressBook: AddressBook; } declare class Registrar { connections: Map; getConnection(peerId: import("peer-id")): LibP2pConnection; handle (): void register (): void unregister (): void } declare class ConnectionManager { on(event: LibP2p.ConnectionEvents, cb: (event: LibP2pConnection) => any): this; once(event: LibP2p.ConnectionEvents, cb: (event: LibP2pConnection) => any): this; removeListener(event: LibP2p.ConnectionEvents, cb: (event: LibP2pConnection) => any): this; get(peerId: import("peer-id")): LibP2pConnection | null; } declare class LibP2p { readonly _dht: LibP2pKadDht; constructor(options: LibP2p.Options); static create(options: LibP2p.Options): Promise; readonly peerId: import("peer-id"); readonly peerStore: PeerStore; readonly registrar: Registrar; readonly connectionManager: ConnectionManager; readonly _discovery: Map<"bootstrap" | "mdns" | "discv5", LibP2pBootstrap | LibP2pMdns | import("@chainsafe/discv5").Discv5Discovery>; readonly multiaddrs: import("multiaddr")[]; dial(peerInfo: import("peer-id") | import("multiaddr") | string, options?: Object): Promise; dialProtocol(peerInfo: import("peer-id") | import("multiaddr") | string, protocols: string[] | string, options?: Object): Promise; hangUp(peerInfo: import("peer-id") | import("multiaddr") | string): Promise; handle(protocols: string[] | string, handler: (param: {connection: LibP2pConnection; stream: Stream; protocol: string}) => void): void; unhandle(protocols: string[] | string): void; isStarted(): boolean; on(event: LibP2p.Events, cb: (event: any) => any): this; once(event: LibP2p.Events, cb: (event: any) => any): this; removeListener(event: LibP2p.Events, cb: (event: any) => any): this; ping(peerInfo: import("peer-id") | import("multiaddr") | string): Promise; start(): Promise; stop(): Promise; } declare module 'libp2p' { export default LibP2p; }