Skip to main content

Protocol Reference

The HxTP/3.1 protocol uses a FROZEN Pipe-Separated Framing format for signing. This ensures bit-perfect identical representations across JavaScript, Python, Go, and C++ while being more efficient for embedded parsers.

Canonical Framing (Pipe-Separated)​

HxTP/3.1 uses a deterministic framing string. This string is built by concatenating specific fields separated by the pipe character (|).

Deterministic Rules​

  1. Strict Order: Fields must follow the exact 11-field sequence defined below.
  2. Escaping: Special characters within fields (|, \, \n, \r) must be escaped with a backslash.
  3. NFC Normalization: All strings are normalized using Unicode NFC before framing.
  4. Timestamp/Sequence: Numeric values are converted to their base-10 string representation.

Canonical Fields (11 total)​

The following fields are included in the signature base string, in this exact order:

version|device_id|tenant_id|client_id|message_id|request_id|sequence_number|timestamp|nonce|message_type|payload_hash
FieldTypeDescription
versionstringProtocol version (must be "HxTP/3.1")
device_idstringOriginating device ID (UUID)
tenant_idstringTenant namespace (UUID or slug)
client_idstringOriginating client ID or MQTT Session Token
message_idstringUnique message ID (UUID v4)
request_idstringCorrelation ID (UUID v4)
sequence_numbernumberMonotonic sequence number
timestampnumberUnix timestamp (seconds or milliseconds)
noncestringCryptographic nonce (minimum 16 bytes)
message_typestringMessage type (state, command, heartbeat, hello, ack)
payload_hashstringSHA-256 hex digest of the payload (params or state)

Implementation Examples​

JavaScript (TypeScript)​

import { BuildCanonical } from 'hxtp-js';

const message = {
version: 'HxTP/3.1',
device_id: '...',
tenant_id: '...',
client_id: '...',
message_id: '...',
request_id: '...',
sequence_number: 101,
timestamp: 1713984000,
nonce: '...',
message_type: 'command',
payload_hash: '...',
};

const canonical = BuildCanonical(message);
// Result: HxTP/3.1|device-uuid|tenant-uuid|client-uuid|msg-uuid|req-uuid|101|1713984000|nonce|command|hash

Validation Pipeline​

Server (7 Steps)​

  1. Version — Must equal HxTP/3.1.
  2. Timestamp Freshness — Must be within ±30 seconds of server time.
  3. Payload Size — Hard limit of 16KB.
  4. Nonce Uniqueness — Verified against global Redis cache (60s TTL).
  5. Payload Hash — SHA-256 of the payload (canonical JSON) must match the header.
  6. Sequence Monotonicity — Must be strictly increasing per-device/tenant boundary.
  7. Ed25519 Signature — Verified using the device's registered Public Key.

Client (Embedded)​

  1. Version — Must equal HxTP/3.1.
  2. Timestamp Freshness — Validated using internal RTC or NTP sync.
  3. Payload Size — Validated against internal buffer capacity.
  4. Nonce — Optional local replay cache.
  5. Payload Hash — SHA-256 verification of the command params.
  6. Signature — Ed25519 verification using the hardcoded Cloud Root Public Key.

Error Codes​

CodeDescription
VERSION_MISMATCHUnsupported protocol version (requires 3.1)
TIMESTAMP_REJECTEDMessage outside allowed Âą30s window
NONCE_REUSEDReplay detected via nonce cache
PAYLOAD_TOO_LARGEExceeds 16KB limit
HASH_MISMATCHPayload hash verification failed
SEQUENCE_VIOLATIONSequence number is not strictly increasing
SIGNATURE_INVALIDEd25519 signature verification failed
DEVICE_NOT_ACTIVEDevice has not completed the HELLO handshake
DEVICE_REVOKEDDevice permanently blacklisted