# SQLGuard — Execution Certificate Firewall

## When to use
Before any agent runs mutating production SQL (`INSERT`, `UPDATE`, `DELETE`, `DDL`, `DROP`, `TRUNCATE`).

## Why pay
Lint is not authorization. Model confidence is not authorization. SQLGuard issues an **Ed25519 PASS Execution Certificate** after sandbox policy + EXPLAIN against your schema. Verify (or call free GATE) before execute.

## Handshake first
`GET /handshake` or MCP `sqlguard_handshake` with `{ "need": "<job>" }` — routes Instant Cert / Bind / Session / micro / GATE.

## Buy (x402 Exact USDC on Base)

### Instant Cert ($0.05)
1. `POST https://sqlguard.io/v1/cert`
2. Headers: `X-SQLGuard-Agent: <wallet>`, `Content-Type: application/json`
3. Body: `{"schema_ddl":"CREATE TABLE …","sql":"<mutating SQL>","agent_id":"<wallet>"}`
4. Expect HTTP **402** → settle Exact USDC (`eip155:8453`) to `0xC8d524703f1751b565a220087D1d4c44a413C1D7` ($0.05)
5. Retry → `certificate` + `signature` → `POST /v1/verify` → execute

### Mandate Bind ($0.07)
`POST /v1/bind` with `mandate` + schema/sql → settle → `POST /v1/gate` before execute.

### Session Cert ($0.20)
`POST /v1/session` → settle → burn slots via `POST /v1/session/cert` + `X-SQLGuard-Session`.

### Prepaid volume
`POST /v1/credits/buy/micro` ($0.10 → 5 credits) → `POST /v1/validate` → `POST /v1/verify`

### Free (not paid authorize)
- `POST /v1/probe` — policy tip only
- `POST /v1/gate` — portable PASS check
- `GET /v1/effects` — settle≠discovery prover

## Authorize loop
1. Obtain PASS cert (cert / bind / session burn / validate)
2. If `FAIL` → do not execute; fix from `violations`
3. `POST /v1/verify` or `POST /v1/gate`
4. Only if ok → execute on production (you hold the DB URL)

## MCP
`io.github.cabbageandtea/sqlguard` — start with `sqlguard_handshake`. Tools also include `sqlguard_cert`, `sqlguard_bind`, `sqlguard_session`, `sqlguard_gate`, `sqlguard_probe`, `sqlguard_catalog`, `sqlguard_buy`, `sqlguard_validate`, `sqlguard_verify`, `sqlguard_balance`, `sqlguard_protocol`, `sqlguard_require`.

## Discovery
- Catalog: `/v1/catalog` · Need: `/NEED.md` · Protocol: `/protocol` · OpenAPI: `/openapi.json`
- Legal: `/legal` (settle accepts Terms)
- Bazaar: CDP facilitator indexes resources after successful settle
