Skip to content

Commit 4b133b1

Browse files
authoredApr 4, 2020
Merge pull request #66 from ChainSafe/mpetrunic/type-definitions
add typescript definitions
2 parents 7c6f65b + 7e17f12 commit 4b133b1

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"src",
99
"dist"
1010
],
11+
"types": "src/index.d.ts",
1112
"scripts": {
1213
"lint": "aegir lint",
1314
"release": "aegir release",

‎src/index.d.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Type definitions for libp2p-gossipsub v0.2.3
2+
// Project https://github.com/ChainSafe/gossipsub-js
3+
4+
/// <reference types="node"/>
5+
6+
import PeerInfo = require('peer-info');
7+
8+
export interface Registrar {
9+
handle: Function;
10+
register(topology: Object): string;
11+
unregister(id: string): boolean;
12+
}
13+
14+
export interface IGossipMessage {
15+
from: Buffer | string;
16+
data: Buffer;
17+
seqno: Buffer;
18+
topicIDs: string[];
19+
}
20+
21+
export interface Options {
22+
emitSelf?: boolean,
23+
gossipIncoming?: boolean,
24+
fallbackToFloodsub?: boolean,
25+
}
26+
27+
import * as Events from "events";
28+
29+
interface GossipSub extends Events.EventEmitter {}
30+
31+
declare class GossipSub {
32+
constructor(peerInfo: PeerInfo, registrar: Registrar, options: Options);
33+
publish(topic: string, data: Buffer): Promise<void>;
34+
start(): Promise<void>;
35+
stop(): Promise<void>;
36+
subscribe(topic: string): void;
37+
unsubscribe(topic: string): void;
38+
validate(message: IGossipMessage): Promise<boolean>;
39+
_emitMessage(topics: string[], message: IGossipMessage): void;
40+
getTopics(): string[];
41+
_publish(messages: IGossipMessage[]): void;
42+
}
43+
44+
export default GossipSub;

‎tsconfig.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"lib": [
6+
"es6"
7+
],
8+
"target": "ES5",
9+
"noImplicitAny": false,
10+
"noImplicitThis": true,
11+
"strictFunctionTypes": true,
12+
"strictNullChecks": true,
13+
"esModuleInterop": true,
14+
"resolveJsonModule": true,
15+
"allowJs": true,
16+
"checkJs": true,
17+
"baseUrl": ".",
18+
},
19+
"types": [
20+
"node",
21+
"mocha",
22+
"chai"
23+
],
24+
"noEmit": true,
25+
"forceConsistentCasingInFileNames": true
26+
},
27+
"files": [
28+
"./src/index.d.ts"
29+
]
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.