@benkovy/doh-protocol
v0.1.2
Published
Shared protocol schemas and envelope types for DOH
Readme
@benkovy/doh-protocol
Shared protocol package for all DOH runtime components.
Purpose
This package defines wire-level message schemas and strongly-typed envelopes used by:
@benkovy/doh-backend@benkovy/doh-host- future DOH channel clients
Using one package for contracts prevents drift between backend and host/client implementations.
Scope
Current schema set includes:
- host handshake envelopes (
host.hello,backend.challenge,host.proof,backend.ready,backend.error) - relay command envelopes (
relay.send,relay.history.request,relay.conversations.request) - relay stream envelopes (
relay.event,relay.history.response,relay.conversations.response) - client stream control envelopes (
client.hello,client.subscribe,client.unsubscribe) - backend->client stream envelopes (
backend.client.ready,backend.client.event,backend.client.error)
Host auth handshake (P1-1)
Current handshake sequence:
- Host sends
host.hello - Backend replies with
backend.challenge(challengeId,nonce,expiresAt) - Host sends
host.proofwith HMAC signature over canonical proof base - Backend replies
backend.readyon success, orbackend.erroron failure
buildHostProofBase(...) is exported and should be used by both backend and connector to avoid signature drift.
Backend auth error codes
AUTH_REQUIREDAUTH_INVALID_HOSTAUTH_CHALLENGE_REQUIREDAUTH_CHALLENGE_EXPIREDAUTH_CHALLENGE_MISMATCHAUTH_TIMESTAMP_SKEWAUTH_SIGNATURE_INVALIDAUTH_REPLAY_DETECTEDBAD_ENVELOPEINTERNAL_ERROR
Validation approach
- Runtime validation uses
zod - Compile-time types are inferred from schemas
- Envelope parsing should happen at every trust boundary
Usage
import { parseBackendEnvelope } from "@benkovy/doh-protocol";
const envelope = parseBackendEnvelope(JSON.parse(raw));Design notes
- Keep envelope
typevalues stable and additive - Prefer optional fields for backward compatible evolution
- Use explicit ids (
eventId,requestId,clientMessageId) for idempotency and reconciliation
