Architecture
A reading guide for someone picking up aitp-rs for the first time.
aitp-rs is the Rust reference implementation of the
Agent Identity & Trust Protocol
(AITP). AITP is a JSON-only, A2A (agent-to-agent) trust protocol:
two agents perform a Mutual Handshake, exchange signed Trust
Context Tokens (TCTs), and then invoke each other's capabilities
under those TCTs.
This workspace tracks AITP v0.3 (protocol version literal
aitp/0.3). AITP signs its artifacts under two profiles: the portable
trust artifacts (TCT, grant voucher, delegation token) are RFC 7515
compact JWS, and the protocol-internal artifacts stay on the JCS
embedded-signature profile. The protocol side of that split is in the
spec's architecture overview §2.1;
which aitp-rs code implements each profile is in the
table below.
This document covers the topology — what the pieces are and how they
fit — and then the rationale for why the library is layered the way it
is. For the deeper, topic-specific dives, see the sibling docs:
jcs.md, handshake-transcripts.md,
and conformance.md.
The signed wire types
Every AITP interaction reduces to producing and verifying a signed
artifact. Each has its own RFC, JSON Schema, and a module of aitp.
| Type | RFC | Module | Purpose |
|---|---|---|---|
| Manifest | RFC-AITP-0003 | aitp::manifest | Self-description an agent publishes at /.well-known/aitp-manifest: which handshake endpoint to hit, which identity provider it uses, which capabilities it offers/requires |
| TCT (Trust Context Token) | RFC-AITP-0005 | aitp::tct | A signed, audience-bound, capability-scoped grant. Each peer holds the TCT issued to it by its counterpart |
| Grant voucher | RFC-AITP-0005 §8 | aitp::tct | A companion artifact the TCT issuer mints alongside the TCT (same handshake commit). Lets the subject delegate without anyone reconstructing TCT bytes; replaces the v0.1 grant_proof mechanism |
| Delegation token | RFC-AITP-0006 | aitp::delegation | Single-hop subdelegation: B holds A's TCT + voucher, issues a derived token to C with a subset of grants, embedding A's voucher verbatim |
| Revocation snapshot | RFC-AITP-0008 | aitp::tct::revocation | Periodically-refreshed signed list of revoked TCT JTIs. An empty list is also signed — defends against suppression of fresher snapshots |
The two signing profiles
The profiles themselves (wire form, signing input, the boundary rule, the
alg/typ pinning) are defined in
RFC-AITP-0001 §5.4 and explained in
the spec's architecture overview §2.1
and the Implementer Quickstart.
This is where each one lives in aitp-rs:
| Profile | Shared machinery | Artifacts and their modules |
|---|---|---|
| Compact JWS (RFC-AITP-0001 §5.4.5) | aitp::crypto::jws (crates/aitp/src/crypto/jws.rs): strict compact parsing, alg derived from the signer's AID, exact typ match (TOKEN_ALG_MISMATCH / TOKEN_TYP_MISMATCH) | TCT and grant voucher: aitp::tct. Delegation token: aitp::delegation |
| JCS embedded-signature (RFC-AITP-0001 §5.4.1) | aitp::core::jcs (canonicalization) + aitp::crypto (Ed25519 / P-256 signing); see jcs.md | Envelope: aitp::envelope, over the domain-tagged aitp-envelope-v2 input (aitp::core::envelope_signing_input, RFC-AITP-0001 §5.4). Manifest: aitp::manifest. Revocation snapshot: aitp::tct::revocation. Session-bundle outer signature: aitp_experimental::session_bundle. Handshake payloads: aitp::handshake::payloads |
Both profiles support Ed25519 and P-256 (ES256) in every module above.
Debugging a TCT
Because a TCT (and the grant voucher, and a delegation token) is now an ordinary compact JWS, you can decode and verify it with no AITP tooling at all:
- Paste the compact string into jwt.io to inspect the header and claims.
- Verify it programmatically with any JOSE library — node
jose, pythonPyJWT— supplying the issuer's public key. The key is derivable from the issuer AID (iss): the AID is the base64url public key (or itsp256:variant), andcnf.jktis the RFC 7638 thumbprint of the subject key.
The claims you'll see on a TCT are the registered JWT names
ver, jti, iss, sub, aud, iat, exp plus the private grants array,
the RFC 7800 cnf confirmation claim (jkt member) and an optional
ext object (TctClaims in crates/aitp/src/tct/types.rs).
The four-message handshake
The exchange (MUTUAL_HELLO, MUTUAL_HELLO_ACK, MUTUAL_COMMIT,
MUTUAL_COMMIT_ACK) is defined in
RFC-AITP-0004 and walked
through in the spec's
architecture overview §3.2.
In aitp-rs it is split across three layers:
| Layer | Where | What it does |
|---|---|---|
| State machines | aitp::handshake (crates/aitp/src/handshake/state_machine.rs: Initiator, Responder) | Sync, no I/O. Build and verify each message; identity proofs in pinned_key.rs / identity_oidc.rs; issue the peer TCT and grant voucher through aitp::tct |
| HTTP binding | aitp::transport (HandshakeServer, ManifestFetcher) | Serve the responder side and fetch the peer Manifest over SSRF-guarded HTTPS |
| One-call driver | aitp::facade::run_initiator_handshake (async) | Runs the initiator side end to end against a peer's handshake endpoint |
For the bytes on the wire, see
handshake-transcripts.md.
Crate map
Three crates are published: aitp (the protocol library, one module per
layer), aitp-experimental (no stability promise) and aitp-cli.
aitp the protocol library (crates/aitp)
├── core primitives: Aid, JCS, base64url, Timestamp,
│ ExtensionsMap, AitpEnvelope, ErrorCode
├── crypto Ed25519 (verify_strict) + P-256/ES256
│ (canonical low-S) + compact JWS + JWK thumbprint
├── envelope sign_envelope + verify_envelope_signature —
│ sync, no I/O
├── manifest ManifestBuilder + verify_manifest
├── tct TctBuilder + verify_tct + PoP exchange +
│ revocation snapshots
├── delegation DelegationBuilder + verify_delegation
│ (single-hop; multi-hop chains opt-in at runtime)
├── handshake Initiator/Responder state machines, OIDC
│ and pinned-key identity proofs, RSA-2048 floor
│ on OIDC RSA keys, IdentityVerifier hook
├── transport ManifestServer + HandshakeServer (axum,
│ http-server) + ManifestFetcher + JwksFetcher
│ (reqwest, http-client), RSA-2048 floor on JWKS keys
└── facade async run_initiator_handshake +
TctStore (http-client)
aitp-experimental session_bundle: SessionBundleBuilder +
verify_session_bundle (RFC-0010), plus
SessionBundleServer (http-server feature);
delegation (multi-hop, RFC-0011); renewal
(RFC-0013); spiffe: SpiffeVerifier
(spiffe-identity feature); a2a: Agent Card
binding (RFC-0014, a2a-agent-card feature)
aitp-cli `aitp` binary — offline keygen / aid /
tct inspect+verify / manifest verify;
manifest fetch + handshake (http-client)
aitp-conformance runner + Adapter trait + SubprocessAdapter
(unpublished) + InProcessRustAdapter, and the
`aitp-rs-adapter` binary (rs_adapter module),
Tier A/B/C/D
bindings/aitp-py Python SDK (PyO3) — excluded from the workspace
bindings/aitp-node Node.js SDK (NAPI-rs) — excluded from the workspace
bindings/interop cross-language interop tests — `make interop`
examples/two-agents end-to-end demo — `make demo`
tools/mint-signed-examples mint signed artifacts from spec KAT seeds
tools/mint-conformance-fixtures walk spec fixtures, substitute placeholdersThe tree shows what each crate contains, not a dependency chain. The
dependency edges between the modules of aitp (from their use crate::…
imports) are:
coredepends on no other module.cryptodepends oncore.envelope,manifestandtctdepend oncore+crypto.delegationdepends oncore+crypto+manifest+tct.handshakedepends oncore+crypto+manifest+tct.transportdepends oncore+crypto+envelope+manifest+handshake+tct. It does not depend ondelegation.facadedepends ontransportand the protocol modules it drives.aitp-experimentaldepends onaitp(default-features = false); itshttp-serverfeature turns onaitp/http-server.
flowchart BT crypto --> core envelope --> crypto manifest --> crypto tct --> crypto delegation --> manifest delegation --> tct handshake --> manifest handshake --> tct transport --> envelope transport --> handshake facade --> transport experimental["aitp-experimental"] --> transport
The protocol modules are sync. Async code lives in aitp::transport
(behind the http-client / http-server features) and in
aitp::facade's run_initiator_handshake.
Why the library is layered this way
The layering is load-bearing — it exists to serve three audiences with different needs from one codebase:
- TCT-only consumers (e.g. the MACP runtime) want to verify TCTs and nothing else — no HTTP client, no handshake server, no OIDC JWT library.
- Standalone agents want the full handshake, TCT exchange, manifest fetch, and HTTP serving behind a one-line dependency.
- The conformance runner needs an in-process adapter that can call into every layer.
One crate serves all three because the heavy dependencies sit behind features and the module boundaries below stay one-directional:
aitp::corehas no crypto. Wire types, JCS, base64url, AID parsing — usable by anything that handles AITP data (storage, logging, analysis).aitp::cryptohas no protocol. It wrapsed25519-dalekandp256with AITP key handling, implements the compact-JWS profile and the JWK thumbprint; it does not know what a Manifest or TCT is.aitp::envelopeis the sync envelope codec.sign_envelope/verify_envelope_signaturedepend only oncore+crypto— no HTTP, no async — so the language bindings (and other sync consumers) can sign/verify without a transport stack; the transport uses it too.aitp::tctdoes not depend onaitp::handshake. TCT verification is the per-request hot path and must not reach into the state machine.handshakedepends ontct+manifest— it issues TCTs and verifies Manifests, so that direction is correct.aitp::transportis feature-gated and is where the HTTP lives.http-clientpullsreqwest,http-serverpullsaxum. No protocol module depends on it, so a consumer on a different transport (gRPC, MessagePack) buildsaitpwithdefault-features = false, implements just the wire layer and reuses every protocol module.aitp::facadeadds the asyncrun_initiator_handshakehelper on top (http-clientfeature, on by default). This is what most users call. A TCT-only consumer usesaitp::tct+aitp::cryptofromaitpwithdefault-features = false.- Session Trust Bundles are a separate crate.
aitp-experimentalcarries the Draft RFC-0010 surface with no semver promise, so it can change without a breaking release ofaitp. - The conformance runner and the Rust adapter share an unpublished
crate. The runner is language-agnostic; the adapter
(
aitp_conformance::rs_adapter, theaitp-rs-adapterbinary) isaitp-rs-specific, and other-language adapters speak to the same runner over NDJSON.
Async story
The protocol modules are sync. Async code lives in aitp::transport
(because reqwest / axum are) and in aitp::facade's
run_initiator_handshake, which drives it. This keeps TCT
verification callable from sync codebases and from non-Rust runtimes via
FFI: the language bindings build aitp with default-features = false
and call the protocol modules directly, not the facade.
Why multi-hop delegation is unreachable by default
Until a verifier opts into RFC-AITP-0011, the multi-hop guard in
RFC-AITP-0006 §4 requires it to
reject any delegation token carrying a chain claim with
DELEGATION_MULTIHOP_NOT_SUPPORTED. A chain also widens what the verifier
must get right: per-hop signatures, issuer/subject continuity, transitive
scope subsetting, chain_hash truncation defence, per-hop revocation and a
hop limit against verification DoS
(RFC-AITP-0011 §9).
The grant voucher inside chain[0] also discloses the root grant
profile to every later hop. A deployment that never asked for chains should not carry that surface.
So the multi-hop code is in the aitp-experimental crate
(aitp_experimental::delegation), not in aitp. The stable
aitp::delegation::verify_delegation rejects a chain claim before any
other claim check, and rejects the multi-hop jti and chain_hash claims
(crates/aitp/src/delegation/verifier.rs). Chains verify only through
aitp_experimental::delegation::verify_chained_delegation. The
language bindings follow the same rule: verify_delegation /
verifyDelegation stays strict,
and chains need the separate verify_delegation_multihop /
verifyDelegationMultihop call. Details: multihop-delegation.md.
Identity types aitp does not verify
aitp verifies oidc and pinned_key identities itself. Any other
IdentityKind (today spiffe, RFC-AITP-0002 §6) is verified by the
IdentityVerifier attached with PeerConfig::with_identity_verifier:
- It runs at the step where
aitpverifies anoidcorpinned_keyproof, after the Manifest and the subject and type matches, and before the envelope signature. handles(kind)false, or no verifier attached:INCOMPATIBLE_IDENTITY_TYPE(RFC-AITP-0002 §6.6).- The verifier's error is returned unchanged:
HandshakeError::IdentityisIDENTITY_FAILED,KeyResolutionFailedisKEY_RESOLUTION_FAILED. - It is never called for
oidcorpinned_key. - On success the peer key is derived from the sender's AID.
IdentityVerifyContextis#[non_exhaustive]and built only byaitp.
aitp_experimental::spiffe::SpiffeVerifier (feature spiffe-identity)
is the spiffe verifier, over a SpiffeBundleStore. HandshakeServer
takes no verifier.
Workspace conventions
- Workspace deps only. Every third-party crate is pinned once in the
root
[workspace.dependencies]and referenced via{ workspace = true }, so the lock holds exactly one version of each — upgrades are one-line. - MSRV 1.90, in lockstep with the
1.90.0toolchain pin inrust-toolchain.toml. MSRV rose from 1.75 once transitive deps (time,icu_*,idna_adapter,clap_lex) began requiring edition 2024, then from 1.89 to 1.90 whenmetrics-util0.20 pulled inordered-float5.5.0;cargo msrv verifygates it in CI. - Dual MIT OR Apache-2.0 — standard Rust convention (same as
tokio,serde,tower), friendlier to enterprise adoption than either alone. #![forbid(unsafe_code)]on every library root undercrates/(src/lib.rs). It is not set on the separate binary rootscrates/aitp-cli/src/main.rs,crates/aitp-conformance/src/main.rsandcrates/aitp-conformance/src/bin/aitp-rs-adapter.rs, onexamples/two-agents(library and bins), or on thetools/*binaries. The binding crates omit it on purpose: the PyO3 / NAPI-rs export macros expand tounsafeglue.#![warn(missing_docs)]is set onaitpandaitp-experimental.
What's anchored to the spec, not just self-consistent
A common failure mode for early protocol implementations is
"works against itself, fails against any other implementation."
Five test families pin aitp-rs against spec-published reference
values rather than its own output:
- Keypair derivation (
crates/aitp/tests/crypto_kat.rs) — seed → pubkey → AID for every pinned keypair (Ed25519 and P-256) - JWK thumbprints (same file) — RFC 7638 thumbprints for the
pinned keypairs (also the
cnf.jktvalue on a v0.2 TCT) - JCS + SHA-256 (
crates/aitp/tests/core_kat.rs) — canonical bytes and SHA-256 digest of the JCS-profile artifacts (Manifest, revocation snapshot, session bundle). The v0.1 TCT and delegation JCS vectors are retired with the move to compact JWS. - Compact-JWS vectors (
tests/schemas/known-answer/signed-examples/, checked bycrates/aitp/tests/crypto_jws_kat.rsandcrates/aitp/tests/tct_kat.rs) — the pinned TCT, grant voucher, and delegation tokens; verified over their exact transmitted bytes, not reconstructed. - Revocation snapshot (
crates/aitp/src/tct/revocation.rs::rfc_kat_canonical_bytes_match) — canonical bytes byte-for-byte againstkat-revocation-001
If any of these break, the implementation has drifted from the spec — investigate before touching the test.
How the schemas stay honest
tests/schemas/ is a vendored copy of the spec
repo's JSON schemas, pinned to a specific spec commit by the
SPEC_VERSION file. A CI job
(spec-schemas in .github/workflows/ci.yml)
re-runs scripts/sync-schemas.sh
against the pinned commit and fails if the vendored copies have
drifted. The per-module crates/aitp/tests/*_schema.rs files validate
fully-populated wire types against those schemas. Together the firewall catches
the class of drift where Rust types and spec schemas accidentally
diverge.
When the spec moves, the workflow is:
- Re-run
scripts/sync-schemas.sh(pulls new schemas and KAT vectors intotests/schemas/) - Schema tests fail with a precise diagnostic about the new field
- Fix the Rust types
- Update
SPEC_VERSION - Commit
Conformance
aitp-conformance defines the runner and the
Adapter trait. Two adapters ship: SubprocessAdapter (speaks NDJSON over
stdin/stdout to any binary that implements the protocol — the
aitp-rs-adapter binary (rs_adapter)
is the Rust one) and InProcessRustAdapter (calls aitp directly, for
fast local dev). The
op vocabulary spans four tiers — verification, issuance, stateful flows,
and test-only.
A cross-language adapter need only implement that NDJSON protocol; the
runner, fixtures, and assertion machinery are shared. The full wire
protocol, the per-tier op table, and the live fixture matrix all live in
conformance.md.
Language bindings
bindings/aitp-py (PyO3) and
bindings/aitp-node (NAPI-rs) are thin SDKs
over aitp — an AitpAgent plus initiator/responder
session types whose methods take and return JSON strings (the HTTP
request/response bodies), so agent code never handles a Rust type.
Both depend on aitp with default-features = false (plus
aitp-experimental for session bundles) and call aitp::envelope
directly, so a binding can sign and verify envelopes without an HTTP
stack.
The bindings are excluded from the Cargo workspace — they are
cdylibs built by maturin / napi-cli against an external toolchain.
Each SDK has its own in-process handshake tests
(aitp-py/tests,
aitp-node/tests).
bindings/interop goes further: it runs a real
four-message handshake between the two SDKs, in both directions, to
prove they emit wire-compatible envelopes. make interop builds both
bindings and runs that suite.
Where to read further
jcs.md— JSON canonicalization strategy, test vectors, the surrogate-pair historyconformance.md— the full NDJSON adapter protocol and the per-fixture matrixhandshake-transcripts.md— the four-message exchange, byte by bytesession-bundle.md,multihop-delegation.md,tct-renewal.md— the opt-in extensions (RFC-0010 and RFC-0011 and RFC-0013 are Draft)sdk-python.md/sdk-node.mdandtransport-hardening.md— SDK guides and the HTTP-transport hardening register../crates/aitp/CHANGELOG.md— release history and current direction- The AITP RFCs themselves — the protocol is normatively defined there; this implementation tracks them
Where to start reading the code
- New to AITP and want to understand what a handshake produces?
Read
crates/aitp/src/handshake/state_machine.rs - Want to see end-to-end usage in ~250 lines?
Read
examples/two-agents/or runmake demo - Writing an adapter in another language? Read
conformance.mdand look atcrates/aitp-conformance/src/rs_adapter/mod.rsfor a working reference - Curious about a specific signed wire type? Each
crates/aitp/src/<module>/types.rshas rustdoc pluscrates/aitp/tests/<module>_round_trip.rsshowing the full lifecycle