@toon-protocol/relay 1.3.1 → 1.3.3

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/dist/index.js CHANGED
@@ -1,675 +1,28 @@
1
- // src/types.ts
2
- var DEFAULT_RELAY_CONFIG = {
3
- port: 7e3,
4
- maxConnections: 100,
5
- maxSubscriptionsPerConnection: 20,
6
- maxFiltersPerSubscription: 10,
7
- databasePath: ":memory:"
8
- };
9
-
10
- // src/filters/matchFilter.ts
11
- function matchFilter(event, filter) {
12
- if (Object.keys(filter).length === 0) {
13
- return true;
14
- }
15
- if (filter.ids !== void 0 && filter.ids.length > 0) {
16
- const matches = filter.ids.some((id) => event.id.startsWith(id));
17
- if (!matches) return false;
18
- }
19
- if (filter.authors !== void 0 && filter.authors.length > 0) {
20
- const matches = filter.authors.some(
21
- (author) => event.pubkey.startsWith(author)
22
- );
23
- if (!matches) return false;
24
- }
25
- if (filter.kinds !== void 0 && filter.kinds.length > 0) {
26
- if (!filter.kinds.includes(event.kind)) return false;
27
- }
28
- if (filter.since !== void 0) {
29
- if (event.created_at < filter.since) return false;
30
- }
31
- if (filter.until !== void 0) {
32
- if (event.created_at > filter.until) return false;
33
- }
34
- for (const key of Object.keys(filter)) {
35
- if (key.startsWith("#") && key.length === 2) {
36
- const tagName = key.slice(1);
37
- const filterValues = filter[key];
38
- if (filterValues !== void 0 && filterValues.length > 0) {
39
- const eventTagValues = event.tags.filter((tag) => tag[0] === tagName).map((tag) => tag[1]);
40
- const hasMatch = filterValues.some((v) => eventTagValues.includes(v));
41
- if (!hasMatch) return false;
42
- }
43
- }
44
- }
45
- return true;
46
- }
47
-
48
- // src/storage/InMemoryEventStore.ts
49
- var InMemoryEventStore = class {
50
- events = /* @__PURE__ */ new Map();
51
- store(event) {
52
- this.events.set(event.id, event);
53
- }
54
- get(id) {
55
- return this.events.get(id);
56
- }
57
- query(filters) {
58
- const allEvents = Array.from(this.events.values());
59
- if (filters.length === 0) {
60
- return allEvents.sort((a, b) => b.created_at - a.created_at);
61
- }
62
- const matchingEvents = [];
63
- for (const event of allEvents) {
64
- for (const filter of filters) {
65
- if (matchFilter(event, filter)) {
66
- matchingEvents.push(event);
67
- break;
68
- }
69
- }
70
- }
71
- matchingEvents.sort((a, b) => b.created_at - a.created_at);
72
- const limitFilter = filters.find((f) => f.limit !== void 0);
73
- if (limitFilter?.limit !== void 0) {
74
- return matchingEvents.slice(0, limitFilter.limit);
75
- }
76
- return matchingEvents;
77
- }
78
- /**
79
- * Close the storage backend (no-op for in-memory store).
80
- */
81
- close() {
82
- }
83
- };
84
-
85
- // src/storage/SqliteEventStore.ts
86
- import Database from "better-sqlite3";
87
- var SCHEMA_SQL = `
88
- CREATE TABLE IF NOT EXISTS events (
89
- id TEXT PRIMARY KEY,
90
- pubkey TEXT NOT NULL,
91
- kind INTEGER NOT NULL,
92
- content TEXT NOT NULL,
93
- tags TEXT NOT NULL,
94
- created_at INTEGER NOT NULL,
95
- sig TEXT NOT NULL,
96
- received_at INTEGER NOT NULL
97
- )
98
- `;
99
- var INDEX_SQL = [
100
- "CREATE INDEX IF NOT EXISTS idx_events_pubkey ON events(pubkey)",
101
- "CREATE INDEX IF NOT EXISTS idx_events_kind ON events(kind)",
102
- "CREATE INDEX IF NOT EXISTS idx_events_created_at ON events(created_at)",
103
- "CREATE INDEX IF NOT EXISTS idx_events_pubkey_kind ON events(pubkey, kind)"
104
- ];
105
- function initializeSchema(db) {
106
- db.exec(SCHEMA_SQL);
107
- for (const indexSql of INDEX_SQL) {
108
- db.exec(indexSql);
109
- }
110
- }
111
- var RelayError = class extends Error {
112
- constructor(message, code) {
113
- super(message);
114
- this.code = code;
115
- this.name = "RelayError";
116
- }
117
- };
118
- function isReplaceableKind(kind) {
119
- return kind >= 1e4 && kind <= 19999;
120
- }
121
- function isParameterizedReplaceableKind(kind) {
122
- return kind >= 3e4 && kind <= 39999;
123
- }
124
- function getDTagValue(tags) {
125
- const dTag = tags.find((tag) => tag[0] === "d");
126
- return dTag?.[1] ?? "";
127
- }
128
- var SqliteEventStore = class {
129
- db;
130
- insertStmt;
131
- getStmt;
132
- deleteByPubkeyKindStmt;
133
- deleteByPubkeyKindDTagStmt;
134
- getByPubkeyKindStmt;
135
- getByPubkeyKindDTagStmt;
136
- /**
137
- * Create a new SqliteEventStore.
138
- * @param dbPath - Path to the database file. Use ':memory:' for in-memory database.
139
- */
140
- constructor(dbPath = ":memory:") {
141
- try {
142
- this.db = new Database(dbPath);
143
- initializeSchema(this.db);
144
- this.insertStmt = this.db.prepare(`
145
- INSERT OR REPLACE INTO events (id, pubkey, kind, content, tags, created_at, sig, received_at)
146
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
147
- `);
148
- this.getStmt = this.db.prepare("SELECT * FROM events WHERE id = ?");
149
- this.deleteByPubkeyKindStmt = this.db.prepare(
150
- "DELETE FROM events WHERE pubkey = ? AND kind = ?"
151
- );
152
- this.deleteByPubkeyKindDTagStmt = this.db.prepare(
153
- "DELETE FROM events WHERE pubkey = ? AND kind = ? AND json_extract(tags, '$') LIKE ?"
154
- );
155
- this.getByPubkeyKindStmt = this.db.prepare(
156
- "SELECT id, created_at FROM events WHERE pubkey = ? AND kind = ?"
157
- );
158
- this.getByPubkeyKindDTagStmt = this.db.prepare(
159
- "SELECT id, created_at FROM events WHERE pubkey = ? AND kind = ? AND tags LIKE ?"
160
- );
161
- } catch (error) {
162
- throw new RelayError(
163
- `Failed to initialize database: ${error instanceof Error ? error.message : String(error)}`,
164
- "STORAGE_ERROR"
165
- );
166
- }
167
- }
168
- /**
169
- * Store an event in the database.
170
- * Handles replaceable and parameterized replaceable events according to NIP-01.
171
- */
172
- store(event) {
173
- try {
174
- const tagsJson = JSON.stringify(event.tags);
175
- const receivedAt = Math.floor(Date.now() / 1e3);
176
- if (isReplaceableKind(event.kind)) {
177
- this.storeReplaceableEvent(event, tagsJson, receivedAt);
178
- } else if (isParameterizedReplaceableKind(event.kind)) {
179
- this.storeParameterizedReplaceableEvent(event, tagsJson, receivedAt);
180
- } else {
181
- const insertOrIgnore = this.db.prepare(`
182
- INSERT OR IGNORE INTO events (id, pubkey, kind, content, tags, created_at, sig, received_at)
183
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
184
- `);
185
- insertOrIgnore.run(
186
- event.id,
187
- event.pubkey,
188
- event.kind,
189
- event.content,
190
- tagsJson,
191
- event.created_at,
192
- event.sig,
193
- receivedAt
194
- );
195
- }
196
- } catch (error) {
197
- if (error instanceof RelayError) {
198
- throw error;
199
- }
200
- throw new RelayError(
201
- `Failed to store event: ${error instanceof Error ? error.message : String(error)}`,
202
- "STORAGE_ERROR"
203
- );
204
- }
205
- }
206
- /**
207
- * Store a replaceable event (kinds 10000-19999).
208
- * Only keeps the latest event per pubkey+kind.
209
- */
210
- storeReplaceableEvent(event, tagsJson, receivedAt) {
211
- const existing = this.getByPubkeyKindStmt.get(event.pubkey, event.kind);
212
- if (existing) {
213
- if (event.created_at > existing.created_at || event.created_at === existing.created_at && event.id < existing.id) {
214
- const transaction = this.db.transaction(() => {
215
- this.deleteByPubkeyKindStmt.run(event.pubkey, event.kind);
216
- this.insertStmt.run(
217
- event.id,
218
- event.pubkey,
219
- event.kind,
220
- event.content,
221
- tagsJson,
222
- event.created_at,
223
- event.sig,
224
- receivedAt
225
- );
226
- });
227
- transaction();
228
- }
229
- } else {
230
- this.insertStmt.run(
231
- event.id,
232
- event.pubkey,
233
- event.kind,
234
- event.content,
235
- tagsJson,
236
- event.created_at,
237
- event.sig,
238
- receivedAt
239
- );
240
- }
241
- }
242
- /**
243
- * Store a parameterized replaceable event (kinds 30000-39999).
244
- * Only keeps the latest event per pubkey+kind+d-tag.
245
- */
246
- storeParameterizedReplaceableEvent(event, tagsJson, receivedAt) {
247
- const dTagValue = getDTagValue(event.tags);
248
- let existing;
249
- if (dTagValue === "") {
250
- const candidates = this.db.prepare(
251
- "SELECT id, created_at, tags FROM events WHERE pubkey = ? AND kind = ?"
252
- ).all(event.pubkey, event.kind);
253
- for (const candidate of candidates) {
254
- const candidateTags = JSON.parse(candidate.tags);
255
- const candidateDTagValue = getDTagValue(candidateTags);
256
- if (candidateDTagValue === "") {
257
- existing = { id: candidate.id, created_at: candidate.created_at };
258
- break;
259
- }
260
- }
261
- } else {
262
- const dTagPattern = `%["d","${dTagValue}"%`;
263
- existing = this.getByPubkeyKindDTagStmt.get(
264
- event.pubkey,
265
- event.kind,
266
- dTagPattern
267
- );
268
- }
269
- if (existing) {
270
- if (event.created_at > existing.created_at || event.created_at === existing.created_at && event.id < existing.id) {
271
- const transaction = this.db.transaction(() => {
272
- this.db.prepare("DELETE FROM events WHERE id = ?").run(existing.id);
273
- this.insertStmt.run(
274
- event.id,
275
- event.pubkey,
276
- event.kind,
277
- event.content,
278
- tagsJson,
279
- event.created_at,
280
- event.sig,
281
- receivedAt
282
- );
283
- });
284
- transaction();
285
- }
286
- } else {
287
- this.insertStmt.run(
288
- event.id,
289
- event.pubkey,
290
- event.kind,
291
- event.content,
292
- tagsJson,
293
- event.created_at,
294
- event.sig,
295
- receivedAt
296
- );
297
- }
298
- }
299
- /**
300
- * Retrieve an event by its ID.
301
- */
302
- get(id) {
303
- try {
304
- const row = this.getStmt.get(id);
305
- if (!row) {
306
- return void 0;
307
- }
308
- return {
309
- id: row.id,
310
- pubkey: row.pubkey,
311
- kind: row.kind,
312
- content: row.content,
313
- tags: JSON.parse(row.tags),
314
- created_at: row.created_at,
315
- sig: row.sig
316
- };
317
- } catch (error) {
318
- throw new RelayError(
319
- `Failed to get event: ${error instanceof Error ? error.message : String(error)}`,
320
- "STORAGE_ERROR"
321
- );
322
- }
323
- }
324
- /**
325
- * Query events matching any of the provided filters.
326
- */
327
- query(filters) {
328
- try {
329
- const { sql, params } = this.buildQuerySql(filters);
330
- const stmt = this.db.prepare(sql);
331
- const rows = stmt.all(...params);
332
- return rows.map((row) => ({
333
- id: row.id,
334
- pubkey: row.pubkey,
335
- kind: row.kind,
336
- content: row.content,
337
- tags: JSON.parse(row.tags),
338
- created_at: row.created_at,
339
- sig: row.sig
340
- }));
341
- } catch (error) {
342
- throw new RelayError(
343
- `Failed to query events: ${error instanceof Error ? error.message : String(error)}`,
344
- "STORAGE_ERROR"
345
- );
346
- }
347
- }
348
- /**
349
- * Build SQL query from filters.
350
- */
351
- buildQuerySql(filters) {
352
- if (filters.length === 0) {
353
- return {
354
- sql: "SELECT * FROM events ORDER BY created_at DESC",
355
- params: []
356
- };
357
- }
358
- const conditions = [];
359
- const params = [];
360
- for (const filter of filters) {
361
- const filterConditions = [];
362
- if (filter.ids?.length) {
363
- const idConditions = filter.ids.map(() => "id LIKE ?");
364
- filterConditions.push(`(${idConditions.join(" OR ")})`);
365
- params.push(...filter.ids.map((id) => `${id}%`));
366
- }
367
- if (filter.authors?.length) {
368
- const authorConditions = filter.authors.map(() => "pubkey LIKE ?");
369
- filterConditions.push(`(${authorConditions.join(" OR ")})`);
370
- params.push(...filter.authors.map((a) => `${a}%`));
371
- }
372
- if (filter.kinds?.length) {
373
- filterConditions.push(
374
- `kind IN (${filter.kinds.map(() => "?").join(", ")})`
375
- );
376
- params.push(...filter.kinds);
377
- }
378
- if (filter.since !== void 0) {
379
- filterConditions.push("created_at >= ?");
380
- params.push(filter.since);
381
- }
382
- if (filter.until !== void 0) {
383
- filterConditions.push("created_at <= ?");
384
- params.push(filter.until);
385
- }
386
- for (const [key, values] of Object.entries(filter)) {
387
- if (key.startsWith("#") && Array.isArray(values) && values.length > 0) {
388
- const tagName = key.slice(1);
389
- const tagConditions = values.map(() => `tags LIKE ?`);
390
- filterConditions.push(`(${tagConditions.join(" OR ")})`);
391
- params.push(...values.map((v) => `%["${tagName}","${v}"%`));
392
- }
393
- }
394
- if (filterConditions.length > 0) {
395
- conditions.push(`(${filterConditions.join(" AND ")})`);
396
- }
397
- }
398
- let sql = "SELECT * FROM events";
399
- if (conditions.length > 0) {
400
- sql += ` WHERE ${conditions.join(" OR ")}`;
401
- }
402
- sql += " ORDER BY created_at DESC";
403
- const limitFilter = filters.find((f) => f.limit !== void 0);
404
- if (limitFilter?.limit !== void 0) {
405
- sql += " LIMIT ?";
406
- params.push(limitFilter.limit);
407
- }
408
- return { sql, params };
409
- }
410
- /**
411
- * Close the database connection.
412
- */
413
- close() {
414
- this.db.close();
415
- }
416
- };
417
-
418
- // src/toon/index.ts
419
1
  import {
2
+ ConnectionHandler,
3
+ DEFAULT_RELAY_CONFIG,
4
+ EIP_3009_TYPES,
5
+ InMemoryEventStore,
6
+ NostrRelayServer,
7
+ RelayError,
8
+ RelaySubscriber,
9
+ SqliteEventStore,
10
+ ToonDecodeError,
11
+ ToonEncodeError,
12
+ USDC_ABI,
13
+ USDC_EIP712_DOMAIN,
14
+ calculateX402Price,
15
+ createEventStorageHandler,
16
+ createHealthResponse,
17
+ createX402Handler,
18
+ decodeEventFromToon,
420
19
  encodeEventToToon,
421
- encodeEventToToonString,
422
- ToonEncodeError
423
- } from "@toon-protocol/core";
424
- import { decodeEventFromToon, ToonDecodeError } from "@toon-protocol/core";
425
-
426
- // src/websocket/ConnectionHandler.ts
427
- var ConnectionHandler = class {
428
- constructor(ws, eventStore, config = {}) {
429
- this.ws = ws;
430
- this.eventStore = eventStore;
431
- this.config = { ...DEFAULT_RELAY_CONFIG, ...config };
432
- }
433
- subscriptions = /* @__PURE__ */ new Map();
434
- config;
435
- /**
436
- * Handle an incoming message from the WebSocket.
437
- */
438
- handleMessage(data) {
439
- console.log(`[ConnectionHandler] Received message:`, data.slice(0, 150));
440
- let message;
441
- try {
442
- const parsed = JSON.parse(data);
443
- if (!Array.isArray(parsed)) {
444
- this.sendNotice("error: invalid message format, expected JSON array");
445
- return;
446
- }
447
- message = parsed;
448
- } catch {
449
- this.sendNotice("error: invalid JSON");
450
- return;
451
- }
452
- const messageType = message[0];
453
- console.log(`[ConnectionHandler] Message type: ${messageType}`);
454
- if (messageType === "REQ") {
455
- const subscriptionId = message[1];
456
- const filters = message.slice(2);
457
- this.handleReq(subscriptionId, filters);
458
- } else if (messageType === "EVENT") {
459
- const event = message[1];
460
- this.handleEvent(event);
461
- } else if (messageType === "CLOSE") {
462
- const subscriptionId = message[1];
463
- this.handleClose(subscriptionId);
464
- } else {
465
- this.sendNotice(`error: unknown message type: ${messageType}`);
466
- }
467
- }
468
- /**
469
- * Handle a REQ message to create/update a subscription.
470
- */
471
- handleReq(subscriptionId, filters) {
472
- if (typeof subscriptionId !== "string" || subscriptionId.length === 0) {
473
- this.sendNotice("error: invalid subscription id");
474
- return;
475
- }
476
- if (!this.subscriptions.has(subscriptionId)) {
477
- if (this.subscriptions.size >= this.config.maxSubscriptionsPerConnection) {
478
- this.sendNotice("error: too many subscriptions");
479
- return;
480
- }
481
- }
482
- if (filters.length > this.config.maxFiltersPerSubscription) {
483
- this.sendNotice("error: too many filters");
484
- return;
485
- }
486
- this.subscriptions.set(subscriptionId, {
487
- id: subscriptionId,
488
- filters
489
- });
490
- console.log(
491
- `[ConnectionHandler] REQ: ${subscriptionId}, filters:`,
492
- JSON.stringify(filters).slice(0, 100)
493
- );
494
- const events = this.eventStore.query(filters);
495
- console.log(
496
- `[ConnectionHandler] Query returned ${events.length} events for ${subscriptionId}`
497
- );
498
- for (const event of events) {
499
- console.log(
500
- `[ConnectionHandler] Sending event ${event.id.slice(0, 16)}... to ${subscriptionId}`
501
- );
502
- this.sendEvent(subscriptionId, event);
503
- }
504
- console.log(`[ConnectionHandler] Sending EOSE for ${subscriptionId}`);
505
- this.sendEose(subscriptionId);
506
- }
507
- /**
508
- * Handle an EVENT message from a WebSocket client.
509
- *
510
- * Rejects all external writes — the relay is ILP-gated (pay to write).
511
- * Events are only stored through the ILP packet handler which calls
512
- * eventStore.store() directly and then broadcastEvent() to notify subscribers.
513
- */
514
- handleEvent(event) {
515
- this.sendOk(event.id, false, "restricted: writes require ILP payment");
516
- }
517
- /**
518
- * Handle a CLOSE message to terminate a subscription.
519
- */
520
- handleClose(subscriptionId) {
521
- this.subscriptions.delete(subscriptionId);
522
- }
523
- /**
524
- * Push a new event to all matching subscriptions on this connection.
525
- * Used when events are stored outside the WebSocket flow (e.g., via ILP).
526
- */
527
- notifyNewEvent(event) {
528
- for (const sub of this.subscriptions.values()) {
529
- const matches = sub.filters.some((f) => matchFilter(event, f));
530
- if (matches) {
531
- this.sendEvent(sub.id, event);
532
- }
533
- }
534
- }
535
- /**
536
- * Clean up all subscriptions for this connection.
537
- */
538
- cleanup() {
539
- this.subscriptions.clear();
540
- }
541
- /**
542
- * Get the number of active subscriptions.
543
- */
544
- getSubscriptionCount() {
545
- return this.subscriptions.size;
546
- }
547
- sendEvent(subscriptionId, event) {
548
- this.send(["EVENT", subscriptionId, encodeEventToToonString(event)]);
549
- }
550
- sendEose(subscriptionId) {
551
- this.send(["EOSE", subscriptionId]);
552
- }
553
- sendOk(eventId, success, message) {
554
- this.send(["OK", eventId, success, message]);
555
- }
556
- sendNotice(message) {
557
- this.send(["NOTICE", message]);
558
- }
559
- send(message) {
560
- if (this.ws.readyState === 1) {
561
- this.ws.send(JSON.stringify(message));
562
- }
563
- }
564
- };
565
-
566
- // src/websocket/NostrRelayServer.ts
567
- import { WebSocketServer } from "ws";
568
- var NostrRelayServer = class {
569
- constructor(config = {}, eventStore) {
570
- this.eventStore = eventStore;
571
- this.config = { ...DEFAULT_RELAY_CONFIG, ...config };
572
- }
573
- wss = null;
574
- handlers = /* @__PURE__ */ new Map();
575
- config;
576
- /**
577
- * Start the WebSocket server.
578
- */
579
- async start() {
580
- return new Promise((resolve, reject) => {
581
- try {
582
- this.wss = new WebSocketServer({ port: this.config.port });
583
- this.wss.on("connection", (ws) => {
584
- this.handleConnection(ws);
585
- });
586
- this.wss.on("error", (error) => {
587
- console.error("[NostrRelayServer] Server error:", error.message);
588
- });
589
- this.wss.on("listening", () => {
590
- const address = this.wss?.address();
591
- if (address && typeof address === "object") {
592
- console.log(`[NostrRelayServer] Listening on port ${address.port}`);
593
- }
594
- resolve();
595
- });
596
- } catch (error) {
597
- reject(error);
598
- }
599
- });
600
- }
601
- /**
602
- * Stop the WebSocket server and close all connections.
603
- */
604
- async stop() {
605
- return new Promise((resolve) => {
606
- if (!this.wss) {
607
- resolve();
608
- return;
609
- }
610
- for (const [ws, handler] of this.handlers) {
611
- handler.cleanup();
612
- ws.close();
613
- }
614
- this.handlers.clear();
615
- this.wss.close(() => {
616
- this.wss = null;
617
- resolve();
618
- });
619
- });
620
- }
621
- /**
622
- * Get the port the server is listening on.
623
- * Returns 0 if the server is not started.
624
- */
625
- getPort() {
626
- if (!this.wss) return 0;
627
- const address = this.wss.address();
628
- if (address && typeof address === "object") {
629
- return address.port;
630
- }
631
- return 0;
632
- }
633
- /**
634
- * Get the number of connected clients.
635
- */
636
- getClientCount() {
637
- return this.handlers.size;
638
- }
639
- /**
640
- * Broadcast an event to all connected clients with matching subscriptions.
641
- * Call this after storing an event outside the WebSocket flow (e.g., via ILP)
642
- * so that discovery subscribers are notified.
643
- */
644
- broadcastEvent(event) {
645
- for (const handler of this.handlers.values()) {
646
- handler.notifyNewEvent(event);
647
- }
648
- }
649
- handleConnection(ws) {
650
- if (this.handlers.size >= this.config.maxConnections) {
651
- ws.close(1013, "max connections reached");
652
- return;
653
- }
654
- console.log("[NostrRelayServer] Client connected");
655
- const handler = new ConnectionHandler(ws, this.eventStore, this.config);
656
- this.handlers.set(ws, handler);
657
- ws.on("message", (data) => {
658
- const message = typeof data === "string" ? data : data.toString();
659
- handler.handleMessage(message);
660
- });
661
- ws.on("close", () => {
662
- console.log("[NostrRelayServer] Client disconnected");
663
- handler.cleanup();
664
- this.handlers.delete(ws);
665
- });
666
- ws.on("error", (error) => {
667
- console.error("[NostrRelayServer] Client error:", error.message);
668
- handler.cleanup();
669
- this.handlers.delete(ws);
670
- });
671
- }
672
- };
20
+ matchFilter,
21
+ runPreflight,
22
+ settleEip3009,
23
+ startRelay,
24
+ startTown
25
+ } from "./chunk-ZKWFGHZ7.js";
673
26
 
674
27
  // src/bls/types.ts
675
28
  var PUBKEY_REGEX = /^[0-9a-f]{64}$/;
@@ -1086,69 +439,6 @@ function parseKindOverridesJson(jsonStr) {
1086
439
  return result;
1087
440
  }
1088
441
 
1089
- // src/subscriber/RelaySubscriber.ts
1090
- import { SimplePool } from "nostr-tools/pool";
1091
- import { verifyEvent as verifyEvent2 } from "nostr-tools/pure";
1092
- var RelaySubscriber = class {
1093
- config;
1094
- eventStore;
1095
- pool;
1096
- started = false;
1097
- /**
1098
- * @param config - Subscriber configuration
1099
- * @param eventStore - Storage backend to write events into
1100
- * @param pool - Optional SimplePool instance (creates new one if not provided)
1101
- */
1102
- constructor(config, eventStore, pool) {
1103
- this.config = config;
1104
- this.eventStore = eventStore;
1105
- this.pool = pool ?? new SimplePool();
1106
- }
1107
- /**
1108
- * Start subscribing to the configured upstream relays.
1109
- *
1110
- * @returns Handle with unsubscribe() to stop the subscription
1111
- * @throws Error if already started
1112
- */
1113
- start() {
1114
- if (this.started) {
1115
- throw new Error("RelaySubscriber already started");
1116
- }
1117
- this.started = true;
1118
- const shouldVerify = this.config.verifySignatures !== false;
1119
- let isUnsubscribed = false;
1120
- const subCloser = this.pool.subscribeMany(
1121
- this.config.relayUrls,
1122
- this.config.filter,
1123
- {
1124
- onevent: (event) => {
1125
- if (isUnsubscribed) return;
1126
- if (shouldVerify && !verifyEvent2(event)) {
1127
- return;
1128
- }
1129
- try {
1130
- this.eventStore.store(event);
1131
- } catch (error) {
1132
- console.warn(
1133
- "[RelaySubscriber] Failed to store event:",
1134
- error instanceof Error ? error.message : "Unknown error"
1135
- );
1136
- }
1137
- }
1138
- }
1139
- );
1140
- return {
1141
- unsubscribe: () => {
1142
- if (!isUnsubscribed) {
1143
- isUnsubscribed = true;
1144
- subCloser.close();
1145
- this.started = false;
1146
- }
1147
- }
1148
- };
1149
- }
1150
- };
1151
-
1152
442
  // src/index.ts
1153
443
  var VERSION = "0.1.0";
1154
444
  export {
@@ -1156,6 +446,7 @@ export {
1156
446
  BusinessLogicServer,
1157
447
  ConnectionHandler,
1158
448
  DEFAULT_RELAY_CONFIG,
449
+ EIP_3009_TYPES,
1159
450
  ILP_ERROR_CODES,
1160
451
  InMemoryEventStore,
1161
452
  NostrRelayServer,
@@ -1166,12 +457,22 @@ export {
1166
457
  SqliteEventStore,
1167
458
  ToonDecodeError,
1168
459
  ToonEncodeError,
460
+ USDC_ABI,
461
+ USDC_EIP712_DOMAIN,
1169
462
  VERSION,
463
+ calculateX402Price,
464
+ createEventStorageHandler,
465
+ createHealthResponse,
466
+ createX402Handler,
1170
467
  decodeEventFromToon,
1171
468
  encodeEventToToon,
1172
469
  isValidPubkey,
1173
470
  loadPricingConfigFromEnv,
1174
471
  loadPricingConfigFromFile,
1175
- matchFilter
472
+ matchFilter,
473
+ runPreflight,
474
+ settleEip3009,
475
+ startRelay,
476
+ startTown
1176
477
  };
1177
478
  //# sourceMappingURL=index.js.map