pocket-messaging
Version:
A small cryptographic messaging library written in TypeScript both for browser and nodejs supporting TCP and WebSockets
30 lines (29 loc) • 1.25 kB
TypeScript
/// <reference types="node" />
import { ClientInterface, SocketDataCallback, WrappedClient } from "pocket-sockets";
/**
* Wrap an already connected and handshooked socket client as encrypted.
*
*/
export declare class EncryptedClient extends WrappedClient {
protected outgoingKey: Buffer;
protected outgoingNonce: Buffer;
protected incomingKey: Buffer;
protected incomingNonce: Buffer;
protected peerPublicKey: Buffer;
protected handlers: {
[type: string]: ((data?: any) => void)[];
};
protected incomingData: Buffer;
constructor(client: ClientInterface, outgoingKey: Buffer, outgoingNonce: Buffer, incomingKey: Buffer, incomingNonce: Buffer, peerPublicKey: Buffer);
init(): Promise<void>;
unRead(data: Buffer): void;
getPeerPublicKey(): Buffer;
protected decryptData(): void;
send(data: Buffer): void;
onData(fn: SocketDataCallback): void;
offData(fn: SocketDataCallback): void;
protected handleOnData: (data: Buffer | string) => Promise<void>;
protected hookEvent(type: string, callback: (...args: any[]) => void): void;
protected unhookEvent(type: string, callback: (...args: any[]) => void): void;
protected triggerEvent(type: string, ...args: any[]): void;
}