/** * @file protocol.ts * @description DTLS 1.2 wire-format constants and TLV/vector encoders. * @module dtls/protocol * * Covers exactly what WebRTC's data channel needs: * cipher suite TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xC02B) * curve secp256r1, signature scheme ecdsa_secp256r1_sha256. * * References: RFC 6347 (DTLS 1.2), RFC 5246 (TLS 1.2), RFC 8422 (ECC). */ export declare const DTLS_1_2 = 65277; export declare const CONTENT_TYPE: Readonly<{ CHANGE_CIPHER_SPEC: 20; ALERT: 21; HANDSHAKE: 22; APPLICATION_DATA: 23; }>; export declare const HANDSHAKE_TYPE: Readonly<{ HELLO_REQUEST: 0; CLIENT_HELLO: 1; SERVER_HELLO: 2; HELLO_VERIFY_REQUEST: 3; CERTIFICATE: 11; SERVER_KEY_EXCHANGE: 12; CERTIFICATE_REQUEST: 13; SERVER_HELLO_DONE: 14; CERTIFICATE_VERIFY: 15; CLIENT_KEY_EXCHANGE: 16; FINISHED: 20; }>; export declare const ALERT_LEVEL: Readonly<{ WARNING: 1; FATAL: 2; }>; export declare const ALERT_DESC: Readonly<{ CLOSE_NOTIFY: 0; HANDSHAKE_FAILURE: 40; BAD_CERTIFICATE: 42; DECRYPT_ERROR: 51; INTERNAL_ERROR: 80; }>; export declare const CIPHER_SUITE = 49195; export declare const NAMED_GROUP: Readonly<{ secp256r1: 23; }>; export declare const EC_POINT_FORMAT: Readonly<{ uncompressed: 0; }>; export declare const HASH_ALG: Readonly<{ sha256: 4; sha384: 5; sha512: 6; }>; export declare const SIG_ALG: Readonly<{ rsa: 1; ecdsa: 3; }>; export declare const CERT_TYPE: Readonly<{ ecdsa_sign: 64; rsa_sign: 1; }>; export declare const EXTENSION: Readonly<{ SUPPORTED_GROUPS: 10; EC_POINT_FORMATS: 11; SIGNATURE_ALGORITHMS: 13; EXTENDED_MASTER_SECRET: 23; RENEGOTIATION_INFO: 65281; }>; export declare const FINISHED_LABEL: Readonly<{ CLIENT: "client finished"; SERVER: "server finished"; }>; /** A parsed DTLS record from {@link parseRecords}. */ export interface Record { type: number; version: number; epoch: number; seq: number; fragment: Buffer; } /** A parsed handshake message header from {@link parseHandshake}. */ export interface Handshake { msgType: number; length: number; messageSeq: number; fragmentOffset: number; fragmentLength: number; body: Buffer; } /** Encode a uint24 (3 bytes, big-endian). */ export declare function uint24(n: number): Buffer; /** Read a uint24 at offset. */ export declare function readUint24(buf: Buffer, off: number): number; /** Length-prefixed vector with a 1-byte length. */ export declare function vec8(body: Buffer): Buffer; /** Length-prefixed vector with a 2-byte length. */ export declare function vec16(body: Buffer): Buffer; /** Length-prefixed vector with a 3-byte length. */ export declare function vec24(body: Buffer): Buffer; /** * Encode a DTLS record (13-byte header + fragment). * @param type - CONTENT_TYPE * @param epoch * @param seq - 48-bit sequence number * @param fragment * @param version */ export declare function encodeRecord(type: number, epoch: number, seq: number, fragment: Buffer, version?: number): Buffer; /** * Parse one or more DTLS records from a datagram. Multiple records may be * packed into a single UDP packet. * @param packet */ export declare function parseRecords(packet: Buffer): Record[]; /** * Encode a DTLS handshake message header + body (unfragmented). * @param msgType - HANDSHAKE_TYPE * @param messageSeq * @param body */ export declare function encodeHandshake(msgType: number, messageSeq: number, body: Buffer): Buffer; /** * Parse a handshake message header. * @param buf - starts at the handshake header */ export declare function parseHandshake(buf: Buffer): Handshake;