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