/** * ESPHome Noise Protocol Implementation * * Implements the Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake pattern * for encrypted communication with ESPHome devices. * * Reference: https://noiseprotocol.org/noise.html */ import { Bytes, type BytesView } from "@zwave-js/shared"; export declare const NOISE_INDICATOR = 1; export declare const PLAINTEXT_INDICATOR = 0; export interface ServerHello { protocolVersion: number; deviceName: string; macAddress: string; } /** * Parse the ServerHello message sent by ESPHome during Noise handshake */ export declare function parseServerHello(data: BytesView): ServerHello; /** * Encode a Noise frame with indicator and size header */ export declare function encodeNoiseFrame(payload: BytesView): Bytes; /** * Decode a Noise frame, extracting the payload * Returns the payload and number of bytes consumed */ export declare function decodeNoiseFrame(data: BytesView): { payload: Bytes; bytesRead: number; }; /** * Cipher state for Noise protocol encryption/decryption */ export declare class NoiseCipherState { private k; private n; /** * Initialize the cipher with a key */ initializeKey(key: BytesView): void; /** * Check if a key has been set */ hasKey(): boolean; /** * Get the current nonce as a 12-byte buffer (4 zero bytes + 8-byte LE counter) */ private getNonce; /** * Encrypt with associated data */ encryptWithAd(ad: BytesView, plaintext: BytesView): Promise; /** * Decrypt with associated data */ decryptWithAd(ad: BytesView, ciphertext: BytesView): Promise; } /** * Symmetric state for Noise protocol handshake */ export declare class NoiseSymmetricState { private ck; private h; private cipherState; private constructor(); /** * Initialize symmetric state with protocol name */ static initialize(protocolName: string): Promise; /** * Mix key material into the chaining key */ mixKey(inputKeyMaterial: BytesView): Promise; /** * Mix data into the handshake hash */ mixHash(data: BytesView): Promise; /** * Mix key and hash (for PSK) */ mixKeyAndHash(inputKeyMaterial: BytesView): Promise; /** * Encrypt and mix into hash */ encryptAndHash(plaintext: BytesView): Promise; /** * Decrypt and mix into hash */ decryptAndHash(ciphertext: BytesView): Promise; /** * Split into two cipher states for transport */ split(): Promise<{ c1: NoiseCipherState; c2: NoiseCipherState; }>; /** * Get the current handshake hash (for debugging) */ getHandshakeHash(): Bytes; } /** * Handshake state implementing the NNpsk0 pattern for initiator (client) * * NNpsk0 pattern: * -> psk, e * <- e, ee */ export declare class NoiseHandshakeState { private symmetricState; private e; private re; private psk; private messageIndex; private initialized; constructor(psk: BytesView); /** * Initialize the handshake state (must be called before writeMessage/readMessage) */ initialize(): Promise; /** * Write the first handshake message: -> psk, e */ writeMessage(payload: BytesView): Promise; /** * Read the second handshake message: <- e, ee */ readMessage(message: BytesView): Promise; /** * Split into transport cipher states after handshake completion */ split(): Promise<{ sendCipher: NoiseCipherState; receiveCipher: NoiseCipherState; }>; } //# sourceMappingURL=NoiseProtocol.d.ts.map