CHAPTER 03 // ED25519 JWKS, RFC 8785 JCS & S4-REJECT-005

Signing /.well-known/agent-card.json with Ed25519 JWKS, RFC 8785 JCS & ProtoJSON S4-REJECT-005 Guard

Production cryptographic specification for A2A v1.0.1 §8.4.2 AgentCardSignature — covering UTF-16 code-unit RFC 8785 JCS canonicalization, out-of-band Ed25519 JWKS key rotation, and blocking cross-SDK ProtoJSON dual-case signature smuggling (S4-REJECT-005).

RFC 8785 JCS · RFC 7515 JWS · RFC 8032 ED25519
Live Browser JCS Validator →

1. Four-Step Cryptographic Signing Pipeline (A2A v1.0.1 §8.4.2)

  1. Omit top-level signatures: Clone the AgentCard map and strip only the root "signatures" field.
  2. Canonicalize via RFC 8785 JCS: Sort object keys by UTF-16BE code units, format numbers using ECMAScript shortest round-trip rules (-0.0 → 0, reject NaN/Inf), and emit compact UTF-8 bytes.
  3. Build Protected JWS Header: Base64url-encode {"alg":"EdDSA","cty":"application/a2a-agent-card+json","kid":"...","typ":"JOSE"}; block alg: "none", inline self-asserted jwk, and untrusted remote jku/x5u URLs.
  4. Sign with Ed25519 & Serve Out-of-Band JWKS: Sign ASCII(protected_b64) + "." + UTF8(jcs_payload) with an RFC 8032 Ed25519 key and publish the public OKP keyset at /.well-known/jwks.json.

2. ProtoJSON vs RFC 8785 JCS Divergence & S4-REJECT-005

Standard ProtoJSON parsers accept both camelCase and snake_case representations of the same Proto3 field, whereas JCS hashes them as distinct string keys — creating a classic parser-differential smuggling vector (tracked across A2A#2122, a2a-js#627, and a2a-tck#261):

Wire Anomaly Unhardened ProtoJSON Parser Hardened S4-REJECT-005 JCS Guard
Dual-Case Field Pair (defaultInputModes + default_input_modes)Hydrates both into one Proto3 field (last key wins)Fails closed with A2A_JSON_DUAL_CASE_SMUGGLING
Duplicate Identical Keys ({"url": "a", "url": "b"})Silently overwrites first valueFails closed inside object_pairs_hook
Proto3 Default Elision ("streaming": false)Drops false if re-serialized before JCSHashes exact raw wire JSON before Proto hydration

3. Pure-Python Reference: S4-REJECT-005 Parser + RFC 8785 JCS

python // rfc8785_jcs_and_s4_guard.py (0 runtime dependencies)
import base64
import json
import re
from typing import Any

def _to_camel(key: str) -> str:
    return re.sub(r"_([a-zA-Z0-9])", lambda m: m.group(1).upper(), key)

def parse_strict_a2a_json(raw_text: str) -> dict[str, Any]:
    def _pairs_hook(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
        out: dict[str, Any] = {}
        seen_canonical: dict[str, str] = {}
        for k, v in pairs:
            if k in out:
                raise ValueError(f"S4-REJECT-005 duplicate JSON key: {k!r}")
            canon = _to_camel(k)
            if canon in seen_canonical:
                raise ValueError(
                    f"A2A_JSON_DUAL_CASE_SMUGGLING (S4-REJECT-005): {k!r} vs {seen_canonical[canon]!r}"
                )
            seen_canonical[canon] = k
            out[k] = v
        return out

    parsed = json.loads(raw_text, object_pairs_hook=_pairs_hook)
    if not isinstance(parsed, dict):
        raise ValueError("AgentCard root must be a JSON object")
    return parsed

def jcs_canonicalize(value: Any) -> str:
    if value is None or isinstance(value, bool):
        return json.dumps(value)
    if isinstance(value, int):
        return str(value)
    if isinstance(value, float):
        if value != value or value in (float("inf"), float("-inf")):
            raise ValueError("RFC 8785 forbids NaN and Infinity")
        if value == 0.0:
            return "0"
        if value.is_integer() and abs(value) < 10**21:
            return str(int(value))
        return json.dumps(value, allow_nan=False)
    if isinstance(value, str):
        return json.dumps(value, ensure_ascii=False)
    if isinstance(value, list):
        return "[" + ",".join(jcs_canonicalize(v) for v in value) + "]"
    if isinstance(value, dict):
        items = sorted(value.items(), key=lambda kv: kv[0].encode("utf-16-be"))
        return "{" + ",".join(f"{json.dumps(k, ensure_ascii=False)}:{jcs_canonicalize(v)}" for k, v in items) + "}"
    raise TypeError(f"Unsupported JSON type: {type(value)!r}")

def build_jws_signing_input(card: dict[str, Any], kid: str) -> bytes:
    unsigned = {k: v for k, v in card.items() if k != "signatures"}
    hdr = {"alg": "EdDSA", "cty": "application/a2a-agent-card+json", "kid": kid, "typ": "JOSE"}
    p_b64 = base64.urlsafe_b64encode(jcs_canonicalize(hdr).encode("utf-8")).rstrip(b"=").decode("ascii")
    return f"{p_b64}.".encode("ascii") + jcs_canonicalize(unsigned).encode("utf-8")
1-CLICK .MCPB BUNDLES • MANIFEST V0.3 • ZERO RUNTIME DEPS

Install Companion A2A & MCP Verification Bundles in 1 Click

Full 9-Server .mcpb Hub →
a2a-wiki.mcpb .mcpb v0.3

Offline A2A v1.0.1 + MCP encyclopedia search & wire-diff reference server

a2a-iq-mcp.mcpb .mcpb v0.3

8-Dimension A2A v1.0.1 & MCP Model IQ Benchmark (IQ 60-160 + SVG radar)

mcp-tool-guard.mcpb PRIMARY

7-tool A2A v1.0.1 JCS/JWKS verifier, 11-CVE SCA & 5-layer MCP guard

a2a-registry-bridge-mcp.mcpb .mcpb v0.3

Bidirectional A2A v1.0.1 <-> MCP converter & RFC 8032 Ed25519 card signer

a2a-x402-guard-mcp.mcpb .mcpb v0.3

HTTP 402 x402 v2 Base USDC EIP-3009, Stacks sBTC & AP2 mandate guard

a2a-task-orchestrator-mcp.mcpb .mcpb v0.3

CAS atomic A2A TaskState FSM, 4-tuple WAL idempotency & BFT quorum

FIXED-SCOPE A2A & MCP ENGINEERING • 100% WRITTEN WORKFLOW

Need Production A2A v1.0.1 / MCP Bridging ($145–$290) or a 72h Security Hardening Audit ($450)?

I operate a transparent A2A engineering practice strictly via written channels (Email, GitHub Specs/PRs — zero live meetings), leading with Code-First PoCs, deterministic pytest/vitest suites, and $0 upfront Pay-on-Green-PR-Pass first-time trials ($145–$250).

Scope Fixed-Price A2A / MCP Sprint → 72h A2A & MCP Hardening ($450) → Test Agent IQ (60–160) →
A2A AGENT CARDv1.1.0 · VERIFIED_EDDSA
UPSTREAM TRACK33+ Merged Pull Requests
SECURITY SUITEmcp-tool-guard v0.7.0 (0 Deps)
WRITTEN SLA< 2–4h Initial Async Reply