Skip to main content
Glama
README.md
# Purser

**A post-quantum wallet for AI agents.** Purser is an MCP server that lets an AI agent
(Claude Code, Claude Desktop, any MCP client) pay for things from your QoreChain account,
inside limits that QoreChain and a contract enforce, never the agent itself. Every
instruction between you and the agent is signed with ML-DSA-87 (FIPS 204).

A purser is the officer who keeps a ship's money: they spend it for the crew, by the
captain's rules, and keep the books. That is the job we give the agent.

- **Live app:** https://purser-wallet.vercel.app (try the live demo account, no wallet needed)
- **Demo video:** _being recorded; the link goes here_
- **Contract:** `Purser` at [`0x4E7ef853B02Dc7b8Ce4656f51fF5397B22e66637`](https://explore.qore.network/address/0x4E7ef853B02Dc7b8Ce4656f51fF5397B22e66637) on the QoreChain testnet (`qorechain-diana`, EVM chain 9800)
- **Track:** Post-Quantum AI Agents · Build Before Q-Day Developer Fest 2026

## Why

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. One prompt injection, bad tool or bug then
spends whatever that key can reach, and the key is a classical ECDSA/Ed25519 key that a
quantum computer will forge.

## What Purser does differently

| | |
| --- | --- |
| **Works with any AI agent** | An MCP server with 11 tools; one line of config for Claude Code / Claude Desktop. |
| **Limits live on chain** | Per-payment and daily caps, expiry and allowed calls are a QoreChain session key; payees, per-payee and per-agent caps, budget, payments per day are the Purser contract. A modified MCP server changes nothing. |
| **Post-quantum at every step** | The owner signs policies, approvals and instructions with ML-DSA-87 in QoreX; the agent signs every payment, note and approval request with its own ML-DSA-87 key; the contract verifies both with the `pqcVerify` and `pqcKeyStatus` precompiles. |
| **Human in the loop for big payments** | Above a threshold the agent files a signed approval request on chain; one QoreX signature approves it; the payment can then go through exactly once. |
| **Agent commerce over HTTP 402** | `fetch_paid` pays a "402 Payment Required" invoice and fetches the resource; merchants check `paymentForRef` on chain. A live paid API (real Open-Meteo forecasts) is included. |
| **Prompt-injection resistant** | The agent obeys only instructions you signed in QoreX (`read_owner_messages`); web content comes back marked as untrusted; refusals are final. |
| **You see everything** | Dashboard reads the chain: agents, limits, payments with receipts, notes, approvals, and alerts for any session-key spend that bypassed Purser. |

## How a payment is checked

```
agent (MCP server)                  QoreChain                              Purser contract
──────────────────                  ─────────                              ───────────────
signs the intent with ML-DSA-87 ─►  session key (x/abstractaccount):   ─►  payee on the owner's ML-DSA-87-signed list,
signs MsgExecuteEVM with its        per-payment cap, daily cap, expiry,    per-payee and per-agent daily caps, budget,
ed25519 session key; relays it      only pay/postNote/requestApproval      payments per day, approval above a threshold,
in a hybrid tx (ML-DSA-87)          on this contract                       agent's ML-DSA-87 signature (pqcVerify)
```

## Track requirements

| Requirement (Post-Quantum AI Agents) | Where in Purser | Proof |
| --- | --- | --- |
| **The agent's own scoped EVM window** (transaction, value, duration and target limits) | The agent identity opens a window scoped to the Purser contract only (`allowedTargets`), with `maxTxs`, `maxValue` and a block limit, and uses it for its signed notes, approval requests and to deliver owner-signed policies. `core/src/evm.ts`, `purser window`, shown in `guard_status`. | [9FC80204…](https://explore.qore.network/tx/9FC802048961DFE9C73B2C7D7242BB7C4F29FD7C1D5584B776052830EF52094C), [0x3581d643…](https://explore.qore.network/tx/0x3581d64306dcd659862c04d05f944374d7cf949ded03eaa67a12a6e708ac2d7e) |
| **Smart-account spending rules** | `x/abstractaccount` session key: `permissions: ["evm"]`, rule `purser` with per-tx and daily caps, `allowedDenoms: ["uqor"]`, `allowed_evm_calls` = Purser's `pay`, `postNote`, `requestApproval`; expiry; instant revoke. `core/src/owner.ts`. | [7FE653AE…](https://explore.qore.network/tx/7FE653AE63942291C697280F3CC5BE23D386A371F4893BF88297639D2337C3B1) |
| **Transaction, value, duration and target limits** | Chain: per-payment and daily value caps, expiry, allowed calls; window: tx count, value, blocks, target. Contract: payments per day, per-payee and per-agent daily caps, budget, policy expiry. | E2E table below |
| **Authenticated messaging** | Owner → agent: QoreX-signed transactions (memo `purser:msg:…`), verified by the chain and re-verified by the MCP server. Agent → owner: notes and approval requests signed with ML-DSA-87, verified by the contract. | [0AC7456E…](https://explore.qore.network/tx/0AC7456E9F9386CD2E3306FF50FE56D689A8774AFC325C0CDEE258CC6E7CBCB7), [0xe05c6f0d…](https://explore.qore.network/tx/0xe05c6f0dd1314759ad2131dbcb1755524de43c372070808b1e13c94297c80c5c) |

## What happened on chain

Every row is a real transaction on the testnet from `pnpm --filter @purser/core e2e`:

| # | What | Result | Transaction |
| --- | --- | --- | --- |
| 1 | Owner links the agent's session key: 1 QOR per payment, 20 QOR/day, 2 h, may call only `Purser.pay` | linked | [7FE653AE…](https://explore.qore.network/tx/7FE653AE63942291C697280F3CC5BE23D386A371F4893BF88297639D2337C3B1) |
| 2 | Agent opens its own scoped EVM window: target = Purser only, 100 txs, value cap, ~1 day | opened | [9FC80204…](https://explore.qore.network/tx/9FC802048961DFE9C73B2C7D7242BB7C4F29FD7C1D5584B776052830EF52094C) |
| 3 | Owner signs the policy with ML-DSA-87 (2 payees, budget 2 QOR, 5 payments/day, approval above 0.6 QOR) | signed | [4F36F61B…](https://explore.qore.network/tx/4F36F61B2877EDDE0B74F52F46279B78EEAA40B18D91AD346A20201820B32280) |
| 4 | The agent delivers it from its window; `setPolicy` verifies the owner's signature (`pqcKeyStatus` + `pqcVerify`) | stored | [0x3581d643…](https://explore.qore.network/tx/0x3581d64306dcd659862c04d05f944374d7cf949ded03eaa67a12a6e708ac2d7e) |
| 5 | Agent pays 0.4 QOR to weather-api (intent signed with ML-DSA-87, hybrid envelope) | **paid** | [30825135…](https://explore.qore.network/tx/30825135E4A22D4F9E8A357D60DD64C2314CD8C2AA287E4486A5037F81756CD5) |
| 6 | 1.2 QOR, sent past the agent's own checks | **refused by QoreChain**: per-tx limit | [5CF30783…](https://explore.qore.network/tx/5CF30783CC33E65CFE305921903A4106E2BD64023CCBC7B6362545B0DB8E8FDF) |
| 7 | 0.1 QOR to an address the owner never allowed | **refused by the contract**: `PayeeNotAllowed` | [31423F33…](https://explore.qore.network/tx/31423F33848323CD6524B07C30E64DD36966F5F1AEF9048305395658910F966B) |
| 8 | 0.7 QOR, above the 0.6 QOR approval threshold | **refused by the contract**: `ApprovalRequired` | [3E5C5E80…](https://explore.qore.network/tx/3E5C5E80E8D62A5657038EF41A2AA0C65C45FFC8693D6AED1719210673373AAC) |
| 9 | Agent files an ML-DSA-87-signed approval request from its window | requested | [0x66076721…](https://explore.qore.network/tx/0x6607672184b12a3d8a2bdedee84ac9e6a7a86df2702f9b15019c094b3ab7fc3f) |
| 10 | Owner approves it with an ML-DSA-87 signature; the contract verifies it | approved | [ADD129BE…](https://explore.qore.network/tx/ADD129BE647FF47866A8A046007982D2171E64C9D9090A442034103E41A834AE) |
| 11 | Agent pays the approved 0.7 QOR | **paid** | [2BEEAA3C…](https://explore.qore.network/tx/2BEEAA3CB6D6FC38673AA3ED7ED57DF3A2CBEF6375F421F86F9DEB209A19000D) |
| 12 | The same 0.7 QOR again | **refused**: an approval works once | [DBD9B3C7…](https://explore.qore.network/tx/DBD9B3C7EDFD04DDB2F20574C1A1A6B70993FF9DCDF9E8291129B888902F4F5B) |
| 13 | 0.5 QOR more after 1.6 QOR: past the 2 QOR budget | **refused by the contract**: `BudgetExceeded` | [F4FE79B6…](https://explore.qore.network/tx/F4FE79B6FAB5C6DB6067BEA889D506B29F7F07325422A04AD95ECA27C61E598F) |
| 14 | A 6th payment in the day (limit 5) | **refused by the contract**: `DailyPaymentCountExceeded` | [86638E63…](https://explore.qore.network/tx/86638E63CC0053419EBB8052DB9822A476F5D4368557C125B2811256D154F624) |
| 15 | The session key used directly for a plain `MsgSend` | **refused by QoreChain**: no `send` permission | [EC9143E7…](https://explore.qore.network/tx/EC9143E7E8CACDE6BD87AD12B3FA3A32CE2162B14DEB9C9E715830EC15EF1104) |
| 16 | The session key used directly to call another Purser function | **refused by QoreChain**: not in `allowed_evm_calls` | [3199444E…](https://explore.qore.network/tx/3199444E34784B1FED6867BDC640DEC9FF33BE4B247FCEBB164D1C5DFA5B21D7) |
| 17 | The session key used directly for a 1.5 QOR plain transfer | **refused by QoreChain**: per-tx limit | [BECFF1E7…](https://explore.qore.network/tx/BECFF1E7A8C7B3A0E622BF18D3E97154F2292360BC4F5A1C4ADC3F86C8346D97) |
| 18 | Agent posts a note from its window; the contract verifies its ML-DSA-87 signature | posted | [0xe05c6f0d…](https://explore.qore.network/tx/0xe05c6f0dd1314759ad2131dbcb1755524de43c372070808b1e13c94297c80c5c) |
| 19 | Owner messages the agent; read back verified by the chain and locally | verified | [0AC7456E…](https://explore.qore.network/tx/0AC7456E9F9386CD2E3306FF50FE56D689A8774AFC325C0CDEE258CC6E7CBCB7) |
| 20 | Owner revokes the session key; the next payment | **refused by QoreChain** | [F463B86A…](https://explore.qore.network/tx/F463B86AF1F09465A568E933500B66E2CEACFEEFE5A83F9D197FC0C5E444708A) |

The run also checks that check_transaction re-verifies the agent's ML-DSA-87 signature of step 5, and a rerun the same day was refused with AgentDailyCapExceeded (the agent's day counters carry across policy versions).

Also verified with a **real QoreX wallet**: a payee policy signed in QoreX and verified by
the contract ([`325BB44F…`](https://explore.qore.network/tx/325BB44F8D97097EB06C739CF47BD0B010CC6C0509DB1BCA3461C59BF9772419), v1 contract),
and unscripted **Claude Code sessions** that paid a live HTTP 402 API and went through the
approval flow: [docs/AGENT_RUN.md](docs/AGENT_RUN.md).

## Use it

### 1. The agent's machine

Node 20+ and pnpm 12 (`corepack enable` picks the right pnpm).

```sh
git clone https://github.com/imthegoodboy/purser && cd purser
pnpm install --filter purser-mcp...        # the MCP server and its library only
pnpm --filter purser-mcp build
node mcp/dist/purser.mjs init --owner <your qor1 address>
# send ~2 testnet QOR for fees to the agent identity it prints (https://dashboard.qorechain.io/faucet)
node mcp/dist/purser.mjs register          # registers the agent identity's ML-DSA-87 key
node mcp/dist/purser.mjs link-code         # a pr1:… code for the owner
```

### 2. The owner (QoreX)

- **Link the session key.** Current QoreX builds keep spending rules inside the wallet and
  refuse `MsgUpdateSpendingRules` from websites (we tested it: *"managed by the wallet
  itself, not by a website"*), so link with the CLI; the dashboard shows the exact command:
  `PURSER_OWNER_MNEMONIC="…" node mcp/dist/purser.mjs owner link <code> --per-tx 1 --daily 5 --hours 24`.
  Works with a QoreX recovery phrase or an SDK account (testnet only; the phrase is used to
  sign and never stored).
- **Set payees and limits** at https://purser-wallet.vercel.app/app (signed in QoreX).
- **Approve big payments, message the agent, watch everything, revoke** (`owner revoke`).

### 3. Connect your AI client

Claude Code picks up `.mcp.json` in this folder. Any MCP client:

```json
{ "mcpServers": { "purser": { "command": "node", "args": ["<repo>/mcp/dist/purser.mjs", "mcp"] } } }
```

| Tool | What it does |
| --- | --- |
| `guard_status` | Session key, chain caps, payees and what is left today, budget, the agent's scoped EVM window, fees left, alerts |
| `list_payees` | The payees the owner allowed |
| `pay` | Pay an allowed payee (ML-DSA-87 intent + session key, checked by chain and contract) |
| `request_approval` | Ask the owner to approve a payment above the threshold (signed, on chain) |
| `fetch_paid` | GET a public URL; pay its HTTP 402 invoice up to `max_qor` and fetch it again |
| `list_payments` | This agent's receipts |
| `send_note` | A signed note to the owner, verified by the contract |
| `read_owner_messages` | The owner's ML-DSA-87-signed instructions, verified by the chain and 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 purser-mcp demo` runs a scripted session over the same protocol.

## Repository

| Path | What |
| --- | --- |
| `contracts/` | `Purser.sol`, `HybridTx.sol` (parses a hybrid-signed QoreChain transaction), tests, deploy script |
| `core/` | TypeScript library: session-key payments, ML-DSA-87 intents, approvals, owner policy, messages, alerts |
| `mcp/` | The MCP server and `purser` CLI (bundled to `mcp/dist/purser.mjs`) |
| `web/` | Owner app (Vite + React) with its serverless relayer and the paid demo API |
| `docs/` | [Architecture](docs/ARCHITECTURE.md), [contract](docs/CONTRACT.md), [threat model](docs/THREAT_MODEL.md), [audits](docs/AUDIT.md), [real agent run](docs/AGENT_RUN.md) |

## Tests

| Suite | Command | Result |
| --- | --- | --- |
| Contract (Hardhat 3 + viem; real ML-DSA-87 signatures, real hybrid-signed transactions, malformed-input fuzz cases) | `pnpm --filter contracts test` | 115 passing |
| Core library unit tests | `pnpm --filter @purser/core test` | 9 passing |
| MCP protocol (official MCP client over stdio **and** Streamable HTTP) | `pnpm --filter purser-mcp test` | 5 passing |
| Live testnet end to end (every lock, every refusal) | `pnpm --filter @purser/core e2e` | 25 steps, `E2E OK` |
| Owner app in Edge with QoreChain's QoreX test double, against the live chain | `pnpm --filter web ui-e2e` | all steps pass |

CI runs the first three and the app build on every push.

## Security

[docs/THREAT_MODEL.md](docs/THREAT_MODEL.md) and [docs/AUDIT.md](docs/AUDIT.md). In short: the
agent can be tricked or taken over and the owner's exposure stays bounded by the chain caps
and the expiry; every Purser payment also needs an owner-approved payee and the agent's
ML-DSA-87 signature. One chain fact we verified and state plainly: `allowed_evm_calls`
covers calls with calldata, so a stolen session key could still make plain transfers up to
the chain caps; Purser flags any such transfer in the dashboard and the agent status. Keep
caps small and expiries short. Testnet only.

## Credits

- Scaffolded with **create-qorechain-dapp 0.14.0** (folders `contracts/` and `web/`):
  `npx -y create-qorechain-dapp@0.14.0 contracts --template hardhat --network testnet --package-manager pnpm --yes --no-install`
  and the same with `web --template fullstack-web`.
- QoreChain kits: `@qorechain/sdk` (session keys, hybrid signing, PQC registration),
  `@qorechain/qoresign` (QoreSign message signing, hybrid tx verification), `@qorechain/evm`
  (EVM windows), `@qorechain/pqc`, `@qorechain/qorex-wallet-mock` (browser tests),
  the QoreX wallet API.
- The agent pattern (owner, ed25519 agent key, gas wallet) follows QoreChain's Build Before
  Q-Day Workshop 2 (`02-pq-agent`).
- `HybridTx.sol` comes from our first fest entry, [Pactum](https://github.com/imthegoodboy/pactum).
- Model Context Protocol SDK (`@modelcontextprotocol/sdk`), viem, CosmJS, Hardhat, React,
  Vite, TanStack Query, Playwright; forecasts from [Open-Meteo](https://open-meteo.com).

## License

MIT. Built with Claude Code; see [AI_USAGE.md](AI_USAGE.md).