QoreGuard
by imthegoodboy
README.md
# QoreGuard
**A wallet your AI agent can use but cannot abuse.** QoreGuard is an MCP server that lets
an AI agent (Claude Code, Claude Desktop, any MCP client) pay for things from your QoreChain
account. The limits are enforced by QoreChain and by a contract, not by the agent or the
server, and every instruction between you and the agent is signed with ML-DSA-87
(FIPS 204), the post-quantum signature QoreChain uses.
- **Dashboard:** {{APP_URL}}
- **Demo video:** {{VIDEO_URL}}
- **Contract:** `QoreGuard` at [`0xA279D4c67483cc04497E9A88834c9AF7614f91D5`](https://explore.qore.network/address/0xA279D4c67483cc04497E9A88834c9AF7614f91D5) on the QoreChain testnet (`qorechain-diana`, EVM 9800)
- **Track:** Post-Quantum AI Agents · Build Before Q-Day Developer Fest
## The problem
Agents that act for you need to pay: APIs, data, compute, other agents. Today that means
handing the agent a private key or a card number. A prompt injection, a bad tool or a bug
then spends whatever the key can reach, and the key itself is an ECDSA or Ed25519 key that
a quantum computer will forge.
## How QoreGuard stops it: three locks on every payment
```
agent (MCP) QoreChain QoreGuard contract
─────────── ───────── ──────────────────
signs intent with ML-DSA-87 ──► 1. session key: per-payment cap, ──► 2. payee on the owner's list,
signs execution with the daily cap, expiry, only pay() and per-payee daily cap (policy the
ed25519 session key postNote() on this contract owner signed with ML-DSA-87)
relays in a hybrid tx 3. agent's ML-DSA-87 signature
(secp256k1 + ML-DSA-87) over the exact intent (pqcVerify)
```
1. **Chain session key** (`x/abstractaccount`). The owner links the agent's ed25519 key to
their account with `permissions: ["evm"]` and a spending rule: per-payment limit, daily
limit, expiry, and `allowed_evm_calls` = only QoreGuard's `pay` and `postNote`. QoreChain
refuses everything else before any contract runs. One click revokes it.
2. **Owner's payee policy, verified on chain.** The owner signs the payee list (who, how
much per day, until when) in the QoreX wallet. The contract rebuilds the bytes QoreX
signed, reads the owner's registered key from the `pqcKeyStatus` precompile and checks
the ML-DSA-87 signature with `pqcVerify`. Relayers can deliver a policy but never change it.
3. **Agent's own ML-DSA-87 signature.** The agent identity (a QoreChain account with a
registered ML-DSA-87 key) signs every payment intent in the QoreSign format; `pay`
verifies it with `pqcVerify`, so no QoreGuard payment can be made with a classical
signature alone.
And two **authenticated channels**: the owner's instructions are QoreX-signed transactions
(the agent obeys nothing else, so a web page cannot instruct it), and the agent's reports
are notes signed with ML-DSA-87 and verified by the contract.
## What happened on chain
Every row is a real transaction on the testnet, produced by `pnpm --filter @qoreguard/core e2e`:
| # | What | Who decided | Transaction |
| --- | --- | --- | --- |
| 1 | Owner links the agent's session key: 1 QOR per payment, 20 QOR per day, 2 h, only `pay`/`postNote` | — | [F4832B8E…](https://explore.qore.network/tx/F4832B8E06AE9E012EE827347DDBF5501D9B54F048F2B2617EB66B32CDE2E672) |
| 2 | Owner signs the payee policy with ML-DSA-87 (1 uqor self-transfer, memo = policy digest) | — | [DD52812E…](https://explore.qore.network/tx/DD52812EB456556406D49927B536EB5699923384A831591E67A3E24AC356F8A7) |
| 3 | `setPolicy` verifies that signature on chain (`pqcKeyStatus` + `pqcVerify`) | contract | [0x0d9c479f…](https://explore.qore.network/tx/0x0d9c479f8fc1d29560b8ad444247e66d4bd661ff3de3116cf13a2a951ab58433) |
| 4 | Agent pays 0.4 QOR to `weather-api` (intent signed with ML-DSA-87, envelope hybrid-signed) | paid | [18C12727…](https://explore.qore.network/tx/18C12727173053E70B8FB3C2A51A9FAB52542978D674D26CB5A90DB2FC407E4A) |
| 5 | 1.2 QOR, sent past the MCP server's own checks | **refused by QoreChain**: per-tx limit | [95D56B50…](https://explore.qore.network/tx/95D56B500A251C8BAEAB97B34A656A436201F4C03D11207E7087DCB58DB8D9B9) |
| 6 | 0.1 QOR to an address the owner never allowed | **refused by the contract**: `PayeeNotAllowed` | [6C544372…](https://explore.qore.network/tx/6C54437293C365BC2CD3BA9F36BF1CE7464D2C029C27B47EAF4939BC305F5982) |
| 7 | 0.3 QOR over `weather-api`'s 1.5 QOR daily limit | **refused by the contract**: `DailyCapExceeded` | [5D998CA1…](https://explore.qore.network/tx/5D998CA1A02B091CE1D9C5392F032E8C3BD95BC4C49C21F22C1A52594467CC1A) |
| 8 | The session key used directly to call another contract | **refused by QoreChain**: not in `allowed_evm_calls` | [3A676A0A…](https://explore.qore.network/tx/3A676A0A49544200C3BD7A30973E680674319DCDF9428E6734899952920A6DE6) |
| 9 | The session key used directly for a 1.5 QOR plain transfer | **refused by QoreChain**: per-tx limit | [ACA372DB…](https://explore.qore.network/tx/ACA372DBD5D0BF6D689ABEC79628314CF6DE089A2972ACAA6965134413FD8388) |
| 10 | Agent posts a note to the owner, ML-DSA-87 verified by the contract | posted | [C555172E…](https://explore.qore.network/tx/C555172EBBD3909AC410F8B65B67E6F52581B00C69FF922F32AA417A7D3DD514) |
| 11 | Owner revokes the session key (kill switch); the next payment is refused | **refused by QoreChain** | [CCAEB802…](https://explore.qore.network/tx/CCAEB80212556A2A581B1F81E03B141CEABFA84A6694F1CA607BE2AC76EA2784) |
The same run also checks that a plain `MsgSend` with the session key is refused (it has
no `send` permission), that the owner's instruction is verified by the chain and again
locally, and that `check_transaction` re-verifies the agent's ML-DSA-87 signature of step 4.
## Use it
### 1. Agent side (your machine)
```sh
git clone https://github.com/imthegoodboy/qoreguard && cd qoreguard
pnpm install && pnpm --filter qoreguard-mcp build
node mcp/dist/qoreguard.mjs init --owner <your qor1 address>
# send ~2 testnet QOR for fees to the agent identity it prints (faucet: https://dashboard.qorechain.io/faucet)
node mcp/dist/qoreguard.mjs register # registers the agent identity's ML-DSA-87 key
node mcp/dist/qoreguard.mjs link-code # paste this in the dashboard
```
### 2. Owner side (QoreX wallet)
Open {{APP_URL}}/app/link, connect QoreX, paste the link code, choose the limits and sign.
Then add the payees the agent may pay and sign the policy.
### 3. Connect your AI client
Claude Code (from the repo folder, `.mcp.json` is included) or any MCP client:
```json
{ "mcpServers": { "qoreguard": { "command": "node", "args": ["<repo>/mcp/dist/qoreguard.mjs", "mcp"] } } }
```
| Tool | What it does |
| --- | --- |
| `guard_status` | Session key state and expiry, chain limits, payees and what is left today, problems |
| `list_payees` | The payees the owner allowed |
| `pay` | Pay an allowed payee (ML-DSA-87 intent + session key, enforced by chain and contract) |
| `fetch_paid` | GET a URL; if it answers HTTP 402 with a QoreGuard payment request, pay up to `max_qor` and fetch again |
| `send_note` | Post a signed note to the owner (verified on chain) |
| `read_owner_messages` | The owner's ML-DSA-87-signed instructions, verified by the chain and re-verified locally |
| `sign_message` / `verify_message` | QoreSign hybrid signatures against keys registered on chain |
| `check_transaction` | Was a transaction signed post-quantum, refused, and does the agent's signature verify |
No AI client at hand? `pnpm --filter qoreguard-mcp demo` runs a scripted agent session
through the same MCP protocol.
## Repository
| Path | What |
| --- | --- |
| `contracts/` | `QoreGuard.sol`, `HybridTx.sol` (parses a hybrid-signed QoreChain transaction), tests, deploy script |
| `core/` | TypeScript library: session-key payments, ML-DSA-87 intents, owner policy, messages, transaction checks |
| `mcp/` | The MCP server and `qoreguard` CLI (bundled to `mcp/dist/qoreguard.mjs`) |
| `web/` | Owner dashboard (Vite + React) and its serverless relayer and paid demo API |
| `docs/` | [Architecture](docs/ARCHITECTURE.md), [contract](docs/CONTRACT.md), [threat model](docs/THREAT_MODEL.md) |
## Tests
| Suite | Command | Result |
| --- | --- | --- |
| Contract (Hardhat 3, viem; real ML-DSA-87 signatures from `@qorechain/qoresign`, real hybrid-signed transactions for `setPolicy`) | `pnpm --filter contracts test` | 78 passing |
| MCP protocol (official MCP client over stdio against the bundled server) | `pnpm --filter qoreguard-mcp test` | 4 passing |
| Live testnet end to end (every lock, every refusal path) | `pnpm --filter @qoreguard/core e2e` | 17 steps, `E2E OK` |
Gas measured in the contract tests (QoreGuard's own cost, without the precompiles):
`setPolicy` with 2 payees ~499k, `pay` ~304–478k, `postNote` ~311–438k.
## Security notes
See [docs/THREAT_MODEL.md](docs/THREAT_MODEL.md). In short: the agent can be tricked or
taken over and the owner's exposure stays bounded by the chain's per-payment and daily
caps and the expiry, which QoreChain enforces on every use of the session key. Every
QoreGuard payment additionally needs an owner-approved payee and the agent's ML-DSA-87
signature. One chain fact we verified and document honestly: `allowed_evm_calls` restricts
calls with calldata, so a stolen or forged session key could still make plain transfers
up to the caps; keep the caps small and the expiry short. Testnet only.
## License
MIT. Built with Claude Code; see [AI_USAGE.md](AI_USAGE.md).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues