Expand interfaces

This commit is contained in:
Jaco Greeff 2018-06-22 15:43:18 +02:00
parent 771654d5a9
commit 0ff18a85bb
27 changed files with 135 additions and 56 deletions

View File

@ -1,4 +1,4 @@
import blake = require('blakejs'); import blake from 'blakejs';
blake.blake2bHex(new Uint8Array([1, 2, 3, 4, 5])); blake.blake2bHex(new Uint8Array([1, 2, 3, 4, 5]));
blake.blake2sHex(Buffer.from([1, 2, 3, 4, 5])); blake.blake2sHex(Buffer.from([1, 2, 3, 4, 5]));

6
blakejs/index.d.ts vendored
View File

@ -14,7 +14,7 @@ type BlakeJsContext = {
outlen: number outlen: number
}; };
interface blakejs { interface BlakeJs {
blake2b: (data: Buffer | Uint8Array | string, key?: Uint8Array | null, outlen?: number) => Uint8Array, blake2b: (data: Buffer | Uint8Array | string, key?: Uint8Array | null, outlen?: number) => Uint8Array,
blake2bFinal: (context: BlakeJsContext) => Uint8Array, blake2bFinal: (context: BlakeJsContext) => Uint8Array,
blake2bHex: (data: Buffer | Uint8Array | string, key?: Uint8Array | null, outlen?: number) => string, blake2bHex: (data: Buffer | Uint8Array | string, key?: Uint8Array | null, outlen?: number) => string,
@ -27,5 +27,7 @@ interface blakejs {
blake2sUpdate: (context: BlakeJsContext, data: Buffer | Uint8Array | string) => void blake2sUpdate: (context: BlakeJsContext, data: Buffer | Uint8Array | string) => void
} }
export = blakejs; const blakejs: BlakeJs;
export default blakejs;
} }

View File

@ -1,4 +1,4 @@
import BN = require('bn.js'); import BN from 'bn.js';
let bn = new BN(42); let bn = new BN(42);
bn = bn.add(bn); bn = bn.add(bn);

View File

@ -3,10 +3,13 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import PeerInfo = require('peer-info'); // @ts-ignore
import PeerInfo from 'peer-info';
declare interface Connection { declare module 'interface-connection' {
interface Connection {
getPeerInfo (cb: (error: Error | null, peerInfo?: PeerInfo) => any): void; getPeerInfo (cb: (error: Error | null, peerInfo?: PeerInfo) => any): void;
} }
export = Connection; export = Connection;
}

View File

@ -3,7 +3,9 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare interface Transport { declare module 'interface-transport' {
interface Transport {
} }
export = Transport; export = Transport;
}

4
keccak/index.d.ts vendored
View File

@ -16,7 +16,7 @@ interface KeccakHasher {
type KeccakTypes = 'keccak224' | 'keccak256' | 'keccak384' | 'keccak512' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'shake128' | 'shake256'; type KeccakTypes = 'keccak224' | 'keccak256' | 'keccak384' | 'keccak512' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'shake128' | 'shake256';
type keccak = (type: KeccakTypes) => KeccakHasher; const keccak: (type: KeccakTypes) => KeccakHasher;
export = keccak; export default keccak;
} }

View File

@ -1,4 +1,4 @@
import createKeccak = require('keccak'); import createKeccak from 'keccak';
const context = createKeccak('keccak256'); const context = createKeccak('keccak256');

View File

@ -3,7 +3,11 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class LibP2pKadDht { declare module 'libp2p-kad-dht' {
export class LibP2pKadDht {
} }
export = LibP2pKadDht; const DHT: typeof LibP2pKadDht;
export default DHT;
}

View File

@ -3,8 +3,10 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import PeerInfo = require('peer-info'); // @ts-ignore
import PeerInfo from 'peer-info';
declare module 'libp2p-mdns' {
type Options = { type Options = {
broadcast?: boolean, broadcast?: boolean,
interval?: number, interval?: number,
@ -15,10 +17,13 @@ type Options = {
type Events = 'peer'; type Events = 'peer';
declare class LibP2pMdns { export class LibP2pMdns {
constructor (options: Options); constructor (options: Options);
on (event: Events, cb: (peerInfo: PeerInfo) => any): void; on (event: Events, cb: (peerInfo: PeerInfo) => any): void;
} }
export = LibP2pMdns; const Mdns: typeof LibP2pMdns;
export default Mdns;
}

View File

@ -3,9 +3,10 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'libp2p-mplex' {
type Muxer = {}; type Muxer = {};
declare type LibP2pMplex = { export type LibP2pMplex = {
(conn: any, isListener: boolean): Muxer; (conn: any, isListener: boolean): Muxer;
dialer (conn: any): Muxer; dialer (conn: any): Muxer;
@ -14,4 +15,7 @@ declare type LibP2pMplex = {
muticodec: string; muticodec: string;
} }
export = LibP2pMplex; const mplex: LibP2pMplex;
export default mplex;
}

View File

@ -3,9 +3,12 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import MultiAddr = require('multiaddr'); // @ts-ignore
import PeerInfo = require('peer-info'); import MultiAddr from 'multiaddr';
// @ts-ignore
import PeerInfo from 'peer-info';
declare module 'libp2p-railing' {
type Options = { type Options = {
list: Array<string | MultiAddr>, list: Array<string | MultiAddr>,
interval?: number interval?: number
@ -13,10 +16,11 @@ type Options = {
type Events = 'peer'; type Events = 'peer';
declare class LibP2pRailing { export class LibP2pRailing {
constructor (options: Options); constructor (options: Options);
on (event: Events, cb: (peerInfo: PeerInfo) => any): void; on (event: Events, cb: (peerInfo: PeerInfo) => any): void;
} }
export = LibP2pRailing; export = LibP2pRailing;
}

View File

@ -3,12 +3,17 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import PeerId = require('peer-id'); // @ts-ignore
import PeerId from 'peer-id';
declare type LibP2pSecio = { declare module 'libp2p-secio' {
export type LibP2pSecio = {
tag: '/secio/1.0.0', tag: '/secio/1.0.0',
encrypt (localId: PeerId, conn: any, remoteId: PeerId, callback: () => any): void encrypt (localId: PeerId, conn: any, remoteId: PeerId, callback: () => any): void
} }
export = LibP2pSecio; const secio: LibP2pSecio;
export default secio;
}

View File

@ -3,9 +3,10 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'libp2p-spdy' {
type Muxer = {}; type Muxer = {};
declare type LibP2pSpdy = { export type LibP2pSpdy = {
(conn: any, isListener: boolean): Muxer; (conn: any, isListener: boolean): Muxer;
dialer (conn: any): Muxer; dialer (conn: any): Muxer;
@ -14,4 +15,7 @@ declare type LibP2pSpdy = {
muticodec: string; muticodec: string;
} }
export = LibP2pSpdy; const spdy: LibP2pSpdy;
export default spdy;
}

View File

@ -0,0 +1 @@
import spdy from 'libp2p-spdy';

View File

@ -3,9 +3,12 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Transport = require('interface-transport'); // @ts-ignore
import Transport from 'interface-transport';
declare class LibP2pTcp implements Transport { declare module 'libp2p-tcp' {
export class LibP2pTcp implements Transport {
} }
export = LibP2pTcp; export = LibP2pTcp;
}

View File

@ -3,9 +3,12 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Transport = require('interface-transport'); // @ts-ignore
import Transport from 'interface-transport';
declare class LibP2pWebRtcDirect implements Transport { declare module 'libp2p-webrtc-direct' {
export class LibP2pWebRtcDirect implements Transport {
} }
export = LibP2pWebRtcDirect; export = LibP2pWebRtcDirect;
}

View File

@ -3,9 +3,12 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Transport = require('interface-transport'); // @ts-ignore
import Transport from 'interface-transport';
declare class LibP2pWebRtcStar implements Transport { declare module 'libp2p-webrtc-star' {
export class LibP2pWebRtcStar implements Transport {
} }
export = LibP2pWebRtcStar; export = LibP2pWebRtcStar;
}

View File

@ -3,9 +3,12 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Transport = require('interface-transport'); // @ts-ignore
import Transport from 'interface-transport';
declare class LibP2pWebsockets implements Transport { declare module 'libp2p-websockets' {
export class LibP2pWebsockets implements Transport {
} }
export = LibP2pWebsockets; export = LibP2pWebsockets;
}

36
libp2p/index.d.ts vendored
View File

@ -3,17 +3,28 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Connection = require('interface-connection'); // @ts-ignore
import Transport = require('interface-transport'); import Connection from 'interface-connection';
import Libp2pKadDHT = require('libp2p-kad-dht'); // @ts-ignore
import LibP2pMdns = require('libp2p-mdns'); import Transport from 'interface-transport';
import LibP2pMplex = require('libp2p-mplex'); // @ts-ignore
import LibP2pRailing = require('libp2p-railing'); import { Libp2pKadDHT } from 'libp2p-kad-dht';
import LibP2pSecio = require('libp2p-secio'); // @ts-ignore
import LibP2pSpdy = require('libp2p-spdy'); import LibP2pMdns from 'libp2p-mdns';
import PeerBook = require('peer-book'); // @ts-ignore
import PeerInfo = require('peer-info'); import { LibP2pMplex } from 'libp2p-mplex';
// @ts-ignore
import LibP2pRailing from 'libp2p-railing';
// @ts-ignore
import { LibP2pSecio } from 'libp2p-secio';
// @ts-ignore
import { LibP2pSpdy } from 'libp2p-spdy';
// @ts-ignore
import PeerBook from 'peer-book';
// @ts-ignore
import PeerInfo from 'peer-info';
declare module 'libp2p' {
type CreateOptions = { type CreateOptions = {
DHT: typeof Libp2pKadDHT, DHT: typeof Libp2pKadDHT,
connection: { connection: {
@ -26,7 +37,7 @@ type CreateOptions = {
type Events = 'peer:connect' | 'peer:disconnect' | 'peer:discovery' | 'start' | 'stop'; type Events = 'peer:connect' | 'peer:disconnect' | 'peer:discovery' | 'start' | 'stop';
declare class LibP2p { export class LibP2p {
constructor (peerInfo: PeerInfo, PeerBook: PeerBook, options: CreateOptions); constructor (peerInfo: PeerInfo, PeerBook: PeerBook, options: CreateOptions);
dial (peerInfo: PeerInfo, cb: (error: Error | null) => any): void; dial (peerInfo: PeerInfo, cb: (error: Error | null) => any): void;
@ -38,4 +49,5 @@ declare class LibP2p {
stop (cb: (error: Error | null) => any): void; stop (cb: (error: Error | null) => any): void;
} }
export = LibP2p; export default LibP2p;
}

View File

@ -5,8 +5,10 @@
/// <reference types="node"/> /// <reference types="node"/>
import PeerId = require('peer-id'); // @ts-ignore
import PeerId from 'peer-id';
declare module 'multiaddr' {
type Address = { type Address = {
family: string, family: string,
host: string, host: string,
@ -27,7 +29,7 @@ type Tuple = [ number, Buffer ];
type TupleString = [ number, string ]; type TupleString = [ number, string ];
declare class MultiAddr { class MultiAddr {
constructor (addr: MultiAddr | Buffer | string); constructor (addr: MultiAddr | Buffer | string);
static isMultiAddr (addr: any): addr is MultiAddr; static isMultiAddr (addr: any): addr is MultiAddr;
@ -51,3 +53,4 @@ declare class MultiAddr {
} }
export = MultiAddr; export = MultiAddr;
}

View File

@ -7,7 +7,7 @@
"license": "ISC", "license": "ISC",
"scripts": { "scripts": {
"build": "./build.sh", "build": "./build.sh",
"check": "echo \"No 'yarn run check' available\"", "check": "tsc --noEmit",
"test": "echo \"No 'yarn run test' available\"" "test": "echo \"No 'yarn run test' available\""
}, },
"devDependencies": { "devDependencies": {

10
peer-book/index.d.ts vendored
View File

@ -3,10 +3,13 @@
// Definitions by: Jaco Greeff <https://github.com/jacogr> // Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import PeerId = require('peer-id'); // @ts-ignore
import PeerInfo = require('peer-info'); import PeerId from 'peer-id';
// @ts-ignore
import PeerInfo from 'peer-info';
declare class PeerBook { declare module 'peer-book' {
class PeerBook {
constructor (); constructor ();
get (peer: PeerId | PeerInfo | string): PeerInfo; get (peer: PeerId | PeerInfo | string): PeerInfo;
@ -19,3 +22,4 @@ declare class PeerBook {
} }
export = PeerBook; export = PeerBook;
}

4
peer-id/index.d.ts vendored
View File

@ -5,6 +5,7 @@
/// <reference types="node"/> /// <reference types="node"/>
declare module 'peer-id' {
type CreateCb = (error: Error | null, peerId?: PeerId) => any; type CreateCb = (error: Error | null, peerId?: PeerId) => any;
type CreateOptions = { type CreateOptions = {
@ -17,7 +18,7 @@ type JSON = {
privKey: string privKey: string
}; };
declare class PeerId { class PeerId {
constructor (id: Buffer, privKey?: any, pubKey?: any); constructor (id: Buffer, privKey?: any, pubKey?: any);
static create (optsOrCb: CreateOptions | CreateCb, cb?: CreateCb): PeerId; static create (optsOrCb: CreateOptions | CreateCb, cb?: CreateCb): PeerId;
@ -36,3 +37,4 @@ declare class PeerId {
} }
export = PeerId; export = PeerId;
}

10
peer-info/index.d.ts vendored
View File

@ -5,9 +5,12 @@
/// <reference types="node"/> /// <reference types="node"/>
import MultiAddr = require('multiaddr'); // @ts-ignore
import PeerId = require('peer-id'); import MultiAddr from 'multiaddr';
// @ts-ignore
import PeerId from 'peer-id';
declare module 'peer-info' {
type CreateCb = (error: Error | null, peerId?: PeerId) => any; type CreateCb = (error: Error | null, peerId?: PeerId) => any;
type CreateOptions = { type CreateOptions = {
@ -32,7 +35,7 @@ type MultiAddrSet = {
toArray (): MultiAddr[]; toArray (): MultiAddr[];
}; };
declare class PeerInfo { class PeerInfo {
constructor (id?: PeerId); constructor (id?: PeerId);
static create (optsOrCb: CreateOptions | CreateCb, cb?: CreateCb): PeerInfo; static create (optsOrCb: CreateOptions | CreateCb, cb?: CreateCb): PeerInfo;
@ -46,3 +49,4 @@ declare class PeerInfo {
} }
export = PeerInfo; export = PeerInfo;
}

3
tsconfig.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "./node_modules/@polkadot/dev/config/tsconfig"
}

View File

@ -56,5 +56,7 @@ type TweetNacl = {
sign: Sign sign: Sign
}; };
export = TweetNacl; const tweetnacl: TweetNacl;
export default tweetnacl;
} }

View File

@ -0,0 +1,3 @@
import nacl from 'tweetnacl';
nacl.randomBytes(24);