Skip to content

feat(zap): ZAP wire v1.0 — handshake/seq/retry/FIN session layer + spec + vectors (#85)#129

Open
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/issue-85-zap-wire-v1
Open

feat(zap): ZAP wire v1.0 — handshake/seq/retry/FIN session layer + spec + vectors (#85)#129
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/issue-85-zap-wire-v1

Conversation

@Pattermesh

Copy link
Copy Markdown
Collaborator

Implements ZAP wire v1.0 for #85: spec doc, pure-Python session state machine, conformance vectors, 25 TDD tests.

🤖 Generated with Claude Code

Add the connection-level ZAP wire v1.0 session semantics that sit under the
existing PaymentOffer/PaymentProof codecs. Pure-Python, no zap_py dependency.

Spec (docs/zap-wire-spec-v1.0.md): 26-byte frame header (magic 0x5A50,
wire version, frame type, flags, per-direction u32 seq, cumulative u32 ack,
u64 request_id, length-prefixed payload); HELLO/WELCOME handshake; capability
bitmask = 8 bits version + 24 bits feature flags (baseline 0x0100001F);
cumulative ACK; configurable-RTT retry with exponential backoff; request_id
idempotency/dedup; graceful FIN with orphaned-sequence handling; RST error
codes; full state machine.

Code (switchboard/zap_transport.py): SessionFrame encode/decode, capability
make/negotiate helpers, and the ZapSession state machine (handshake, in-order
+ reorder-buffered delivery, cumulative ack, retransmit queue with injectable
clock, idempotent dedup, FIN/close + incomplete-gap detection).

Tests: 25 new pure-Python tests in tests/test_zap_transport.py plus static
byte-for-byte conformance vectors in tests/protocol_vectors/zap_session.v1.json.
`python3 -m pytest tests/test_zap_transport.py -q` -> 28 passed, 36 skipped.

Does not touch x402_middleware.py, gas_*.py, or lucidly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FRAME_RST,
}
# Frame types that consume sequence space (spec §5).
_SEQ_CONSUMING = {FRAME_HELLO, FRAME_WELCOME, FRAME_DATA, FRAME_FIN}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants