@elisym/sdk 0.2.1 → 0.3.1

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.d.cts CHANGED
@@ -182,7 +182,7 @@ declare class MediaService {
182
182
  }
183
183
 
184
184
  /**
185
- * Ping/pong and NIP-17 DM service.
185
+ * Ephemeral ping/pong service (kinds 20200/20201).
186
186
  *
187
187
  * Uses a session identity (random keypair) for ping operations to avoid
188
188
  * relay rate-limiting. The session identity persists for the lifetime of
@@ -190,7 +190,7 @@ declare class MediaService {
190
190
  *
191
191
  * Requires `globalThis.crypto` (Node 20+, Bun, browsers).
192
192
  */
193
- declare class MessagingService {
193
+ declare class PingService {
194
194
  private pool;
195
195
  private static readonly PING_CACHE_MAX;
196
196
  private sessionIdentity;
@@ -213,17 +213,6 @@ declare class MessagingService {
213
213
  subscribeToPings(identity: ElisymIdentity, onPing: (senderPubkey: string, nonce: string) => void): SubCloser;
214
214
  /** Send an ephemeral pong response to ALL relays. */
215
215
  sendPong(identity: ElisymIdentity, recipientPubkey: string, nonce: string): Promise<void>;
216
- /** Send a NIP-17 DM. */
217
- sendMessage(identity: ElisymIdentity, recipientPubkey: string, content: string): Promise<void>;
218
- /** Fetch historical NIP-17 DMs from relays. Returns decrypted messages sorted by time. */
219
- fetchMessageHistory(identity: ElisymIdentity, since: number): Promise<{
220
- senderPubkey: string;
221
- content: string;
222
- createdAt: number;
223
- rumorId: string;
224
- }[]>;
225
- /** Subscribe to incoming NIP-17 DMs. */
226
- subscribeToMessages(identity: ElisymIdentity, onMessage: (senderPubkey: string, content: string, createdAt: number, rumorId: string) => void, since?: number): SubCloser;
227
216
  }
228
217
 
229
218
  interface ElisymClientFullConfig extends ElisymClientConfig {
@@ -235,7 +224,7 @@ declare class ElisymClient {
235
224
  readonly pool: NostrPool;
236
225
  readonly discovery: DiscoveryService;
237
226
  readonly marketplace: MarketplaceService;
238
- readonly messaging: MessagingService;
227
+ readonly ping: PingService;
239
228
  readonly media: MediaService;
240
229
  readonly payment: PaymentStrategy;
241
230
  constructor(config?: ElisymClientFullConfig);
@@ -308,7 +297,6 @@ declare const KIND_JOB_REQUEST_BASE = 5000;
308
297
  declare const KIND_JOB_RESULT_BASE = 6000;
309
298
  declare const KIND_JOB_FEEDBACK = 7000;
310
299
  declare const DEFAULT_KIND_OFFSET = 100;
311
- declare const KIND_GIFT_WRAP = 1059;
312
300
  /** Default job request kind (5000 + 100). */
313
301
  declare const KIND_JOB_REQUEST: number;
314
302
  /** Default job result kind (6000 + 100). */
@@ -351,8 +339,7 @@ declare const LIMITS: {
351
339
  readonly MAX_CAPABILITIES: 20;
352
340
  readonly MAX_DESCRIPTION_LENGTH: 500;
353
341
  readonly MAX_AGENT_NAME_LENGTH: 64;
354
- readonly MAX_MESSAGE_LENGTH: 10000;
355
342
  readonly MAX_CAPABILITY_LENGTH: 64;
356
343
  };
357
344
 
358
- export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_GIFT_WRAP, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, MessagingService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
345
+ export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, PingService, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
package/dist/index.d.ts CHANGED
@@ -182,7 +182,7 @@ declare class MediaService {
182
182
  }
183
183
 
184
184
  /**
185
- * Ping/pong and NIP-17 DM service.
185
+ * Ephemeral ping/pong service (kinds 20200/20201).
186
186
  *
187
187
  * Uses a session identity (random keypair) for ping operations to avoid
188
188
  * relay rate-limiting. The session identity persists for the lifetime of
@@ -190,7 +190,7 @@ declare class MediaService {
190
190
  *
191
191
  * Requires `globalThis.crypto` (Node 20+, Bun, browsers).
192
192
  */
193
- declare class MessagingService {
193
+ declare class PingService {
194
194
  private pool;
195
195
  private static readonly PING_CACHE_MAX;
196
196
  private sessionIdentity;
@@ -213,17 +213,6 @@ declare class MessagingService {
213
213
  subscribeToPings(identity: ElisymIdentity, onPing: (senderPubkey: string, nonce: string) => void): SubCloser;
214
214
  /** Send an ephemeral pong response to ALL relays. */
215
215
  sendPong(identity: ElisymIdentity, recipientPubkey: string, nonce: string): Promise<void>;
216
- /** Send a NIP-17 DM. */
217
- sendMessage(identity: ElisymIdentity, recipientPubkey: string, content: string): Promise<void>;
218
- /** Fetch historical NIP-17 DMs from relays. Returns decrypted messages sorted by time. */
219
- fetchMessageHistory(identity: ElisymIdentity, since: number): Promise<{
220
- senderPubkey: string;
221
- content: string;
222
- createdAt: number;
223
- rumorId: string;
224
- }[]>;
225
- /** Subscribe to incoming NIP-17 DMs. */
226
- subscribeToMessages(identity: ElisymIdentity, onMessage: (senderPubkey: string, content: string, createdAt: number, rumorId: string) => void, since?: number): SubCloser;
227
216
  }
228
217
 
229
218
  interface ElisymClientFullConfig extends ElisymClientConfig {
@@ -235,7 +224,7 @@ declare class ElisymClient {
235
224
  readonly pool: NostrPool;
236
225
  readonly discovery: DiscoveryService;
237
226
  readonly marketplace: MarketplaceService;
238
- readonly messaging: MessagingService;
227
+ readonly ping: PingService;
239
228
  readonly media: MediaService;
240
229
  readonly payment: PaymentStrategy;
241
230
  constructor(config?: ElisymClientFullConfig);
@@ -308,7 +297,6 @@ declare const KIND_JOB_REQUEST_BASE = 5000;
308
297
  declare const KIND_JOB_RESULT_BASE = 6000;
309
298
  declare const KIND_JOB_FEEDBACK = 7000;
310
299
  declare const DEFAULT_KIND_OFFSET = 100;
311
- declare const KIND_GIFT_WRAP = 1059;
312
300
  /** Default job request kind (5000 + 100). */
313
301
  declare const KIND_JOB_REQUEST: number;
314
302
  /** Default job result kind (6000 + 100). */
@@ -351,8 +339,7 @@ declare const LIMITS: {
351
339
  readonly MAX_CAPABILITIES: 20;
352
340
  readonly MAX_DESCRIPTION_LENGTH: 500;
353
341
  readonly MAX_AGENT_NAME_LENGTH: 64;
354
- readonly MAX_MESSAGE_LENGTH: 10000;
355
342
  readonly MAX_CAPABILITY_LENGTH: 64;
356
343
  };
357
344
 
358
- export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_GIFT_WRAP, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, MessagingService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
345
+ export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, PingService, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
package/dist/index.js CHANGED
@@ -2,8 +2,6 @@ import { PublicKey, Keypair, SystemProgram, Transaction } from '@solana/web3.js'
2
2
  import Decimal2 from 'decimal.js-light';
3
3
  import { verifyEvent, finalizeEvent, getPublicKey, nip19, generateSecretKey, SimplePool } from 'nostr-tools';
4
4
  import * as nip44 from 'nostr-tools/nip44';
5
- import * as nip17 from 'nostr-tools/nip17';
6
- import * as nip59 from 'nostr-tools/nip59';
7
5
 
8
6
  // src/constants.ts
9
7
  var RELAYS = [
@@ -18,7 +16,6 @@ var KIND_JOB_REQUEST_BASE = 5e3;
18
16
  var KIND_JOB_RESULT_BASE = 6e3;
19
17
  var KIND_JOB_FEEDBACK = 7e3;
20
18
  var DEFAULT_KIND_OFFSET = 100;
21
- var KIND_GIFT_WRAP = 1059;
22
19
  var KIND_JOB_REQUEST = KIND_JOB_REQUEST_BASE + DEFAULT_KIND_OFFSET;
23
20
  var KIND_JOB_RESULT = KIND_JOB_RESULT_BASE + DEFAULT_KIND_OFFSET;
24
21
  function jobRequestKind(offset) {
@@ -62,7 +59,6 @@ var LIMITS = {
62
59
  MAX_CAPABILITIES: 20,
63
60
  MAX_DESCRIPTION_LENGTH: 500,
64
61
  MAX_AGENT_NAME_LENGTH: 64,
65
- MAX_MESSAGE_LENGTH: 1e4,
66
62
  MAX_CAPABILITY_LENGTH: 64
67
63
  };
68
64
  function assertLamports(value, field) {
@@ -1529,38 +1525,6 @@ var MediaService = class {
1529
1525
  }
1530
1526
  }
1531
1527
  };
1532
-
1533
- // src/primitives/bounded-set.ts
1534
- var BoundedSet = class {
1535
- constructor(maxSize) {
1536
- this.maxSize = maxSize;
1537
- if (maxSize <= 0) {
1538
- throw new Error("BoundedSet maxSize must be positive.");
1539
- }
1540
- this.items = new Array(maxSize);
1541
- }
1542
- items;
1543
- set = /* @__PURE__ */ new Set();
1544
- head = 0;
1545
- count = 0;
1546
- has(item) {
1547
- return this.set.has(item);
1548
- }
1549
- add(item) {
1550
- if (this.set.has(item)) {
1551
- return;
1552
- }
1553
- if (this.count >= this.maxSize) {
1554
- const evicted = this.items[this.head];
1555
- this.set.delete(evicted);
1556
- } else {
1557
- this.count++;
1558
- }
1559
- this.items[this.head] = item;
1560
- this.head = (this.head + 1) % this.maxSize;
1561
- this.set.add(item);
1562
- }
1563
- };
1564
1528
  var ElisymIdentity = class _ElisymIdentity {
1565
1529
  _secretKey;
1566
1530
  publicKey;
@@ -1601,8 +1565,8 @@ var ElisymIdentity = class _ElisymIdentity {
1601
1565
  }
1602
1566
  };
1603
1567
 
1604
- // src/services/messaging.ts
1605
- var MessagingService = class _MessagingService {
1568
+ // src/services/ping.ts
1569
+ var PingService = class _PingService {
1606
1570
  // dedup in-flight pings
1607
1571
  constructor(pool) {
1608
1572
  this.pool = pool;
@@ -1627,7 +1591,7 @@ var MessagingService = class _MessagingService {
1627
1591
  }
1628
1592
  this.pingCache.delete(agentPubkey);
1629
1593
  }
1630
- if (this.pingCache.size > _MessagingService.PING_CACHE_MAX / 2) {
1594
+ if (this.pingCache.size > _PingService.PING_CACHE_MAX / 2) {
1631
1595
  const now = Date.now();
1632
1596
  for (const [key, ts] of this.pingCache) {
1633
1597
  if (now - ts >= DEFAULTS.PING_CACHE_TTL_MS) {
@@ -1639,7 +1603,7 @@ var MessagingService = class _MessagingService {
1639
1603
  if (pending) {
1640
1604
  return pending;
1641
1605
  }
1642
- if (this.pendingPings.size >= _MessagingService.PING_CACHE_MAX) {
1606
+ if (this.pendingPings.size >= _PingService.PING_CACHE_MAX) {
1643
1607
  return { online: false, identity: null };
1644
1608
  }
1645
1609
  const promise = this._doPingWithRetry(agentPubkey, timeoutMs, retries, signal);
@@ -1688,7 +1652,7 @@ var MessagingService = class _MessagingService {
1688
1652
  if (online) {
1689
1653
  this.pingCache.delete(agentPubkey);
1690
1654
  this.pingCache.set(agentPubkey, Date.now());
1691
- if (this.pingCache.size > _MessagingService.PING_CACHE_MAX) {
1655
+ if (this.pingCache.size > _PingService.PING_CACHE_MAX) {
1692
1656
  const oldest = this.pingCache.keys().next().value;
1693
1657
  if (oldest !== void 0) {
1694
1658
  this.pingCache.delete(oldest);
@@ -1772,75 +1736,41 @@ var MessagingService = class _MessagingService {
1772
1736
  );
1773
1737
  await this.pool.publishAll(pongEvent);
1774
1738
  }
1775
- /** Send a NIP-17 DM. */
1776
- async sendMessage(identity, recipientPubkey, content) {
1777
- if (!/^[0-9a-f]{64}$/.test(recipientPubkey)) {
1778
- throw new Error("Invalid recipient pubkey: expected 64 hex characters.");
1779
- }
1780
- if (content.length > LIMITS.MAX_MESSAGE_LENGTH) {
1781
- throw new Error(
1782
- `Message too long: ${content.length} chars (max ${LIMITS.MAX_MESSAGE_LENGTH}).`
1783
- );
1739
+ };
1740
+
1741
+ // src/primitives/bounded-set.ts
1742
+ var BoundedSet = class {
1743
+ constructor(maxSize) {
1744
+ this.maxSize = maxSize;
1745
+ if (maxSize <= 0) {
1746
+ throw new Error("BoundedSet maxSize must be positive.");
1784
1747
  }
1785
- const wrap = nip17.wrapEvent(identity.secretKey, { publicKey: recipientPubkey }, content);
1786
- await this.pool.publish(wrap);
1748
+ this.items = new Array(maxSize);
1787
1749
  }
1788
- /** Fetch historical NIP-17 DMs from relays. Returns decrypted messages sorted by time. */
1789
- async fetchMessageHistory(identity, since) {
1790
- const events = await this.pool.querySync({
1791
- kinds: [KIND_GIFT_WRAP],
1792
- "#p": [identity.publicKey],
1793
- since
1794
- });
1795
- const seen = new BoundedSet(1e4);
1796
- const messages = [];
1797
- for (const ev of events) {
1798
- try {
1799
- const rumor = nip59.unwrapEvent(ev, identity.secretKey);
1800
- if (rumor.kind !== 14) {
1801
- continue;
1802
- }
1803
- if (seen.has(rumor.id)) {
1804
- continue;
1805
- }
1806
- seen.add(rumor.id);
1807
- messages.push({
1808
- senderPubkey: rumor.pubkey,
1809
- content: rumor.content,
1810
- createdAt: rumor.created_at,
1811
- rumorId: rumor.id
1812
- });
1813
- } catch {
1814
- }
1815
- }
1816
- return messages.sort((a, b) => a.createdAt - b.createdAt);
1750
+ items;
1751
+ set = /* @__PURE__ */ new Set();
1752
+ head = 0;
1753
+ count = 0;
1754
+ has(item) {
1755
+ return this.set.has(item);
1817
1756
  }
1818
- /** Subscribe to incoming NIP-17 DMs. */
1819
- subscribeToMessages(identity, onMessage, since) {
1820
- const seen = new BoundedSet(1e4);
1821
- const filter = {
1822
- kinds: [KIND_GIFT_WRAP],
1823
- "#p": [identity.publicKey]
1824
- };
1825
- if (since !== void 0) {
1826
- filter.since = since;
1757
+ add(item) {
1758
+ if (this.set.has(item)) {
1759
+ return;
1827
1760
  }
1828
- return this.pool.subscribe(filter, (ev) => {
1829
- try {
1830
- const rumor = nip59.unwrapEvent(ev, identity.secretKey);
1831
- if (rumor.kind !== 14) {
1832
- return;
1833
- }
1834
- if (seen.has(rumor.id)) {
1835
- return;
1836
- }
1837
- seen.add(rumor.id);
1838
- onMessage(rumor.pubkey, rumor.content, rumor.created_at, rumor.id);
1839
- } catch {
1840
- }
1841
- });
1761
+ if (this.count >= this.maxSize) {
1762
+ const evicted = this.items[this.head];
1763
+ this.set.delete(evicted);
1764
+ } else {
1765
+ this.count++;
1766
+ }
1767
+ this.items[this.head] = item;
1768
+ this.head = (this.head + 1) % this.maxSize;
1769
+ this.set.add(item);
1842
1770
  }
1843
1771
  };
1772
+
1773
+ // src/transport/pool.ts
1844
1774
  var NostrPool = class {
1845
1775
  pool;
1846
1776
  relays;
@@ -2087,14 +2017,14 @@ var ElisymClient = class {
2087
2017
  pool;
2088
2018
  discovery;
2089
2019
  marketplace;
2090
- messaging;
2020
+ ping;
2091
2021
  media;
2092
2022
  payment;
2093
2023
  constructor(config = {}) {
2094
2024
  this.pool = new NostrPool(config.relays ?? RELAYS);
2095
2025
  this.discovery = new DiscoveryService(this.pool);
2096
2026
  this.marketplace = new MarketplaceService(this.pool);
2097
- this.messaging = new MessagingService(this.pool);
2027
+ this.ping = new PingService(this.pool);
2098
2028
  this.media = new MediaService(config.uploadUrl);
2099
2029
  this.payment = config.payment ?? new SolanaPaymentStrategy();
2100
2030
  }
@@ -2161,6 +2091,6 @@ function serializeConfig(config) {
2161
2091
  return JSON.stringify(config, null, 2) + "\n";
2162
2092
  }
2163
2093
 
2164
- export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymIdentity, KIND_APP_HANDLER, KIND_GIFT_WRAP, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, MessagingService, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, RELAYS, SolanaPaymentStrategy, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
2094
+ export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymIdentity, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, PingService, RELAYS, SolanaPaymentStrategy, assertExpiry, assertLamports, calculateProtocolFee, formatSol, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
2165
2095
  //# sourceMappingURL=index.js.map
2166
2096
  //# sourceMappingURL=index.js.map