@mega-yfue/eufy-sdk / hexToRawDp
Function: hexToRawDp()
function hexToRawDp(hex): string | undefined;Hex the biz stream carries, re-encoded as the base64 a RawDpCodec reads — or undefined when the input is not clean hex.
The validation is the point, and it is not paranoia. Buffer.from(s, "hex") never throws: it decodes until it meets a character that is not a hex digit and silently returns what it got, and it drops a trailing half-byte from an odd-length string. For base64 that silent truncation is harmless, because the codec's length prefix will not match the shortened body and the payload is rejected — the reader's own doc says so. Hex breaks that guarantee: truncation removes bytes from the END, so "02" + "aabb" + <garbage> decodes to a prefix of 2 followed by exactly two bytes, passes the length check, and hands back a message with the garbage quietly discarded. A shorter, self-consistent, WRONG payload is the one failure the codec cannot catch for us, so it is caught here instead.
An empty string is undefined rather than an empty frame: the envelope omits the field entirely when there is nothing to send, so "" means "no payload", not "a payload of no bytes".
Parameters
hex
string
Returns
string | undefined