Files
web-terminal/relay-e2e/src/errors.ts
Yaojia Wang 2af57e6686 feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)
Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.

Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
  capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay:   native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent:        host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e:    browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth:   Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web:    browser login + Web Crypto E2E + client-side preview rendering

Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.

NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
2026-07-02 06:10:16 +02:00

60 lines
2.0 KiB
TypeScript

/**
* T0 — typed error classes for relay-e2e (PLAN_RELAY_E2E §3 T0).
*
* Every error subclasses {@link E2EError} and carries a stable, greppable `code`. Per INV9,
* a thrown message MUST NEVER embed key/nonce/plaintext material — callers surface the code,
* not secret bytes. No `console` here; the caller decides how to handle.
*/
/** Base class for all relay-e2e crypto errors. */
export class E2EError extends Error {
readonly code: string
constructor(code: string, message: string) {
super(message)
this.name = new.target.name
this.code = code
}
}
/** Pinned enroll_fpr / registry pubkey disagreement ⇒ MITM abort (§4d). */
export class FingerprintMismatchError extends E2EError {
constructor(message = 'host fingerprint mismatch') {
super('E2E_FINGERPRINT_MISMATCH', message)
}
}
/** AEAD tag verification failed ⇒ drop the frame and tear the session down. */
export class AeadOpenError extends E2EError {
constructor(message = 'AEAD authentication failed') {
super('E2E_AEAD_OPEN', message)
}
}
/** Sequence number non-monotonic / duplicate / reordered / gapped (INV13). */
export class ReplayError extends E2EError {
constructor(message = 'sequence replay/reorder rejected') {
super('E2E_REPLAY', message)
}
}
/** Illegal handshake transition, wrong phase, or unusable negotiation. */
export class HandshakeStateError extends E2EError {
constructor(message = 'illegal handshake state transition') {
super('E2E_HANDSHAKE_STATE', message)
}
}
/** Malformed wire bytes / unsupported version / bad AEAD id. */
export class EnvelopeFormatError extends E2EError {
constructor(message = 'malformed envelope') {
super('E2E_ENVELOPE_FORMAT', message)
}
}
/** No WebCrypto / CSPRNG available in the host environment (fail-fast boundary). */
export class CryptoUnavailableError extends E2EError {
constructor(message = 'WebCrypto is unavailable in this environment') {
super('E2E_CRYPTO_UNAVAILABLE', message)
}
}