libp2p-ts/types/libp2p/index.d.ts

132 lines
4.5 KiB
TypeScript
Raw Normal View History

2018-07-02 10:38:26 +02:00
// Type definitions for libp2p 0.22.0
2018-06-21 15:23:22 +02:00
// Project: https://github.com/libp2p/js-libp2p
// Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="libp2p-bootstrap"/>
2018-06-24 10:46:14 +02:00
/// <reference types="interface-connection"/>
/// <reference types="interface-transport"/>
/// <reference types="libp2p-kad-dht"/>
/// <reference types="libp2p-mdns"/>
/// <reference types="libp2p-mplex"/>
/// <reference types="libp2p-spdy"/>
/// <reference types="peer-info"/>
2020-04-03 11:04:37 +02:00
/// <reference types="peer-id"/>
2018-06-24 10:16:29 +02:00
declare namespace LibP2p {
2018-07-02 10:38:26 +02:00
export type OptionsConfig = {
2019-08-26 12:31:34 +02:00
contentRouting?: {},
2018-07-02 10:38:26 +02:00
dht?: {
kBucketSize?: number
},
peerDiscovery?: {
2019-08-27 09:44:14 +02:00
autoDial?: boolean,
2019-08-26 12:31:34 +02:00
enabled?: boolean,
2019-05-30 11:41:19 -05:00
bootstrap?: {
enabled?: boolean,
2020-04-04 15:05:16 -05:00
list: Array<string | import("multiaddr")>,
interval?: number,
2019-05-30 11:41:19 -05:00
},
2018-07-02 10:38:26 +02:00
mdns?: {
enabled?: boolean,
broadcast?: boolean,
interval?: number,
peerInfo: PeerInfo,
port?: number,
serviceTag?: string
2018-07-02 10:38:26 +02:00
},
2019-03-05 14:03:52 +01:00
webRTCStar?: {
2018-07-02 10:38:26 +02:00
interval?: number
enabled?: boolean
2019-03-05 14:03:52 +01:00
},
websocketStar?: {
enabled?: boolean
2018-07-02 10:38:26 +02:00
}
},
peerRouting?: {},
2019-08-26 12:31:34 +02:00
pubsub?: {
enabled?: boolean,
2019-08-26 13:22:53 +02:00
emitSelf?: boolean,
signMessages?: boolean,
strictSigning?: boolean
2019-08-26 12:31:34 +02:00
},
2018-07-02 10:46:32 +02:00
relay?: {
2018-07-02 10:38:26 +02:00
enabled?: boolean,
hop?: {
enabled?: boolean,
active?: boolean
}
}
};
export type OptionsModules = {
2020-04-03 11:04:37 +02:00
connEncryption?: Array<ConnectionEncryption>,
2020-02-05 16:05:00 +07:00
streamMuxer: Array<LibP2pMplex | LibP2pSpdy>,
2018-07-02 10:38:26 +02:00
dht?: typeof LibP2pKadDht,
2020-04-22 06:04:11 +07:00
peerDiscovery: Array<typeof LibP2pBootstrap | typeof LibP2pMdns | typeof import("@chainsafe/discv5").Discv5Discovery>,
2018-06-24 10:16:29 +02:00
transport: LibP2pTransport[]
};
2018-07-02 10:38:26 +02:00
export type Options = {
config: OptionsConfig,
modules: OptionsModules,
peerInfo: PeerInfo,
};
export interface ConnectionEncryption {
protocol: string,
secureInbound(localPeer: import("peer-id"), connection: LibP2pConnection, remotePeer: import("peer-id")): Promise<SecureConnection>;
secureOutbound(localPeer: import("peer-id"), connection: LibP2pConnection, remotePeer?: import("peer-id")): Promise<SecureConnection>;
}
export interface SecureConnection {
conn: LibP2pConnection,
remotePeer: import("peer-id")
}
2018-06-24 15:27:48 +02:00
export type Events = 'peer:connect' | 'peer:disconnect' | 'peer:discovery' | 'start' | 'stop';
2018-06-24 10:16:29 +02:00
}
declare class PeerStore {
readonly peers: Map<string, PeerInfo>;
}
declare class Registrar {
2020-05-15 14:14:09 +02:00
connections: Map<string, LibP2pConnection[]>;
getConnection(peerInfo: PeerInfo): LibP2pConnection;
handle: Function;
register(topology: Object): string;
unregister(id: string): boolean;
}
2018-06-24 10:16:29 +02:00
declare class LibP2p {
2018-09-07 16:10:43 +02:00
readonly _dht: LibP2pKadDht;
2018-09-17 12:11:48 -04:00
constructor(options: LibP2p.Options);
2018-06-21 15:23:22 +02:00
static create(options: LibP2p.Options): Promise<LibP2p>;
2018-09-17 12:11:48 -04:00
readonly peerInfo: PeerInfo;
readonly peerStore: PeerStore;
readonly registrar: Registrar;
2020-04-22 06:04:11 +07:00
readonly _discovery: Map<"bootstrap" | "mdns" | "discv5", LibP2pBootstrap | LibP2pMdns | import("@chainsafe/discv5").Discv5Discovery>;
2018-09-17 12:11:48 -04:00
2020-04-04 15:05:16 -05:00
dial(peerInfo: PeerInfo | import("peer-id") | import("multiaddr") | string, options?: Object): Promise<LibP2pConnection | {stream: Stream; protocol: string}>;
dialProtocol(peerInfo: PeerInfo | import("peer-id") | import("multiaddr") | string, protocols: string[] | string, options?: Object): Promise<LibP2pConnection | {stream: Stream; protocol: string}>;
hangUp(peerInfo: PeerInfo | import("peer-id") | import("multiaddr") | string): Promise<void>;
2020-02-07 09:17:27 +07:00
handle(protocols: string[] | string, handler: (param: {connection: LibP2pConnection; stream: Stream; protocol: string}) => void): void;
unhandle(protocols: string[] | string): void;
2018-09-17 12:11:48 -04:00
isStarted(): boolean;
2019-05-30 11:41:19 -05:00
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;
2020-04-04 15:05:16 -05:00
ping(peerInfo: PeerInfo | import("peer-id") | import("multiaddr") | string): Promise<void>;
2019-08-26 12:31:34 +02:00
start(): Promise<void>;
stop(): Promise<void>;
2018-06-21 15:23:22 +02:00
}
2018-06-24 10:16:29 +02:00
declare module 'libp2p' {
2018-09-17 12:11:48 -04:00
export default LibP2p;
2018-06-22 15:43:18 +02:00
}