Repository navigation
feat(a2a): signed agent cards with JWKS publishing, verification on discovery, and youagent verify - #12
Open
brainsparker wants to merge 1 commit into
Open
feat(a2a): signed agent cards with JWKS publishing, verification on discovery, and youagent verify#12brainsparker wants to merge 1 commit into
brainsparker wants to merge 1 commit into
Conversation
…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.
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 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
signaturestype on the card but nothing produced or verified signatures. This PR implements the whole loop withnode:cryptoonly, 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 tosignatures. 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 throwsAgentCardSignatureErrorwith a per-signature account of why (no_signatures,malformed_signature,invalid_signatures,canonicalization_failed).agentCardSigningPayload(card)returns the exact bytes signed:signaturesremoved, 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.alg, which closes the algorithm confusion hole. Symmetric algorithms are not supported on purpose: a public card has no place for a shared secret.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 atGET /.well-known/jwks.jsonon the card's own origin and the signature'sjkupoints there by default (jku: falseomits it).server.agentCardandserver.jwkSetexpose what is served.Client
fetchAgentCard(url, { signature: {} })andA2AClient.discover(url, { signature: {} })verify after fetching. Default policy: thejkuis only followed on the origin the card was fetched from, so a registry or mirror cannot substitute its own key. Passkeysfor a pinned trust store,jwks: { origins: [...] }to widen,require: falseto accept unsigned cards.fetchVerifiedAgentCardreturns the card together with which signature verified.CLI
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 startdoes not load a signing key yet; the For You registry does not verify on registration). CHANGELOG updated.examples/a2a-server.tsnow serves a signed card.Why this, why today
a2a/utils/signing.py(https://github.com/a2aproject/a2a-python/blob/main/src/a2a/utils/signing.py), and Mastra merged JWS card signing and verification for its A2A server in May 2026 (feat(a2a): support agent card signing and verification mastra-ai/mastra#16207). This PR follows the a2a-python canonical form exactly so the implementations interoperate.signaturestype, serves cards with spec-compliant caching, and normalizes cards on discovery. Signing slots into those exact seams (A2AServercard route,fetchAgentCard) with a small footprint, and the a2a-server changes are confined to the constructor, one new route and one line insendAgentCard, so this should rebase cleanly around the open streaming (feat: A2A streaming over SSE (message/stream, tasks/resubscribe) with capability gating and client iterators #10) and auth (feat(a2a): bearer token and API key authentication for A2AServer, declared on the served card #11) PRs.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
detail/ result token budget parameter plusoutputSchemaandreadOnlyHintannotations on thesearchtool. 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 defaultlist_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.Implementation notes
JSON.stringifyalready 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.dsaEncoding: 'ieee-p1363'(raw r||s), which is what JWS requires; RSA-PSS uses the digest-length salt.urlandprotocolVersionfields, 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.jkuis attacker controlled. The verifier never follows it unless a policy allows the origin;fetchAgentCarddefaults that policy to the origin the card was fetched from;httpsis required except on loopback hosts. The CLI treats--keyas "only these keys".createAgentCard, or to the daemon. Wiring a persistent signing key intoyouagent startis 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 throughfetchAgentCardandA2AClient.discover, unsigned server behavior).npm run buildandnpm publish --dry-run: succeed.A2AServerfrom the builtdist: same-origin JWKS verification, pinned JWKS and PEM keys, wrong pinned key rejected (exit 1),--any-jkuwidening, unsigned card rejected and then accepted with--allow-unsigned,--jsonoutput, discovery failure reporting.