Skip to content

feat(a2a): signed agent cards with JWKS publishing, verification on discovery, and youagent verify - #12

Open
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-09-22-signed-agent-cards
Open

brainsparker wants to merge 1 commit into
mainfrom
feature/2026-09-22-signed-agent-cards

Conversation

@brainsparker

Copy link
Copy Markdown
Owner

What this does

A2A v1.0 lets an agent sign its Agent Card (spec section 8.4) so that a card fetched from a registry, a cache or a mirror can be checked against the key of the agent that published it. youagent already had the signatures type on the card but nothing produced or verified signatures. This PR implements the whole loop with node:crypto only, no new dependencies.

Library (src/a2a/card-signing.ts, exported from the package root)

  • signAgentCard(card, { key, kid, alg?, jku?, header? }) appends a detached JWS to signatures. Existing signatures are kept, so key rotation is signing with both keys for a while.
  • verifyAgentCardSignatures(card, { keys?, resolveKey?, jwks?, algorithms? }) succeeds when at least one signature verifies against a trusted key, otherwise throws AgentCardSignatureError with a per-signature account of why (no_signatures, malformed_signature, invalid_signatures, canonicalization_failed).
  • agentCardSigningPayload(card) returns the exact bytes signed: signatures removed, then null, empty strings, empty arrays and empty objects dropped recursively, then RFC 8785 (JCS). This matches the a2a-python reference SDK's _canonicalize_agent_card, so cards signed by either implementation verify in the other.
  • Algorithms: ES256, ES384, ES512, EdDSA (Ed25519), RS256, PS256. The key type and curve must match the signature's alg, which closes the algorithm confusion hole. Symmetric algorithms are not supported on purpose: a public card has no place for a shared secret.
  • Helpers: generateCardSigningKeyPair, toPublicJwk, fetchJwks, jkuAllowed, decodeProtectedHeader, canonicalizeJson, removeEmptyValues.

Server

  • new A2AServer({ agentCard, signing: { key, kid, alg?, jku?, additionalJwks? } }) signs the card once at construction and serves it signed on every discovery path (same ETag on all of them). The public key is published at GET /.well-known/jwks.json on the card's own origin and the signature's jku points there by default (jku: false omits it). server.agentCard and server.jwkSet expose what is served.

Client

  • fetchAgentCard(url, { signature: {} }) and A2AClient.discover(url, { signature: {} }) verify after fetching. Default policy: the jku is only followed on the origin the card was fetched from, so a registry or mirror cannot substitute its own key. Pass keys for a pinned trust store, jwks: { origins: [...] } to widen, require: false to accept unsigned cards. fetchVerifiedAgentCard returns the card together with which signature verified.

CLI

youagent verify https://agent.example              # fetch, verify via same-origin JWKS, exit 1 on failure
youagent verify https://agent.example --key jwks.json   # pinned keys only (jku ignored unless --any-jku)
youagent verify https://agent.example --json        # for scripts and CI

Docs: README gains a "Signed agent cards" section, the CLI table row, and the Known gaps entry is narrowed to what is still missing (youagent start does not load a signing key yet; the For You registry does not verify on registration). CHANGELOG updated. examples/a2a-server.ts now serves a signed card.

Why this, why today

Spec reference: https://a2a-protocol.org/latest/specification/ section 8.4 (Agent Card Signing), 8.4.1 canonicalization, 8.4.2 signature format, 8.4.3 verification.

Runner-up opportunities passed on today

  1. you-aware (MCP-Profiles): a detail / result token budget parameter plus outputSchema and readOnlyHint annotations on the search tool. Token bloat from search MCP results is a documented complaint (MCP search/query responses exceed token cap on common-term queries (--limit 20 → 90KB persisted to disk) garrytan/gbrain#953, Optimize token usage in default list_ tools github/github-mcp-server#2016) and the MCP spec moved to 2026-07-28 with caching hints (https://modelcontextprotocol.io/specification/2026-07-28). Passed because frugal already shipped the same idea (#90) and MCP-Profiles has two unmerged PRs stacked.
  2. free-mail-merge: ZIP sort before render and paste-from-spreadsheet import. Real but thin demand signals; the print alignment PR (Integration tracking: Handler (alDuncanson/Handler) youagent interop guide #4) is still open.

Implementation notes

  • RFC 8785 in TypeScript is small because JSON.stringify already renders every scalar the way the RFC requires (ECMAScript number formatting, minimal escaping with lowercase \u00xx) and default string comparison sorts by UTF-16 code unit. The module adds key ordering, whitespace removal, depth bounding (128, extension params are caller controlled) and rejection of NaN, Infinity and lone surrogates. Tests include the spec's own canonicalization example.
  • ECDSA signatures use dsaEncoding: 'ieee-p1363' (raw r||s), which is what JWS requires; RSA-PSS uses the digest-length salt.
  • "Sign the form you serve": youagent's transitional card keeps the legacy url and protocolVersion fields, and they are part of the signed payload. A strict v1.0 copy (toV1AgentCard) needs its own signature. There is a test pinning this behavior and the README says so.
  • jku is attacker controlled. The verifier never follows it unless a policy allows the origin; fetchAgentCard defaults that policy to the origin the card was fetched from; https is required except on loopback hosts. The CLI treats --key as "only these keys".
  • No changes to the card schema, to createAgentCard, or to the daemon. Wiring a persistent signing key into youagent start is a natural follow-up once the daemon serves the A2A server.

Test status

  • npm run typecheck: clean.
  • npm test: 16 files, 187 tests pass (46 new: RFC 8785 vectors, sign and verify round trips for all six algorithms, tamper detection, algorithm confusion rejection, JWKS origin policy and single-fetch caching, malformed signature skipping, server JWKS route and same-origin end-to-end verification through fetchAgentCard and A2AClient.discover, unsigned server behavior).
  • npm run build and npm publish --dry-run: succeed.
  • Manual CLI smoke test against a live signed A2AServer from the built dist: same-origin JWKS verification, pinned JWKS and PEM keys, wrong pinned key rejected (exit 1), --any-jku widening, unsigned card rejected and then accepted with --allow-unsigned, --json output, discovery failure reporting.

…iscovery, and youagent verify

Implements A2A v1.0 spec section 8.4: detached JWS over the RFC 8785 canonical card, matching the a2a-python reference canonicalization. A2AServer signs the served card and publishes /.well-known/jwks.json; fetchAgentCard and A2AClient.discover verify with a same-origin JWKS policy by default; new CLI command youagent verify <agent-url>. node:crypto only, no new dependencies.
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.

1 participant