opencard 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/API.md +564 -0
  2. package/DATABASE.md +143 -0
  3. package/README.md +106 -0
  4. package/admin/index.html +18 -0
  5. package/admin/package-lock.json +2663 -0
  6. package/admin/package.json +25 -0
  7. package/admin/postcss.config.js +6 -0
  8. package/admin/src/App.tsx +198 -0
  9. package/admin/src/index.css +44 -0
  10. package/admin/src/main.tsx +10 -0
  11. package/admin/src/pages/Cards.tsx +181 -0
  12. package/admin/src/pages/Dashboard.tsx +139 -0
  13. package/admin/src/pages/Transactions.tsx +223 -0
  14. package/admin/tailwind.config.js +27 -0
  15. package/admin/tsconfig.json +20 -0
  16. package/admin/tsconfig.tsbuildinfo +1 -0
  17. package/admin/vite.config.ts +17 -0
  18. package/drizzle.config.ts +11 -0
  19. package/examples/agent-client-sdk.ts +36 -0
  20. package/examples/agent-client.ts +111 -0
  21. package/examples/agent-fund-sdk.ts +35 -0
  22. package/package.json +41 -0
  23. package/sdk/README.md +139 -0
  24. package/sdk/package-lock.json +240 -0
  25. package/sdk/package.json +43 -0
  26. package/sdk/src/client.ts +194 -0
  27. package/sdk/src/errors.ts +66 -0
  28. package/sdk/src/index.ts +35 -0
  29. package/sdk/src/types.ts +138 -0
  30. package/sdk/src/x402.ts +158 -0
  31. package/sdk/tsconfig.json +20 -0
  32. package/src/config/env.ts +45 -0
  33. package/src/config/tiers.ts +51 -0
  34. package/src/db/index.ts +9 -0
  35. package/src/db/migrate.ts +16 -0
  36. package/src/db/schema.ts +82 -0
  37. package/src/index.ts +89 -0
  38. package/src/middleware/errorHandler.ts +27 -0
  39. package/src/middleware/rateLimit.ts +54 -0
  40. package/src/middleware/walletAuth.ts +89 -0
  41. package/src/middleware/x402.ts +194 -0
  42. package/src/routes/admin.ts +150 -0
  43. package/src/routes/cards.ts +120 -0
  44. package/src/routes/paid.ts +154 -0
  45. package/src/routes/public.ts +40 -0
  46. package/src/services/cardService.ts +395 -0
  47. package/src/services/kripicard.ts +128 -0
  48. package/src/services/walletService.ts +78 -0
  49. package/src/types/index.ts +128 -0
  50. package/src/utils/logger.ts +19 -0
  51. package/src/utils/pricing.ts +75 -0
  52. package/tsconfig.json +21 -0
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # OpenCard
2
+
3
+ **x402-Powered Virtual Card Issuance API for AI Agents**
4
+
5
+ OpenCard lets AI agents purchase and manage virtual debit cards by paying with USDC on Base via the x402 payment protocol. No accounts, no API keys, no signups — **payment IS authentication**.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ AI Agent (Base wallet + USDC)
11
+
12
+
13
+ HTTP Request (no auth)
14
+
15
+
16
+ ┌─────────────────────────────┐
17
+ │ OpenCard API │
18
+ │ (Express + x402) │
19
+ │ │
20
+ │ x402 paid (tier-based): │
21
+ │ POST /cards/create/tier/N │
22
+ │ POST /cards/fund/tier/N │
23
+ │ │
24
+ │ Wallet-signed (free): │
25
+ │ GET /cards │
26
+ │ GET /cards/:id │
27
+ │ GET /cards/:id/details │
28
+ │ POST /cards/:id/freeze │
29
+ │ POST /cards/:id/unfreeze │
30
+ │ │
31
+ │ Public: │
32
+ │ GET /health │
33
+ │ GET /pricing │
34
+ │ GET /cards/tiers │
35
+ │ │
36
+ │ Admin: /admin/app │
37
+ └──────────┬──────────────────┘
38
+
39
+ ┌─────┴─────┐
40
+ ▼ ▼
41
+ Coinbase KripiCard
42
+ Facilitator API
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ```bash
48
+ # Install dependencies
49
+ npm install
50
+
51
+ # Copy environment template
52
+ cp .env.example .env
53
+ # Edit .env with your credentials
54
+
55
+ # Push database schema
56
+ npm run db:push
57
+
58
+ # Start development server
59
+ npm run dev
60
+ ```
61
+
62
+ ## Environment Variables
63
+
64
+ | Variable | Description |
65
+ | ------------------------- | --------------------------------------------- |
66
+ | `PORT` | Server port (default: 3000) |
67
+ | `ADMIN_SECRET` | Admin dashboard password |
68
+ | `TREASURY_WALLET_ADDRESS` | 0x address to receive USDC payments |
69
+ | `KRIPICARD_API_KEY` | KripiCard API key |
70
+ | `DATABASE_URL` | Neon PostgreSQL connection string |
71
+ | `CDP_API_KEY_ID` | Coinbase Developer Platform key (optional) |
72
+ | `CDP_API_KEY_SECRET` | Coinbase Developer Platform secret (optional) |
73
+
74
+ ## Pricing Tiers
75
+
76
+ | Load Amount | Total Cost (Creation) | Endpoint |
77
+ | ----------- | --------------------- | ----------------------------- |
78
+ | $10 | $17.20 | `POST /cards/create/tier/10` |
79
+ | $25 | $32.50 | `POST /cards/create/tier/25` |
80
+ | $50 | $58.00 | `POST /cards/create/tier/50` |
81
+ | $100 | $110.00 | `POST /cards/create/tier/100` |
82
+ | $200 | $214.00 | `POST /cards/create/tier/200` |
83
+ | $500 | $522.00 | `POST /cards/create/tier/500` |
84
+
85
+ ## Authentication Modes
86
+
87
+ ### x402 Payment (paid endpoints)
88
+
89
+ Agent sends request → receives 402 with USDC payment details → x402 client auto-pays → receives card details.
90
+
91
+ ### Wallet Signature (free endpoints)
92
+
93
+ Agent signs EIP-712 typed data (`action: "opencard-auth"`, `timestamp`) and sends via headers:
94
+
95
+ - `X-WALLET-ADDRESS`
96
+ - `X-WALLET-SIGNATURE`
97
+ - `X-WALLET-TIMESTAMP`
98
+
99
+ ## Tech Stack
100
+
101
+ - **Runtime**: Node.js 20+ / TypeScript (strict)
102
+ - **Framework**: Express.js
103
+ - **Database**: PostgreSQL via Neon (serverless) + Drizzle ORM
104
+ - **Payments**: x402 protocol (@x402/express, @coinbase/x402)
105
+ - **Crypto**: viem (EIP-712 signature verification)
106
+ - **Admin**: React + Vite + Tailwind CSS
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>OpenCard Admin</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9
+ <link
10
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
11
+ rel="stylesheet"
12
+ />
13
+ </head>
14
+ <body>
15
+ <div id="root"></div>
16
+ <script type="module" src="/src/main.tsx"></script>
17
+ </body>
18
+ </html>