@useagentpay/sdk 0.1.1 → 0.1.2

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.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # @useagentpay/sdk
2
+
3
+ Secure payments infrastructure for AI agents. Local-first SDK and CLI that lets agents purchase things on the web without ever seeing a user's credit card.
4
+
5
+ Credentials are encrypted locally, purchases require human approval with Ed25519 signatures, and checkout happens via headless browser with placeholder injection — real values exist in the DOM for milliseconds.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @useagentpay/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ **Human — set up credentials:**
16
+ ```bash
17
+ agentpay setup # encrypt & store billing credentials locally
18
+ agentpay budget --set 200
19
+ ```
20
+
21
+ **Agent — propose & execute:**
22
+ ```typescript
23
+ import { AgentPay } from '@useagentpay/sdk';
24
+ const ap = new AgentPay();
25
+
26
+ const tx = await ap.transactions.propose({
27
+ merchant: 'amazon.com',
28
+ amount: 29.99,
29
+ description: 'Wireless mouse',
30
+ url: 'https://amazon.com/dp/B09ABC1234',
31
+ });
32
+
33
+ const result = await ap.transactions.waitForApproval(tx.id);
34
+
35
+ if (result.status === 'approved') {
36
+ const receipt = await ap.transactions.execute(tx.id);
37
+ }
38
+ ```
39
+
40
+ **Human — approve:**
41
+ ```bash
42
+ agentpay approve tx_a1b2c3
43
+ ```
44
+
45
+ ## CLI Commands
46
+
47
+ | Command | Description |
48
+ |---------|-------------|
49
+ | `agentpay setup` | One-time interactive setup — passphrase, card details, billing/shipping address |
50
+ | `agentpay budget` | View/set spending limits (`--set <amount>`, `--limit-per-tx <amount>`) |
51
+ | `agentpay propose` | Create a pending transaction (`--merchant`, `--amount`, `--description`, `--url`) |
52
+ | `agentpay pending` | List pending purchase proposals |
53
+ | `agentpay approve <txId>` | Approve a purchase (signs an Ed25519 mandate) |
54
+ | `agentpay reject <txId>` | Reject a purchase (`--reason` optional) |
55
+ | `agentpay status` | Wallet balance, budget, limits, recent transactions |
56
+ | `agentpay history` | Full transaction history |
57
+ | `agentpay qr` | QR code for web-based setup (`--budget`, `--message`) |
58
+ | `agentpay dashboard` | Browser-based GUI (`--port`, default 3141) |
59
+ | `agentpay mcp` | Start MCP server (`--http` for HTTP transport) |
60
+ | `agentpay reset` | Delete all AgentPay data |
61
+
62
+ ## SDK API
63
+
64
+ ```typescript
65
+ import { AgentPay } from '@useagentpay/sdk';
66
+
67
+ const ap = new AgentPay({
68
+ passphrase: 'your-passphrase', // optional
69
+ home: '/custom/data/dir', // optional, default ~/.agentpay
70
+ executor: {
71
+ provider: myCustomProvider, // optional, defaults to local Chromium
72
+ modelApiKey: process.env.ANTHROPIC_API_KEY,
73
+ },
74
+ });
75
+ ```
76
+
77
+ ### Methods
78
+
79
+ | Method | Description |
80
+ |--------|-------------|
81
+ | `ap.status()` | Overall system status |
82
+ | `ap.wallet.getBalance()` | Current balance and budget |
83
+ | `ap.wallet.getHistory()` | Transaction history |
84
+ | `ap.wallet.getLimits()` | Budget and per-tx limits |
85
+ | `ap.wallet.generateFundingQR(options?)` | QR code for setup |
86
+ | `ap.transactions.propose(options)` | Create a pending transaction |
87
+ | `ap.transactions.get(txId)` | Get transaction details |
88
+ | `ap.transactions.waitForApproval(txId, options?)` | Long-poll for approval |
89
+ | `ap.transactions.requestApproval(txId)` | Open browser approval UI |
90
+ | `ap.transactions.execute(txId)` | Execute an approved purchase |
91
+ | `ap.transactions.getReceipt(txId)` | Get receipt for completed purchase |
92
+ | `ap.audit.getLog()` | Audit log entries |
93
+
94
+ ### Custom Browser Provider
95
+
96
+ By default, `PurchaseExecutor` runs local Chromium via Playwright + Stagehand. Implement the `BrowserProvider` interface to use a different backend:
97
+
98
+ ```typescript
99
+ import { AgentPay, type BrowserProvider } from '@useagentpay/sdk';
100
+ import { Stagehand } from '@browserbasehq/stagehand';
101
+
102
+ const myProvider: BrowserProvider = {
103
+ createStagehand(modelApiKey?: string) {
104
+ return new Stagehand({ env: 'LOCAL', /* ... */ });
105
+ },
106
+ async close() {},
107
+ };
108
+
109
+ const ap = new AgentPay({
110
+ executor: { provider: myProvider },
111
+ });
112
+ ```
113
+
114
+ ## Security Model
115
+
116
+ - **AES-256-GCM vault** — credentials encrypted with PBKDF2 (SHA-512, 100k iterations), random salt + IV per encryption
117
+ - **Placeholder injection** — forms filled with `{{card_number}}` placeholders; real values swapped via atomic `page.evaluate()` at submission time
118
+ - **Ed25519 signed mandates** — every purchase requires a cryptographic human approval
119
+ - **Browser security boundary** — sensitive operations (setup, approval) open an ephemeral localhost browser window; credentials never pass through the terminal
120
+
121
+ ## Transaction States
122
+
123
+ ```
124
+ pending → approved → executing → completed
125
+ ↘ rejected ↘ failed
126
+ ```
127
+
128
+ ## Environment Variables
129
+
130
+ | Variable | Purpose | Default |
131
+ |----------|---------|---------|
132
+ | `ANTHROPIC_API_KEY` | LLM API key for browser navigation | — |
133
+ | `AGENTPAY_HOME` | Override data directory | `~/.agentpay` |
134
+ | `AGENTPAY_WEB_URL` | Base URL for QR codes | `http://localhost:3000` |
135
+
136
+ ## Data Directory (`~/.agentpay/`)
137
+
138
+ | File | Purpose |
139
+ |------|---------|
140
+ | `credentials.enc` | AES-256-GCM encrypted billing credentials |
141
+ | `keys/private.pem` | Ed25519 private key (passphrase-protected) |
142
+ | `keys/public.pem` | Ed25519 public key |
143
+ | `wallet.json` | Budget, balance, per-tx limit, spent total |
144
+ | `transactions.json` | All transactions |
145
+ | `audit.log` | Append-only action log |
146
+
147
+ ## License
148
+
149
+ MIT