@hybrd/xmtp 1.0.10 → 1.1.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.
Files changed (55) hide show
  1. package/.cache/tsbuildinfo.json +1 -1
  2. package/.turbo/turbo-build.log +42 -2
  3. package/biome.jsonc +1 -1
  4. package/dist/index.cjs +3385 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +860 -0
  7. package/dist/index.d.ts +860 -0
  8. package/dist/index.js +3323 -0
  9. package/dist/index.js.map +1 -0
  10. package/package.json +8 -15
  11. package/src/service-client.ts +1 -1
  12. package/tsconfig.json +5 -10
  13. package/tsup.config.ts +14 -0
  14. package/.turbo/turbo-lint$colon$fix.log +0 -6
  15. package/.turbo/turbo-typecheck.log +0 -5
  16. package/dist/scripts/generate-keys.d.ts +0 -1
  17. package/dist/scripts/generate-keys.js +0 -19
  18. package/dist/scripts/refresh-identity.d.ts +0 -1
  19. package/dist/scripts/refresh-identity.js +0 -93
  20. package/dist/scripts/register-wallet.d.ts +0 -1
  21. package/dist/scripts/register-wallet.js +0 -75
  22. package/dist/scripts/revoke-all-installations.d.ts +0 -2
  23. package/dist/scripts/revoke-all-installations.js +0 -68
  24. package/dist/scripts/revoke-installations.d.ts +0 -2
  25. package/dist/scripts/revoke-installations.js +0 -62
  26. package/dist/src/abi/l2_resolver.d.ts +0 -992
  27. package/dist/src/abi/l2_resolver.js +0 -699
  28. package/dist/src/client.d.ts +0 -76
  29. package/dist/src/client.js +0 -709
  30. package/dist/src/constants.d.ts +0 -3
  31. package/dist/src/constants.js +0 -6
  32. package/dist/src/index.d.ts +0 -22
  33. package/dist/src/index.js +0 -46
  34. package/dist/src/lib/message-listener.d.ts +0 -69
  35. package/dist/src/lib/message-listener.js +0 -235
  36. package/dist/src/lib/message-listener.test.d.ts +0 -1
  37. package/dist/src/lib/message-listener.test.js +0 -303
  38. package/dist/src/lib/subjects.d.ts +0 -24
  39. package/dist/src/lib/subjects.js +0 -68
  40. package/dist/src/resolver/address-resolver.d.ts +0 -57
  41. package/dist/src/resolver/address-resolver.js +0 -168
  42. package/dist/src/resolver/basename-resolver.d.ts +0 -134
  43. package/dist/src/resolver/basename-resolver.js +0 -409
  44. package/dist/src/resolver/ens-resolver.d.ts +0 -95
  45. package/dist/src/resolver/ens-resolver.js +0 -249
  46. package/dist/src/resolver/index.d.ts +0 -1
  47. package/dist/src/resolver/index.js +0 -1
  48. package/dist/src/resolver/resolver.d.ts +0 -162
  49. package/dist/src/resolver/resolver.js +0 -238
  50. package/dist/src/resolver/xmtp-resolver.d.ts +0 -95
  51. package/dist/src/resolver/xmtp-resolver.js +0 -297
  52. package/dist/src/service-client.d.ts +0 -77
  53. package/dist/src/service-client.js +0 -198
  54. package/dist/src/types.d.ts +0 -123
  55. package/dist/src/types.js +0 -5
@@ -0,0 +1,860 @@
1
+ import { Client, Conversation, DecodedMessage, Signer } from '@xmtp/node-sdk';
2
+ export { Client, DecodedMessage, Dm, IdentifierKind, LogLevel, Signer, XmtpEnv } from '@xmtp/node-sdk';
3
+ import { privateKeyToAccount } from 'viem/accounts';
4
+ import { GroupUpdated } from '@xmtp/content-type-group-updated';
5
+ export { ContentTypeGroupUpdated, GroupUpdated, GroupUpdatedCodec } from '@xmtp/content-type-group-updated';
6
+ import { Reaction } from '@xmtp/content-type-reaction';
7
+ export { ContentTypeReaction, Reaction } from '@xmtp/content-type-reaction';
8
+ import { Reply } from '@xmtp/content-type-reply';
9
+ export { ContentTypeReply, Reply, ReplyCodec } from '@xmtp/content-type-reply';
10
+ import { TransactionReference } from '@xmtp/content-type-transaction-reference';
11
+ export { ContentTypeTransactionReference, TransactionReference } from '@xmtp/content-type-transaction-reference';
12
+ import { WalletSendCallsParams } from '@xmtp/content-type-wallet-send-calls';
13
+ export { ContentTypeWalletSendCalls, WalletSendCallsParams } from '@xmtp/content-type-wallet-send-calls';
14
+ import { PublicClient, Address } from 'viem';
15
+ import { EventEmitter } from 'node:events';
16
+ export { ContentTypeText, TextParameters } from '@xmtp/content-type-text';
17
+
18
+ declare const BasenameTextRecordKeys: {
19
+ readonly Email: "email";
20
+ readonly Url: "url";
21
+ readonly Avatar: "avatar";
22
+ readonly Description: "description";
23
+ readonly Notice: "notice";
24
+ readonly Keywords: "keywords";
25
+ readonly Twitter: "com.twitter";
26
+ readonly Github: "com.github";
27
+ readonly Discord: "com.discord";
28
+ readonly Telegram: "org.telegram";
29
+ readonly Snapshot: "snapshot";
30
+ readonly Location: "location";
31
+ };
32
+ type BasenameTextRecordKey = (typeof BasenameTextRecordKeys)[keyof typeof BasenameTextRecordKeys];
33
+ type BaseName = string;
34
+ interface BasenameResolverOptions {
35
+ /**
36
+ * Maximum number of basenames to cache
37
+ * @default 500
38
+ */
39
+ maxCacheSize?: number;
40
+ /**
41
+ * Cache TTL in milliseconds
42
+ * @default 3600000 (1 hour)
43
+ */
44
+ cacheTtl?: number;
45
+ /**
46
+ * Public client
47
+ * @default null
48
+ */
49
+ publicClient: PublicClient;
50
+ }
51
+ /**
52
+ * Convert an chainId to a coinType hex for reverse chain resolution
53
+ */
54
+ declare const convertChainIdToCoinType: (chainId: number) => string;
55
+ /**
56
+ * Helper function to convert an address to its reverse node for ENS lookups
57
+ */
58
+ declare const convertReverseNodeToBytes: (address: Address, chainId: number) => `0x${string}`;
59
+ declare class BasenameResolver {
60
+ private cache;
61
+ private textRecordCache;
62
+ private readonly maxCacheSize;
63
+ private readonly cacheTtl;
64
+ private readonly baseClient;
65
+ private resolverAddress;
66
+ private chainId;
67
+ constructor(options: BasenameResolverOptions);
68
+ /**
69
+ * Initialize the resolver address based on the client's chain ID
70
+ */
71
+ private initializeResolver;
72
+ /**
73
+ * Get the resolver address, initializing if necessary
74
+ */
75
+ private getResolverAddress;
76
+ /**
77
+ * Resolve a basename from an Ethereum address
78
+ */
79
+ getBasename(address: Address): Promise<string | null>;
80
+ /**
81
+ * Get the avatar URL for a basename
82
+ */
83
+ getBasenameAvatar(basename: BaseName): Promise<string | null>;
84
+ /**
85
+ * Get a text record for a basename
86
+ */
87
+ getBasenameTextRecord(basename: BaseName, key: BasenameTextRecordKey): Promise<string | null>;
88
+ /**
89
+ * Get the Ethereum address that owns a basename
90
+ */
91
+ getBasenameAddress(basename: BaseName): Promise<Address | null>;
92
+ /**
93
+ * Get all basic metadata for a basename
94
+ */
95
+ getBasenameMetadata(basename: BaseName): Promise<{
96
+ basename: string;
97
+ avatar: string | null;
98
+ description: string | null;
99
+ twitter: string | null;
100
+ github: string | null;
101
+ url: string | null;
102
+ } | null>;
103
+ /**
104
+ * Resolve a full basename profile (name + metadata) from an address
105
+ */
106
+ resolveBasenameProfile(address: Address): Promise<{
107
+ basename?: string | undefined;
108
+ avatar?: string | null | undefined;
109
+ description?: string | null | undefined;
110
+ twitter?: string | null | undefined;
111
+ github?: string | null | undefined;
112
+ url?: string | null | undefined;
113
+ address: `0x${string}`;
114
+ } | null>;
115
+ /**
116
+ * Get cached basename if not expired
117
+ */
118
+ private getCachedBasename;
119
+ /**
120
+ * Cache basename with LRU eviction
121
+ */
122
+ private setCachedBasename;
123
+ /**
124
+ * Get cached text record if not expired
125
+ */
126
+ private getCachedTextRecord;
127
+ /**
128
+ * Cache text record
129
+ */
130
+ private setCachedTextRecord;
131
+ /**
132
+ * Clear all caches
133
+ */
134
+ clearCache(): void;
135
+ /**
136
+ * Get cache statistics
137
+ */
138
+ getCacheStats(): {
139
+ basenameCache: {
140
+ size: number;
141
+ maxSize: number;
142
+ };
143
+ textRecordCache: {
144
+ size: number;
145
+ };
146
+ chainId: number | null;
147
+ resolverAddress: Address | null;
148
+ };
149
+ }
150
+
151
+ interface ResolverOptions {
152
+ /**
153
+ * XMTP Client for message and address resolution
154
+ */
155
+ xmtpClient: XmtpClient;
156
+ /**
157
+ * Mainnet public client for ENS resolution
158
+ */
159
+ mainnetClient: PublicClient;
160
+ /**
161
+ * Base network public client for basename resolution
162
+ */
163
+ baseClient: PublicClient;
164
+ /**
165
+ * Maximum cache size for each resolver
166
+ * @default 1000
167
+ */
168
+ maxCacheSize?: number;
169
+ /**
170
+ * Cache TTL in milliseconds
171
+ * @default 3600000 (1 hour)
172
+ */
173
+ cacheTtl?: number;
174
+ }
175
+ /**
176
+ * Master Resolver that wraps all individual resolvers
177
+ * Provides a unified interface for basename, ENS, address, and XMTP resolution
178
+ */
179
+ declare class Resolver {
180
+ private addressResolver;
181
+ private ensResolver;
182
+ private basenameResolver;
183
+ private xmtpResolver;
184
+ constructor(options: ResolverOptions);
185
+ /**
186
+ * Resolve user address from inbox ID with caching
187
+ * Uses both AddressResolver and XmtpResolver for redundancy
188
+ */
189
+ resolveAddress(inboxId: string, conversationId?: string): Promise<`0x${string}` | null>;
190
+ /**
191
+ * Resolve an ENS name to an Ethereum address
192
+ */
193
+ resolveENSName(ensName: string): Promise<Address | null>;
194
+ /**
195
+ * Resolve an address to its primary ENS name (reverse resolution)
196
+ */
197
+ resolveAddressToENS(address: Address): Promise<string | null>;
198
+ /**
199
+ * Get ENS avatar for a given ENS name
200
+ */
201
+ getENSAvatar(ensName: string): Promise<string | null>;
202
+ /**
203
+ * Get ENS text record for a given ENS name and key
204
+ */
205
+ getENSTextRecord(ensName: string, key: string): Promise<string | null>;
206
+ /**
207
+ * Get complete ENS profile for a given ENS name
208
+ */
209
+ getENSProfile(ensName: string): Promise<{
210
+ ensName: string;
211
+ address: `0x${string}` | null;
212
+ avatar: string | null;
213
+ description: string | null;
214
+ twitter: string | null;
215
+ github: string | null;
216
+ url: string | null;
217
+ } | null>;
218
+ /**
219
+ * Get basename from an Ethereum address
220
+ */
221
+ getBasename(address: Address): Promise<string | null>;
222
+ /**
223
+ * Get basename avatar for a given basename
224
+ */
225
+ getBasenameAvatar(basename: BaseName): Promise<string | null>;
226
+ /**
227
+ * Get basename text record for a given basename and key
228
+ */
229
+ getBasenameTextRecord(basename: BaseName, key: BasenameTextRecordKey): Promise<string | null>;
230
+ /**
231
+ * Resolve basename to an Ethereum address
232
+ */
233
+ getBasenameAddress(basename: BaseName): Promise<Address | null>;
234
+ /**
235
+ * Get basename metadata for a given basename
236
+ */
237
+ getBasenameMetadata(basename: BaseName): Promise<{
238
+ basename: string;
239
+ avatar: string | null;
240
+ description: string | null;
241
+ twitter: string | null;
242
+ github: string | null;
243
+ url: string | null;
244
+ } | null>;
245
+ /**
246
+ * Get complete basename profile for a given address
247
+ */
248
+ resolveBasenameProfile(address: Address): Promise<{
249
+ basename?: string | undefined;
250
+ avatar?: string | null | undefined;
251
+ description?: string | null | undefined;
252
+ twitter?: string | null | undefined;
253
+ github?: string | null | undefined;
254
+ url?: string | null | undefined;
255
+ address: `0x${string}`;
256
+ } | null>;
257
+ /**
258
+ * Find any message by ID with caching
259
+ */
260
+ findMessage(messageId: string): Promise<XmtpMessage | null>;
261
+ /**
262
+ * Find root message by ID (traverses reply chain)
263
+ */
264
+ findRootMessage(messageId: string): Promise<XmtpMessage | null>;
265
+ /**
266
+ * Universal name resolution - tries to resolve any name (ENS or basename) to an address
267
+ */
268
+ resolveName(name: string): Promise<Address | null>;
269
+ /**
270
+ * Universal reverse resolution - tries to resolve an address to any name (ENS or basename)
271
+ */
272
+ resolveAddressToName(address: Address): Promise<string | null>;
273
+ /**
274
+ * Get complete profile for an address (combines ENS and basename data)
275
+ */
276
+ getCompleteProfile(address: Address): Promise<{
277
+ address: `0x${string}`;
278
+ ensName: string | null;
279
+ basename: string | null;
280
+ ensProfile: {
281
+ ensName: string;
282
+ address: `0x${string}` | null;
283
+ avatar: string | null;
284
+ description: string | null;
285
+ twitter: string | null;
286
+ github: string | null;
287
+ url: string | null;
288
+ } | null;
289
+ basenameProfile: {
290
+ basename?: string | undefined;
291
+ avatar?: string | null | undefined;
292
+ description?: string | null | undefined;
293
+ twitter?: string | null | undefined;
294
+ github?: string | null | undefined;
295
+ url?: string | null | undefined;
296
+ address: `0x${string}`;
297
+ } | null;
298
+ }>;
299
+ /**
300
+ * Pre-populate all resolver caches
301
+ */
302
+ prePopulateAllCaches(): Promise<void>;
303
+ /**
304
+ * Create a complete XmtpSender object from an address or inboxId
305
+ * Uses the resolver to get the best available name and profile information
306
+ */
307
+ createXmtpSender(addressOrInboxId: string, conversationId?: string): Promise<XmtpSender>;
308
+ }
309
+
310
+ /**
311
+ * @fileoverview XMTP Types
312
+ *
313
+ * Type definitions for both the XMTP core client and service client library.
314
+ */
315
+
316
+ type HonoVariables = {
317
+ xmtpClient: XmtpClient;
318
+ resolver?: Resolver;
319
+ };
320
+ type Codec = GroupUpdated | Reaction | Reply | TransactionReference | WalletSendCallsParams;
321
+ type XmtpClient = Client<string | Codec>;
322
+ type XmtpConversation = Conversation<string | Codec>;
323
+ type XmtpMessage = DecodedMessage<string | Codec>;
324
+ type XmtpSender = {
325
+ address: string;
326
+ inboxId: string;
327
+ name: string;
328
+ basename?: string;
329
+ };
330
+ type XmtpSubjects = Record<string, `0x${string}`>;
331
+ interface MessageEvent {
332
+ conversation: XmtpConversation;
333
+ message: XmtpMessage;
334
+ rootMessage: XmtpMessage;
335
+ parentMessage?: XmtpMessage;
336
+ sender: XmtpSender;
337
+ subjects: XmtpSubjects;
338
+ }
339
+ interface XmtpServiceClientConfig {
340
+ serviceUrl: string;
341
+ serviceToken: string;
342
+ }
343
+ interface TransactionCall {
344
+ to: string;
345
+ data: string;
346
+ gas?: string;
347
+ value?: string;
348
+ metadata?: Record<string, unknown>;
349
+ }
350
+ interface TransactionRequest {
351
+ fromAddress: string;
352
+ chainId: string;
353
+ calls: TransactionCall[];
354
+ }
355
+ interface XmtpServiceResponse<T = unknown> {
356
+ success: boolean;
357
+ data?: T;
358
+ error?: string;
359
+ }
360
+ interface XmtpServiceMessage {
361
+ id: string;
362
+ conversationId: string;
363
+ content: string | Record<string, unknown>;
364
+ senderInboxId: string;
365
+ sentAt: string;
366
+ contentType?: {
367
+ typeId: string;
368
+ authorityId?: string;
369
+ versionMajor?: number;
370
+ versionMinor?: number;
371
+ };
372
+ }
373
+ interface XmtpRootMessageResponse {
374
+ id: string;
375
+ conversationId: string;
376
+ content: string | Record<string, unknown>;
377
+ senderInboxId: string;
378
+ sentAt: string;
379
+ contentType?: {
380
+ typeId: string;
381
+ authorityId?: string;
382
+ versionMajor?: number;
383
+ versionMinor?: number;
384
+ };
385
+ }
386
+ interface SendMessageParams {
387
+ content: string;
388
+ }
389
+ interface SendReplyParams {
390
+ content: string;
391
+ messageId: string;
392
+ }
393
+ interface SendReactionParams {
394
+ messageId: string;
395
+ emoji: string;
396
+ action: "added" | "removed";
397
+ }
398
+ interface SendTransactionParams extends TransactionRequest {
399
+ }
400
+ interface GetMessageParams {
401
+ messageId: string;
402
+ }
403
+ interface GetRootMessageParams {
404
+ messageId: string;
405
+ }
406
+ interface SendMessageResponse {
407
+ success: boolean;
408
+ action: "send";
409
+ conversationId: string;
410
+ }
411
+ interface SendReplyResponse {
412
+ success: boolean;
413
+ action: "reply";
414
+ conversationId: string;
415
+ }
416
+ interface SendReactionResponse {
417
+ success: boolean;
418
+ action: "react";
419
+ conversationId: string;
420
+ }
421
+ interface SendTransactionResponse {
422
+ success: boolean;
423
+ action: "transaction";
424
+ conversationId: string;
425
+ }
426
+
427
+ interface User {
428
+ key: `0x${string}`;
429
+ account: ReturnType<typeof privateKeyToAccount>;
430
+ wallet: any;
431
+ }
432
+ declare const createUser: (key: string) => User;
433
+ declare const createSigner: (key: string) => Signer;
434
+ declare function createXMTPClient(privateKey: string, opts?: {
435
+ persist?: boolean;
436
+ maxRetries?: number;
437
+ storagePath?: string;
438
+ }): Promise<XmtpClient>;
439
+ /**
440
+ * Generate a random encryption key
441
+ * @returns The encryption key as a hex string
442
+ */
443
+ declare const generateEncryptionKeyHex: () => string;
444
+ /**
445
+ * Get the encryption key from a hex string
446
+ * @param hex - The hex string
447
+ * @returns The encryption key as Uint8Array
448
+ */
449
+ declare const getEncryptionKeyFromHex: (hex: string) => Uint8Array;
450
+ declare const getDbPath: (description?: string, storagePath?: string) => Promise<string>;
451
+ declare const backupDbToPersistentStorage: (dbPath: string, description: string) => Promise<void>;
452
+ declare const logAgentDetails: (clients: XmtpClient | XmtpClient[]) => Promise<void>;
453
+ declare function validateEnvironment(vars: string[]): Record<string, string>;
454
+ /**
455
+ * Diagnose XMTP environment and identity issues
456
+ */
457
+ declare function diagnoseXMTPIdentityIssue(client: XmtpClient, inboxId: string, environment: string): Promise<{
458
+ canResolve: boolean;
459
+ suggestions: string[];
460
+ details: Record<string, any>;
461
+ }>;
462
+ interface XMTPConnectionConfig {
463
+ maxRetries?: number;
464
+ retryDelayMs?: number;
465
+ healthCheckIntervalMs?: number;
466
+ connectionTimeoutMs?: number;
467
+ reconnectOnFailure?: boolean;
468
+ }
469
+ interface XMTPConnectionHealth {
470
+ isConnected: boolean;
471
+ lastHealthCheck: Date;
472
+ consecutiveFailures: number;
473
+ totalReconnects: number;
474
+ avgResponseTime: number;
475
+ }
476
+ declare class XMTPConnectionManager {
477
+ private client;
478
+ private privateKey;
479
+ private config;
480
+ private health;
481
+ private healthCheckTimer;
482
+ private isReconnecting;
483
+ constructor(privateKey: string, config?: XMTPConnectionConfig);
484
+ connect(persist?: boolean): Promise<XmtpClient>;
485
+ private startHealthMonitoring;
486
+ private performHealthCheck;
487
+ private handleConnectionFailure;
488
+ private sleep;
489
+ getHealth(): XMTPConnectionHealth;
490
+ getClient(): XmtpClient | null;
491
+ disconnect(): Promise<void>;
492
+ }
493
+ declare function createXMTPConnectionManager(privateKey: string, config?: XMTPConnectionConfig): Promise<XMTPConnectionManager>;
494
+ /**
495
+ * Resolve user address from inbox ID with automatic identity refresh on association errors
496
+ */
497
+ declare function resolveUserAddress(client: XmtpClient, senderInboxId: string, maxRetries?: number): Promise<string>;
498
+ declare const startPeriodicBackup: (dbPath: string, description: string, intervalMs?: number) => NodeJS.Timeout;
499
+
500
+ declare const DEFAULT_OPTIONS: string[];
501
+ declare const DEFAULT_AMOUNT = "0.1";
502
+ declare const MAX_USDC_AMOUNT = 10;
503
+
504
+ interface MessageListenerConfig {
505
+ publicClient: PublicClient;
506
+ xmtpClient: XmtpClient;
507
+ /**
508
+ * Filter function to determine which messages to process
509
+ * Return true to process the message, false to skip
510
+ */
511
+ filter?: (event: Pick<MessageEvent, "conversation" | "message" | "rootMessage">) => Promise<boolean> | boolean;
512
+ /**
513
+ * Heartbeat interval in milliseconds (default: 5 minutes)
514
+ */
515
+ heartbeatInterval?: number;
516
+ /**
517
+ * Conversation check interval in milliseconds (default: 30 seconds)
518
+ */
519
+ conversationCheckInterval?: number;
520
+ /**
521
+ * Environment variable key for XMTP environment (default: "XMTP_ENV")
522
+ */
523
+ envKey?: string;
524
+ }
525
+ interface MessageListenerEvents {
526
+ message: [data: MessageEvent];
527
+ error: [error: Error];
528
+ started: [];
529
+ stopped: [];
530
+ heartbeat: [stats: {
531
+ messageCount: number;
532
+ conversationCount: number;
533
+ }];
534
+ }
535
+ /**
536
+ * A flexible XMTP message listener that can be configured for different applications
537
+ */
538
+ declare class MessageListener extends EventEmitter {
539
+ private xmtpClient;
540
+ private resolver;
541
+ private filter?;
542
+ private heartbeatInterval?;
543
+ private fallbackCheckInterval?;
544
+ private messageCount;
545
+ private conversations;
546
+ private readonly config;
547
+ constructor(config: MessageListenerConfig);
548
+ on<U extends keyof MessageListenerEvents>(event: U, listener: (...args: MessageListenerEvents[U]) => void): this;
549
+ emit<U extends keyof MessageListenerEvents>(event: U, ...args: MessageListenerEvents[U]): boolean;
550
+ start(): Promise<void>;
551
+ private cleanup;
552
+ stop(): void;
553
+ /**
554
+ * Get current statistics
555
+ */
556
+ getStats(): {
557
+ messageCount: number;
558
+ conversationCount: number;
559
+ isActive: boolean;
560
+ };
561
+ }
562
+ /**
563
+ * Helper function to start a message listener
564
+ */
565
+ declare function startMessageListener(config: MessageListenerConfig): Promise<MessageListener>;
566
+ /**
567
+ * Factory function to create a message listener with common filters
568
+ */
569
+ declare function createMessageListener(config: MessageListenerConfig): MessageListener;
570
+
571
+ interface ENSResolverOptions {
572
+ /**
573
+ * Maximum number of ENS names to cache
574
+ * @default 500
575
+ */
576
+ maxCacheSize?: number;
577
+ /**
578
+ * Cache TTL in milliseconds
579
+ * @default 3600000 (1 hour)
580
+ */
581
+ cacheTtl?: number;
582
+ /**
583
+ * Mainnet public client for ENS resolution
584
+ */
585
+ mainnetClient: PublicClient;
586
+ }
587
+ /**
588
+ * ENS Resolver for mainnet .eth names
589
+ * Handles resolution of ENS names to addresses and reverse resolution
590
+ */
591
+ declare class ENSResolver {
592
+ private cache;
593
+ private reverseCache;
594
+ private readonly maxCacheSize;
595
+ private readonly cacheTtl;
596
+ private readonly mainnetClient;
597
+ constructor(options: ENSResolverOptions);
598
+ /**
599
+ * Resolve an ENS name to an Ethereum address
600
+ */
601
+ resolveENSName(ensName: string): Promise<Address | null>;
602
+ /**
603
+ * Resolve an address to its primary ENS name (reverse resolution)
604
+ */
605
+ resolveAddressToENS(address: Address): Promise<string | null>;
606
+ /**
607
+ * Get ENS avatar for a name
608
+ */
609
+ getENSAvatar(ensName: string): Promise<string | null>;
610
+ /**
611
+ * Get ENS text record
612
+ */
613
+ getENSTextRecord(ensName: string, key: string): Promise<string | null>;
614
+ /**
615
+ * Get comprehensive ENS profile
616
+ */
617
+ getENSProfile(ensName: string): Promise<{
618
+ ensName: string;
619
+ address: `0x${string}` | null;
620
+ avatar: string | null;
621
+ description: string | null;
622
+ twitter: string | null;
623
+ github: string | null;
624
+ url: string | null;
625
+ } | null>;
626
+ /**
627
+ * Check if a name is a valid ENS name (.eth)
628
+ */
629
+ isENSName(name: string): boolean;
630
+ /**
631
+ * Get cached address if not expired
632
+ */
633
+ private getCachedAddress;
634
+ /**
635
+ * Cache address with LRU eviction
636
+ */
637
+ private setCachedAddress;
638
+ /**
639
+ * Get cached ENS name if not expired
640
+ */
641
+ private getCachedENSName;
642
+ /**
643
+ * Cache ENS name with LRU eviction
644
+ */
645
+ private setCachedENSName;
646
+ /**
647
+ * Clear all caches
648
+ */
649
+ clearCache(): void;
650
+ /**
651
+ * Get cache statistics
652
+ */
653
+ getCacheStats(): {
654
+ addressCache: {
655
+ size: number;
656
+ maxSize: number;
657
+ };
658
+ reverseCache: {
659
+ size: number;
660
+ maxSize: number;
661
+ };
662
+ };
663
+ }
664
+
665
+ /**
666
+ * Extract basenames/ENS names from message content using @mention pattern
667
+ * @param content The message content to parse
668
+ * @returns Array of unique names found in the message
669
+ */
670
+ declare function extractMentionedNames(content: string): string[];
671
+ /**
672
+ * Resolve mentioned names to addresses and return as subjects object
673
+ * @param mentionedNames Array of names to resolve
674
+ * @param basenameResolver Basename resolver instance
675
+ * @param ensResolver ENS resolver instance
676
+ * @returns Promise that resolves to subjects object mapping names to addresses
677
+ */
678
+ declare function resolveSubjects(mentionedNames: string[], basenameResolver: BasenameResolver, ensResolver: ENSResolver): Promise<Record<string, `0x${string}`>>;
679
+ /**
680
+ * Extract subjects from message content (combines extraction and resolution)
681
+ * @param content The message content to parse
682
+ * @param basenameResolver Basename resolver instance
683
+ * @param ensResolver ENS resolver instance
684
+ * @returns Promise that resolves to subjects object mapping names to addresses
685
+ */
686
+ declare function extractSubjects(content: string, basenameResolver: BasenameResolver, ensResolver: ENSResolver): Promise<Record<string, `0x${string}`>>;
687
+
688
+ interface XmtpResolverOptions {
689
+ /**
690
+ * Maximum number of addresses to cache
691
+ * @default 1000
692
+ */
693
+ maxCacheSize?: number;
694
+ /**
695
+ * Cache TTL in milliseconds
696
+ * @default 86400000 (24 hours)
697
+ */
698
+ cacheTtl?: number;
699
+ /**
700
+ * Maximum number of messages to cache
701
+ * @default 1000
702
+ */
703
+ maxMessageCacheSize?: number;
704
+ /**
705
+ * Message cache TTL in milliseconds
706
+ * @default 3600000 (1 hour)
707
+ */
708
+ messageCacheTtl?: number;
709
+ }
710
+ declare class XmtpResolver {
711
+ private client;
712
+ private addressCache;
713
+ private messageCache;
714
+ private readonly maxCacheSize;
715
+ private readonly cacheTtl;
716
+ private readonly maxMessageCacheSize;
717
+ private readonly messageCacheTtl;
718
+ constructor(client: XmtpClient, options?: XmtpResolverOptions);
719
+ /**
720
+ * Resolve user address from inbox ID with caching
721
+ */
722
+ resolveAddress(inboxId: string, conversationId?: string): Promise<`0x${string}` | null>;
723
+ /**
724
+ * Find any message by ID with caching
725
+ */
726
+ findMessage(messageId: string): Promise<XmtpMessage | null>;
727
+ /**
728
+ * Find root message with caching
729
+ */
730
+ findRootMessage(messageId: string): Promise<XmtpMessage | null>;
731
+ /**
732
+ * Recursively finds the root message in a reply chain by following reply references
733
+ */
734
+ private findRootMessageRecursive;
735
+ /**
736
+ * Resolve address from conversation members
737
+ */
738
+ private resolveFromConversation;
739
+ /**
740
+ * Resolve address from inbox state (network fallback)
741
+ */
742
+ private resolveFromInboxState;
743
+ /**
744
+ * Get cached address if not expired
745
+ */
746
+ private getCachedAddress;
747
+ /**
748
+ * Cache address with LRU eviction
749
+ */
750
+ private setCachedAddress;
751
+ /**
752
+ * Get cached message if not expired
753
+ */
754
+ private getCachedMessage;
755
+ /**
756
+ * Cache message with LRU eviction
757
+ */
758
+ private setCachedMessage;
759
+ /**
760
+ * Pre-populate address cache from existing conversations
761
+ */
762
+ prePopulateCache(): Promise<void>;
763
+ /**
764
+ * Clear all caches
765
+ */
766
+ clearCache(): void;
767
+ /**
768
+ * Get cache statistics
769
+ */
770
+ getCacheStats(): {
771
+ address: {
772
+ size: number;
773
+ maxSize: number;
774
+ };
775
+ message: {
776
+ size: number;
777
+ maxSize: number;
778
+ };
779
+ };
780
+ }
781
+
782
+ /**
783
+ * @fileoverview XMTP Service Client Library
784
+ *
785
+ * Clean, reusable client for making HTTP calls to the XMTP listener service.
786
+ * Handles authentication, request formatting, and error handling.
787
+ *
788
+ * This is different from the direct XMTP client - this is for external services
789
+ * talking to our XMTP listener service.
790
+ */
791
+
792
+ declare class XmtpServiceClient {
793
+ private config;
794
+ constructor(config: XmtpServiceClientConfig);
795
+ private request;
796
+ sendMessage(params: SendMessageParams): Promise<XmtpServiceResponse<SendMessageResponse>>;
797
+ sendReply(params: SendReplyParams): Promise<XmtpServiceResponse<SendReplyResponse>>;
798
+ sendReaction(params: SendReactionParams): Promise<XmtpServiceResponse<SendReactionResponse>>;
799
+ sendTransaction(params: SendTransactionParams): Promise<XmtpServiceResponse<SendTransactionResponse>>;
800
+ /**
801
+ * Get a single message by ID
802
+ */
803
+ getMessage(params: GetMessageParams): Promise<XmtpServiceResponse<XmtpServiceMessage>>;
804
+ }
805
+ /**
806
+ * Create an XMTP service client from runtime context
807
+ * Expects the runtime context to have xmtpServiceUrl and xmtpServiceToken
808
+ */
809
+ declare function createXmtpServiceClient(serviceUrl: string, serviceToken: string): XmtpServiceClient;
810
+ interface XmtpAuthConfig {
811
+ serviceUrl: string;
812
+ serviceToken: string;
813
+ source: "callback" | "environment";
814
+ }
815
+ /**
816
+ * Get XMTP authentication configuration from multiple sources
817
+ * Priority: callback credentials > environment credentials
818
+ */
819
+ declare function getXmtpAuthConfig(callbackUrl?: string, callbackToken?: string): XmtpAuthConfig | null;
820
+ /**
821
+ * Create an authenticated XMTP service client
822
+ * Handles both callback and environment credential sources
823
+ */
824
+ declare function createAuthenticatedXmtpClient(callbackUrl?: string, callbackToken?: string): XmtpServiceClient;
825
+ /**
826
+ * Constructs a URL for XMTP tools API endpoints with token authentication
827
+ *
828
+ * @param {string} baseUrl - The base URL of the XMTP service (e.g., "https://api.example.com")
829
+ * @param {string} action - The specific action/endpoint to call (e.g., "send", "receive", "status")
830
+ * @param {string} token - Authentication token (either JWT or API key)
831
+ * @returns {string} Complete URL with token as query parameter
832
+ *
833
+ * @description
834
+ * Builds URLs for XMTP tools endpoints using query parameter authentication.
835
+ * The token is appended as a query parameter for GET request authentication,
836
+ * following the pattern: `/xmtp-tools/{action}?token={token}`
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * const url = getXMTPToolsUrl(
841
+ * "https://api.hybrid.dev",
842
+ * "send",
843
+ * "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
844
+ * );
845
+ * // Returns: "https://api.hybrid.dev/xmtp-tools/send?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
846
+ * ```
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * // Using with API key
851
+ * const url = getXMTPToolsUrl(
852
+ * process.env.XMTP_BASE_URL,
853
+ * "status",
854
+ * process.env.XMTP_API_KEY
855
+ * );
856
+ * ```
857
+ */
858
+ declare function getXMTPToolsUrl(baseUrl: string, action: string, token: string): string;
859
+
860
+ export { type BaseName, BasenameResolver, type BasenameTextRecordKey, BasenameTextRecordKeys, DEFAULT_AMOUNT, DEFAULT_OPTIONS, ENSResolver, type GetMessageParams, type GetRootMessageParams, type HonoVariables, MAX_USDC_AMOUNT, type MessageEvent, MessageListener, type MessageListenerConfig, type MessageListenerEvents, Resolver, type SendMessageParams, type SendMessageResponse, type SendReactionParams, type SendReactionResponse, type SendReplyParams, type SendReplyResponse, type SendTransactionParams, type SendTransactionResponse, type TransactionCall, type TransactionRequest, type XMTPConnectionConfig, type XMTPConnectionHealth, XMTPConnectionManager, type XmtpAuthConfig, type XmtpClient, type XmtpConversation, type XmtpMessage, XmtpResolver, type XmtpRootMessageResponse, type XmtpSender, XmtpServiceClient, type XmtpServiceClientConfig, type XmtpServiceMessage, type XmtpServiceResponse, type XmtpSubjects, backupDbToPersistentStorage, convertChainIdToCoinType, convertReverseNodeToBytes, createAuthenticatedXmtpClient, createMessageListener, createSigner, createUser, createXMTPClient, createXMTPConnectionManager, createXmtpServiceClient, diagnoseXMTPIdentityIssue, extractMentionedNames, extractSubjects, generateEncryptionKeyHex, getDbPath, getEncryptionKeyFromHex, getXMTPToolsUrl, getXmtpAuthConfig, logAgentDetails, resolveSubjects, resolveUserAddress, startMessageListener, startPeriodicBackup, validateEnvironment };