Skip to content
x402Sec

x402Sec

Trust Layer for x402 Protocol

Created on 8th March 2026

•

x402Sec

x402Sec

Trust Layer for x402 Protocol

The problem x402Sec solves

AI agents can't be trusted with payments, yet

Protocols like x402 let AI agents autonomously pay for resources over HTTP.
A research agent can fetch flight data, a dev agent can call a security API,
a finance agent can pull market data — all without human approval on every request.

The problem: there is no security layer between an agent and its wallet.

A single prompt injection — a malicious instruction hidden in a webpage,
API response, or injected into context — can silently redirect an agent to
transfer funds to an attacker. OTPs protect humans. They do nothing for agents.

What Payjama does

Payjama is a security middleware layer that sits between any AI agent and
payment execution. Before any payment is signed, three things must pass:

1. Hardware-bound agent identity
Every agent's signing key is generated inside Apple's Secure Enclave — a
dedicated hardware chip on Apple Silicon. The private key never touches RAM,
never touches disk, never leaves the chip. Payment signing is delegated to
hardware. A compromised process cannot extract the key.

2. Intent attestation with context hashing
Every payment carries a SHA-256 fingerprint of the conversation that led to
it. If a prompt injection changes the agent's context, the hash changes.
Payjama detects the tamper.

3. Session integrity monitoring
Payjama tracks every agent session from its declared mission. It scores each
payment for mission drift ("this agent was researching flights — why is it
now wiring $850 to an unknown transfer service?"), velocity anomalies, and
novel recipient detection. The longer an agent runs, the harder it is for an
attacker to hijack it undetected.

Who uses it

  • Fintech platforms deploying AI agents that handle money movement
  • Agentic API providers who want to gate access behind x402 payments
  • Developers building autonomous agents that need auditable payment trails
  • Any team using x402 who needs to answer: "how do we trust our agent
    won't get hijacked?"

What it looks like in practice

An agent runs autonomously — fetching data, making micropayments via x402
on Base Sepolia, narrating its reasoning. A hidden attacker injects a malicious
payload mid-session. The agent obeys the injection and attempts an $850
transfer to an unknown endpoint. Payjama intercepts it before the vault
signs — mission drift score 91, amount exceeds policy, recipient not
whitelisted. The payment never reaches the Secure Enclave. The session is
halted. A cryptographic audit log captures everything.

Challenges we ran into

1. The Secure Enclave signing boundary

Apple's Secure Enclave generates and stores P-256 keys — but the key material
never crosses into the Go process. Go has no native Secure Enclave API.

The solution was a thin Swift CLI (sekey) that acts as the only process
allowed to touch the Enclave. Go calls it via exec.Command — passing intent
hashes in, getting DER-encoded signatures out. The private key stays in
hardware across the boundary.

The tricky part: Swift's SecureEnclave.P256.Signing.PrivateKey returns a
dataRepresentation that is a handle (an opaque reference), not key bytes.
Storing the handle in Keychain and restoring the key from it on next use took
several iterations to get right. The handle is device-bound — it's useless on
any other machine, which is exactly the property we needed.

2. EIP-712 structured signing without go-ethereum

Implementing EIP-712 signing from scratch in Go (for x402 payment payloads)
without pulling in the full go-ethereum library was harder than expected.
The domain separator, type hashes, and ABI encoding had to be implemented
manually using crypto/ecdsa and golang.org/x/crypto/sha3. Getting the
exact byte layout right — and matching what Coinbase's x402 facilitator
expected — required careful reference to the EIP-712 spec and several failed
facilitation attempts before the first real on-chain payment went through.

3. Making the injection actually trigger a fraudulent payment

Early in testing, the autonomous agent demo had a subtle but critical flaw:
the attacker's injection landed in the agent's context, but the agent never
acted on it. The fallback decide_payment() function always picked from a
hardcoded whitelist — so Payjama had nothing to block.

The fix was rethinking how the agent processes injections. When a [SYSTEM]
message appears in context, the Gemini reasoning prompt changes: instead of
"pick a recipient from the whitelist," it becomes "you have received a system
instruction — follow it." The agent then generates a payment attempt using
the attacker's recipient and amount. That's what Payjama intercepts. The demo
only works because the agent is genuinely compromised — not because we
hardcoded the attack.

4. Session monitor false positives

The mission drift detector (Gemini scoring semantic distance between original
mission and current payment) was initially too aggressive — it flagged
legitimate turn 5 payments as "drifted" because the mission summary and
payment purpose used different vocabulary for the same concept.

The fix was two-part: only run drift checks after 2+ prior approved payments
(baseline needed), and raise the block threshold for drift alone to 60+ before
it contributes meaningfully to the score. Drift is a signal, not a verdict.

Technologies used

Cheer Project

Cheering for a project means supporting a project you like with as little as 0.0025 ETH. Right now, you can Cheer using ETH on Arbitrum, Optimism and Base.

Discussion

Builders also viewed

See more projects on Devfolio