zap_transport: binary wire encoding for PaymentOffer / PaymentProof#21
Open
zap_transport: binary wire encoding for PaymentOffer / PaymentProof#21
Conversation
Python NonceManager class with thread-safe state, ChainClient protocol abstraction, pending nonce tracking, and re-queue callback for reorg handling. Author: @ledgerpilot Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Complete implementation: Solidity AgentEscrow contract with timeout/refund + Python payment client + comprehensive tests. Trustless escrow flow with payer/payee confirmation. Author: @D2758695161 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
) Closes #5. Tracks cumulative gas spent per wallet over rolling hour + day windows, auto-pauses the wallet when a limit is crossed, and exposes status/reset/resume controls. - switchboard/gas_budget.py — tracker, limits, BudgetExhausted - tests/test_gas_budget.py — 14 pytest cases incl. thread-safety and window-roll assertions using an injectable clock No new runtime deps. Rolling windows (not calendar buckets) so a burst at 23:59 cannot reset one minute later.
Adds web/index.html — zero-build explorer of the 2026 agent- payment landscape and how switchboard fits alongside. - Tab-switcher across five rails: x402 (Linux Foundation / USDC HTTP 402), MPP (Stripe × Tempo sessions), AP2 (Google A2A + Verifiable Intent), Circle Nanopayments, switchboard's own on- chain AgentEscrow.sol. - For each: 4-step sequence diagram (SVG, swim-lane per actor, active-step highlight) + wire-level code snippet (HTTP, JSON body, Solidity call) that updates as you click through steps. - Side-by-side compatibility matrix: transport, settlement asset, agent↔agent vs agent↔server, streaming, dispute resolution, fiat rails, license. - "How switchboard fits" section explaining the gap the open rails leave (agent-side keys, nonces, gas budgets, escrow) and pointing at the open issues. Single file, no build, no backend. Same dark palette as the other kcolbchain dashboards. Co-authored-by: Abhishek Krishna <[email protected]>
fix: Add gas budget tracker with configurable limits
…19) Adds X402Middleware that intercepts HTTP 402 responses and automatically pays on-chain via PaymentClient, then retries with X-Payment-Proof header. - Supports exact (direct transfer) and escrow payment schemes - Policy enforcement: max payment cap, recipient allowlist, gas budget - Payment history tracking and spend summaries - 15 tests covering offer parsing, validation, payment execution Closes #16 Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Adds switchboard/zap_transport.py — encode/decode PaymentOffer and
PaymentProof over the ZAP wire format (luxfi/zap, port 9999) as a
zero-allocation alternative to the existing JSON-in-HTTP-headers path.
Why: switchboard's HTTP/JSON transport is fine for HTTP/REST agents
but expensive for high-volume agent-to-agent traffic (every offer
parsed, allocated, copied). When two agents sit on the same Lux
network, ZAP lets them exchange offers/proofs with zero parse-time
allocation and ~10x smaller payloads.
zap_py is an optional dependency. If it isn't installed, the module
still imports cleanly and encode/decode raise ZapNotAvailable so
callers can fall back to the JSON path. Tests use pytest.importorskip
so the suite stays green either way.
Wire layout uses zap_py.StructBuilder so the schema is pinned and a
Go counterpart can mirror it exactly:
PaymentOffer:
scheme(u8) | chain_id(u64) | expires_at(u64, 0=null)
| recipient(address) | amount(bytes,uint256-be) | currency(text)
| description(text) | endpoint(text) | nonce(text)
PaymentProof:
chain_id(u64) | timestamp(u64) | payer(address) | tx_hash(hash32)
| amount(bytes,uint256-be) | nonce(text)
amount is a 32-byte big-endian uint256 rather than a uint64 so realistic
on-chain values aren't truncated.
11 tests cover: schema layout sanity, minimal+full offer roundtrip,
each PaymentScheme value, uint256-max amount, overflow/negative
rejection, proof roundtrip, invalid tx_hash length, ZapNotAvailable
gating, and a wire-size-vs-JSON sanity check.
Existing 40-test switchboard suite remains green. Two pre-existing
test files (test_nonce_manager.py, test_payment_protocol.py) had
collection-time syntax errors before this branch; they remain
unchanged.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
switchboard/zap_transport.py— encode/decodePaymentOfferandPaymentProofover the ZAP wire format (port 9999) as a zero-allocation alternative to the existing JSON-in-HTTP-headers path.Why
The HTTP/JSON transport is fine for HTTP/REST agents but expensive for high-volume agent-to-agent traffic — every offer is parsed, allocated, and copied. When two agents sit on the same Lux network, ZAP lets them exchange offers and proofs with zero parse-time allocation and ~10× smaller payloads (sanity-checked in
test_offer_wire_smaller_than_json).This is the first real consumer of
zap_py, the pure-stdlib Python port of the ZAP protocol. Validates the port end-to-end with a production switchboard data model.Wire layout
Schemas are declared with
zap_py.StructBuilderso a Go counterpart mirrors them exactly:amountis a 32-byte big-endian uint256 rather than auint64, so realistic on-chain values aren't truncated. Otherwise types match the existing JSON shape 1:1.Optional dependency
zap_pyis an optional dependency. If it isn't installed, the module imports cleanly andencode_offer/decode_offerraiseZapNotAvailableso callers fall back to the JSON path. Tests usepytest.importorskipso the suite stays green either way.Install path (until
luxfi-zapis on PyPI):pip install 'luxfi-zap @ git+https://github.com/luxfi/zap@main#subdirectory=python'Test plan
pytest tests/test_zap_transport.py -v— 11 passed with zap_py installedPaymentSchemevalueZapNotAvailablegating when zap_py is forced offpytest tests/test_x402_middleware.py tests/test_gas_budget.py tests/test_gas_tracker.py— 40 passed (existing suite still green)pytest tests/test_zap_transport.pywith zap_py uninstalled — module imports cleanly, suite skipstest_nonce_manager.py,test_payment_protocol.py) have collection-time syntax errors onmain, unrelated to this PR