/** * STUN message codec (RFC 5389 + parts of 5766 for TURN integration). * * Supports the subset we need: * - Binding Request / Binding Success Response (RFC 5389) for SRFLX * discovery and ICE connectivity checks. * - Long-term credential MESSAGE-INTEGRITY (HMAC-SHA1) and FINGERPRINT, * needed by the bootnode TURN servers (coturn). * - XOR-MAPPED-ADDRESS decoding. * - USERNAME, REALM, NONCE, ERROR-CODE attributes (TURN auth dance). * - SOFTWARE / FINGERPRINT attributes for being polite. * * Wire format: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |0 0| STUN Message Type | Message Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Magic Cookie | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | Transaction ID (96 bits) | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * Attributes follow as { type: u16, length: u16, value: bytes, pad to 4 }. * * MESSAGE-INTEGRITY is HMAC-SHA1 over the entire message up to (not * including) the MESSAGE-INTEGRITY attribute itself, with the message * length pre-adjusted as if MESSAGE-INTEGRITY were present. */ export declare const STUN_MAGIC_COOKIE = 554869826; export declare const STUN_BINDING_REQUEST = 1; export declare const STUN_BINDING_SUCCESS = 257; export declare const STUN_BINDING_ERROR = 273; export declare const TURN_ALLOCATE_REQUEST = 3; export declare const TURN_ALLOCATE_SUCCESS = 259; export declare const TURN_ALLOCATE_ERROR = 275; export declare const TURN_REFRESH_REQUEST = 4; export declare const TURN_REFRESH_SUCCESS = 260; export declare const TURN_CREATE_PERMISSION_REQUEST = 8; export declare const TURN_CREATE_PERMISSION_SUCCESS = 264; export declare const TURN_SEND_INDICATION = 22; export declare const TURN_DATA_INDICATION = 23; export declare const STUN_ATTR_MAPPED_ADDRESS = 1; export declare const STUN_ATTR_USERNAME = 6; export declare const STUN_ATTR_MESSAGE_INTEGRITY = 8; export declare const STUN_ATTR_ERROR_CODE = 9; export declare const STUN_ATTR_REALM = 20; export declare const STUN_ATTR_NONCE = 21; export declare const STUN_ATTR_XOR_MAPPED_ADDRESS = 32; export declare const STUN_ATTR_SOFTWARE = 32802; export declare const STUN_ATTR_FINGERPRINT = 32808; export declare const STUN_ATTR_CHANNEL_NUMBER = 12; export declare const STUN_ATTR_LIFETIME = 13; export declare const STUN_ATTR_XOR_PEER_ADDRESS = 18; export declare const STUN_ATTR_DATA = 19; export declare const STUN_ATTR_XOR_RELAYED_ADDRESS = 22; export declare const STUN_ATTR_REQUESTED_TRANSPORT = 25; export declare const STUN_ATTR_DONT_FRAGMENT = 26; export interface StunAttribute { type: number; value: Uint8Array; } export interface StunMessage { type: number; transactionId: Uint8Array; attributes: StunAttribute[]; } export interface AddressValue { family: 4 | 6; address: string; port: number; } export declare function newTransactionId(): Uint8Array; /** * Encode a STUN message. If `integrityKey` is provided, a * MESSAGE-INTEGRITY attribute (HMAC-SHA1) is appended. If `fingerprint` * is true, a FINGERPRINT (CRC32 XOR 0x5354554e) is appended last. * * The order matters because MESSAGE-INTEGRITY must be computed over * the message *as if* it were the last attribute (with length already * adjusted), and FINGERPRINT must be computed over the message * including MESSAGE-INTEGRITY. */ export declare function encodeStun(message: StunMessage, opts?: { integrityKey?: Uint8Array; fingerprint?: boolean; }): Uint8Array; export declare function decodeStun(data: Uint8Array): StunMessage | undefined; export declare function findAttr(message: StunMessage, type: number): Uint8Array | undefined; /** * Decode XOR-MAPPED-ADDRESS (RFC 5389 §15.2). The high bits of the * port and the address are XORed with the magic cookie + transactionId. */ export declare function decodeXorMappedAddress(value: Uint8Array, transactionId: Uint8Array): AddressValue | undefined; /** Encode XOR-MAPPED-ADDRESS for outgoing STUN responses (TURN, conn check). */ export declare function encodeXorMappedAddress(addr: AddressValue, transactionId: Uint8Array): Uint8Array; export declare function encodeErrorCode(code: number, reason: string): Uint8Array; export declare function decodeErrorCode(value: Uint8Array): { code: number; reason: string; } | undefined; /** * Long-term-credential integrity key: MD5("username:realm:password"). * RFC 5389 §15.4. coturn uses this. */ export declare function longTermIntegrityKey(username: string, realm: string, password: string): Uint8Array; /** Short-term-credential integrity key: just the password as UTF-8. */ export declare function shortTermIntegrityKey(password: string): Uint8Array; export declare function buildBindingRequest(transactionId?: Uint8Array): Uint8Array; export declare function buildBindingRequestWithIntegrity(opts: { username: string; password: string; transactionId?: Uint8Array; }): Uint8Array;