node-noise
Version:
49 lines (48 loc) • 1.56 kB
TypeScript
/// <reference types="node" />
import * as streams from 'stream';
import type { bytes } from './@types/basic';
import type { HandshakeHandler } from './@types/handshake-interface';
import type { ICryptoInterface } from './crypto';
import type { Metrics } from './@types/metrics';
import { PbStream } from './pb-stream';
export interface HandshakeParams {
connection: PbStream;
isInitiator: boolean;
remoteStaticPublicKey?: Uint8Array;
handshakeHandler?: HandshakeHandler;
noLengthCodec?: boolean;
noiseMsgMaxLengthBytes?: number;
}
export interface SecuredConnection {
conn: streams.Duplex;
remotePublicKey: Uint8Array;
}
export interface NoiseInit {
protocol?: string;
/**
* x25519 private key, reuse for faster handshakes
*/
staticNoiseKey?: bytes;
crypto?: ICryptoInterface;
prologueBytes?: Uint8Array;
metrics?: Metrics;
}
export declare class Noise {
readonly crypto: ICryptoInterface;
private readonly prologue;
private readonly staticKeys;
private readonly metrics?;
private readonly spec;
private readonly handshake;
constructor(init?: NoiseInit);
getPublicKey(): Uint8Array;
secureConnection(parameters: HandshakeParams): Promise<SecuredConnection>;
/**
* If Noise pipes supported, tries IK handshake first with XX as fallback if it fails.
* If noise pipes disabled or remote peer static key is unknown, use XX.
*
* @param {HandshakeParams} params
*/
private performHandshake;
private createSecureConnection;
}