tuned to make it work for my use case

This commit is contained in:
Peter Murray 2018-09-18 20:09:35 -04:00
parent 0bd14a8898
commit 54775022f6
5 changed files with 45 additions and 28 deletions

View File

@ -31,13 +31,23 @@ declare namespace LibP2pCrypto {
};
}
interface Cipher {
encrypt(data: Buffer, cb: (err?: Error, data?: Buffer) => void): void;
decrypt(data: Buffer, cb: (err?: Error, data?: Buffer) => void): void;
}
interface AES {
create(key: Buffer, iv: Buffer, cb: (err?: Error, cipher?: Cipher) => void): void;
}
interface Crypto {
readonly keys: Keys
readonly keys: Keys,
readonly aes: AES
}
}
declare module 'libp2p-crypto' {
const crypto: LibP2pCrypto.Crypto;
const crypto: LibP2pCrypto.Crypto;
export default crypto;
export default crypto;
}

View File

@ -6,8 +6,9 @@
/// <reference types="interface-transport"/>
declare class LibP2pWebRtcStar implements LibP2pTransport {
constructor(config?: any);
}
declare module 'libp2p-webrtc-star' {
export default LibP2pWebRtcStar;
export default LibP2pWebRtcStar;
}

View File

@ -70,7 +70,7 @@ declare class LibP2p {
readonly peerInfo: PeerInfo;
dial(peerInfo: PeerInfo, cb: (error: Error | null) => any): void;
dialProtocol(peerInfo: PeerInfo, protocol: string, cb: (error: Error | null, conn?: LibP2pConnection) => any): void;
dialProtocol(peerInfo: PeerInfo | Multiaddr.Multiaddr, protocol: string, cb: (error: Error | null, conn?: LibP2pConnection) => any): void;
handle(protocol: string, handler: (protocol: string, conn: LibP2pConnection) => any, matcher?: (protocol: string, requestedProtocol: string, cb: (error: Error | null, accept: boolean) => void) => any): void;
isStarted(): boolean;
on(event: LibP2p.Events, cb: (event: any) => any): void;

View File

@ -21,23 +21,23 @@ declare namespace PeerId {
}
declare class PeerId {
constructor (id: Buffer, privKey?: LibP2pCrypto.PrivateKey, pubKey?: LibP2pCrypto.PublicKey);
constructor(id: Buffer, privKey?: LibP2pCrypto.PrivateKey, pubKey?: LibP2pCrypto.PublicKey);
static create (optsOrCb: PeerId.CreateOptions | PeerId.CreateCb, cb?: PeerId.CreateCb): PeerId;
static createFromB58String (str: string): PeerId;
static createFromBytes (buf: Buffer): PeerId;
static createFromHexString (str: string): PeerId;
static createFromJSON (json: JSON): PeerId;
static createFromPubKey (key: Buffer): PeerId;
static createFromPrivKey (key: Buffer): PeerId;
static create(optsOrCb: PeerId.CreateOptions | PeerId.CreateCb, cb?: PeerId.CreateCb): void;
static createFromB58String(str: string): PeerId;
static createFromBytes(buf: Buffer): PeerId;
static createFromHexString(str: string): PeerId;
static createFromJSON(json: JSON): PeerId;
static createFromPubKey(key: Buffer): PeerId;
static createFromPrivKey(key: Buffer, cb: PeerId.CreateCb): void;
isEqual (other: PeerId | Buffer): boolean;
toB58String (): string;
toBytes (): Buffer;
toHexString (): string;
toJSON (): PeerId.JSON;
isEqual(other: PeerId | Buffer): boolean;
toB58String(): string;
toBytes(): Buffer;
toHexString(): string;
toJSON(): PeerId.JSON;
}
declare module 'peer-id' {
export default PeerId;
export default PeerId;
}

View File

@ -6,16 +6,22 @@
/// <reference types="node"/>
declare module 'pull-stream' {
export type PullStream = {
// FIXME this should be actual streams, not 'any'
(...streams: Array<any>): void;
export type PullStream = {
// FIXME this should be actual streams, not 'any'
(...streams: Array<any>): void;
collect: (cb: (error: Error | null, values: Array<Buffer>) => any) => void,
drain: (handler: (message: Buffer) => void, errorHandler?: (error: Error) => boolean) => void;
values: (values: Array<string | Buffer>) => void;
};
collect: (cb: (error: Error | null, values: Array<Buffer>) => any) => void,
drain: (handler: (message: Buffer) => void, errorHandler?: (error: Error) => boolean) => void;
values: (values: Array<string | Buffer>) => void;
map: (mapper: (x: any) => any) => any;
asyncMap: (mapper: (x: any, cb: (err?: Error, data?: any) => void) => void) => void;
};
const pull: PullStream;
const pull: PullStream;
export default pull;
export default pull;
}
declare module 'pull-catch' {
export default function Catch(handler: (error: Error) => void): any;
}