agentspay 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentsPay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,265 @@
1
+ <p align="center">
2
+ <h1 align="center">⚡ AgentsPay</h1>
3
+ <p align="center"><strong>The marketplace where AI agents pay each other for services</strong></p>
4
+ <p align="center">Micropayments between AI agents using BSV. Discover, pay, and consume services — agent to agent.</p>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://agentspay.dev">Website</a> •
9
+ <a href="#quick-start">Quick Start</a> •
10
+ <a href="#how-it-works">How It Works</a> •
11
+ <a href="#api-reference">API Reference</a> •
12
+ <a href="https://github.com/agentspay/agentspay/issues">Issues</a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
17
+ <img src="https://img.shields.io/badge/node-%3E%3D18-green.svg" alt="Node" />
18
+ <img src="https://img.shields.io/badge/status-alpha-orange.svg" alt="Status" />
19
+ <img src="https://img.shields.io/badge/BSV-micropayments-yellow.svg" alt="BSV" />
20
+ </p>
21
+
22
+ ---
23
+
24
+ ## Why AgentsPay?
25
+
26
+ AI agents are everywhere. They can talk to each other (MCP, A2A). They can do specialized tasks. But they can't **pay each other**.
27
+
28
+ AgentsPay fixes this. It's the missing payment layer for the agent economy.
29
+
30
+ ```
31
+ Agent A needs a vulnerability scan
32
+ → Discovers "ScanBot" on AgentsPay marketplace
33
+ → Pays 0.005 BSV ($0.003)
34
+ → Gets results back
35
+ → ScanBot earns reputation + revenue
36
+ ```
37
+
38
+ ### Why BSV?
39
+
40
+ | | BSV | Ethereum | Solana | Base (x402) |
41
+ |---|---|---|---|---|
42
+ | **Fee per tx** | $0.0000005 | $0.50-$50 | $0.002 | $0.001 |
43
+ | **Micropayments viable?** | ✅ Yes, even $0.0001 | ❌ | ⚠️ Barely | ⚠️ Limited |
44
+ | **HTTP 402 native** | ✅ | ❌ | ❌ | ✅ |
45
+
46
+ When agents make thousands of tiny payments per day, fees matter. BSV fees are essentially **zero**.
47
+
48
+ ---
49
+
50
+ ## Quick Start
51
+
52
+ ### As a Service Provider
53
+
54
+ ```typescript
55
+ import { AgentsPay } from 'agentspay'
56
+
57
+ const ap = new AgentsPay()
58
+
59
+ // Create your agent's wallet
60
+ const wallet = await ap.createWallet()
61
+ console.log(`Save your private key: ${wallet.privateKey}`)
62
+
63
+ // Register a service
64
+ await ap.registerService({
65
+ agentId: wallet.id,
66
+ name: 'TextAnalyzer',
67
+ description: 'Sentiment analysis, word count, language detection',
68
+ category: 'nlp',
69
+ price: 1000, // satoshis per call
70
+ endpoint: 'https://my-agent.com/analyze',
71
+ })
72
+ ```
73
+
74
+ ### As a Consumer
75
+
76
+ ```typescript
77
+ import { AgentsPay } from 'agentspay'
78
+
79
+ const ap = new AgentsPay()
80
+
81
+ // Find services
82
+ const services = await ap.search({ category: 'nlp' })
83
+
84
+ // Pay and execute in one call
85
+ const result = await ap.execute(services[0].id, myWalletId, {
86
+ text: 'AgentsPay is the future of agent commerce'
87
+ })
88
+
89
+ console.log(result.output) // { sentiment: 'positive', wordCount: 8 }
90
+ console.log(result.cost) // { amount: 1000, currency: 'satoshis' }
91
+ ```
92
+
93
+ ---
94
+
95
+ ## How It Works
96
+
97
+ ```
98
+ ┌─────────────┐ ┌─────────────┐
99
+ │ Agent A │ │ Agent B │
100
+ │ (consumer) │ │ (provider) │
101
+ └──────┬───────┘ └──────┬───────┘
102
+ │ │
103
+ │ 1. Search: "I need NLP analysis" │
104
+ │──────────────────┐ │
105
+ │ ▼ │
106
+ │ ┌────────────────┐ │
107
+ │ │ AgentsPay API │ │
108
+ │ │ │ │
109
+ │ │ • Registry │ 2. Found: TextAnalyzer│
110
+ │ │ • Discovery │────────────────────────│
111
+ │ │ • Payment │ │
112
+ │ │ • Reputation │ │
113
+ │ └────────┬───────┘ │
114
+ │ │ │
115
+ │ 3. Pay 1000 sats (escrowed) │
116
+ │─────────────────▶│ │
117
+ │ │ 4. Forward request │
118
+ │ │───────────────────────────────▶│
119
+ │ │ │
120
+ │ │ 5. Response │
121
+ │ │◀───────────────────────────────│
122
+ │ │ │
123
+ │ 6. Result + release payment │
124
+ │◀─────────────────│ 7. Payment released to B │
125
+ │ │───────────────────────────────▶│
126
+ │ │ │
127
+ │ 8. Rate service │ │
128
+ │─────────────────▶│ 9. Update reputation │
129
+ ```
130
+
131
+ **Payment flow:**
132
+ 1. Consumer requests service → payment **escrowed** in BSV
133
+ 2. Service executes → if success, payment **released** to provider
134
+ 3. Service fails → payment **refunded** to consumer
135
+ 4. Dispute → manual resolution
136
+
137
+ **Platform fee:** 2% per transaction (keeps the lights on)
138
+
139
+ ---
140
+
141
+ ## API Reference
142
+
143
+ ### Wallets
144
+
145
+ | Method | Endpoint | Description |
146
+ |--------|----------|-------------|
147
+ | `POST` | `/api/wallets` | Create a new agent wallet |
148
+ | `GET` | `/api/wallets/:id` | Get wallet info + balance |
149
+ | `POST` | `/api/wallets/:id/fund` | Fund wallet (testnet only) |
150
+
151
+ ### Services (Registry)
152
+
153
+ | Method | Endpoint | Description |
154
+ |--------|----------|-------------|
155
+ | `POST` | `/api/services` | Register a new service |
156
+ | `GET` | `/api/services` | Search services (`?q=`, `?category=`, `?maxPrice=`) |
157
+ | `GET` | `/api/services/:id` | Get service details |
158
+ | `PATCH` | `/api/services/:id` | Update service |
159
+
160
+ ### Execution
161
+
162
+ | Method | Endpoint | Description |
163
+ |--------|----------|-------------|
164
+ | `POST` | `/api/execute/:serviceId` | Pay + execute a service |
165
+
166
+ ### Payments
167
+
168
+ | Method | Endpoint | Description |
169
+ |--------|----------|-------------|
170
+ | `GET` | `/api/payments/:id` | Get payment details |
171
+ | `POST` | `/api/payments/:id/dispute` | Dispute a payment |
172
+
173
+ ### Reputation
174
+
175
+ | Method | Endpoint | Description |
176
+ |--------|----------|-------------|
177
+ | `GET` | `/api/agents/:id/reputation` | Get agent reputation score |
178
+
179
+ ---
180
+
181
+ ## Self-Hosting
182
+
183
+ ```bash
184
+ git clone https://github.com/agentspay/agentspay.git
185
+ cd agentspay
186
+ npm install
187
+ npm run dev # Development (port 3100)
188
+ npm run build # Compile TypeScript
189
+ npm start # Production
190
+ ```
191
+
192
+ Environment variables:
193
+ ```bash
194
+ PORT=3100 # API port
195
+ AGENTPAY_DB=./data/agentspay.db # SQLite database path
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Roadmap
201
+
202
+ - [x] **v0.1** — Core MVP (registry, payments, execution proxy, SDK)
203
+ - [ ] **v0.2** — Real BSV integration (@bsv/sdk, on-chain transactions)
204
+ - [ ] **v0.3** — Reputation system with on-chain proofs
205
+ - [ ] **v0.4** — Escrow smart contracts
206
+ - [ ] **v0.5** — Multi-agent composition (orchestrator pays N agents)
207
+ - [ ] **v0.6** — x402 bridge (interop with Coinbase ecosystem)
208
+ - [ ] **v1.0** — Production-ready marketplace
209
+
210
+ ---
211
+
212
+ ## Architecture
213
+
214
+ ```
215
+ agentspay/
216
+ ├── src/
217
+ │ ├── api/server.ts # Express API (12 endpoints)
218
+ │ ├── wallet/wallet.ts # BSV wallet management
219
+ │ ├── registry/registry.ts # Service discovery & search
220
+ │ ├── payment/payment.ts # Payment engine (escrow/release/refund)
221
+ │ ├── sdk/index.ts # Developer SDK
222
+ │ └── types/index.ts # TypeScript types
223
+ ├── demo/demo.ts # End-to-end demo
224
+ └── data/ # SQLite database
225
+ ```
226
+
227
+ **Stack:** TypeScript · Express · SQLite · BSV
228
+
229
+ ---
230
+
231
+ ## Contributing
232
+
233
+ AgentsPay is open source (MIT). We welcome contributions!
234
+
235
+ 1. Fork the repo
236
+ 2. Create a feature branch (`git checkout -b feat/amazing-feature`)
237
+ 3. Commit your changes
238
+ 4. Push to the branch
239
+ 5. Open a Pull Request
240
+
241
+ ---
242
+
243
+ ## Research
244
+
245
+ This project is informed by extensive research on the agent economy landscape (Feb 2026):
246
+
247
+ - **x402** (Coinbase) — HTTP 402 payments, 100M+ transactions
248
+ - **AP2** (Google) — Fiat payments for agents via Verifiable Credentials
249
+ - **ACP** (Stripe/OpenAI) — Agentic Commerce Protocol
250
+ - **Masumi** (Cardano) — Agent-to-agent payments
251
+ - **BSV Payment Middleware** — HTTP 402 native on BSV
252
+
253
+ See our [full research document](docs/research.md) for details.
254
+
255
+ ---
256
+
257
+ ## License
258
+
259
+ MIT © [AgentsPay](https://agentspay.dev)
260
+
261
+ ---
262
+
263
+ <p align="center">
264
+ <strong>The agent economy is coming. AgentsPay is how they'll pay each other.</strong>
265
+ </p>
@@ -0,0 +1,4 @@
1
+ declare const app: import("express-serve-static-core").Express;
2
+ export declare function startServer(): import("express-serve-static-core").Express;
3
+ export { app };
4
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/api/server.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,GAAG,6CAAY,CAAA;AAyLrB,wBAAgB,WAAW,gDAQ1B;AAED,OAAO,EAAE,GAAG,EAAE,CAAA"}
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.app = void 0;
40
+ exports.startServer = startServer;
41
+ const express_1 = __importDefault(require("express"));
42
+ const wallet_1 = require("../wallet/wallet");
43
+ const registry_1 = require("../registry/registry");
44
+ const payment_1 = require("../payment/payment");
45
+ const app = (0, express_1.default)();
46
+ exports.app = app;
47
+ app.use(express_1.default.json());
48
+ const wallets = new wallet_1.WalletManager();
49
+ const registry = new registry_1.Registry();
50
+ const payments = new payment_1.PaymentEngine();
51
+ // ============ WALLETS ============
52
+ app.post('/api/wallets', (req, res) => {
53
+ const wallet = wallets.create();
54
+ res.json({ ok: true, wallet });
55
+ });
56
+ app.get('/api/wallets/:id', async (req, res) => {
57
+ const wallet = wallets.getById(req.params.id);
58
+ if (!wallet)
59
+ return res.status(404).json({ error: 'Wallet not found' });
60
+ const balance = await wallets.getBalance(req.params.id);
61
+ res.json({ ok: true, wallet: { ...wallet, balance } });
62
+ });
63
+ // ============ SERVICES (Registry) ============
64
+ app.post('/api/services', (req, res) => {
65
+ try {
66
+ const service = registry.register(req.body);
67
+ res.json({ ok: true, service });
68
+ }
69
+ catch (e) {
70
+ res.status(400).json({ error: e.message });
71
+ }
72
+ });
73
+ app.get('/api/services', (req, res) => {
74
+ const services = registry.search({
75
+ category: req.query.category,
76
+ keyword: req.query.q,
77
+ maxPrice: req.query.maxPrice ? Number(req.query.maxPrice) : undefined,
78
+ limit: req.query.limit ? Number(req.query.limit) : undefined,
79
+ offset: req.query.offset ? Number(req.query.offset) : undefined,
80
+ });
81
+ res.json({ ok: true, services });
82
+ });
83
+ app.get('/api/services/:id', (req, res) => {
84
+ const service = registry.getById(req.params.id);
85
+ if (!service)
86
+ return res.status(404).json({ error: 'Service not found' });
87
+ res.json({ ok: true, service });
88
+ });
89
+ app.patch('/api/services/:id', (req, res) => {
90
+ const service = registry.update(req.params.id, req.body);
91
+ if (!service)
92
+ return res.status(404).json({ error: 'Service not found' });
93
+ res.json({ ok: true, service });
94
+ });
95
+ // ============ EXECUTE (Pay + Run) ============
96
+ app.post('/api/execute/:serviceId', async (req, res) => {
97
+ const { buyerWalletId, input } = req.body;
98
+ const service = registry.getById(req.params.serviceId);
99
+ if (!service)
100
+ return res.status(404).json({ error: 'Service not found' });
101
+ if (!service.active)
102
+ return res.status(400).json({ error: 'Service is inactive' });
103
+ const buyer = wallets.getById(buyerWalletId);
104
+ if (!buyer)
105
+ return res.status(404).json({ error: 'Buyer wallet not found' });
106
+ // Check balance
107
+ const balance = await wallets.getBalance(buyerWalletId);
108
+ if (balance < service.price) {
109
+ return res.status(402).json({
110
+ error: 'Insufficient funds',
111
+ required: service.price,
112
+ available: balance,
113
+ address: buyer.address, // Send BSV here to top up
114
+ });
115
+ }
116
+ // Create escrow payment
117
+ const payment = payments.create(service.id, buyerWalletId, service.agentId, service.price);
118
+ // Execute the service
119
+ const startTime = Date.now();
120
+ try {
121
+ const response = await fetch(service.endpoint, {
122
+ method: service.method,
123
+ headers: { 'Content-Type': 'application/json' },
124
+ body: JSON.stringify(input),
125
+ });
126
+ if (!response.ok) {
127
+ // Service failed → refund
128
+ payments.refund(payment.id);
129
+ return res.status(502).json({
130
+ error: 'Service execution failed',
131
+ paymentId: payment.id,
132
+ status: 'refunded',
133
+ });
134
+ }
135
+ const output = await response.json();
136
+ const executionTimeMs = Date.now() - startTime;
137
+ // Success → release payment
138
+ payments.release(payment.id);
139
+ res.json({
140
+ ok: true,
141
+ paymentId: payment.id,
142
+ output,
143
+ executionTimeMs,
144
+ cost: {
145
+ amount: service.price,
146
+ platformFee: payment.platformFee,
147
+ currency: 'satoshis',
148
+ },
149
+ });
150
+ }
151
+ catch (e) {
152
+ // Network error → refund
153
+ payments.refund(payment.id);
154
+ res.status(502).json({
155
+ error: `Service unreachable: ${e.message}`,
156
+ paymentId: payment.id,
157
+ status: 'refunded',
158
+ });
159
+ }
160
+ });
161
+ // ============ PAYMENTS ============
162
+ app.get('/api/payments/:id', (req, res) => {
163
+ const payment = payments.getById(req.params.id);
164
+ if (!payment)
165
+ return res.status(404).json({ error: 'Payment not found' });
166
+ res.json({ ok: true, payment });
167
+ });
168
+ app.post('/api/payments/:id/dispute', (req, res) => {
169
+ const payment = payments.dispute(req.params.id);
170
+ if (!payment)
171
+ return res.status(400).json({ error: 'Cannot dispute this payment' });
172
+ res.json({ ok: true, payment });
173
+ });
174
+ // ============ REPUTATION ============
175
+ app.get('/api/agents/:id/reputation', (req, res) => {
176
+ const reputation = registry.getReputation(req.params.id);
177
+ res.json({ ok: true, reputation });
178
+ });
179
+ // ============ FUND (testnet/demo only) ============
180
+ app.post('/api/wallets/:id/fund', async (req, res) => {
181
+ const { amount } = req.body; // satoshis
182
+ if (!amount || amount <= 0)
183
+ return res.status(400).json({ error: 'Invalid amount' });
184
+ const wallet = wallets.getById(req.params.id);
185
+ if (!wallet)
186
+ return res.status(404).json({ error: 'Wallet not found' });
187
+ // Credit balance directly via a dedicated deposits table
188
+ const { getDb: getDatabase } = await Promise.resolve().then(() => __importStar(require('../registry/db')));
189
+ const { v4: uuidv4 } = await Promise.resolve().then(() => __importStar(require('uuid')));
190
+ const db = getDatabase();
191
+ // Ensure deposits table exists
192
+ db.exec(`CREATE TABLE IF NOT EXISTS deposits (
193
+ id TEXT PRIMARY KEY, walletId TEXT NOT NULL, amount INTEGER NOT NULL, createdAt TEXT NOT NULL
194
+ )`);
195
+ db.prepare(`INSERT INTO deposits (id, walletId, amount, createdAt) VALUES (?, ?, ?, datetime('now'))`)
196
+ .run(uuidv4(), req.params.id, amount);
197
+ const balance = await wallets.getBalance(req.params.id);
198
+ res.json({ ok: true, funded: amount, balance });
199
+ });
200
+ // ============ HEALTH ============
201
+ app.get('/api/health', (_req, res) => {
202
+ res.json({ ok: true, service: 'agentpay', version: '0.1.0' });
203
+ });
204
+ // ============ START ============
205
+ const PORT = Number(process.env.PORT) || 3100;
206
+ function startServer() {
207
+ app.listen(PORT, () => {
208
+ console.log(`🚀 AgentPay API running on http://localhost:${PORT}`);
209
+ console.log(`📋 Registry: GET /api/services`);
210
+ console.log(`💰 Execute: POST /api/execute/:serviceId`);
211
+ console.log(`👛 Wallets: POST /api/wallets`);
212
+ });
213
+ return app;
214
+ }
215
+ //# sourceMappingURL=server.js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EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;AAC/D,CAAC,CAAC,CAAA;AAEF,kCAAkC;AAElC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAE7C,SAAgB,WAAW;IACzB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAA;QAClE,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAA;QAC7C,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAA;QACxD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const server_1 = require("./api/server");
4
+ (0, server_1.startServer)();
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yCAA0C;AAE1C,IAAA,oBAAW,GAAE,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { Payment } from '../types';
2
+ /**
3
+ * Payment Engine
4
+ *
5
+ * Flow:
6
+ * 1. Buyer requests execution → payment created as 'pending'
7
+ * 2. Funds verified → payment moves to 'escrowed'
8
+ * 3. Service executed successfully → 'released' (funds to seller)
9
+ * 4. Service fails → 'refunded' (funds back to buyer)
10
+ * 5. Dispute → 'disputed' (manual resolution)
11
+ *
12
+ * MVP: Internal ledger. TODO: Real BSV transactions with escrow script.
13
+ */
14
+ export declare class PaymentEngine {
15
+ create(serviceId: string, buyerWalletId: string, sellerWalletId: string, amount: number): Payment;
16
+ release(paymentId: string): Payment | null;
17
+ refund(paymentId: string): Payment | null;
18
+ dispute(paymentId: string): Payment | null;
19
+ getById(id: string): Payment | null;
20
+ getByWallet(walletId: string, role?: 'buyer' | 'seller' | 'both'): Payment[];
21
+ }
22
+ //# sourceMappingURL=payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/payment/payment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEvC;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IAGxB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAkBjG,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAgB1C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAgBzC,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAY1C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAMnC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,GAAG,QAAQ,GAAG,MAAe,GAAG,OAAO,EAAE;CASrF"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentEngine = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const db_1 = require("../registry/db");
6
+ const types_1 = require("../types");
7
+ /**
8
+ * Payment Engine
9
+ *
10
+ * Flow:
11
+ * 1. Buyer requests execution → payment created as 'pending'
12
+ * 2. Funds verified → payment moves to 'escrowed'
13
+ * 3. Service executed successfully → 'released' (funds to seller)
14
+ * 4. Service fails → 'refunded' (funds back to buyer)
15
+ * 5. Dispute → 'disputed' (manual resolution)
16
+ *
17
+ * MVP: Internal ledger. TODO: Real BSV transactions with escrow script.
18
+ */
19
+ class PaymentEngine {
20
+ // Create a payment (escrow funds)
21
+ create(serviceId, buyerWalletId, sellerWalletId, amount) {
22
+ const db = (0, db_1.getDb)();
23
+ const id = (0, uuid_1.v4)();
24
+ const platformFee = Math.ceil(amount * types_1.PLATFORM_FEE_RATE);
25
+ const now = new Date().toISOString();
26
+ db.prepare(`
27
+ INSERT INTO payments (id, serviceId, buyerWalletId, sellerWalletId, amount, platformFee, status, createdAt)
28
+ VALUES (?, ?, ?, ?, ?, ?, 'escrowed', ?)
29
+ `).run(id, serviceId, buyerWalletId, sellerWalletId, amount, platformFee, now);
30
+ return {
31
+ id, serviceId, buyerWalletId, sellerWalletId,
32
+ amount, platformFee, status: 'escrowed', createdAt: now,
33
+ };
34
+ }
35
+ // Release payment (service completed successfully)
36
+ release(paymentId) {
37
+ const db = (0, db_1.getDb)();
38
+ const now = new Date().toISOString();
39
+ const result = db.prepare(`
40
+ UPDATE payments SET status = 'released', completedAt = ?
41
+ WHERE id = ? AND status = 'escrowed'
42
+ `).run(now, paymentId);
43
+ if (result.changes === 0)
44
+ return null;
45
+ // TODO: Broadcast BSV transaction (escrow → seller)
46
+ return this.getById(paymentId);
47
+ }
48
+ // Refund payment (service failed)
49
+ refund(paymentId) {
50
+ const db = (0, db_1.getDb)();
51
+ const now = new Date().toISOString();
52
+ const result = db.prepare(`
53
+ UPDATE payments SET status = 'refunded', completedAt = ?
54
+ WHERE id = ? AND status = 'escrowed'
55
+ `).run(now, paymentId);
56
+ if (result.changes === 0)
57
+ return null;
58
+ // TODO: Broadcast BSV refund transaction
59
+ return this.getById(paymentId);
60
+ }
61
+ // Dispute payment
62
+ dispute(paymentId) {
63
+ const db = (0, db_1.getDb)();
64
+ db.prepare(`
65
+ UPDATE payments SET status = 'disputed'
66
+ WHERE id = ? AND status = 'escrowed'
67
+ `).run(paymentId);
68
+ return this.getById(paymentId);
69
+ }
70
+ // Get payment by ID
71
+ getById(id) {
72
+ const db = (0, db_1.getDb)();
73
+ return db.prepare('SELECT * FROM payments WHERE id = ?').get(id);
74
+ }
75
+ // Get payments for a wallet
76
+ getByWallet(walletId, role = 'both') {
77
+ const db = (0, db_1.getDb)();
78
+ if (role === 'buyer') {
79
+ return db.prepare('SELECT * FROM payments WHERE buyerWalletId = ? ORDER BY createdAt DESC').all(walletId);
80
+ }
81
+ else if (role === 'seller') {
82
+ return db.prepare('SELECT * FROM payments WHERE sellerWalletId = ? ORDER BY createdAt DESC').all(walletId);
83
+ }
84
+ return db.prepare('SELECT * FROM payments WHERE buyerWalletId = ? OR sellerWalletId = ? ORDER BY createdAt DESC').all(walletId, walletId);
85
+ }
86
+ }
87
+ exports.PaymentEngine = PaymentEngine;
88
+ //# sourceMappingURL=payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../src/payment/payment.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,uCAAsC;AACtC,oCAA4C;AAG5C;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;IAExB,kCAAkC;IAClC,MAAM,CAAC,SAAiB,EAAE,aAAqB,EAAE,cAAsB,EAAE,MAAc;QACrF,MAAM,EAAE,GAAG,IAAA,UAAK,GAAE,CAAA;QAClB,MAAM,EAAE,GAAG,IAAA,SAAI,GAAE,CAAA;QACjB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,yBAAiB,CAAC,CAAA;QACzD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;QAEpC,EAAE,CAAC,OAAO,CAAC;;;KAGV,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,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AAC;IAED,oBAAoB;IACpB,OAAO,CAAC,EAAU;QAChB,MAAM,EAAE,GAAG,IAAA,UAAK,GAAE,CAAA;QAClB,OAAO,EAAE,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAmB,CAAA;IACpF,CAAC;IAED,4BAA4B;IAC5B,WAAW,CAAC,QAAgB,EAAE,OAAoC,MAAM;QACtE,MAAM,EAAE,GAAG,IAAA,UAAK,GAAE,CAAA;QAClB,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,OAAO,CAAC,wEAAwE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAc,CAAA;QACxH,CAAC;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,EAAE,CAAC,OAAO,CAAC,yEAAyE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAc,CAAA;QACzH,CAAC;QACD,OAAO,EAAE,CAAC,OAAO,CAAC,8FAA8F,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAc,CAAA;IACxJ,CAAC;CACF;AAhFD,sCAgFC"}
@@ -0,0 +1,3 @@
1
+ import Database from 'better-sqlite3';
2
+ export declare function getDb(): Database.Database;
3
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/registry/db.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AAUrC,wBAAgB,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAQzC"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDb = getDb;
7
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const __filename2 = __filename;
10
+ const __dirname2 = path_1.default.dirname(__filename2);
11
+ const DB_PATH = process.env.AGENTPAY_DB || path_1.default.join(__dirname2, '../../data/agentpay.db');
12
+ let db;
13
+ function getDb() {
14
+ if (!db) {
15
+ db = new better_sqlite3_1.default(DB_PATH);
16
+ db.pragma('journal_mode = WAL');
17
+ db.pragma('foreign_keys = ON');
18
+ initSchema(db);
19
+ }
20
+ return db;
21
+ }
22
+ function initSchema(db) {
23
+ db.exec(`
24
+ CREATE TABLE IF NOT EXISTS wallets (
25
+ id TEXT PRIMARY KEY,
26
+ publicKey TEXT NOT NULL,
27
+ address TEXT NOT NULL UNIQUE,
28
+ createdAt TEXT NOT NULL DEFAULT (datetime('now'))
29
+ );
30
+
31
+ CREATE TABLE IF NOT EXISTS services (
32
+ id TEXT PRIMARY KEY,
33
+ agentId TEXT NOT NULL REFERENCES wallets(id),
34
+ name TEXT NOT NULL,
35
+ description TEXT NOT NULL,
36
+ category TEXT NOT NULL DEFAULT 'general',
37
+ price INTEGER NOT NULL,
38
+ endpoint TEXT NOT NULL,
39
+ method TEXT NOT NULL DEFAULT 'POST',
40
+ inputSchema TEXT,
41
+ outputSchema TEXT,
42
+ active INTEGER NOT NULL DEFAULT 1,
43
+ createdAt TEXT NOT NULL DEFAULT (datetime('now')),
44
+ updatedAt TEXT NOT NULL DEFAULT (datetime('now'))
45
+ );
46
+
47
+ CREATE TABLE IF NOT EXISTS payments (
48
+ id TEXT PRIMARY KEY,
49
+ serviceId TEXT NOT NULL REFERENCES services(id),
50
+ buyerWalletId TEXT NOT NULL REFERENCES wallets(id),
51
+ sellerWalletId TEXT NOT NULL REFERENCES wallets(id),
52
+ amount INTEGER NOT NULL,
53
+ platformFee INTEGER NOT NULL,
54
+ status TEXT NOT NULL DEFAULT 'pending',
55
+ txId TEXT,
56
+ createdAt TEXT NOT NULL DEFAULT (datetime('now')),
57
+ completedAt TEXT
58
+ );
59
+
60
+ CREATE TABLE IF NOT EXISTS ratings (
61
+ id TEXT PRIMARY KEY,
62
+ paymentId TEXT NOT NULL UNIQUE REFERENCES payments(id),
63
+ fromAgentId TEXT NOT NULL REFERENCES wallets(id),
64
+ toAgentId TEXT NOT NULL REFERENCES wallets(id),
65
+ score INTEGER NOT NULL CHECK(score >= 1 AND score <= 5),
66
+ comment TEXT,
67
+ createdAt TEXT NOT NULL DEFAULT (datetime('now'))
68
+ );
69
+
70
+ CREATE INDEX IF NOT EXISTS idx_services_category ON services(category);
71
+ CREATE INDEX IF NOT EXISTS idx_services_active ON services(active);
72
+ CREATE INDEX IF NOT EXISTS idx_payments_status ON payments(status);
73
+ CREATE INDEX IF NOT EXISTS idx_payments_buyer ON payments(buyerWalletId);
74
+ CREATE INDEX IF NOT EXISTS idx_payments_seller ON payments(sellerWalletId);
75
+ `);
76
+ }
77
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/registry/db.ts"],"names":[],"mappings":";;;;;AAUA,sBAQC;AAlBD,oEAAqC;AACrC,gDAAuB;AAGvB,MAAM,WAAW,GAAG,UAAU,CAAA;AAC9B,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAA;AAE1F,IAAI,EAAqB,CAAA;AAEzB,SAAgB,KAAK;IACnB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,EAAE,GAAG,IAAI,wBAAQ,CAAC,OAAO,CAAC,CAAA;QAC1B,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QAC/B,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;QAC9B,UAAU,CAAC,EAAE,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC;AAED,SAAS,UAAU,CAAC,EAAqB;IACvC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDP,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Service, ServiceQuery, ReputationScore } from '../types';
2
+ export declare class Registry {
3
+ register(service: Omit<Service, 'id' | 'active' | 'createdAt' | 'updatedAt'>): Service;
4
+ search(query: ServiceQuery): Service[];
5
+ getById(id: string): Service | null;
6
+ update(id: string, updates: Partial<Pick<Service, 'name' | 'description' | 'price' | 'endpoint' | 'active'>>): Service | null;
7
+ getReputation(agentId: string): ReputationScore;
8
+ private rowToService;
9
+ }
10
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry/registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEtE,qBAAa,QAAQ;IAEnB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO;IAoBtF,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,EAAE;IAgCtC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAOnC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI;IAgB7H,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe;IA8B/C,OAAO,CAAC,YAAY;CAQrB"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Registry = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const db_1 = require("./db");
6
+ class Registry {
7
+ // Register a new service
8
+ register(service) {
9
+ const db = (0, db_1.getDb)();
10
+ const id = (0, uuid_1.v4)();
11
+ const now = new Date().toISOString();
12
+ db.prepare(`
13
+ INSERT INTO services (id, agentId, name, description, category, price, endpoint, method, inputSchema, outputSchema, active, createdAt, updatedAt)
14
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
15
+ `).run(id, service.agentId, service.name, service.description, service.category, service.price, service.endpoint, service.method, service.inputSchema ? JSON.stringify(service.inputSchema) : null, service.outputSchema ? JSON.stringify(service.outputSchema) : null, now, now);
16
+ return { ...service, id, active: true, createdAt: now, updatedAt: now };
17
+ }
18
+ // Search/discover services
19
+ search(query) {
20
+ const db = (0, db_1.getDb)();
21
+ const conditions = ['active = 1'];
22
+ const params = [];
23
+ if (query.category) {
24
+ conditions.push('category = ?');
25
+ params.push(query.category);
26
+ }
27
+ if (query.keyword) {
28
+ conditions.push('(name LIKE ? OR description LIKE ?)');
29
+ params.push(`%${query.keyword}%`, `%${query.keyword}%`);
30
+ }
31
+ if (query.maxPrice) {
32
+ conditions.push('price <= ?');
33
+ params.push(query.maxPrice);
34
+ }
35
+ const limit = query.limit || 20;
36
+ const offset = query.offset || 0;
37
+ const rows = db.prepare(`
38
+ SELECT * FROM services
39
+ WHERE ${conditions.join(' AND ')}
40
+ ORDER BY createdAt DESC
41
+ LIMIT ? OFFSET ?
42
+ `).all(...params, limit, offset);
43
+ return rows.map(this.rowToService);
44
+ }
45
+ // Get service by ID
46
+ getById(id) {
47
+ const db = (0, db_1.getDb)();
48
+ const row = db.prepare('SELECT * FROM services WHERE id = ?').get(id);
49
+ return row ? this.rowToService(row) : null;
50
+ }
51
+ // Update service
52
+ update(id, updates) {
53
+ const db = (0, db_1.getDb)();
54
+ const fields = ['updatedAt = ?'];
55
+ const params = [new Date().toISOString()];
56
+ for (const [key, value] of Object.entries(updates)) {
57
+ fields.push(`${key} = ?`);
58
+ params.push(key === 'active' ? (value ? 1 : 0) : value);
59
+ }
60
+ params.push(id);
61
+ db.prepare(`UPDATE services SET ${fields.join(', ')} WHERE id = ?`).run(...params);
62
+ return this.getById(id);
63
+ }
64
+ // Get reputation for an agent
65
+ getReputation(agentId) {
66
+ const db = (0, db_1.getDb)();
67
+ const stats = db.prepare(`
68
+ SELECT
69
+ COUNT(*) as totalJobs,
70
+ SUM(CASE WHEN status = 'released' THEN 1 ELSE 0 END) as successJobs,
71
+ SUM(CASE WHEN sellerWalletId = ? THEN amount ELSE 0 END) as totalEarned,
72
+ SUM(CASE WHEN buyerWalletId = ? THEN amount ELSE 0 END) as totalSpent
73
+ FROM payments
74
+ WHERE (buyerWalletId = ? OR sellerWalletId = ?)
75
+ AND status IN ('released', 'refunded', 'disputed')
76
+ `).get(agentId, agentId, agentId, agentId);
77
+ const avgRating = db.prepare(`
78
+ SELECT AVG(score) as avgScore
79
+ FROM ratings WHERE toAgentId = ?
80
+ `).get(agentId);
81
+ return {
82
+ agentId,
83
+ totalJobs: stats?.totalJobs || 0,
84
+ successRate: stats?.totalJobs > 0 ? (stats.successJobs / stats.totalJobs) : 0,
85
+ avgResponseTimeMs: 0, // TODO: track execution times
86
+ totalEarned: stats?.totalEarned || 0,
87
+ totalSpent: stats?.totalSpent || 0,
88
+ rating: avgRating?.avgScore || 0,
89
+ };
90
+ }
91
+ rowToService(row) {
92
+ return {
93
+ ...row,
94
+ active: !!row.active,
95
+ inputSchema: row.inputSchema ? JSON.parse(row.inputSchema) : undefined,
96
+ outputSchema: row.outputSchema ? JSON.parse(row.outputSchema) : undefined,
97
+ };
98
+ }
99
+ }
100
+ exports.Registry = Registry;
101
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/registry/registry.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,6BAA4B;AAG5B,MAAa,QAAQ;IACnB,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AAU,EAAE,KAAK,EAAE,UAAU,IAAI,CAAC;YAClC,MAAM,EAAE,SAAS,EAAE,QAAQ,IAAI,CAAC;SACjC,CAAA;IACH,CAAC;IAEO,YAAY,CAAC,GAAQ;QAC3B,OAAO;YACL,GAAG,GAAG;YACN,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM;YACpB,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;YACtE,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;SAC1E,CAAA;IACH,CAAC;CACF;AAnHD,4BAmHC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * AgentPay SDK
3
+ *
4
+ * Usage:
5
+ *
6
+ * // As a service provider
7
+ * const ap = new AgentPay({ apiUrl: 'http://localhost:3100' })
8
+ * const wallet = await ap.createWallet()
9
+ * await ap.registerService({
10
+ * agentId: wallet.id,
11
+ * name: 'VulnScanner',
12
+ * description: 'Scan websites for vulnerabilities',
13
+ * category: 'security',
14
+ * price: 5000, // 5000 satoshis
15
+ * endpoint: 'http://my-agent:8080/scan',
16
+ * method: 'POST',
17
+ * })
18
+ *
19
+ * // As a consumer
20
+ * const services = await ap.search({ keyword: 'scan' })
21
+ * const result = await ap.execute(services[0].id, wallet.id, { target: 'https://example.com' })
22
+ * console.log(result.output)
23
+ */
24
+ export declare class AgentPay {
25
+ private apiUrl;
26
+ constructor(opts?: {
27
+ apiUrl?: string;
28
+ });
29
+ createWallet(): Promise<any>;
30
+ getWallet(id: string): Promise<any>;
31
+ registerService(service: {
32
+ agentId: string;
33
+ name: string;
34
+ description: string;
35
+ category: string;
36
+ price: number;
37
+ endpoint: string;
38
+ method?: 'POST' | 'GET';
39
+ }): Promise<any>;
40
+ search(query?: {
41
+ keyword?: string;
42
+ category?: string;
43
+ maxPrice?: number;
44
+ }): Promise<any>;
45
+ execute(serviceId: string, buyerWalletId: string, input: Record<string, unknown>): Promise<unknown>;
46
+ getReputation(agentId: string): Promise<any>;
47
+ }
48
+ export default AgentPay;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAQ;gBAEV,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAIpC,YAAY;IAMZ,SAAS,CAAC,EAAE,EAAE,MAAM;IAMpB,eAAe,CAAC,OAAO,EAAE;QAC7B,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;QACb,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;KACxB;IAUK,MAAM,CAAC,KAAK,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;IAW7E,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAShF,aAAa,CAAC,OAAO,EAAE,MAAM;CAKpC;AAED,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * AgentPay SDK
4
+ *
5
+ * Usage:
6
+ *
7
+ * // As a service provider
8
+ * const ap = new AgentPay({ apiUrl: 'http://localhost:3100' })
9
+ * const wallet = await ap.createWallet()
10
+ * await ap.registerService({
11
+ * agentId: wallet.id,
12
+ * name: 'VulnScanner',
13
+ * description: 'Scan websites for vulnerabilities',
14
+ * category: 'security',
15
+ * price: 5000, // 5000 satoshis
16
+ * endpoint: 'http://my-agent:8080/scan',
17
+ * method: 'POST',
18
+ * })
19
+ *
20
+ * // As a consumer
21
+ * const services = await ap.search({ keyword: 'scan' })
22
+ * const result = await ap.execute(services[0].id, wallet.id, { target: 'https://example.com' })
23
+ * console.log(result.output)
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AgentPay = void 0;
27
+ class AgentPay {
28
+ apiUrl;
29
+ constructor(opts = {}) {
30
+ this.apiUrl = opts.apiUrl || 'http://localhost:3100';
31
+ }
32
+ async createWallet() {
33
+ const res = await fetch(`${this.apiUrl}/api/wallets`, { method: 'POST' });
34
+ const data = await res.json();
35
+ return data.wallet;
36
+ }
37
+ async getWallet(id) {
38
+ const res = await fetch(`${this.apiUrl}/api/wallets/${id}`);
39
+ const data = await res.json();
40
+ return data.wallet;
41
+ }
42
+ async registerService(service) {
43
+ const res = await fetch(`${this.apiUrl}/api/services`, {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify({ method: 'POST', ...service }),
47
+ });
48
+ const data = await res.json();
49
+ return data.service;
50
+ }
51
+ async search(query = {}) {
52
+ const params = new URLSearchParams();
53
+ if (query.keyword)
54
+ params.set('q', query.keyword);
55
+ if (query.category)
56
+ params.set('category', query.category);
57
+ if (query.maxPrice)
58
+ params.set('maxPrice', String(query.maxPrice));
59
+ const res = await fetch(`${this.apiUrl}/api/services?${params}`);
60
+ const data = await res.json();
61
+ return data.services;
62
+ }
63
+ async execute(serviceId, buyerWalletId, input) {
64
+ const res = await fetch(`${this.apiUrl}/api/execute/${serviceId}`, {
65
+ method: 'POST',
66
+ headers: { 'Content-Type': 'application/json' },
67
+ body: JSON.stringify({ buyerWalletId, input }),
68
+ });
69
+ return res.json();
70
+ }
71
+ async getReputation(agentId) {
72
+ const res = await fetch(`${this.apiUrl}/api/agents/${agentId}/reputation`);
73
+ const data = await res.json();
74
+ return data.reputation;
75
+ }
76
+ }
77
+ exports.AgentPay = AgentPay;
78
+ exports.default = AgentPay;
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,MAAa,QAAQ;IACX,MAAM,CAAQ;IAEtB,YAAY,OAA4B,EAAE;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,uBAAuB,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QACzE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAS,CAAA;QACpC,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAU;QACxB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,gBAAgB,EAAE,EAAE,CAAC,CAAA;QAC3D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAS,CAAA;QACpC,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAQrB;QACC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,eAAe,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAA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CAAC,MAAM,eAAe,OAAO,aAAa,CAAC,CAAA;QAC1E,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAS,CAAA;QACpC,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF;AA9DD,4BA8DC;AAED,kBAAe,QAAQ,CAAA"}
@@ -0,0 +1,66 @@
1
+ export interface AgentWallet {
2
+ id: string;
3
+ publicKey: string;
4
+ address: string;
5
+ createdAt: string;
6
+ balance?: number;
7
+ }
8
+ export interface Service {
9
+ id: string;
10
+ agentId: string;
11
+ name: string;
12
+ description: string;
13
+ category: string;
14
+ price: number;
15
+ endpoint: string;
16
+ method: 'POST' | 'GET';
17
+ inputSchema?: object;
18
+ outputSchema?: object;
19
+ active: boolean;
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }
23
+ export interface Payment {
24
+ id: string;
25
+ serviceId: string;
26
+ buyerWalletId: string;
27
+ sellerWalletId: string;
28
+ amount: number;
29
+ platformFee: number;
30
+ status: 'pending' | 'escrowed' | 'released' | 'disputed' | 'refunded';
31
+ txId?: string;
32
+ createdAt: string;
33
+ completedAt?: string;
34
+ }
35
+ export interface ExecutionRequest {
36
+ serviceId: string;
37
+ buyerWalletId: string;
38
+ input: Record<string, unknown>;
39
+ }
40
+ export interface ExecutionResult {
41
+ paymentId: string;
42
+ serviceId: string;
43
+ output: Record<string, unknown>;
44
+ executionTimeMs: number;
45
+ status: 'success' | 'error';
46
+ }
47
+ export interface ReputationScore {
48
+ agentId: string;
49
+ totalJobs: number;
50
+ successRate: number;
51
+ avgResponseTimeMs: number;
52
+ totalEarned: number;
53
+ totalSpent: number;
54
+ rating: number;
55
+ }
56
+ export interface ServiceQuery {
57
+ category?: string;
58
+ keyword?: string;
59
+ maxPrice?: number;
60
+ minRating?: number;
61
+ limit?: number;
62
+ offset?: number;
63
+ }
64
+ export declare const PLATFORM_FEE_RATE = 0.02;
65
+ export declare const MIN_PRICE_SATOSHIS = 1;
66
+ //# sourceMappingURL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,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,SAAS,GAAG,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,iBAAiB,OAAO,CAAA;AACrC,eAAO,MAAM,kBAAkB,IAAI,CAAA"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ // AgentPay Core Types
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MIN_PRICE_SATOSHIS = exports.PLATFORM_FEE_RATE = void 0;
5
+ exports.PLATFORM_FEE_RATE = 0.02; // 2%
6
+ exports.MIN_PRICE_SATOSHIS = 1;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;AAwET,QAAA,iBAAiB,GAAG,IAAI,CAAA,CAAC,KAAK;AAC9B,QAAA,kBAAkB,GAAG,CAAC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import type { AgentWallet } from '../types';
2
+ /**
3
+ * BSV Wallet Manager
4
+ *
5
+ * MVP: Uses simplified key generation.
6
+ * TODO: Integrate @bsv/sdk for real BSV key pairs and transaction signing.
7
+ * For now we generate deterministic-looking keys to build the full flow,
8
+ * then swap in real BSV crypto before mainnet.
9
+ */
10
+ export declare class WalletManager {
11
+ create(): AgentWallet & {
12
+ privateKey: string;
13
+ };
14
+ getById(id: string): AgentWallet | null;
15
+ getByAddress(address: string): AgentWallet | null;
16
+ getBalance(walletId: string): Promise<number>;
17
+ private generateKeyPair;
18
+ }
19
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C;;;;;;;GAOG;AACH,qBAAa,aAAa;IAGxB,MAAM,IAAI,WAAW,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;IAsB9C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAOvC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAO3C,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBnD,OAAO,CAAC,eAAe;CAUxB"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WalletManager = void 0;
7
+ const uuid_1 = require("uuid");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const db_1 = require("../registry/db");
10
+ /**
11
+ * BSV Wallet Manager
12
+ *
13
+ * MVP: Uses simplified key generation.
14
+ * TODO: Integrate @bsv/sdk for real BSV key pairs and transaction signing.
15
+ * For now we generate deterministic-looking keys to build the full flow,
16
+ * then swap in real BSV crypto before mainnet.
17
+ */
18
+ class WalletManager {
19
+ // Create a new agent wallet
20
+ create() {
21
+ const db = (0, db_1.getDb)();
22
+ const id = (0, uuid_1.v4)();
23
+ // MVP: Generate key pair (placeholder - will use @bsv/sdk)
24
+ const keyPair = this.generateKeyPair();
25
+ db.prepare(`
26
+ INSERT INTO wallets (id, publicKey, address, createdAt)
27
+ VALUES (?, ?, ?, ?)
28
+ `).run(id, keyPair.publicKey, keyPair.address, new Date().toISOString());
29
+ return {
30
+ id,
31
+ publicKey: keyPair.publicKey,
32
+ address: keyPair.address,
33
+ createdAt: new Date().toISOString(),
34
+ privateKey: keyPair.privateKey, // Only returned on creation!
35
+ };
36
+ }
37
+ // Get wallet by ID
38
+ getById(id) {
39
+ const db = (0, db_1.getDb)();
40
+ const row = db.prepare('SELECT * FROM wallets WHERE id = ?').get(id);
41
+ return row || null;
42
+ }
43
+ // Get wallet by address
44
+ getByAddress(address) {
45
+ const db = (0, db_1.getDb)();
46
+ const row = db.prepare('SELECT * FROM wallets WHERE address = ?').get(address);
47
+ return row || null;
48
+ }
49
+ // Get balance (MVP: tracked internally, TODO: query BSV network)
50
+ async getBalance(walletId) {
51
+ const db = (0, db_1.getDb)();
52
+ // Deposits (faucet/funding)
53
+ let deposits = 0;
54
+ try {
55
+ const dep = db.prepare(`SELECT COALESCE(SUM(amount), 0) as total FROM deposits WHERE walletId = ?`).get(walletId);
56
+ deposits = dep?.total || 0;
57
+ }
58
+ catch { /* table may not exist yet */ }
59
+ // Sum of received payments (released) minus sent payments
60
+ const received = db.prepare(`
61
+ SELECT COALESCE(SUM(amount - platformFee), 0) as total
62
+ FROM payments WHERE sellerWalletId = ? AND status = 'released'
63
+ `).get(walletId);
64
+ const sent = db.prepare(`
65
+ SELECT COALESCE(SUM(amount), 0) as total
66
+ FROM payments WHERE buyerWalletId = ? AND status IN ('released', 'escrowed')
67
+ `).get(walletId);
68
+ return deposits + (received?.total || 0) - (sent?.total || 0);
69
+ }
70
+ generateKeyPair() {
71
+ // MVP placeholder - generates fake but consistent keys
72
+ // TODO: Replace with @bsv/sdk PrivateKey.fromRandom()
73
+ const privateKeyBytes = crypto_1.default.randomBytes(32);
74
+ const privateKey = privateKeyBytes.toString('hex');
75
+ const publicKey = crypto_1.default.createHash('sha256').update(privateKeyBytes).digest('hex');
76
+ const address = '1' + crypto_1.default.createHash('ripemd160').update(Buffer.from(publicKey, 'hex')).digest('hex').slice(0, 33);
77
+ return { privateKey, publicKey, address };
78
+ }
79
+ }
80
+ exports.WalletManager = WalletManager;
81
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AACjC,oDAA2B;AAC3B,uCAAsC;AAGtC;;;;;;;GAOG;AACH,MAAa,aAAa;IAExB,4BAA4B;IAC5B,MAAM;QACJ,MAAM,EAAE,GAAG,IAAA,UAAK,GAAE,CAAA;QAClB,MAAM,EAAE,GAAG,IAAA,SAAI,GAAE,CAAA;QAEjB,2DAA2D;QAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;QAEtC,EAAE,CAAC,OAAO,CAAC;;;KAGV,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;QAExE,OAAO;YACL,EAAE;YACF,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,6BAA6B;SAC9D,CAAA;IACH,CAAC;IAED,mBAAmB;IACnB,OAAO,C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D,MAAM,eAAe,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QAC9C,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAClD,MAAM,SAAS,GAAG,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACnF,MAAM,OAAO,GAAG,GAAG,GAAG,gBAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAErH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,CAAA;IAC3C,CAAC;CACF;AAzED,sCAyEC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "agentspay",
3
+ "version": "0.1.0",
4
+ "description": "The marketplace where AI agents pay each other for services. Micropayments via BSV.",
5
+ "main": "dist/sdk/index.js",
6
+ "types": "dist/sdk/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/sdk/index.d.ts",
10
+ "require": "./dist/sdk/index.js"
11
+ },
12
+ "./server": {
13
+ "types": "./dist/index.d.ts",
14
+ "require": "./dist/index.js"
15
+ }
16
+ },
17
+ "bin": {
18
+ "agentspay": "./dist/index.js"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "start": "node dist/index.js",
23
+ "dev": "npx tsx src/index.ts",
24
+ "demo": "npx tsx demo/demo.ts",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": ["ai", "agents", "payments", "bsv", "micropayments", "marketplace", "agent-economy", "a2a", "mcp"],
28
+ "author": "d4rkpsych0",
29
+ "license": "MIT",
30
+ "type": "commonjs",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/agentspay/agentspay.git"
34
+ },
35
+ "homepage": "https://agentspay.dev",
36
+ "bugs": {
37
+ "url": "https://github.com/agentspay/agentspay/issues"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "dependencies": {
43
+ "better-sqlite3": "^12.6.2",
44
+ "express": "^5.2.1",
45
+ "uuid": "^13.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/better-sqlite3": "^7.6.13",
49
+ "@types/express": "^5.0.6",
50
+ "@types/node": "^25.2.3",
51
+ "@types/uuid": "^10.0.0",
52
+ "typescript": "^5.9.3"
53
+ }
54
+ }