Skip to content

Commit efabfaa

Browse files
authored
Merge pull request #283 from commandlayer/codex/create-x402-to-clas-receipt-design-doc
Add x402-to-CLAS paid-action receipt integration design doc
2 parents 3d61c98 + 61518a4 commit efabfaa

1 file changed

Lines changed: 270 additions & 0 deletions

File tree

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# x402 → CommandLayer Paid-Action Receipt Integration Design
2+
3+
## 1. Overview
4+
5+
This document defines a **documentation-only** integration design for representing x402 paid HTTP/API actions as CommandLayer-signed CLAS action receipts.
6+
7+
The integration separates two concerns that are often conflated:
8+
9+
1. **Payment settlement attestation (x402 domain)**: whether a payment requirement was negotiated, presented, and accepted under x402-compatible rules.
10+
2. **Execution attestation (CommandLayer domain)**: what action was requested, what runtime executed, and what result was produced, with CLAS `metadata.proof` and signature evidence.
11+
12+
No production x402 implementation is included here.
13+
14+
## 2. Why x402 matters for CommandLayer
15+
16+
x402 introduces a standard interaction model for paid HTTP/API actions. For CommandLayer, this matters because it enables:
17+
18+
- explicit pre-execution payment gating for premium actions,
19+
- uniform expression of payment requirements and acceptance state,
20+
- deterministic mapping from paid request context to signed CLAS receipts,
21+
- portable post-execution verification using CommandLayer signatures and VerifyAgent.
22+
23+
x402 improves economic coordination for APIs, while CommandLayer preserves verifiable agent/runtime execution semantics.
24+
25+
## 3. Trust boundary
26+
27+
### Boundary A: client ↔ x402 payment negotiation/settlement
28+
29+
- Covers payment requirement discovery, payment submission, and settlement acceptance/rejection.
30+
- Establishes whether payment conditions were met for a specific paid action request.
31+
- Trust result: "payment was accepted/rejected under the configured x402 provider flow."
32+
33+
### Boundary B: CommandLayer runtime execution + receipt signing
34+
35+
- Starts after the runtime decides a paid action is authorized to execute.
36+
- Covers action input capture, execution outcome capture, and CLAS receipt signing.
37+
- Trust result: "CommandLayer attests what executed and what result was returned."
38+
39+
**Important**:
40+
41+
- x402 payment proof is **not** a CLAS action receipt.
42+
- x402 does **not** prove that the agent/runtime executed the action correctly.
43+
- Public third-party verification begins when CommandLayer emits a signed CLAS receipt.
44+
45+
## 4. Paid-action lifecycle
46+
47+
1. **Client requests paid action**.
48+
2. **Server returns `402 Payment Required`** with x402 payment requirements.
49+
3. **Client pays through x402** and resubmits proof/payment context.
50+
4. **Server verifies/accepts payment** using configured x402 provider adapters.
51+
5. **Agent/runtime executes action** under CommandLayer policy.
52+
6. **CommandLayer emits signed receipt** containing execution and payment linkage metadata.
53+
7. **VerifyAgent verifies receipt** (signature integrity, policy checks, trace coherence).
54+
55+
## 5. CLAS receipt shape
56+
57+
A CLAS paid-action receipt should encode execution truth plus payment linkage, while keeping payment settlement and execution proof semantically separate:
58+
59+
```json
60+
{
61+
"receipt_id": "rcpt:clas:act_01JW7R6Y8W8JQ5H7GH2D0P0F8N",
62+
"action": "summarize.text",
63+
"status": "succeeded",
64+
"requested_at": "2026-05-22T12:00:00Z",
65+
"executed_at": "2026-05-22T12:00:02Z",
66+
"result": {
67+
"summary": "Short technical summary..."
68+
},
69+
"metadata": {
70+
"trace": {
71+
"request_id": "req_9f2f5f25",
72+
"payment_id": "pay_x402_7f31",
73+
"provider": "x402-compatible",
74+
"workflow_id": "wf_2a10"
75+
},
76+
"proof": {
77+
"payment": {
78+
"scheme": "x402",
79+
"settlement_status": "accepted",
80+
"payment_ref": "pay_x402_7f31"
81+
},
82+
"execution": {
83+
"runtime_id": "rt_prod_1",
84+
"agent_id": "agent_summarizer_v3",
85+
"policy_hash": "sha256:ab12..."
86+
}
87+
}
88+
},
89+
"proof": {
90+
"signature": [
91+
{
92+
"role": "runtime",
93+
"alg": "Ed25519",
94+
"key_id": "cl_runtime_key_2026_01",
95+
"sig": "base64..."
96+
}
97+
]
98+
}
99+
}
100+
```
101+
102+
## 6. `metadata.trace` usage
103+
104+
`metadata.trace` provides correlation fields across request ingress, payment processing, execution, and verification.
105+
106+
Recommended minimum fields:
107+
108+
- `request_id`: idempotency/correlation anchor for the paid action attempt,
109+
- `payment_id`: x402 payment correlation identifier,
110+
- `receipt_id`: CLAS artifact identifier (may also appear top-level),
111+
- `workflow_id` or equivalent runtime correlation identifier.
112+
113+
Guidelines:
114+
115+
- include stable identifiers, not secrets;
116+
- avoid raw private keys, bearer tokens, or full card/wallet secrets;
117+
- keep trace values deterministic enough for replay analysis and duplicate detection.
118+
119+
## 7. `proof.signature` roles
120+
121+
CommandLayer supports single-signature and multi-signature role entries. For paid actions, roles may include:
122+
123+
- `user`: indicates end-user assent or request signing (optional).
124+
- `payer`: indicates payer-side cryptographic attestation where available (optional and provider-dependent).
125+
- `agent`: attests agent-level transformation/decision output.
126+
- `runtime`: attests execution envelope and canonical receipt emission.
127+
- `verifier`: attests post-hoc verification outcome in derived or companion receipts.
128+
129+
Role notes:
130+
131+
- Minimum public-verification baseline is usually a valid `runtime` signature.
132+
- Multi-signature receipts should preserve explicit role labeling to avoid signature ambiguity.
133+
134+
## 8. Example: paid summarize action
135+
136+
### Paid action request
137+
138+
```json
139+
{
140+
"request_id": "req_9f2f5f25",
141+
"action": "summarize.text",
142+
"input": {
143+
"text": "Long technical document..."
144+
},
145+
"payment": {
146+
"required": true,
147+
"plan": "pro",
148+
"max_amount": "0.05",
149+
"currency": "USD"
150+
}
151+
}
152+
```
153+
154+
### Payment accepted event
155+
156+
```json
157+
{
158+
"event": "payment.accepted",
159+
"request_id": "req_9f2f5f25",
160+
"payment_id": "pay_x402_7f31",
161+
"provider": "x402-compatible",
162+
"settled_amount": "0.05",
163+
"currency": "USD",
164+
"accepted_at": "2026-05-22T12:00:01Z"
165+
}
166+
```
167+
168+
### CLAS receipt after execution
169+
170+
```json
171+
{
172+
"receipt_id": "rcpt:clas:act_01JW7R6Y8W8JQ5H7GH2D0P0F8N",
173+
"request_id": "req_9f2f5f25",
174+
"payment_id": "pay_x402_7f31",
175+
"action": "summarize.text",
176+
"status": "succeeded",
177+
"result": {
178+
"summary": "Short technical summary..."
179+
},
180+
"proof": {
181+
"signature": [
182+
{
183+
"role": "runtime",
184+
"alg": "Ed25519",
185+
"key_id": "cl_runtime_key_2026_01",
186+
"sig": "base64..."
187+
}
188+
]
189+
}
190+
}
191+
```
192+
193+
## 9. Example: paid verification call
194+
195+
A verifier-facing flow can be payment-gated while still yielding a CLAS-verifiable output artifact:
196+
197+
1. Client requests `verify.receipt` for a target receipt.
198+
2. Service returns `402` with verification pricing requirements.
199+
3. Client completes x402 payment flow.
200+
4. Service executes VerifyAgent and/or runtime verification.
201+
5. Service returns verification result plus signed verification receipt.
202+
203+
Illustrative response payload:
204+
205+
```json
206+
{
207+
"action": "verify.receipt",
208+
"target_receipt_id": "rcpt:clas:act_01JW7R6Y8W8JQ5H7GH2D0P0F8N",
209+
"verification": {
210+
"status": "valid",
211+
"checks": ["signature", "trace_consistency", "policy_constraints"]
212+
},
213+
"proof": {
214+
"signature": [
215+
{
216+
"role": "verifier",
217+
"alg": "Ed25519",
218+
"key_id": "cl_verify_key_2026_01",
219+
"sig": "base64..."
220+
}
221+
]
222+
}
223+
}
224+
```
225+
226+
## 10. Failure modes
227+
228+
- **payment missing**: no valid payment context after `402` requirement; action is not executed.
229+
- **payment invalid**: payment proof fails provider validation; action is not executed.
230+
- **payment accepted but action failed**: receipt should record `status: failed` with structured error outcome.
231+
- **action executed but receipt signing failed**: execution occurred but no portable attestation; must emit internal critical event and retry/compensate.
232+
- **duplicate payment/action request**: idempotency logic must prevent duplicate execution and duplicate receipts.
233+
- **verifier unavailable**: verification action cannot complete; return explicit retriable/unavailable state.
234+
235+
## 11. Idempotency
236+
237+
Use three distinct identifiers:
238+
239+
- `request_id`: semantic action-attempt identity.
240+
- `payment_id`: settlement identity in x402 provider domain.
241+
- `receipt_id`: CLAS attestation artifact identity.
242+
243+
Recommended constraints:
244+
245+
- one `request_id` maps to at most one canonical execution outcome;
246+
- one accepted `payment_id` is bound to one request scope/policy scope;
247+
- one canonical execution outcome maps to one canonical `receipt_id` (retries should not fork receipt truth).
248+
249+
## 12. Settlement vs execution proof
250+
251+
Settlement proof answers: **"Was payment accepted for this request scope?"**
252+
253+
Execution proof answers: **"What action executed, under what runtime context, with what result?"**
254+
255+
Design rule: keep these proofs linked but non-substitutable. A valid payment signal is insufficient to claim execution correctness; a valid execution receipt does not imply payment settlement unless explicitly linked.
256+
257+
## 13. Future integration with Coinbase AgentKit / Agentic Wallet
258+
259+
Future adapters may use Coinbase AgentKit or Agentic Wallet primitives as one x402-compatible payment backend. In that model:
260+
261+
- AgentKit/Wallet tools can originate payer intents and settlement references.
262+
- CommandLayer still owns canonical action execution receipt emission.
263+
- Provider abstraction remains open so non-Coinbase x402-compatible providers can be added without changing CLAS receipt semantics.
264+
265+
## 14. Non-goals
266+
267+
- This design does **not** claim CommandLayer settles payments.
268+
- This design does **not** claim x402 alone proves agent/runtime execution.
269+
- This design does **not** require Coinbase/CDP as the only x402 provider.
270+
- This design does **not** introduce production x402 runtime code in this change.

0 commit comments

Comments
 (0)