/// /// import { ILogger } from '@node-dlc/logger'; import { Duplex } from 'stream'; import { HANDSHAKE_STATE } from './handshake-state'; import { NoiseSocketOptions } from './noise-socket-options'; import { READ_STATE } from './read-state'; export declare class NoiseSocket extends Duplex { static READ_STATE: typeof READ_STATE; static HANDSHAKE_STATE: typeof HANDSHAKE_STATE; /** * Remote public key as a 33-byte compressed public key for * elliptic curve secp256k1 */ rpk: Buffer; /** * Indicates if the socket was the connection initiator * which will determine how the handshake happens. */ initiator: boolean; /** * Count of messages received by the socket. */ messagesReceived: number; /** * A logger instance */ logger: ILogger; /** * Controls the handshake process at the start of the connection. * The socket is not readable until the handshake has been performed. */ private _handshakeState; /** * Controls how reading and piping from the underlying TCP socket to * the Duplex Streams read buffer works */ private _readState; /** * Private property that maintains the handshakes and * encrypts and decrypts messages while maintaining the * proper key rotation scheme used defined in BOLT #8. */ private _noiseState; /** * The wrapped socket */ private _socket; /** * Message length state used for messages that may be split * across multiple packets. */ private _l; /** * NoiseSocket is a Duplex Stream that wraps a standard TCP Socket * and layers in the BOLT #8 implementation of the Noise Protocol * Framework. * * This socket can be used for any communication that wants to * benefit from the security and privacy enhancing used by the * Noise Protocol Framework. */ constructor({ socket, noiseState, rpk, logger, highWaterMark, }: NoiseSocketOptions); /** * Half-closes the socket. It is still possible that the opposite * side is still sending data. */ end(): this; /** * Destroys the socket and ensures that no more I/O activity happens * on the socket. When an `err` is included, an 'error' event will * be emitted and all listeners will receive the error as an * argument. * @param err optional error to send */ destroy(err?: Error): this; /** * Fires when the socket has connected. This method initiates the * handshake and if there is a failure, terminates the connection. */ private _onConnected; /** * _onData is triggered by the "readable" event on the * underlying TCP socket. It is called each time there is new data * received. It is responsible for reading data from the socket and * performing the appropriate action given the current read state. */ private _onData; private _initiateHandshake; private _processInitiator; private _processInitiatorReply; private _processResponderReply; private _processPacketLength; private _processPacketBody; _read(): void; _write(data: Buffer, encoding: string, cb: (err: Error) => void): void; _final(): void; }